Migrate to lspconfig
This commit is contained in:
parent
031b6403df
commit
f279225201
14 changed files with 116 additions and 349 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -19,3 +19,6 @@
|
|||
[submodule "bundle/nvim-format-buffer"]
|
||||
path = bundle/nvim-format-buffer
|
||||
url = https://github.com/acro5piano/nvim-format-buffer.git
|
||||
[submodule "bundle/nvim-lspconfig"]
|
||||
path = bundle/nvim-lspconfig
|
||||
url = https://github.com/neovim/nvim-lspconfig.git
|
||||
|
|
1
bundle/nvim-lspconfig
Submodule
1
bundle/nvim-lspconfig
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 8b0f47d851ee5343d38fe194a06ad16b9b9bd086
|
|
@ -1,14 +0,0 @@
|
|||
require('nvim-format-buffer').setup({
|
||||
verbose = false,
|
||||
format_rules = {
|
||||
{ pattern = { '*.c', '*.h' }, command = 'clang-format' },
|
||||
{
|
||||
pattern = { '*.js', '*.mjs', '*.ts', '*.mts', '*.cjs', '*.tsx', '*.vue', '*.css' },
|
||||
command = function()
|
||||
return 'prettier --stdin-filepath ' .. vim.api.nvim_buf_get_name(0)
|
||||
end,
|
||||
},
|
||||
{ pattern = { "*.sql" }, command = "pg_format --spaces=2 --wrap-limit=1000 --no-rcfile" },
|
||||
{ pattern = { "*.py", "*.pyi" }, command = "ruff check --select I --fix --silent - | ruff format -" }
|
||||
},
|
||||
})
|
|
@ -1,3 +0,0 @@
|
|||
require("config.tab")
|
||||
require("config.format")
|
||||
require("config.lsp.init")
|
|
@ -1,29 +0,0 @@
|
|||
local bin_name = "clangd"
|
||||
local cmd = {
|
||||
bin_name,
|
||||
"--background-index",
|
||||
"--suggest-missing-includes",
|
||||
"--enable-config",
|
||||
"--query-driver=/usr/lib64/ccache/*,/usr/bin/*",
|
||||
}
|
||||
|
||||
local config = vim.fs.find(".clangd", {
|
||||
upward = true,
|
||||
stop = vim.loop.os_homedir(),
|
||||
path = vim.fs.dirname(vim.api.nvim_buf_get_name(0)),
|
||||
})
|
||||
|
||||
if next(config) then
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "c,cpp",
|
||||
callback = function()
|
||||
vim.lsp.start({
|
||||
name = "clangd",
|
||||
cmd = cmd,
|
||||
root_dir = config[1],
|
||||
settings = {
|
||||
},
|
||||
})
|
||||
end,
|
||||
})
|
||||
end
|
|
@ -1,68 +0,0 @@
|
|||
require('vim.lsp.log').set_format_func(vim.inspect)
|
||||
-- vim.lsp.set_log_level("debug")
|
||||
|
||||
require("config.lsp.pyright")
|
||||
require("config.lsp.ruff")
|
||||
-- require("config.lsp.pylsp")
|
||||
-- require("config.lsp.typescript")
|
||||
require("config.lsp.clangd")
|
||||
require("config.lsp.vls")
|
||||
require("config.lsp.rust_analyzer")
|
||||
|
||||
local api = vim.api
|
||||
local opts = { noremap = true, silent = true }
|
||||
local keymap = vim.keymap.set
|
||||
|
||||
keymap("n", "[d", "<cmd>lua vim.diagnostic.jump({count = -1, float = true})<CR>", opts)
|
||||
keymap("n", "]d", "<cmd>lua vim.diagnostic.jump({count = 1, float = true})<CR>", opts)
|
||||
keymap("n", "[e", "<cmd>lua vim.diagnostic.jump({count = -1, severity = vim.diagnostic.severity.ERROR, float = true})<CR>", opts)
|
||||
keymap("n", "]e", "<cmd>lua vim.diagnostic.jump({count = -1, severity = vim.diagnostic.severity.ERROR, float = true})<CR>", opts)
|
||||
|
||||
keymap("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
|
||||
keymap("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts)
|
||||
keymap("n", "gh", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
|
||||
keymap("n", "gI", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
|
||||
keymap("n", "gt", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
|
||||
|
||||
keymap("n", "ca", "<cmd>lua require('fzf-lua').lsp_code_actions()<CR>", opts)
|
||||
|
||||
keymap("n", "gl", "<cmd>lua vim.diagnostic.reset()<CR>", opts)
|
||||
|
||||
-- Automatic completion triggering
|
||||
-- vim.api.nvim_create_autocmd('LspAttach', {
|
||||
-- callback = function(ev)
|
||||
-- local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||||
-- if client:supports_method('textDocument/completion') then
|
||||
-- vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true })
|
||||
-- end
|
||||
-- end,
|
||||
-- })
|
||||
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
callback = function(ev)
|
||||
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||||
if client:supports_method('textDocument/completion') then
|
||||
vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = false })
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Old on-attach
|
||||
-- vim.api.nvim_create_autocmd('LspAttach', {
|
||||
-- callback = function(ev)
|
||||
-- local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||||
--
|
||||
-- if client.server_capabilities.completionProvider then
|
||||
-- vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
|
||||
-- vim.bo[ev.buf].completefunc = "v:lua.vim.lsp.omnifunc"
|
||||
-- end
|
||||
--
|
||||
-- if client.server_capabilities.definitionProvider then
|
||||
-- vim.bo[ev.buf].tagfunc = "v:lua.vim.lsp.tagfunc"
|
||||
-- end
|
||||
--
|
||||
-- if client.server_capabilities.documentFormattingProvider then
|
||||
-- vim.bo[ev.buf].formatexpr = "v:lua.vim.lsp.formatexpr()"
|
||||
-- end
|
||||
-- end,
|
||||
-- })
|
|
@ -1,43 +0,0 @@
|
|||
local root_files = {
|
||||
"pyproject.toml",
|
||||
"setup.py",
|
||||
"setup.cfg",
|
||||
"requirements.txt",
|
||||
"Pipfile",
|
||||
"pyrightconfig.json",
|
||||
".git",
|
||||
}
|
||||
|
||||
local root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1])
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "python",
|
||||
callback = function()
|
||||
vim.lsp.start({
|
||||
name = "pylsp",
|
||||
cmd = { "pylsp", "--log-config", "/tmp/logging.json", },
|
||||
root_dir = root_dir,
|
||||
settings = {
|
||||
pylsp = {
|
||||
plugins = {
|
||||
pyflakes = {
|
||||
enabled = false,
|
||||
},
|
||||
pycodestyle = {
|
||||
enabled = false,
|
||||
},
|
||||
mccabe = {
|
||||
enabled = false,
|
||||
},
|
||||
flake8 = {
|
||||
enabled = true,
|
||||
},
|
||||
pylsp_mypy = {
|
||||
enabled = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
})
|
|
@ -1,28 +0,0 @@
|
|||
local bin_name = "pyright-langserver"
|
||||
local cmd = { bin_name, "--stdio", }
|
||||
|
||||
local root_files = {
|
||||
"pyproject.toml",
|
||||
"requirements.txt",
|
||||
".git",
|
||||
}
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "python",
|
||||
callback = function()
|
||||
vim.lsp.start({
|
||||
name = "pyright",
|
||||
cmd = cmd,
|
||||
root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]),
|
||||
settings = {
|
||||
python = {
|
||||
analysis = {
|
||||
autoSearchPaths = true,
|
||||
useLibraryCodeForTypes = true,
|
||||
diagnosticMode = "workspace",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
})
|
|
@ -1,28 +0,0 @@
|
|||
local bin_name = "ruff"
|
||||
local cmd = { bin_name, "server", }
|
||||
|
||||
local root_files = {
|
||||
"pyproject.toml",
|
||||
"requirements.txt",
|
||||
".git",
|
||||
}
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "python",
|
||||
callback = function()
|
||||
vim.lsp.start({
|
||||
name = "ruff-server",
|
||||
cmd = cmd,
|
||||
root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]),
|
||||
settings = {
|
||||
},
|
||||
})
|
||||
|
||||
-- vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
-- pattern = { "*.py", "*.pyi" },
|
||||
-- callback = function()
|
||||
-- vim.lsp.buf.format { timeout_ms = 2000 }
|
||||
-- end,
|
||||
-- })
|
||||
end,
|
||||
})
|
|
@ -1,44 +0,0 @@
|
|||
local bin_name = "rust-analyzer"
|
||||
local cmd = { bin_name }
|
||||
|
||||
local config = vim.fs.find("Cargo.toml", {
|
||||
upward = true,
|
||||
stop = vim.loop.os_homedir(),
|
||||
path = vim.fs.dirname(vim.api.nvim_buf_get_name(0)),
|
||||
})
|
||||
|
||||
if next(config) then
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "rust",
|
||||
callback = function()
|
||||
vim.lsp.start({
|
||||
name = "rust-analyzer",
|
||||
cmd = cmd,
|
||||
root_dir = config[1],
|
||||
settings = {
|
||||
["rust-analyzer"] = {
|
||||
checkOnSave = {
|
||||
command = "clippy",
|
||||
enable = true
|
||||
},
|
||||
diagnostics = {
|
||||
enable = false,
|
||||
},
|
||||
check = {
|
||||
command = "check",
|
||||
extraArgs = {"--all-features"}
|
||||
},
|
||||
},
|
||||
},
|
||||
capabilities = vim.lsp.protocol.make_client_capabilities(),
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
pattern = "*.rs",
|
||||
callback = function()
|
||||
vim.lsp.buf.format({ timeout_ms = 2000 })
|
||||
end,
|
||||
})
|
||||
end
|
|
@ -1,27 +0,0 @@
|
|||
local bin_name = "typescript-language-server"
|
||||
local cmd = { bin_name, "--stdio" }
|
||||
|
||||
local root_files = {
|
||||
"package.json",
|
||||
".git",
|
||||
}
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "typescript,javascript,javascriptreact,typescriptreact",
|
||||
callback = function()
|
||||
vim.lsp.start({
|
||||
name = "typescript-language-server",
|
||||
cmd = cmd,
|
||||
root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1]),
|
||||
settings = {
|
||||
init_options = {
|
||||
completionDisableFilterText = true,
|
||||
hostInfo = 'neovim',
|
||||
preferences = {
|
||||
includeCompletionsForModuleExports = false
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
})
|
|
@ -1,41 +0,0 @@
|
|||
local root_files = {
|
||||
"package.json",
|
||||
".git",
|
||||
}
|
||||
|
||||
local root_dir = vim.fs.dirname(vim.fs.find(root_files, { upward = true })[1])
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "typescript,javascript,javascriptreact,typescriptreact,vue",
|
||||
callback = function()
|
||||
-- vim.lsp.start({
|
||||
-- name = "typescript-language-server",
|
||||
-- cmd = { "typescript-language-server", "--stdio" },
|
||||
-- root_dir = root_dir,
|
||||
-- settings = {
|
||||
-- init_options = {
|
||||
-- completionDisableFilterText = true,
|
||||
-- plugins = {
|
||||
-- name = "@vue/typescript-plugin",
|
||||
-- location = "/home/mordae/.config/yarn/global/node_modules/@vue/language-server",
|
||||
-- languages = { "vue" }
|
||||
-- },
|
||||
-- },
|
||||
-- },
|
||||
-- })
|
||||
|
||||
vim.lsp.start({
|
||||
name = "volar",
|
||||
cmd = { "vue-language-server", "--stdio" },
|
||||
root_dir = root_dir,
|
||||
init_options = {
|
||||
typescript = {
|
||||
tsdk = "/home/mordae/.config/yarn/global/node_modules/typescript/lib",
|
||||
},
|
||||
vue = {
|
||||
hybridMode = false,
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
})
|
|
@ -1,14 +0,0 @@
|
|||
local function check_back_space()
|
||||
local col = vim.fn.col('.') - 1
|
||||
return col <= 0 or vim.fn.getline('.'):sub(col, col):match('%s')
|
||||
end
|
||||
|
||||
function tab_complete()
|
||||
if check_back_space() then
|
||||
return vim.api.nvim_replace_termcodes('<Tab>', true, false, true)
|
||||
end
|
||||
return vim.api.nvim_replace_termcodes('<C-p>', true, false, true)
|
||||
end
|
||||
|
||||
vim.api.nvim_set_keymap('i', '<Tab>', 'v:lua.tab_complete()', { expr = true, noremap = true })
|
||||
vim.api.nvim_set_keymap('i', '<S-Tab>', '<C-n>', { noremap = true })
|
122
lua/init.lua
122
lua/init.lua
|
@ -1,7 +1,7 @@
|
|||
-- Work around https://github.com/neovim/neovim/issues/21856
|
||||
vim.api.nvim_create_autocmd({ "VimLeave" }, {
|
||||
callback = function()
|
||||
vim.fn.jobstart('/bin/true', {detach=true})
|
||||
vim.fn.jobstart("/bin/true", { detach = true })
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -17,8 +17,8 @@ vim.diagnostic.config({
|
|||
|
||||
-- Open in floating window
|
||||
float = {
|
||||
source = 'always',
|
||||
border = 'shadow',
|
||||
source = "always",
|
||||
border = "shadow",
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -48,13 +48,14 @@ require("fzf-lua").setup {
|
|||
},
|
||||
}
|
||||
|
||||
vim.keymap.set('n', '<C-p>', '<cmd>lua require("fzf-lua").files()<CR>', { silent = true })
|
||||
vim.keymap.set('n', '<C-g>', '<cmd>lua require("fzf-lua").git_status()<CR>', { silent = true })
|
||||
vim.keymap.set('n', '<C-/>', '<cmd>lua require("fzf-lua").live_grep()<CR>', { silent = true })
|
||||
vim.keymap.set('n', '<C-\\>', '<cmd>lua require("fzf-lua").buffers()<CR>', { silent = true })
|
||||
vim.keymap.set('n', '<C-b>', '<cmd>lua require("fzf-lua").builtin()<CR>', { silent = true })
|
||||
vim.keymap.set("n", "<C-p>", "<cmd>lua require('fzf-lua').files()<CR>", { noremap = true, silent = true })
|
||||
vim.keymap.set("n", "<C-g>", "<cmd>lua require('fzf-lua').git_status()<CR>", { noremap = true, silent = true })
|
||||
vim.keymap.set("n", "<C-/>", "<cmd>lua require('fzf-lua').live_grep()<CR>", { noremap = true, silent = true })
|
||||
vim.keymap.set("n", "<C-\\>", "<cmd>lua require('fzf-lua').buffers()<CR>", { noremap = true, silent = true })
|
||||
vim.keymap.set("n", "<C-b>", "<cmd>lua require('fzf-lua').builtin()<CR>", { noremap = true, silent = true })
|
||||
vim.keymap.set("n", "ca", "<cmd>lua require('fzf-lua').lsp_code_actions()<CR>", { noremap = true, silent = true })
|
||||
|
||||
require('nvim-treesitter.configs').setup {
|
||||
require("nvim-treesitter.configs").setup {
|
||||
highlight = {
|
||||
enable = true,
|
||||
additional_vim_regex_highlighting = false,
|
||||
|
@ -65,4 +66,105 @@ require('nvim-treesitter.configs').setup {
|
|||
}
|
||||
}
|
||||
|
||||
require("config.init")
|
||||
require("nvim-format-buffer").setup({
|
||||
verbose = false,
|
||||
format_rules = {
|
||||
{ pattern = { "*.c", "*.h" }, command = "clang-format" },
|
||||
{
|
||||
pattern = { "*.js", "*.mjs", "*.ts", "*.mts", "*.cjs", "*.tsx", "*.vue", "*.css" },
|
||||
command = function()
|
||||
return "prettier --stdin-filepath " .. vim.api.nvim_buf_get_name(0)
|
||||
end,
|
||||
},
|
||||
{ pattern = { "*.sql" }, command = "pg_format --spaces=2 --wrap-limit=1000 --no-rcfile" },
|
||||
{ pattern = { "*.py", "*.pyi" }, command = "ruff check --select I --fix --silent - | ruff format -" }
|
||||
},
|
||||
})
|
||||
|
||||
require("vim.lsp.log").set_format_func(vim.inspect)
|
||||
-- vim.lsp.set_log_level("debug")
|
||||
|
||||
vim.keymap.set("n", "[d", "<cmd>lua vim.diagnostic.jump({count = -1, float = true})<CR>", { noremap = true, silent = true })
|
||||
vim.keymap.set("n", "]d", "<cmd>lua vim.diagnostic.jump({count = 1, float = true})<CR>", { noremap = true, silent = true })
|
||||
vim.keymap.set("n", "[e", "<cmd>lua vim.diagnostic.jump({count = -1, severity = vim.diagnostic.severity.ERROR, float = true})<CR>", { noremap = true, silent = true })
|
||||
vim.keymap.set("n", "]e", "<cmd>lua vim.diagnostic.jump({count = -1, severity = vim.diagnostic.severity.ERROR, float = true})<CR>", { noremap = true, silent = true })
|
||||
|
||||
vim.keymap.set("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", { noremap = true, silent = true })
|
||||
vim.keymap.set("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", { noremap = true, silent = true })
|
||||
vim.keymap.set("n", "gh", "<cmd>lua vim.lsp.buf.signature_help()<CR>", { noremap = true, silent = true })
|
||||
vim.keymap.set("n", "gI", "<cmd>lua vim.lsp.buf.implementation()<CR>", { noremap = true, silent = true })
|
||||
vim.keymap.set("n", "gt", "<cmd>lua vim.lsp.buf.type_definition()<CR>", { noremap = true, silent = true })
|
||||
|
||||
vim.keymap.set("n", "gl", "<cmd>lua vim.diagnostic.reset()<CR>", { noremap = true, silent = true })
|
||||
|
||||
vim.lsp.enable("pyright")
|
||||
vim.lsp.config("pyright", {})
|
||||
|
||||
vim.lsp.enable("ts_ls")
|
||||
vim.lsp.config("ts_ls", {
|
||||
init_options = {
|
||||
plugins = {
|
||||
{
|
||||
name = "@vue/typescript-plugin",
|
||||
location = "/home/mordae/.config/yarn/global/node_modules/@vue/typescript-plugin",
|
||||
languages = { "javascript", "typescript", "vue" },
|
||||
},
|
||||
},
|
||||
},
|
||||
filetypes = {
|
||||
"javascript",
|
||||
"typescript",
|
||||
"vue",
|
||||
},
|
||||
})
|
||||
|
||||
vim.lsp.enable("volar")
|
||||
vim.lsp.config("volar", {
|
||||
init_options = {
|
||||
typescript = {
|
||||
tsdk = "/home/mordae/.config/yarn/global/node_modules/typescript/lib",
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
vim.lsp.enable("clangd")
|
||||
vim.lsp.config("clangd", {
|
||||
cmd = {
|
||||
"clangd",
|
||||
"--background-index",
|
||||
"--suggest-missing-includes",
|
||||
"--enable-config",
|
||||
"--query-driver=/usr/lib64/ccache/*,/usr/bin/*",
|
||||
}
|
||||
})
|
||||
|
||||
vim.lsp.enable("ruff")
|
||||
vim.lsp.config("ruff", {})
|
||||
|
||||
vim.lsp.enable("rust_analyzer")
|
||||
vim.lsp.config("rust_analyzer", {})
|
||||
|
||||
-- Automatic completion triggering
|
||||
-- vim.api.nvim_create_autocmd("LspAttach", {
|
||||
-- callback = function(ev)
|
||||
-- local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||||
-- if client:supports_method("textDocument/completion") then
|
||||
-- vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true })
|
||||
-- end
|
||||
-- end,
|
||||
-- })
|
||||
|
||||
local function check_back_space()
|
||||
local col = vim.fn.col('.') - 1
|
||||
return col <= 0 or vim.fn.getline('.'):sub(col, col):match('%s')
|
||||
end
|
||||
|
||||
function tab_complete()
|
||||
if check_back_space() then
|
||||
return vim.api.nvim_replace_termcodes('<Tab>', true, false, true)
|
||||
end
|
||||
return vim.api.nvim_replace_termcodes('<C-p>', true, false, true)
|
||||
end
|
||||
|
||||
vim.api.nvim_set_keymap('i', '<Tab>', 'v:lua.tab_complete()', { expr = true, noremap = true })
|
||||
vim.api.nvim_set_keymap('i', '<S-Tab>', '<C-n>', { noremap = true })
|
||||
|
|
Loading…
Reference in a new issue