dotfiles
shell, editor, ssh.
git clone https://owenrusk.dev/dotfiles.git
dotfiles / nvim/lua/owen/lsp.lua -rw-r--r-- · 1791 bytes
1 -- servers come from the system, not from neovim.
2 vim.lsp.config("pyright", {
3 cmd = { "pyright-langserver", "--stdio" },
4 filetypes = { "python" },
5 root_markers = { "pyproject.toml", "setup.py", ".git" },
6 settings = { python = { analysis = { typeCheckingMode = "standard" } } },
7 })
8
9 vim.lsp.config("ruff", {
10 cmd = { "ruff", "server" },
11 filetypes = { "python" },
12 root_markers = { "pyproject.toml", "ruff.toml", ".git" },
13 })
14
15 vim.lsp.config("lua_ls", {
16 cmd = { "lua-language-server" },
17 filetypes = { "lua" },
18 root_markers = { ".luarc.json", ".git" },
19 settings = {
20 Lua = {
21 runtime = { version = "LuaJIT" },
22 workspace = { library = { vim.env.VIMRUNTIME } },
23 },
24 },
25 })
26
27 vim.lsp.enable({ "pyright", "ruff", "lua_ls" })
28
29 vim.api.nvim_create_autocmd("LspAttach", {
30 callback = function(args)
31 local client = vim.lsp.get_client_by_id(args.data.client_id)
32 -- pyright answers hover better
33 if client and client.name == "ruff" then
34 client.server_capabilities.hoverProvider = false
35 end
36 -- completion on ctrl-x ctrl-o, when i ask. not a popup on every key.
37 if client and client:supports_method("textDocument/completion") then
38 vim.lsp.completion.enable(true, client.id, args.buf, { autotrigger = false })
39 end
40 -- grn, grr, gra and K come with 0.11. gd doesn't.
41 vim.keymap.set("n", "gd", vim.lsp.buf.definition, { buffer = args.buf })
42 end,
43 })
44
45 vim.api.nvim_create_autocmd("BufWritePre", {
46 pattern = "*.py",
47 callback = function(args)
48 vim.lsp.buf.format({ bufnr = args.buf, name = "ruff", timeout_ms = 1000 })
49 end,
50 })
51
52 -- 0.11 turned virtual text off. i want it.
53 vim.diagnostic.config({
54 virtual_text = { spacing = 2 },
55 severity_sort = true,
56 })
57
58 vim.keymap.set("n", "<leader>d", vim.diagnostic.open_float)