Skip to content

Commit

Permalink
chore: cleanup and minor syntax improvements (ayamir#1217)
Browse files Browse the repository at this point in the history
* chore: cleanup and minor syntax improvements

This commit mainly tackled several minor touch-ups and syntax
improvements:

- Addressed `luacheck` issues from previous commits.
- Added some to-do comments for `_buf_vtext`.
- Eliminated redundant/outdated options.
- Temporarily removed the ability to install nightly-version configs
  and updated the names of relevant functions:
    - `clone_by_https_or_ssh` -> `clone_repo`
- Rewrote `dotstutor` to make it more readable.

* perf(debugpy): simplify venv detection logic

* fixup! chore: cleanup and minor syntax improvements

* fixup! Merge branch 'main' into chore/cleanups
  • Loading branch information
Jint-lzxy authored and husheng committed Apr 9, 2024
1 parent 0336ec6 commit af28bad
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 181 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/lint_code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: lint code
on: [push, pull_request]

jobs:
luacheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: lunarmodules/luacheck@v1
with:
args: . --std luajit --globals vim _toggle_lazygit _buf_vtext _command_panel _flash_esc_or_noh _debugging --max-line-length 150 --no-config
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Branch info:
| Branch | Supported neovim version |
| :----: | :----------------------: |
| main | nvim 0.9 stable |
| 0.10 | nvim 0.10 nightly |
| 0.8 | nvim 0.8 |
| 0.7 | nvim 0.7 |

Expand Down
13 changes: 13 additions & 0 deletions lua/keymap/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,16 @@ _G._toggle_lazygit = function()
vim.notify("Command [lazygit] not found!", vim.log.levels.ERROR, { title = "toggleterm.nvim" })
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()
if mode ~= "v" and mode ~= "V" then
vim.cmd([[normal! gv]])
end
vim.cmd([[silent! normal! "aygv]])
local text = vim.fn.getreg("a")
vim.fn.setreg("a", a_orig)
return text
end
6 changes: 6 additions & 0 deletions lua/keymap/tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ local plug_map = {
:with_desc("edit: Change current direrctory by zoxide"),
["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() })
end)
:with_noremap()
:with_silent()
:with_desc("find: Selection text"),
["n|<leader>fd"] = map_cu("Telescope persisted"):with_noremap():with_silent():with_desc("find: Session"),

-- Plugin: dap
Expand Down
35 changes: 20 additions & 15 deletions lua/modules/configs/tool/dap/clients/python.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
-- https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings
return function()
local dap = require("dap")
local debugpy = vim.fn.exepath("debugpy-adapter")
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 @@ -22,7 +19,9 @@ return function()
else
callback({
type = "executable",
command = debugpy,
command = is_windows and debugpy_root .. "/venv/Scripts/pythonw.exe"
or debugpy_root .. "/venv/bin/python",
args = { "-m", "debugpy.adapter" },
options = { source_filetype = "python" },
})
end
Expand All @@ -37,8 +36,9 @@ return function()
console = "integratedTerminal",
program = utils.input_file_path(),
pythonPath = function()
if not is_empty(vim.env.CONDA_PREFIX) then
return 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 "python3"
end
Expand All @@ -53,15 +53,20 @@ 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 then
return venv .. "/bin/python"
elseif vim.fn.executable(cwd .. "/venv/bin/python") == 1 then
return cwd .. "/venv/bin/python"
elseif vim.fn.executable(cwd .. "/.venv/bin/python") == 1 then
return 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 "python3"
return is_windows and "pythonw.exe" or "python3"
end
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
47 changes: 19 additions & 28 deletions scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,23 @@ function check_nvim_version ([Parameter(Mandatory = $True)][ValidateNotNullOrEmp
return ($nvim_version -ge $RequiredVersionMin)
}

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" $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 @"
You have a legacy Neovim distribution installed.
Please make sure you have nvim v$REQUIRED_NVIM_VERSION_LEGACY installed at the very least.
"@
}
}

function ring_bell {
[System.Console]::beep()
}
Expand Down Expand Up @@ -353,35 +370,9 @@ You must install Git before installing this Nvim config. See:
info -Msg "Fetching in progress..."

if ($USE_SSH) {
if ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION)) {
safe_execute -WithCmd { git clone --progress -b "$env:CCLONE_BRANCH" "$env:CCLONE_ATTR" 'git@github.com:ayamir/nvimdots.git' "$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 0.8 "$env:CCLONE_ATTR" 'git@github.com:ayamir/nvimdots.git' "$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 @"
You have a legacy Neovim distribution installed.
Please make sure you have nvim v$REQUIRED_NVIM_VERSION_LEGACY installed at the very least.
"@
}
clone_repo -WithURL 'git@github.com:ayamir/nvimdots.git'
} else {
if ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION)) {
safe_execute -WithCmd { git clone --progress -b "$env:CCLONE_BRANCH" "$env:CCLONE_ATTR" 'https://github.com/ayamir/nvimdots.git' "$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 0.8 "$env:CCLONE_ATTR" 'https://github.com/ayamir/nvimdots.git' "$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 @"
You have a legacy Neovim distribution installed.
Please make sure you have nvim v$REQUIRED_NVIM_VERSION_LEGACY installed at the very least.
"@
}
clone_repo -WithURL 'https://github.com/ayamir/nvimdots.git'
}

safe_execute -WithCmd { Set-Location -Path "$env:CCDEST_DIR" }
Expand Down
50 changes: 20 additions & 30 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,24 @@ check_nvim_version() {
fi
}

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})."
info "Automatically redirecting you to the latest compatible version..."
execute "git" "clone" "-b" "0.8" "${CLONE_ATTR[@]}" "$1" "${DEST_DIR}"
else
warn "You have outdated Nvim installed (< ${REQUIRED_NVIM_VERSION_LEGACY})."
abort "$(
cat <<EOABORT
You have a legacy Neovim distribution installed.
Please make sure you have nvim v${REQUIRED_NVIM_VERSION_LEGACY} installed at the very least.
EOABORT
)"
fi
}

