1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

11 Commits

Author SHA1 Message Date
jdhao
082111fa4e update LSP config (#410) 2025-05-13 18:15:08 +02:00
jdhao
30b3c09dda update readme 2025-04-30 19:07:07 +02:00
jdhao
3b964c3d1f remove format mapping for lsp 2025-04-30 19:04:44 +02:00
jdhao
999a1733cf use nvim-cmp for cmd line completion
- remove wilder.nvim and its config
- add blink.cmp config as backup solution
2025-04-30 19:01:57 +02:00
Alessandro Zini
b69dcb3a6b fix neovim link for linux install script (#408) 2025-04-30 11:00:50 +02:00
jdhao
ea23f913b4 set default conf for all LSP in one place (#405) 2025-04-26 22:02:48 +02:00
jdhao
8839201450 upgrade nvim to 0.11.1 (#404) 2025-04-26 21:48:18 +02:00
jdhao
ba991064b6 change lualine refresh interval 2025-04-26 19:00:11 +02:00
jdhao
6c620ecc32 update the enabled lsp server list 2025-04-26 18:59:25 +02:00
jdhao
be862a83d6 Use new lsp configuration structure (#403)
In this new structure, the main configuration for a LSP server is
provided by the plugin nvim-lspconfig.
Some of the config may be overridden by the configuration under
directory `after/lsp/xxx.lua`, where `xxx` is the lsp server name used
by nvim-lspconfig.

Note that it is necessary to put the custom lsp server configuration
under `after/` directory, in order to correctly override the config
provided by nvim-lspconfig.
2025-04-26 17:19:46 +02:00
jdhao
488ba52644 use new api vim.lsp.config for lsp configuration (#402)
Now nvim-lspconfig serves as ready made configuration for different lsp
server configurations.
See also related PR in lspconfig: https://github.com/neovim/nvim-lspconfig/pull/3659
2025-04-22 17:54:29 +02:00
15 changed files with 278 additions and 227 deletions

View File

@@ -10,10 +10,7 @@
<img alt="Windows" src="https://img.shields.io/badge/Windows-%23.svg?style=flat-square&logo=windows&color=0078D6&logoColor=white" />
</a>
<a href="https://github.com/neovim/neovim/releases/tag/stable">
<img src="https://img.shields.io/badge/Neovim-0.11.0-blueviolet.svg?style=flat-square&logo=Neovim&logoColor=green" alt="Neovim minimum version"/>
</a>
<a href="https://github.com/jdhao/nvim-config/releases/latest">
<img alt="Latest release" src="https://img.shields.io/github/v/release/jdhao/nvim-config" />
<img src="https://img.shields.io/badge/Neovim-0.11.1-blueviolet.svg?style=flat-square&logo=Neovim&logoColor=green" alt="Neovim minimum version"/>
</a>
<a href="https://github.com/jdhao/nvim-config/search?l=vim-script">
<img src="https://img.shields.io/github/languages/top/jdhao/nvim-config" alt="Top languages"/>
@@ -69,7 +66,6 @@ and how to set up on different platforms (Linux, macOS, and Windows).
+ File tree explorer via [nvim-tree.lua](https://github.com/nvim-tree/nvim-tree.lua).
+ Better quickfix list with [nvim-bqf](https://github.com/kevinhwang91/nvim-bqf).
+ Show search index and count with [nvim-hlslens](https://github.com/kevinhwang91/nvim-hlslens).
+ Command line auto-completion via [wilder.nvim](https://github.com/gelguy/wilder.nvim).
+ User-defined mapping hint via [which-key.nvim](https://github.com/folke/which-key.nvim).
+ Asynchronous code execution via [asyncrun.vim](https://github.com/skywind3000/asyncrun.vim).
+ Code highlighting via [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter).
@@ -111,12 +107,6 @@ For more UI demos, check [here](https://github.com/jdhao/nvim-config/issues/15).
<img src="https://user-images.githubusercontent.com/16662357/128590833-aaa05d53-19ef-441d-a5a9-ba1bbd3936c1.gif" width="800">
</p>
## Command-line autocompletion with wilder.nvim
<p align="center">
<img src="https://user-images.githubusercontent.com/16662357/147677787-8e5d229a-a16a-420e-98f5-88f2a1be84a2.gif" width="800">
</p>
## Tags
<p align="center">

3
after/lsp/clangd.lua Normal file
View File

@@ -0,0 +1,3 @@
return {
filetypes = { "c", "cpp", "cc" },
}

8
after/lsp/ltex.lua Normal file
View File

@@ -0,0 +1,8 @@
return {
filetypes = { "text", "plaintex", "tex", "markdown" },
settings = {
ltex = {
language = "en",
},
},
}

14
after/lsp/lua_ls.lua Normal file
View File

@@ -0,0 +1,14 @@
-- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/
return {
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
hint = {
enable = true,
},
},
},
}

51
after/lsp/pyright.lua Normal file
View File

@@ -0,0 +1,51 @@
-- For what diagnostic is enabled in which type checking mode, check doc:
-- https://github.com/microsoft/pyright/blob/main/docs/configuration.md#diagnostic-settings-defaults
-- Currently, the pyright also has some issues displaying hover documentation:
-- https://www.reddit.com/r/neovim/comments/1gdv1rc/what_is_causeing_the_lsp_hover_docs_to_looks_like/
local new_capability = {
-- this will remove some of the diagnostics that duplicates those from ruff, idea taken and adapted from
-- here: https://github.com/astral-sh/ruff-lsp/issues/384#issuecomment-1989619482
textDocument = {
publishDiagnostics = {
tagSupport = {
valueSet = { 2 },
},
},
hover = {
contentFormat = { "plaintext" },
dynamicRegistration = true,
},
},
}
return {
cmd = { "delance-langserver", "--stdio" },
settings = {
pyright = {
-- disable import sorting and use Ruff for this
disableOrganizeImports = true,
disableTaggedHints = false,
},
python = {
analysis = {
autoSearchPaths = true,
diagnosticMode = "workspace",
typeCheckingMode = "standard",
useLibraryCodeForTypes = true,
-- we can this setting below to redefine some diagnostics
diagnosticSeverityOverrides = {
deprecateTypingAliases = false,
},
-- inlay hint settings are provided by pylance?
inlayHints = {
callArgumentNames = "partial",
functionReturnTypes = true,
pytestParameters = true,
variableTypes = true,
},
},
},
},
capabilities = new_capability,
}

8
after/lsp/ruff.lua Normal file
View File

@@ -0,0 +1,8 @@
return {
init_options = {
-- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/
settings = {
organizeImports = true,
},
},
}

View File

@@ -221,7 +221,7 @@ fi
NVIM_DIR=$HOME/tools/nvim
NVIM_SRC_NAME=$HOME/packages/nvim-linux64.tar.gz
NVIM_CONFIG_DIR=$HOME/.config/nvim
NVIM_LINK="https://github.com/neovim/neovim/releases/download/stable/nvim-linux64.tar.gz"
NVIM_LINK="https://github.com/neovim/neovim/releases/download/stable/nvim-linux-x86_64.tar.gz"
if [[ ! -f "$NVIM_DIR/bin/nvim" ]]; then
echo "Installing Nvim"
echo "Creating nvim directory under tools directory"

View File

@@ -13,7 +13,7 @@ vim.loader.enable()
local utils = require("utils")
local expected_version = "0.11.0"
local expected_version = "0.11.1"
utils.is_compatible_version(expected_version)
local config_dir = vim.fn.stdpath("config")

View File

@@ -1,12 +1,7 @@
local api = vim.api
local keymap = vim.keymap
local lsp = vim.lsp
local lspconfig = require("lspconfig")
local utils = require("utils")
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("buf_behavior_conf", { clear = true }),
group = vim.api.nvim_create_augroup("lsp_buf_conf", { clear = true }),
callback = function(event_context)
local client = vim.lsp.get_client_by_id(event_context.data.client_id)
-- vim.print(client.name, client.server_capabilities)
@@ -22,10 +17,48 @@ vim.api.nvim_create_autocmd("LspAttach", {
opts = opts or {}
opts.silent = true
opts.buffer = bufnr
keymap.set(mode, l, r, opts)
vim.keymap.set(mode, l, r, opts)
end
map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" })
map("n", "gd", function()
vim.lsp.buf.definition {
on_list = function(options)
-- custom logic to avoid showing multiple definition when you use this style of code:
-- `local M.my_fn_name = function() ... end`.
-- See also post here: https://www.reddit.com/r/neovim/comments/19cvgtp/any_way_to_remove_redundant_definition_in_lua_file/
-- vim.print(options.items)
local unique_defs = {}
local def_loc_hash = {}
-- each item in options.items contain the location info for a definition provided by LSP server
for _, def_location in pairs(options.items) do
-- use filename and line number to uniquelly indentify a definition,
-- we do not expect/want multiple definition in single line!
local hash_key = def_location.filename .. def_location.lnum
if not def_loc_hash[hash_key] then
def_loc_hash[hash_key] = true
table.insert(unique_defs, def_location)
end
end
options.items = unique_defs
-- set the location list
---@diagnostic disable-next-line: param-type-mismatch
vim.fn.setloclist(0, {}, " ", options)
-- open the location list when we have more than 1 definitions found,
-- otherwise, jump directly to the definition
if #options.items > 1 then
vim.cmd.lopen()
else
vim.cmd([[silent! lfirst]])
end
end,
}
end, { desc = "go to definition" })
map("n", "<C-]>", vim.lsp.buf.definition)
map("n", "K", function()
vim.lsp.buf.hover { border = "single", max_height = 25, max_width = 120 }
@@ -40,10 +73,6 @@ vim.api.nvim_create_autocmd("LspAttach", {
end, { desc = "list workspace folder" })
-- Set some key bindings conditional on server capabilities
if client.server_capabilities.documentFormattingProvider and client.name ~= "lua_ls" then
map({ "n", "x" }, "<space>f", vim.lsp.buf.format, { desc = "format code" })
end
-- Disable ruff hover feature in favor of Pyright
if client.name == "ruff" then
client.server_capabilities.hoverProvider = false
@@ -55,20 +84,20 @@ vim.api.nvim_create_autocmd("LspAttach", {
-- The blow command will highlight the current variable and its usages in the buffer.
if client.server_capabilities.documentHighlightProvider then
local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true })
api.nvim_create_autocmd("CursorHold", {
local gid = vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true })
vim.api.nvim_create_autocmd("CursorHold", {
group = gid,
buffer = bufnr,
callback = function()
lsp.buf.document_highlight()
vim.lsp.buf.document_highlight()
end,
})
api.nvim_create_autocmd("CursorMoved", {
vim.api.nvim_create_autocmd("CursorMoved", {
group = gid,
buffer = bufnr,
callback = function()
lsp.buf.clear_references()
vim.lsp.buf.clear_references()
end,
})
end
@@ -77,139 +106,38 @@ vim.api.nvim_create_autocmd("LspAttach", {
desc = "Configure buffer keymap and behavior based on LSP",
})
local capabilities = vim.lsp.protocol.make_client_capabilities()
-- Enable lsp servers when they are available
-- required by nvim-ufo
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
local capabilities = require("lsp_utils").get_default_capabilities()
vim.lsp.config("*", {
capabilities = capabilities,
flags = {
debounce_text_changes = 500,
},
})
-- A mapping from lsp server name to the executable name
local enabled_lsp_servers = {
pyright = "delance-langserver",
ruff = "ruff",
lua_ls = "lua-language-server",
-- ltex = "ltex-ls",
-- clangd = "clangd",
vimls = "vim-language-server",
bashls = "bash-language-server",
yamlls = "yaml-language-server",
}
-- For what diagnostic is enabled in which type checking mode, check doc:
-- https://github.com/microsoft/pyright/blob/main/docs/configuration.md#diagnostic-settings-defaults
-- Currently, the pyright also has some issues displaying hover documentation:
-- https://www.reddit.com/r/neovim/comments/1gdv1rc/what_is_causeing_the_lsp_hover_docs_to_looks_like/
if utils.executable("pyright") then
local new_capability = {
-- this will remove some of the diagnostics that duplicates those from ruff, idea taken and adapted from
-- here: https://github.com/astral-sh/ruff-lsp/issues/384#issuecomment-1989619482
textDocument = {
publishDiagnostics = {
tagSupport = {
valueSet = { 2 },
},
},
hover = {
contentFormat = { "plaintext" },
dynamicRegistration = true,
},
},
}
local merged_capability = vim.tbl_deep_extend("force", capabilities, new_capability)
lspconfig.pyright.setup {
cmd = { "delance-langserver", "--stdio" },
capabilities = merged_capability,
settings = {
pyright = {
-- disable import sorting and use Ruff for this
disableOrganizeImports = true,
disableTaggedHints = false,
},
python = {
analysis = {
autoSearchPaths = true,
diagnosticMode = "workspace",
typeCheckingMode = "standard",
useLibraryCodeForTypes = true,
-- we can this setting below to redefine some diagnostics
diagnosticSeverityOverrides = {
deprecateTypingAliases = false,
},
-- inlay hint settings are provided by pylance?
inlayHints = {
callArgumentNames = "partial",
functionReturnTypes = true,
pytestParameters = true,
variableTypes = true,
},
},
},
},
}
else
vim.notify("pyright not found!", vim.log.levels.WARN, { title = "Nvim-config" })
end
if utils.executable("ruff") then
require("lspconfig").ruff.setup {
capabilities = capabilities,
init_options = {
-- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/
settings = {
organizeImports = true,
},
},
}
end
if utils.executable("ltex-ls") then
lspconfig.ltex.setup {
cmd = { "ltex-ls" },
filetypes = { "text", "plaintex", "tex", "markdown" },
settings = {
ltex = {
language = "en",
},
},
flags = { debounce_text_changes = 300 },
}
end
if utils.executable("clangd") then
lspconfig.clangd.setup {
capabilities = capabilities,
filetypes = { "c", "cpp", "cc" },
flags = {
debounce_text_changes = 500,
},
}
end
-- set up vim-language-server
if utils.executable("vim-language-server") then
lspconfig.vimls.setup {
flags = {
debounce_text_changes = 500,
},
capabilities = capabilities,
}
else
vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Nvim-config" })
end
-- set up bash-language-server
if utils.executable("bash-language-server") then
lspconfig.bashls.setup {
capabilities = capabilities,
}
end
-- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/
if utils.executable("lua-language-server") then
lspconfig.lua_ls.setup {
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
hint = {
enable = true,
},
},
},
capabilities = capabilities,
}
for server_name, lsp_executable in pairs(enabled_lsp_servers) do
if utils.executable(lsp_executable) then
vim.lsp.enable(server_name)
else
local msg = string.format(
"Executable '%s' for server '%s' not found! Server will not be enabled",
lsp_executable,
server_name
)
vim.notify(msg, vim.log.levels.WARN, { title = "Nvim-config" })
end
end

View File

@@ -210,7 +210,7 @@ require("lualine").setup {
disabled_filetypes = {},
always_divide_middle = true,
refresh = {
statusline = 500,
statusline = 1000,
},
},
sections = {

View File

@@ -7,6 +7,7 @@ require("cmp_path")
require("cmp_buffer")
require("cmp_omni")
require("cmp_nvim_ultisnips")
require("cmp_cmdline")
local MiniIcons = require("mini.icons")
@@ -71,6 +72,23 @@ cmp.setup.filetype("tex", {
},
})
cmp.setup.cmdline("/", {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = "buffer" },
},
})
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "path" },
}, {
{ name = "cmdline" },
}),
matching = { disallow_symbol_nonprefix_matching = false },
})
-- see https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance#how-to-add-visual-studio-code-dark-theme-colors-to-the-menu
vim.cmd([[
highlight! link CmpItemMenu Comment

15
lua/lsp_utils.lua Normal file
View File

@@ -0,0 +1,15 @@
local M = {}
M.get_default_capabilities = function()
local capabilities = vim.lsp.protocol.make_client_capabilities()
-- required by nvim-ufo
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
}
return capabilities
end
return M

View File

@@ -104,7 +104,7 @@ keymap.set("n", "<leader>v", "printf('`[%s`]', getregtype()[0])", {
})
-- Always use very magic mode for searching
keymap.set("n", "/", [[/\v]])
-- keymap.set("n", "/", [[/\v]])
-- Search in selected region
-- xnoremap / :<C-U>call feedkeys('/\%>'.(line("'<")-1).'l\%<'.(line("'>")+1)."l")<CR>

View File

@@ -26,15 +26,79 @@ local plugin_specs = {
{ "hrsh7th/cmp-path", lazy = true },
{ "hrsh7th/cmp-buffer", lazy = true },
{ "hrsh7th/cmp-omni", lazy = true },
{ "hrsh7th/cmp-cmdline", lazy = true },
{ "quangnguyen30192/cmp-nvim-ultisnips", lazy = true },
{
"hrsh7th/nvim-cmp",
name = "nvim-cmp",
event = "InsertEnter",
event = "VeryLazy",
config = function()
require("config.nvim-cmp")
end,
},
--{
-- "saghen/blink.cmp",
-- -- optional: provides snippets for the snippet source
-- dependencies = { "rafamadriz/friendly-snippets" },
-- -- use a release tag to download pre-built binaries
-- version = "1.*",
-- ---@module 'blink.cmp'
-- ---@type blink.cmp.Config
-- opts = {
-- -- 'default' (recommended) for mappings similar to built-in completions (C-y to accept)
-- -- 'super-tab' for mappings similar to vscode (tab to accept)
-- -- 'enter' for enter to accept
-- -- 'none' for no mappings
-- --
-- keymap = {
-- preset = "default",
-- ["<Tab>"] = { "select_next", "fallback" },
-- ["<S-Tab>"] = { "select_prev", "fallback" },
-- ["<Enter>"] = { "select_and_accept", "fallback" },
-- ["<C-U>"] = { "scroll_documentation_up", "fallback" },
-- ["<C-D>"] = { "scroll_documentation_down", "fallback" },
-- },
-- appearance = {
-- -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
-- -- Adjusts spacing to ensure icons are aligned
-- nerd_font_variant = "mono",
-- },
-- -- (Default) Only show the documentation popup when manually triggered
-- completion = {
-- documentation = {
-- auto_show = true,
-- },
-- },
-- -- Default list of enabled providers defined so that you can extend it
-- -- elsewhere in your config, without redefining it, due to `opts_extend`
-- sources = {
-- default = { "lsp", "path", "buffer" },
-- },
-- -- (Default) Rust fuzzy matcher for typo resistance and significantly better performance
-- -- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation,
-- -- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"`
-- --
-- -- See the fuzzy documentation for more information
-- fuzzy = { implementation = "prefer_rust_with_warning" },
-- cmdline = {
-- completion = {
-- menu = {
-- auto_show = true,
-- },
-- },
-- keymap = {
-- ["<Enter>"] = { "select_and_accept", "fallback" },
-- },
-- },
-- },
-- opts_extend = { "sources.default" },
--},
{
"neovim/nvim-lspconfig",
event = { "BufRead", "BufNewFile" },
@@ -251,9 +315,13 @@ local plugin_specs = {
},
-- Snippet engine and snippet template
{ "SirVer/ultisnips", dependencies = {
"honza/vim-snippets",
}, event = "InsertEnter" },
{
"SirVer/ultisnips",
dependencies = {
"honza/vim-snippets",
},
event = "InsertEnter",
},
-- Automatic insertion and deletion of a pair of characters
{
@@ -263,10 +331,13 @@ local plugin_specs = {
},
-- Comment plugin
{ "tpope/vim-commentary", keys = {
{ "gc", mode = "n" },
{ "gc", mode = "v" },
} },
{
"tpope/vim-commentary",
keys = {
{ "gc", mode = "n" },
{ "gc", mode = "v" },
},
},
-- Multiple cursor plugin like Sublime Text?
-- 'mg979/vim-visual-multi'
@@ -307,9 +378,6 @@ local plugin_specs = {
event = { "InsertEnter" },
},
-- Auto format tools
{ "sbdchd/neoformat", cmd = { "Neoformat" } },
-- Git command inside vim
{
"tpope/vim-fugitive",
@@ -464,12 +532,6 @@ local plugin_specs = {
cmd = { "OSCYank", "OSCYankReg" },
},
-- The missing auto-completion for cmdline!
{
"gelguy/wilder.nvim",
build = ":UpdateRemotePlugins",
},
-- showing keybindings
{
"folke/which-key.nvim",

View File

@@ -240,49 +240,3 @@ endif
""""""""""""""""""""""""""""""nvim-gdb settings""""""""""""""""""""""""""""""
nnoremap <leader>dp :<C-U>GdbStartPDB python -m pdb %<CR>
""""""""""""""""""""""""""""""wilder.nvim settings""""""""""""""""""""""""""""""
call timer_start(250, { -> s:wilder_init() })
function! s:wilder_init() abort
try
call wilder#setup({
\ 'modes': [':', '/', '?'],
\ 'next_key': '<Tab>',
\ 'previous_key': '<S-Tab>',
\ 'accept_key': '<C-y>',
\ 'reject_key': '<C-e>'
\ })
call wilder#set_option('pipeline', [
\ wilder#branch(
\ wilder#cmdline_pipeline({
\ 'language': 'python',
\ 'fuzzy': 1,
\ 'sorter': wilder#python_difflib_sorter(),
\ 'debounce': 30,
\ }),
\ wilder#python_search_pipeline({
\ 'pattern': wilder#python_fuzzy_pattern(),
\ 'sorter': wilder#python_difflib_sorter(),
\ 'engine': 're',
\ 'debounce': 30,
\ }),
\ ),
\ ])
let l:hl = wilder#make_hl('WilderAccent', 'Pmenu', [{}, {}, {'foreground': '#f4468f'}])
call wilder#set_option('renderer', wilder#popupmenu_renderer({
\ 'highlighter': wilder#basic_highlighter(),
\ 'max_height': 15,
\ 'highlights': {
\ 'accent': l:hl,
\ },
\ 'left': [' ', wilder#popupmenu_devicons(),],
\ 'right': [' ', wilder#popupmenu_scrollbar(),],
\ 'apply_incsearch_fix': 0,
\ }))
catch /^Vim\%((\a\+)\)\=:E117/
echohl Error |echomsg "Wilder.nvim missing"| echohl None
endtry
endfunction