Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup and minor syntax improvements #1217

Merged
merged 5 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ jobs:
- uses: actions/checkout@v4
- uses: lunarmodules/luacheck@v1
with:
args: . --std luajit --globals vim _toggle_lazygit _command_panel _flash_esc_or_noh _debugging --max-line-length 150 --no-config
args: . --std luajit --globals vim _toggle_lazygit _buf_vtext _command_panel _flash_esc_or_noh _debugging --max-line-length 150 --no-config
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ Branch info:

| Branch | Supported neovim version |
| :----: | :----------------------: |
| 0.10 | nvim 0.10 nightly |
| main | nvim 0.9 stable |
| 0.10 | nvim 0.10 nightly |
| 0.8 | nvim 0.8 |
| 0.7 | nvim 0.7 |

Expand Down
1 change: 1 addition & 0 deletions lua/keymap/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ _G._toggle_lazygit = function()
end
end

-- TODO: Update this function to use `vim.getregion()` when v0.10 is released.
_G._buf_vtext = function()
local a_orig = vim.fn.getreg("a")
local mode = vim.fn.mode()
Expand Down
2 changes: 1 addition & 1 deletion lua/keymap/tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ local plug_map = {
["n|<leader>fb"] = map_cu("Telescope buffers"):with_noremap():with_silent():with_desc("find: Buffer opened"),
["n|<leader>fs"] = map_cu("Telescope grep_string"):with_noremap():with_silent():with_desc("find: Current word"),
["v|<leader>fs"] = map_callback(function()
require("telescope.builtin").grep_string({ search = _buf_vtext() }) -- luacheck: ignore
require("telescope.builtin").grep_string({ search = _buf_vtext() })
end)
:with_noremap()
:with_silent()
Expand Down
48 changes: 18 additions & 30 deletions lua/modules/configs/tool/dap/clients/python.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
-- https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings
return function()
local dap = require("dap")
local is_windows = require("core.global").is_windows
local data_dir = require("core.global").data_dir
local python = is_windows and data_dir .. "../mason/packages/debugpy/venv/Scripts/pythonw.exe"
or data_dir .. "../mason/packages/debugpy/venv/bin/python"
local utils = require("modules.utils.dap")

local function is_empty(s)
return s == nil or s == ""
end
local is_windows = require("core.global").is_windows
local debugpy_root = require("mason-registry").get_package("debugpy"):get_install_path()

dap.adapters.python = function(callback, config)
if config.request == "attach" then
Expand All @@ -25,7 +19,8 @@ return function()
else
callback({
type = "executable",
command = python,
command = is_windows and debugpy_root .. "/venv/Scripts/pythonw.exe"
or debugpy_root .. "/venv/bin/python",
args = { "-m", "debugpy.adapter" },
options = { source_filetype = "python" },
})
Expand All @@ -41,9 +36,9 @@ return function()
console = "integratedTerminal",
program = utils.input_file_path(),
pythonPath = function()
if not is_empty(vim.env.CONDA_PREFIX) then
return is_windows and vim.env.CONDA_PREFIX .. "/Scripts/pythonw.exe"
or vim.env.CONDA_PREFIX .. "/bin/python"
local venv = vim.env.CONDA_PREFIX
if venv then
return is_windows and venv .. "/Scripts/pythonw.exe" or venv .. "/bin/python"
else
return is_windows and "pythonw.exe" or "python3"
end
Expand All @@ -58,25 +53,18 @@ return function()
console = "integratedTerminal",
program = utils.input_file_path(),
pythonPath = function()
-- Prefer the venv that is defined by the designated environment variable.
local cwd, venv = vim.fn.getcwd(), os.getenv("VIRTUAL_ENV")
if
venv
and (
vim.fn.executable(venv .. "/bin/python") == 1
or vim.fn.executable(venv .. "/Scripts/pythonw.exe") == 1
)
then
return is_windows and venv .. "/Scripts/pythonw.exe" or venv .. "/bin/python"
elseif
(vim.fn.executable(cwd .. "/venv/bin/python") == 1)
or (vim.fn.executable(cwd .. "/venv/Scripts/pythonw.exe") == 1)
then
return is_windows and cwd .. "/venv/Scripts/pythonw.exe" or cwd .. "/venv/bin/python"
elseif
(vim.fn.executable(cwd .. "/.venv/bin/python") == 1)
or (vim.fn.executable(cwd .. "/.venv/Scripts/pythonw.exe") == 1)
then
return is_windows and cwd .. "/.venv/Scripts/pythonw.exe" or cwd .. "/.venv/bin/python"
local python = venv and (is_windows and venv .. "/Scripts/pythonw.exe" or venv .. "/bin/python") or ""
if vim.fn.executable(python) == 1 then
return python
end

-- Otherwise, fall back to check if there are any local venvs available.
venv = vim.fn.isdirectory(cwd .. "/venv") == 1 and cwd .. "/venv" or cwd .. "/.venv"
python = is_windows and venv .. "/Scripts/pythonw.exe" or venv .. "/bin/python"
if vim.fn.executable(python) == 1 then
return python
else
return is_windows and "pythonw.exe" or "python3"
end
Expand Down
1 change: 0 additions & 1 deletion lua/modules/configs/tool/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ return function()
case_mode = "smart_case",
},
frecency = {
use_sqlite = false,
show_scores = true,
show_unindexed = true,
ignore_patterns = { "*.git/*", "*/tmp/*" },
Expand Down
16 changes: 6 additions & 10 deletions scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Set-StrictMode -Version 3.0
$ErrorActionPreference = "Stop" # Exit when command fails

# global-scope vars
$REQUIRED_NVIM_VERSION_NIGHTLY = [version]'0.10'
$REQUIRED_NVIM_VERSION = [version]'0.9.0'
$REQUIRED_NVIM_VERSION_LEGACY = [version]'0.8.0'
$USE_SSH = $True
Expand All @@ -21,7 +20,6 @@ $installer_pkg_matrix = @{ "NodeJS" = "npm"; "Python" = "pip"; "Ruby" = "gem" }
# env vars
$env:XDG_CONFIG_HOME ??= $env:LOCALAPPDATA
$env:CCPACK_MGR ??= 'unknown'
$env:CCLONE_BRANCH_NIGHTLY ??= '0.10'
$env:CCLONE_BRANCH ??= 'main'
$env:CCLONE_BRANCH_LEGACY ??= '0.8'
$env:CCLONE_ATTR ??= 'undef'
Expand Down Expand Up @@ -285,15 +283,13 @@ function check_nvim_version ([Parameter(Mandatory = $True)][ValidateNotNullOrEmp
return ($nvim_version -ge $RequiredVersionMin)
}

function clone_by_https_or_ssh ([Parameter(Mandatory = $True)][ValidateNotNullOrEmpty()] [string]$CloneUrl) {
if ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION_NIGHTLY)) {
safe_execute -WithCmd { git clone --progress -b "$env:CCLONE_BRANCH_NIGHTLY" "$env:CCLONE_ATTR" $CloneUrl "$env:CCDEST_DIR" }
} elseif ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION)) {
safe_execute -WithCmd { git clone --progress -b "$env:CCLONE_BRANCH" "$env:CCLONE_ATTR" $CloneUrl "$env:CCDEST_DIR" }
function clone_repo ([Parameter(Mandatory = $True)][ValidateNotNullOrEmpty()] [string]$WithURL) {
if ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION)) {
safe_execute -WithCmd { git clone --progress -b "$env:CCLONE_BRANCH" "$env:CCLONE_ATTR" $WithURL "$env:CCDEST_DIR" }
} elseif ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION_LEGACY)) {
warn -Msg "You have outdated Nvim installed (< $REQUIRED_NVIM_VERSION)."
info -Msg "Automatically redirecting you to the latest compatible version..."
safe_execute -WithCmd { git clone --progress -b "$env:CCLONE_BRANCH_LEGACY" "$env:CCLONE_ATTR" $CloneUrl "$env:CCDEST_DIR" }
safe_execute -WithCmd { git clone --progress -b "$env:CCLONE_BRANCH_LEGACY" "$env:CCLONE_ATTR" $WithURL "$env:CCDEST_DIR" }
} else {
warn -Msg "You have outdated Nvim installed (< $REQUIRED_NVIM_VERSION_LEGACY)."
_abort -Msg "This Neovim distribution is no longer supported." -Type "NotImplemented" -Info_msg @"
Expand Down Expand Up @@ -375,9 +371,9 @@ You must install Git before installing this Nvim config. See:
info -Msg "Fetching in progress..."

if ($USE_SSH) {
clone_by_https_or_ssh '[email protected]:ayamir/nvimdots.git'
clone_repo -WithURL '[email protected]:ayamir/nvimdots.git'
} else {
clone_by_https_or_ssh 'https://github.com/ayamir/nvimdots.git'
clone_repo -WithURL 'https://github.com/ayamir/nvimdots.git'
}

safe_execute -WithCmd { Set-Location -Path "$env:CCDEST_DIR" }
Expand Down
11 changes: 4 additions & 7 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ set -u
DEST_DIR="${HOME}/.config/nvim"
BACKUP_DIR="${DEST_DIR}_backup-$(date +%Y%m%dT%H%M%S)"
CLONE_ATTR=("--progress")
REQUIRED_NVIM_VERSION_NIGHTLY=0.10
REQUIRED_NVIM_VERSION=0.9.0
REQUIRED_NVIM_VERSION_LEGACY=0.8.0
USE_SSH=1
Expand Down Expand Up @@ -170,10 +169,8 @@ check_nvim_version() {
fi
}

clone_by_https_or_ssh() {
if check_nvim_version "${REQUIRED_NVIM_VERSION_NIGHTLY}"; then
execute "git" "clone" "-b" "0.10" "${CLONE_ATTR[@]}" "$1" "${DEST_DIR}"
elif check_nvim_version "${REQUIRED_NVIM_VERSION}"; then
clone_repo() {
if check_nvim_version "${REQUIRED_NVIM_VERSION}"; then
execute "git" "clone" "-b" "main" "${CLONE_ATTR[@]}" "$1" "${DEST_DIR}"
elif check_nvim_version "${REQUIRED_NVIM_VERSION_LEGACY}"; then
warn "You have outdated Nvim installed (< ${REQUIRED_NVIM_VERSION})."
Expand Down Expand Up @@ -273,9 +270,9 @@ fi

info "Fetching in progress..."
if [[ "${USE_SSH}" -eq "1" ]]; then
clone_by_https_or_ssh "[email protected]:ayamir/nvimdots.git"
clone_repo "[email protected]:ayamir/nvimdots.git"
else
clone_by_https_or_ssh "https://github.com/ayamir/nvimdots.git"
clone_repo "https://github.com/ayamir/nvimdots.git"
fi

cd "${DEST_DIR}" || return
Expand Down
Loading