owenrusk.dev

dotfiles

shell, editor, ssh.

git clone https://owenrusk.dev/dotfiles.git

commit cf0dd5d529210b0b32983c3e7b28cebb8cab68a3
parent c7f4a07853bb3365d30e623cd0bcb6e734dbaca1
author Owen Rusk <owen@papermothgames.com>
date   2024-03-11 16:05:33 -0500
nvim: pyright for python
nvim/init.lua+1-0
nvim/lua/owen/lsp.lua+31-0
diff --git a/nvim/init.lua b/nvim/init.lua
index a05f9cf..01339e1 100644
--- a/nvim/init.lua
+++ b/nvim/init.lua
@@ -1,3 +1,4 @@
 -- no plugins. neovim does enough on its own.
 require("owen.options")
 require("owen.keymaps")
+require("owen.lsp")
diff --git a/nvim/lua/owen/lsp.lua b/nvim/lua/owen/lsp.lua
new file mode 100644
index 0000000..3309698
--- /dev/null
+++ b/nvim/lua/owen/lsp.lua
@@ -0,0 +1,31 @@
+-- servers come from the system, not from neovim.
+local function root(buf, markers)
+  local name = vim.api.nvim_buf_get_name(buf)
+  local found = vim.fs.find(markers, { upward = true, path = vim.fs.dirname(name) })[1]
+  return found and vim.fs.dirname(found) or nil
+end
+
+vim.api.nvim_create_autocmd("FileType", {
+  pattern = "python",
+  callback = function(args)
+    vim.lsp.start({
+      name = "pyright",
+      cmd = { "pyright-langserver", "--stdio" },
+      root_dir = root(args.buf, { "pyproject.toml", "setup.py", ".git" }),
+      settings = { python = { analysis = { typeCheckingMode = "standard" } } },
+    })
+  end,
+})
+
+vim.api.nvim_create_autocmd("LspAttach", {
+  callback = function(args)
+    local opts = { buffer = args.buf }
+    vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
+    vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
+    vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
+    vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
+    vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts)
+  end,
+})
+
+vim.keymap.set("n", "<leader>d", vim.diagnostic.open_float)