From 0bec5c50d8f6c065c8909a3a9cf7f88efc1a3ade Mon Sep 17 00:00:00 2001 From: Jint-lzxy <50296129+Jint-lzxy@users.noreply.github.com> Date: Thu, 4 Apr 2024 16:58:51 +0800 Subject: [PATCH 1/4] 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. --- .github/workflows/lint_code.yml | 2 +- README.md | 2 +- lua/keymap/helpers.lua | 2 + lua/keymap/tool.lua | 2 +- lua/modules/configs/completion/cmp.lua | 6 +- lua/modules/configs/tool/telescope.lua | 1 - scripts/install.ps1 | 16 +- scripts/install.sh | 11 +- tutor/dots.tutor | 238 +++++++++++++------------ 9 files changed, 142 insertions(+), 138 deletions(-) diff --git a/.github/workflows/lint_code.yml b/.github/workflows/lint_code.yml index f5ed67ddc..9e88fa59e 100644 --- a/.github/workflows/lint_code.yml +++ b/.github/workflows/lint_code.yml @@ -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 diff --git a/README.md b/README.md index 8c0e05eef..894b7bfa0 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/lua/keymap/helpers.lua b/lua/keymap/helpers.lua index 94dbf54b9..682703a40 100644 --- a/lua/keymap/helpers.lua +++ b/lua/keymap/helpers.lua @@ -39,6 +39,8 @@ _G._toggle_lazygit = function() end end +-- TODO: Update this function to use `vim.region()`. +-- TODO: Change `vim.region() [deprecated in nvim 0.10]` to `vim.getregion()` when v0.10 is released. _G._buf_vtext = function() local a_orig = vim.fn.getreg("a") local mode = vim.fn.mode() diff --git a/lua/keymap/tool.lua b/lua/keymap/tool.lua index d95d8c63e..9ec29a30d 100644 --- a/lua/keymap/tool.lua +++ b/lua/keymap/tool.lua @@ -133,7 +133,7 @@ local plug_map = { ["n|fb"] = map_cu("Telescope buffers"):with_noremap():with_silent():with_desc("find: Buffer opened"), ["n|fs"] = map_cu("Telescope grep_string"):with_noremap():with_silent():with_desc("find: Current word"), ["v|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() diff --git a/lua/modules/configs/completion/cmp.lua b/lua/modules/configs/completion/cmp.lua index fcb44ce92..c602b4e72 100644 --- a/lua/modules/configs/completion/cmp.lua +++ b/lua/modules/configs/completion/cmp.lua @@ -85,7 +85,7 @@ return function() }, }), }) - local luasnip = require("luasnip") + require("modules.utils").load_plugin("cmp", { preselect = cmp.PreselectMode.Item, window = { @@ -157,8 +157,8 @@ return function() [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() - elseif luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() + elseif require("luasnip").expand_or_locally_jumpable() then + require("luasnip").expand_or_jump() else fallback() end diff --git a/lua/modules/configs/tool/telescope.lua b/lua/modules/configs/tool/telescope.lua index 79aa263b1..d8fdddd44 100644 --- a/lua/modules/configs/tool/telescope.lua +++ b/lua/modules/configs/tool/telescope.lua @@ -58,7 +58,6 @@ return function() case_mode = "smart_case", }, frecency = { - use_sqlite = false, show_scores = true, show_unindexed = true, ignore_patterns = { "*.git/*", "*/tmp/*" }, diff --git a/scripts/install.ps1 b/scripts/install.ps1 index d5f275683..4d725c6e4 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -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 @@ -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' @@ -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 @" @@ -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 'git@github.com:ayamir/nvimdots.git' + clone_repo -WithURL 'git@github.com: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" } diff --git a/scripts/install.sh b/scripts/install.sh index 3a6f3304e..6796f1a0f 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -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 @@ -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})." @@ -273,9 +270,9 @@ fi info "Fetching in progress..." if [[ "${USE_SSH}" -eq "1" ]]; then - clone_by_https_or_ssh "git@github.com:ayamir/nvimdots.git" + clone_repo "git@github.com: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 diff --git a/tutor/dots.tutor b/tutor/dots.tutor index 80fb5a860..7def1078d 100644 --- a/tutor/dots.tutor +++ b/tutor/dots.tutor @@ -1,43 +1,47 @@ -# Welcome to the nvimdots tutor +# Welcome to the nvimdots Tutor -Nvimdots is a neovim config suite that is designed for extensibility, -performance, and ease of use. It provides the ability to work with textfile, -yet feels like you are working within an IDE environment. -This tutor will walk through how one can utilize this configuration suite to -use Neovim as a powerful code editor. +Nvimdots is a [neovim](https://neovim.io/) config suite designed for extensibility, performance, and ease +of use. It provides the ability to work with text files yet feels like you are +working within an IDE environment. -As a modern neovim config, it provides all of the features you need, code -completion, snippet run, tree-sitter, DAP, fuzzy find, and more. It comes -with state-of-the-art (SOTA) neovim plugins from the community to provide the -best user experience. +This tutor will walk you through how to utilize our configuration to use neovim as a +powerful code editor. + +As a modern neovim config, it provides all the features you need: code completion, +(partial) code testing, tree-sitter, DAP, fuzzy find, and more. It comes with state- +of-the-art (SOTA) neovim plugins from the community to provide the best user +experience. The default []() key is ``{normal}. -The approximate time required to complete the tutor is 5 minutes, depending -upon how much time is spent with experimentation. +The approximate time required to complete the tutorial is 5 minutes, although the +exact duration may vary depending on the amount of time spent experimenting. -# Lesson 1.1: EXPLANATION OF UI +# Lesson 1.1: EXPLANATION OF THE UI -The opened buffers are showed at the top, you can use ``{normal} and ``{normal} to -switch between them. Also, ``{normal}(n meaning No) can be used to switch to the -target buffer directly. +The opened buffers are shown at the top; you can use ``{normal} and ``{normal} to switch +between them. Also, ``{normal} (with `n`{normal} being any number between 1-9) can be used to +switch to the desired buffer directly. -Note: For macOS, you need to remap your `