commit 0f234ec6d26a5e8f0945e810e4d7659deba1220e
parent 124d9395aa0de99b4ff25ae79821d56af0428928
Author: Chris Bracken <chris@bracken.jp>
Date: Tue, 12 May 2026 13:27:52 +0900
nvim: use path-based LSP config
As of neovim 0.11 (or 0.12?) nvim automatically reads LSP plugins from
files under ~/.confg/nvim/lsp. This simplifies our languages.lua.
Diffstat:
4 files changed, 36 insertions(+), 30 deletions(-)
diff --git a/.config/nvim/lsp/basedpyright.lua b/.config/nvim/lsp/basedpyright.lua
@@ -0,0 +1,11 @@
+return {
+ settings = {
+ basedpyright = {
+ analysis = {
+ autoImportCompletions = true,
+ typeCheckingMode = "basic",
+ diagnosticMode = "openFilesOnly",
+ },
+ },
+ },
+}
diff --git a/.config/nvim/lsp/beancount.lua b/.config/nvim/lsp/beancount.lua
@@ -0,0 +1,14 @@
+return {
+ cmd = { "beancount-language-server", "--stdio" },
+ init_options = {
+ journal_file = (function()
+ -- Search upwards for main.beancount starting from the current working directory
+ local file = vim.fn.findfile('main.beancount', '.;')
+ if file ~= '' then
+ -- Expand the relative result into a full absolute path
+ return vim.fn.fnamemodify(file, ':p')
+ end
+ return ""
+ end)(),
+ },
+}
diff --git a/.config/nvim/lua/config/options.lua b/.config/nvim/lua/config/options.lua
@@ -13,7 +13,8 @@ vim.opt.wildmenu = true -- Nicer autocomplete.
vim.opt.wildmode = {'longest', 'full'}
vim.opt.wildignore = {'*.o', '*.pyc'} -- Ignore some filetypes during completion.
vim.opt.spelllang = 'en_ca' -- Set the spelling language.
-vim.opt.completeopt:append('longest') -- Insert longest common prefix of options.
+vim.opt.autocomplete = false -- Enable native auto-completion.
+vim.opt.completeopt = 'menu,menuone,noselect,popup,longest' -- Improved completion behaviour.
vim.opt.autoindent = true -- Copy indent from current line when starting a new line.
vim.opt.smartindent = true -- Attempt to autoindent when starting a new line.
vim.opt.smarttab = true -- Use shiftwidth rather than tabstop at start of line.
diff --git a/.config/nvim/lua/plugins/languages.lua b/.config/nvim/lua/plugins/languages.lua
@@ -67,36 +67,18 @@ return {
event = { "BufReadPre", "BufNewFile" },
config = function()
if vim.fn.executable('clangd') == 1 then
- vim.lsp.config.clangd = {}
vim.lsp.enable('clangd')
end
if vim.fn.executable('lua-language-server') == 1 then
- vim.lsp.config.lua_ls = {}
vim.lsp.enable('lua_ls')
end
if vim.fn.executable('zls') == 1 then
- vim.lsp.config.zls = {}
vim.lsp.enable('zls')
end
if vim.fn.executable('rust-analyzer') == 1 then
- vim.lsp.config.rust_analyzer = {}
vim.lsp.enable('rust_analyzer')
end
if vim.fn.executable('beancount-language-server') == 1 then
- vim.lsp.config.beancount = {
- cmd = { "beancount-language-server", "--stdio" },
- init_options = {
- journal_file = (function()
- -- Search upwards for main.beancount starting from the current working directory
- local file = vim.fn.findfile('main.beancount', '.;')
- if file ~= '' then
- -- Expand the relative result into a full absolute path
- return vim.fn.fnamemodify(file, ':p')
- end
- return ""
- end)(),
- },
- }
vim.lsp.enable('beancount')
end
if vim.fn.executable('sourcekit-lsp') == 1 then
@@ -105,17 +87,6 @@ return {
vim.lsp.enable('sourcekit')
end
if vim.fn.executable('basedpyright-langserver') == 1 then
- vim.lsp.config.basedpyright = {
- settings = {
- basedpyright = {
- analysis = {
- autoImportCompletions = true,
- typeCheckingMode = "basic",
- diagnosticMode = "openFilesOnly",
- },
- },
- },
- }
vim.lsp.enable('basedpyright')
end
@@ -123,6 +94,15 @@ return {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
local opts = { buffer = ev.buf, silent = true }
+
+ -- Enable auto-completion if supported/enabled by the client.
+ local client = vim.lsp.get_client_by_id(ev.data.client_id)
+ if client and client:supports_method("textDocument/completion") then
+ vim.lsp.completion.enable(true, ev.data.client_id, ev.buf, {
+ autotrigger = false,
+ })
+ end
+
opts.desc = "See available code actions"
vim.keymap.set({"n", "v"}, "<leader>ca", vim.lsp.buf.code_action, opts)
opts.desc = "Smart rename"