aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.github/ci/run_sanitizer.sh59
-rw-r--r--CONTRIBUTING.md8
-rw-r--r--lsp/basedpyright.lua4
-rw-r--r--lsp/clangd.lua4
-rw-r--r--lsp/denols.lua2
-rw-r--r--lsp/ds_pinyin_lsp.lua4
-rw-r--r--lsp/eslint.lua4
-rw-r--r--lsp/julials.lua2
-rw-r--r--lsp/markdown_oxide.lua6
-rw-r--r--lsp/pyright.lua4
-rw-r--r--lsp/rust_analyzer.lua2
-rw-r--r--lsp/svelte.lua27
-rw-r--r--lsp/svlangserver.lua4
-rw-r--r--lsp/texlab.lua16
-rw-r--r--lsp/tinymist.lua13
-rw-r--r--lsp/zk.lua6
16 files changed, 88 insertions, 77 deletions
diff --git a/.github/ci/run_sanitizer.sh b/.github/ci/run_sanitizer.sh
index 9b560d84..6f1577da 100644
--- a/.github/ci/run_sanitizer.sh
+++ b/.github/ci/run_sanitizer.sh
@@ -1,24 +1,53 @@
#!/usr/bin/env bash
+
+# USAGE: To run locally:
+# bash .github/ci/run_sanitizer.sh origin/master HEAD
+
set -e
REF_BRANCH="$1"
PR_BRANCH="$2"
-# checks for added lines that contain search pattern and prints them
-SEARCH_PATTERN='(path\.dirname|fn\.cwd)'
+# Enforce buffer-local commands.
+_check_cmd_buflocal() {
+ if git grep -P 'nvim_create_user_command' -- 'lsp/*.lua' ; then
+ echo
+ echo 'Define commands with nvim_buf_create_user_command (buffer-local), not nvim_create_user_command'
+ exit 1
+ fi
+}
+
+# Enforce "Lsp" prefix on all user commands.
+_check_lsp_cmd_prefix() {
+ local exclude='tinymist'
+ if git grep -P 'nvim_buf_create_user_command' -- 'lsp/*.lua' | grep -v "$exclude" | grep --color -v Lsp ; then
+ echo
+ echo 'Command names must start with "Lsp" prefix'
+ exit 1
+ fi
+}
+
+_check_deprecated_utils() {
+ # checks for added lines that contain search pattern and prints them
+ SEARCH_PATTERN='(path\.dirname|fn\.cwd)'
+
+ if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANCH}" -- '*.lua' | grep -Ev '(configs|utils)\.lua$' | grep -E "^\+.*${SEARCH_PATTERN}" ; then
+ echo
+ echo 'String "dirname" found. There is a high risk that this might contradict the directive:'
+ echo '"Do not use vim.fn.cwd or util.path.dirname in root_dir".'
+ echo "see: https://github.com/neovim/nvim-lspconfig/blob/master/CONTRIBUTING.md#adding-a-server-to-lspconfig."
+ exit 1
+ fi
-if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANCH}" -- '*.lua' | grep -Ev '(configs|utils)\.lua$' | grep -E "^\+.*${SEARCH_PATTERN}" ; then
- echo
- echo 'String "dirname" found. There is a high risk that this might contradict the directive:'
- echo '"Do not use vim.fn.cwd or util.path.dirname in root_dir".'
- echo "see: https://github.com/neovim/nvim-lspconfig/blob/master/CONTRIBUTING.md#adding-a-server-to-lspconfig."
- exit 1
-fi
+ SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists|util\.path\.is_file|util\.path\.is_dir|util\.path\.join|util\.path\.iterate_parents|util\.path\.traverse_parents|util\.find_mercurial_ancestor|util\.find_node_modules_ancestor|util\.find_package_json_ancestor|util\.find_git_ancestor|util\.get_lsp_clients|util\.get_active_client_by_name)'
-SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists|util\.path\.is_file|util\.path\.is_dir|util\.path\.join|util\.path\.iterate_parents|util\.path\.traverse_parents|util\.find_mercurial_ancestor|util\.find_node_modules_ancestor|util\.find_package_json_ancestor|util\.find_git_ancestor|util\.get_lsp_clients|util\.get_active_client_by_name)'
+ if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANCH}" -- '*.lua' | grep -Ev '\.lua$' | grep -E "^\+.*${SEARCH_PATTERN}" ; then
+ echo
+ echo 'Do not use deprecated util functions: '"${SEARCH_PATTERN}"
+ exit 1
+ fi
+}
-if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANCH}" -- '*.lua' | grep -Ev '\.lua$' | grep -E "^\+.*${SEARCH_PATTERN}" ; then
- echo
- echo 'Do not use deprecated util functions: '"${SEARCH_PATTERN}"
- exit 1
-fi
+_check_cmd_buflocal
+_check_lsp_cmd_prefix
+_check_deprecated_utils
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 734b32eb..44c394f9 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -49,9 +49,9 @@ end
---@brief
---
--- https://github.com/microsoft/pyright
---
--- `pyright`, a static type checker and language server for python
+--- https://github.com/microsoft/pyright
+---
+--- `pyright`, a static type checker and language server for python
return {
cmd = { 'pyright-langserver', '--stdio' },
filetypes = { 'python' },
@@ -73,7 +73,7 @@ return {
},
},
on_attach = function()
- vim.api.nvim_buf_create_user_command(0, 'PyrightOrganizeImports', organize_imports, {})
+ vim.api.nvim_buf_create_user_command(0, 'LspPyrightOrganizeImports', organize_imports, {})
end,
}
```
diff --git a/lsp/basedpyright.lua b/lsp/basedpyright.lua
index bf31539d..f78bbd21 100644
--- a/lsp/basedpyright.lua
+++ b/lsp/basedpyright.lua
@@ -56,11 +56,11 @@ return {
},
},
on_attach = function()
- vim.api.nvim_buf_create_user_command(0, 'PyrightOrganizeImports', organize_imports, {
+ vim.api.nvim_buf_create_user_command(0, 'LspPyrightOrganizeImports', organize_imports, {
desc = 'Organize Imports',
})
- vim.api.nvim_buf_create_user_command(0, 'PyrightSetPythonPath', set_python_path, {
+ vim.api.nvim_buf_create_user_command(0, 'LspPyrightSetPythonPath', set_python_path, {
desc = 'Reconfigure basedpyright with the provided python path',
nargs = 1,
complete = 'file',
diff --git a/lsp/clangd.lua b/lsp/clangd.lua
index 9f7c6ed6..c6037c26 100644
--- a/lsp/clangd.lua
+++ b/lsp/clangd.lua
@@ -81,11 +81,11 @@ return {
offsetEncoding = { 'utf-8', 'utf-16' },
},
on_attach = function()
- vim.api.nvim_buf_create_user_command(0, 'ClangdSwitchSourceHeader', function()
+ vim.api.nvim_buf_create_user_command(0, 'LspClangdSwitchSourceHeader', function()
switch_source_header(0)
end, { desc = 'Switch between source/header' })
- vim.api.nvim_buf_create_user_command(0, 'ClangdShowSymbolInfo', function()
+ vim.api.nvim_buf_create_user_command(0, 'LspClangdShowSymbolInfo', function()
symbol_info()
end, { desc = 'Show symbol info' })
end,
diff --git a/lsp/denols.lua b/lsp/denols.lua
index 19d4fb57..80ff679e 100644
--- a/lsp/denols.lua
+++ b/lsp/denols.lua
@@ -106,7 +106,7 @@ return {
['textDocument/references'] = denols_handler,
},
on_attach = function()
- vim.api.nvim_buf_create_user_command(0, 'DenolsCache', function()
+ vim.api.nvim_buf_create_user_command(0, 'LspDenolsCache', function()
local clients = vim.lsp.get_clients { bufnr = 0, name = 'denols' }
if #clients > 0 then
buf_cache(0, clients[#clients])
diff --git a/lsp/ds_pinyin_lsp.lua b/lsp/ds_pinyin_lsp.lua
index 67407827..c1c8b022 100644
--- a/lsp/ds_pinyin_lsp.lua
+++ b/lsp/ds_pinyin_lsp.lua
@@ -60,10 +60,10 @@ return {
max_suggest = 15,
},
on_attach = function()
- vim.api.nvim_buf_create_user_command(0, 'DsPinyinCompletionOff', function()
+ vim.api.nvim_buf_create_user_command(0, 'LspDsPinyinCompletionOff', function()
ds_pinyin_lsp_off(0)
end, { desc = 'Turn off the ds-pinyin-lsp completion' })
- vim.api.nvim_buf_create_user_command(0, 'DsPinyinCompletionOn', function()
+ vim.api.nvim_buf_create_user_command(0, 'LspDsPinyinCompletionOn', function()
ds_pinyin_lsp_on(0)
end, { desc = 'Turn on the ds-pinyin-lsp completion' })
end,
diff --git a/lsp/eslint.lua b/lsp/eslint.lua
index 01d324f9..4c01f3f2 100644
--- a/lsp/eslint.lua
+++ b/lsp/eslint.lua
@@ -44,8 +44,8 @@ return {
'svelte',
'astro',
},
- on_init = function(client)
- vim.api.nvim_create_user_command('LspEslintFixAll', function()
+ on_attach = function(client)
+ vim.api.nvim_buf_create_user_command(0, 'LspEslintFixAll', function()
local bufnr = vim.api.nvim_get_current_buf()
client:exec_cmd({
diff --git a/lsp/julials.lua b/lsp/julials.lua
index 17565a7c..ccea4d5a 100644
--- a/lsp/julials.lua
+++ b/lsp/julials.lua
@@ -121,7 +121,7 @@ return {
filetypes = { 'julia' },
root_markers = root_files,
on_attach = function()
- vim.api.nvim_buf_create_user_command(0, 'JuliaActivateEnv', activate_env, {
+ vim.api.nvim_buf_create_user_command(0, 'LspJuliaActivateEnv', activate_env, {
desc = 'Activate a Julia environment',
nargs = '?',
complete = 'file',
diff --git a/lsp/markdown_oxide.lua b/lsp/markdown_oxide.lua
index 5059363b..79b11913 100644
--- a/lsp/markdown_oxide.lua
+++ b/lsp/markdown_oxide.lua
@@ -13,17 +13,17 @@ return {
filetypes = { 'markdown' },
cmd = { 'markdown-oxide' },
on_attach = function()
- vim.api.nvim_buf_create_user_command(0, 'Today', function()
+ vim.api.nvim_buf_create_user_command(0, 'LspToday', function()
vim.lsp.buf.execute_command { command = 'jump', arguments = { 'today' } }
end, {
desc = "Open today's daily note",
})
- vim.api.nvim_buf_create_user_command(0, 'Tomorrow', function()
+ vim.api.nvim_buf_create_user_command(0, 'LspTomorrow', function()
vim.lsp.buf.execute_command { command = 'jump', arguments = { 'tomorrow' } }
end, {
desc = "Open tomorrow's daily note",
})
- vim.api.nvim_buf_create_user_command(0, 'Yesterday', function()
+ vim.api.nvim_buf_create_user_command(0, 'LspYesterday', function()
vim.lsp.buf.execute_command { command = 'jump', arguments = { 'yesterday' } }
end, {
desc = "Open yesterday's daily note",
diff --git a/lsp/pyright.lua b/lsp/pyright.lua
index ae46ccdf..161b8e0e 100644
--- a/lsp/pyright.lua
+++ b/lsp/pyright.lua
@@ -56,10 +56,10 @@ return {
},
},
on_attach = function()
- vim.api.nvim_buf_create_user_command(0, 'PyrightOrganizeImports', organize_imports, {
+ vim.api.nvim_buf_create_user_command(0, 'LspPyrightOrganizeImports', organize_imports, {
desc = 'Organize Imports',
})
- vim.api.nvim_buf_create_user_command(0, 'PyrightSetPythonPath', set_python_path, {
+ vim.api.nvim_buf_create_user_command(0, 'LspPyrightSetPythonPath', set_python_path, {
desc = 'Reconfigure pyright with the provided python path',
nargs = 1,
complete = 'file',
diff --git a/lsp/rust_analyzer.lua b/lsp/rust_analyzer.lua
index 754eed09..ada5243d 100644
--- a/lsp/rust_analyzer.lua
+++ b/lsp/rust_analyzer.lua
@@ -113,7 +113,7 @@ return {
end
end,
on_attach = function()
- vim.api.nvim_buf_create_user_command(0, 'CargoReload', function()
+ vim.api.nvim_buf_create_user_command(0, 'LspCargoReload', function()
reload_workspace(0)
end, { desc = 'Reload current cargo workspace' })
end,
diff --git a/lsp/svelte.lua b/lsp/svelte.lua
index ed2c19e1..98fde15f 100644
--- a/lsp/svelte.lua
+++ b/lsp/svelte.lua
@@ -9,29 +9,16 @@
--- npm install -g svelte-language-server
--- ```
-local function migrate_to_svelte_5()
- local clients = vim.lsp.get_clients({
- bufnr = 0,
- name = 'svelte',
- })
- for _, client in ipairs(clients) do
- client:exec_cmd({
- command = 'migrate_to_svelte_5',
- arguments = { vim.uri_from_bufnr(0) },
- })
- end
-end
-
return {
cmd = { 'svelteserver', '--stdio' },
filetypes = { 'svelte' },
root_markers = { 'package.json', '.git' },
- on_attach = function()
- vim.api.nvim_buf_create_user_command(
- 0,
- 'MigrateToSvelte5',
- migrate_to_svelte_5,
- { desc = 'Migrate Component to Svelte 5 Syntax' }
- )
+ on_attach = function(client, bufnr)
+ vim.api.nvim_buf_create_user_command(bufnr, 'LspMigrateToSvelte5', function()
+ client:exec_cmd({
+ command = 'migrate_to_svelte_5',
+ arguments = { vim.uri_from_bufnr(bufnr) },
+ })
+ end, { desc = 'Migrate Component to Svelte 5 Syntax' })
end,
}
diff --git a/lsp/svlangserver.lua b/lsp/svlangserver.lua
index 381e8f89..6121ea9b 100644
--- a/lsp/svlangserver.lua
+++ b/lsp/svlangserver.lua
@@ -35,10 +35,10 @@ return {
},
},
on_attach = function()
- vim.api.nvim_buf_create_user_command(0, 'SvlangserverBuildIndex', build_index, {
+ vim.api.nvim_buf_create_user_command(0, 'LspSvlangserverBuildIndex', build_index, {
desc = 'Instructs language server to rerun indexing',
})
- vim.api.nvim_buf_create_user_command(0, 'SvlangserverReportHierarchy', report_hierarchy, {
+ vim.api.nvim_buf_create_user_command(0, 'LspSvlangserverReportHierarchy', report_hierarchy, {
desc = 'Generates hierarchy for the given module',
})
end,
diff --git a/lsp/texlab.lua b/lsp/texlab.lua
index f4be0f51..8123d5b7 100644
--- a/lsp/texlab.lua
+++ b/lsp/texlab.lua
@@ -193,28 +193,28 @@ return {
},
},
on_attach = function()
- vim.api.nvim_buf_create_user_command(0, 'TexlabBuild', client_with_fn(buf_build), {
+ vim.api.nvim_buf_create_user_command(0, 'LspTexlabBuild', client_with_fn(buf_build), {
desc = 'Build the current buffer',
})
- vim.api.nvim_buf_create_user_command(0, 'TexlabForward', client_with_fn(buf_search), {
+ vim.api.nvim_buf_create_user_command(0, 'LspTexlabForward', client_with_fn(buf_search), {
desc = 'Forward search from current position',
})
- vim.api.nvim_buf_create_user_command(0, 'TexlabCancelBuild', client_with_fn(buf_cancel_build), {
+ vim.api.nvim_buf_create_user_command(0, 'LspTexlabCancelBuild', client_with_fn(buf_cancel_build), {
desc = 'Cancel the current build',
})
- vim.api.nvim_buf_create_user_command(0, 'TexlabDependencyGraph', client_with_fn(dependency_graph), {
+ vim.api.nvim_buf_create_user_command(0, 'LspTexlabDependencyGraph', client_with_fn(dependency_graph), {
desc = 'Show the dependency graph',
})
- vim.api.nvim_buf_create_user_command(0, 'TexlabCleanArtifacts', client_with_fn(command_factory('Artifacts')), {
+ vim.api.nvim_buf_create_user_command(0, 'LspTexlabCleanArtifacts', client_with_fn(command_factory('Artifacts')), {
desc = 'Clean the artifacts',
})
- vim.api.nvim_buf_create_user_command(0, 'TexlabCleanAuxiliary', client_with_fn(command_factory('Auxiliary')), {
+ vim.api.nvim_buf_create_user_command(0, 'LspTexlabCleanAuxiliary', client_with_fn(command_factory('Auxiliary')), {
desc = 'Clean the auxiliary files',
})
- vim.api.nvim_buf_create_user_command(0, 'TexlabFindEnvironments', client_with_fn(buf_find_envs), {
+ vim.api.nvim_buf_create_user_command(0, 'LspTexlabFindEnvironments', client_with_fn(buf_find_envs), {
desc = 'Find the environments at current position',
})
- vim.api.nvim_buf_create_user_command(0, 'TexlabChangeEnvironment', client_with_fn(buf_change_env), {
+ vim.api.nvim_buf_create_user_command(0, 'LspTexlabChangeEnvironment', client_with_fn(buf_change_env), {
desc = 'Change the environment at current position',
})
end,
diff --git a/lsp/tinymist.lua b/lsp/tinymist.lua
index a65302a8..d0a6d5c3 100644
--- a/lsp/tinymist.lua
+++ b/lsp/tinymist.lua
@@ -12,7 +12,7 @@
---@param command_name string
---@return fun():nil run_tinymist_command, string cmd_name, string cmd_desc
-local function create_tinymist_command(command_name)
+local function create_tinymist_command(command_name, client, bufnr)
local export_type = command_name:match 'tinymist%.export(%w+)'
local info_type = command_name:match 'tinymist%.(%w+)'
if info_type and info_type:match '^get' then
@@ -22,11 +22,6 @@ local function create_tinymist_command(command_name)
---Execute the Tinymist command, supporting both 0.10 and 0.11 exec methods
---@return nil
local function run_tinymist_command()
- local bufnr = vim.api.nvim_get_current_buf()
- local client = vim.lsp.get_clients({ name = 'tinymist', buffer = bufnr })[1]
- if not client then
- return vim.notify('No Tinymist client attached to the current buffer', vim.log.levels.ERROR)
- end
local arguments = { vim.api.nvim_buf_get_name(bufnr) }
local title_str = export_type and ('Export ' .. cmd_display) or cmd_display
---@type lsp.Handler
@@ -58,7 +53,7 @@ return {
cmd = { 'tinymist' },
filetypes = { 'typst' },
root_markers = { '.git' },
- on_attach = function(_)
+ on_attach = function(client, bufnr)
for _, command in ipairs {
'tinymist.exportSvg',
'tinymist.exportPng',
@@ -73,8 +68,8 @@ return {
'tinymist.getWorkspaceLabels',
'tinymist.getDocumentMetrics',
} do
- local cmd_func, cmd_name, cmd_desc = create_tinymist_command(command)
- vim.api.nvim_create_user_command(cmd_name, cmd_func, { nargs = 0, desc = cmd_desc })
+ local cmd_func, cmd_name, cmd_desc = create_tinymist_command(command, client, bufnr)
+ vim.api.nvim_buf_create_user_command(0, cmd_name, cmd_func, { nargs = 0, desc = cmd_desc })
end
end,
}
diff --git a/lsp/zk.lua b/lsp/zk.lua
index 6a336b7b..f659cb25 100644
--- a/lsp/zk.lua
+++ b/lsp/zk.lua
@@ -17,7 +17,7 @@ return {
filetypes = { 'markdown' },
root_markers = { '.zk' },
on_attach = function()
- vim.api.nvim_buf_create_user_command(0, 'ZkIndex', function()
+ vim.api.nvim_buf_create_user_command(0, 'LspZkIndex', function()
vim.lsp.buf.execute_command {
command = 'zk.index',
arguments = { vim.api.nvim_buf_get_name(0) },
@@ -26,7 +26,7 @@ return {
desc = 'ZkIndex',
})
- vim.api.nvim_buf_create_user_command(0, 'ZkList', function()
+ vim.api.nvim_buf_create_user_command(0, 'LspZkList', function()
local bufpath = vim.api.nvim_buf_get_name(0)
local root = find_zk_root(bufpath)
@@ -48,7 +48,7 @@ return {
desc = 'ZkList',
})
- vim.api.nvim_buf_create_user_command(0, 'ZkNew', function(...)
+ vim.api.nvim_buf_create_user_command(0, 'LspZkNew', function(...)
vim.lsp.buf_request(0, 'workspace/executeCommand', {
command = 'zk.new',
arguments = {