# Check if both `INTERACTIVE` and `NONINTERACTIVE` are set
# Always use single-quoted strings with `exp` expressions
# shellcheck disable=SC2016
Expand Down Expand Up @@ -252,37 +270,9 @@ fi

info "Fetching in progress..."
if [[ "${USE_SSH}" -eq "1" ]]; then
if check_nvim_version "${REQUIRED_NVIM_VERSION}"; then
execute "git" "clone" "-b" "main" "${CLONE_ATTR[@]}" "git@github.com:ayamir/nvimdots.git" "${DEST_DIR}"
elif check_nvim_version "${REQUIRED_NVIM_VERSION_LEGACY}"; then
warn "You have outdated Nvim installed (< ${REQUIRED_NVIM_VERSION})."
info "Automatically redirecting you to the latest compatible version..."
execute "git" "clone" "-b" "0.8" "${CLONE_ATTR[@]}" "git@github.com:ayamir/nvimdots.git" "${DEST_DIR}"
else
warn "You have outdated Nvim installed (< ${REQUIRED_NVIM_VERSION_LEGACY})."
abort "$(
cat <<EOABORT
You have a legacy Neovim distribution installed.
Please make sure you have nvim v${REQUIRED_NVIM_VERSION_LEGACY} installed at the very least.
EOABORT
)"
fi
clone_repo "git@github.com:ayamir/nvimdots.git"
else
if check_nvim_version "${REQUIRED_NVIM_VERSION}"; then
execute "git" "clone" "-b" "main" "${CLONE_ATTR[@]}" "https://github.com/ayamir/nvimdots.git" "${DEST_DIR}"
elif check_nvim_version "${REQUIRED_NVIM_VERSION_LEGACY}"; then
warn "You have outdated Nvim installed (< ${REQUIRED_NVIM_VERSION})."
info "Automatically redirecting you to the latest compatible version..."
execute "git" "clone" "-b" "0.8" "${CLONE_ATTR[@]}" "https://github.com/ayamir/nvimdots.git" "${DEST_DIR}"
else
warn "You have outdated Nvim installed (< ${REQUIRED_NVIM_VERSION_LEGACY})."
abort "$(
cat <<EOABORT
You have a legacy Neovim distribution installed.
Please make sure you have nvim v${REQUIRED_NVIM_VERSION_LEGACY} installed at the very least.
EOABORT
)"
fi
clone_repo "https://github.com/ayamir/nvimdots.git"
fi

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

0 comments on commit af28bad

Please sign in to comment.