diff options
| author | Mike Vink <mike@pionative.com> | 2025-02-08 08:16:07 +0100 |
|---|---|---|
| committer | Mike Vink <mike@pionative.com> | 2025-02-08 08:16:07 +0100 |
| commit | 7d30d2272ef59166c1b382cab324a400a42d577d (patch) | |
| tree | 8f153f04818c7622b9cd2a3e1a18f9dcce1a1104 /.config/nvim/lua/my/events.lua | |
| parent | fd48011d2ef530b392df72e8685da4e8a2a54d1d (diff) | |
copy config
Diffstat (limited to '.config/nvim/lua/my/events.lua')
| -rw-r--r-- | .config/nvim/lua/my/events.lua | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/.config/nvim/lua/my/events.lua b/.config/nvim/lua/my/events.lua new file mode 100644 index 0000000..933ba19 --- /dev/null +++ b/.config/nvim/lua/my/events.lua @@ -0,0 +1,120 @@ +local lsp = require("my.lsp") +local oil = require("oil") +local lint = require("lint") +local event = vim.api.nvim_create_autocmd +local command = vim.api.nvim_create_user_command + +vim.api.nvim_create_augroup("my", {clear= true}) +vim.api.nvim_create_augroup("conf#events", {clear= true}) + +event( + "User", + {group= "conf#events", + pattern= { "ZoxideDirChanged" }, + callback= function() + vim.schedule(function() + oil.open(vim.fn.getcwd()) + end) + end}) + +event( + "BufReadPost", + {group= "conf#events", + pattern= { "*" }, + callback=function() + local pattern = "'\\s\\+$'" + vim.cmd("syn match TrailingWhitespace " .. pattern) + vim.cmd("hi link TrailingWhitespace IncSearch") + end}) + +event( + "BufWritePost", + {group= "conf#events", + pattern={ "*" }, + callback=function() + lint.try_lint() + vim.schedule(function() vim.diagnostic.setloclist({open= false}) end) + end}) + +local session_file = vim.fn.expand("~/.vimsession.vim") +event( + "VimLeave", + {group= "conf#events", + pattern= { "*" }, + callback=function() + vim.cmd("mksession! " .. session_file) + end}) + +event( + "LspAttach", + {group = "conf#events", + pattern = { "*" }, + callback = function(ev) + lsp.attach({ + client = vim.lsp.get_client_by_id(ev.data.client_id), + buf = ev.buf, + }) + end}) + +event( + "LspAttach", + {group = "conf#events", + pattern = { "*" }, + callback = function(ev) + lsp.attach({ + client = vim.lsp.get_client_by_id(ev.data.client_id), + buf = ev.buf, + }) + end}) + +-- filetypes + +event( + "FileType", { + group="conf#events", + pattern={ "go", "gomod", "gowork", "gotmpl" }, + callback=function(ev) + vim.lsp.start({ + name="gopls", + cmd={ "gopls" }, + root_dir=vim.fs.root(ev.buf, {"go.work", "go.mod", ".git"}) + }) + end, + }) + +event( + "FileType", { + group="conf#events", + pattern={ "python" }, + callback=function(ev) + vim.lsp.start({ + name="basedpyright", + cmd={ "basedpyright-langserver", "--stdio" }, + settings={ + basedpyright = { + analysis = { + autoSearchPaths = true, + diagnosticMode = "openFilesOnly", + useLibraryCodeForTypes = true, + autoImportCompletions = true, + inlayHints = { + variableTypes = true, + callArgumentNames = true, + functionReturnTypes = true, + genericTypes = true, + }, + }, + }, + }, + root_dir=vim.fs.root(ev.buf, { + 'pyproject.toml', + 'setup.py', + 'setup.cfg', + 'requirements.txt', + 'Pipfile', + 'pyrightconfig.json', + '.git', + }) + }) + end, + }) |
