summaryrefslogtreecommitdiffstats
path: root/lua/core/lsp
diff options
context:
space:
mode:
authorSquibid <me@zacharyscheiman.com>2025-05-31 03:32:58 -0400
committerSquibid <me@zacharyscheiman.com>2025-05-31 03:32:58 -0400
commite830931ff421e4380d5de8b1926842000ba9be34 (patch)
tree207584548026db649bc6ab21df3b41b71ebfd830 /lua/core/lsp
parentef678f31fdf24c0e6c4eca9a13ad9f63a53447b9 (diff)
downloadnvim-master.tar.gz
nvim-master.tar.bz2
nvim-master.zip
Diffstat (limited to '')
-rw-r--r--lua/core/lsp.lua84
-rw-r--r--lua/core/lsp/functions.lua100
2 files changed, 84 insertions, 100 deletions
diff --git a/lua/core/lsp.lua b/lua/core/lsp.lua
new file mode 100644
index 0000000..fd03a42
--- /dev/null
+++ b/lua/core/lsp.lua
@@ -0,0 +1,84 @@
+---@diagnostic disable: param-type-mismatch
+
+local misc = require("core.misc")
+local map, auto = misc.map, misc.auto
+local popup_opts, hover_opts, signature_opts, list_opts, location_opts
+
+-- TODO: find a way to make the qflist current item be the one closest to the
+-- cursor whenever we open it
+local function on_list(opts)
+ vim.fn.setqflist({}, "r", opts)
+ if #opts.items > 1 then
+ vim.cmd.copen()
+ end
+ vim.cmd(".cc! 1")
+end
+
+-- disable the default keybinds (they're bad)
+for _, bind in ipairs({ "grn", "gra", "gri", "grr" }) do
+ pcall(vim.keymap.del, "n", bind)
+end
+
+local M = {}
+
+--- setup vim lsp options
+function M.setup()
+ -- options for different lsp functions
+ popup_opts = { border = vim.g.border_style }
+ hover_opts = vim.tbl_deep_extend("force", popup_opts, {})
+ signature_opts = vim.tbl_deep_extend("force", popup_opts, {})
+ list_opts = { on_list = on_list }
+ location_opts = vim.tbl_deep_extend("force", list_opts, {})
+
+ -- confgiure lsp
+ vim.diagnostic.config {
+ virtual_text = false,
+ virtual_lines = {
+ current_line = true
+ },
+ update_in_insert = false,
+ underline = true,
+ severity_sort = true,
+ signs = {
+ text = {
+ [vim.diagnostic.severity.ERROR] = "x",
+ [vim.diagnostic.severity.WARN] = "!",
+ [vim.diagnostic.severity.INFO] = "i",
+ [vim.diagnostic.severity.HINT] = "h"
+ }
+ }
+ }
+
+ -- set default capabilities and attach function
+ vim.lsp.config['*'] = {
+ capabilities = vim.lsp.protocol.make_client_capabilities()
+ }
+
+ -- make my attach function always run
+ auto("LspAttach", {
+ callback = function(event)
+ local opts = { buffer = event.buf, nowait = true }
+
+ -- LSP actions
+ map("n", "K", function() vim.lsp.buf.hover(hover_opts) end, opts)
+ map("n", "gd", function() vim.lsp.buf.definition(location_opts) end, opts)
+ map("n", "gD", function() vim.lsp.buf.declaration(location_opts) end, opts)
+ map("n", "gi", function() vim.lsp.buf.implementation(location_opts) end, opts)
+ map("n", "gy", function() vim.lsp.buf.type_definition(location_opts) end, opts)
+ map("n", "gr", function() vim.lsp.buf.references(nil, list_opts) end, opts)
+ map("n", "<S-Tab>", function() vim.lsp.buf.signature_help(signature_opts) end, opts)
+ map("n", { "<leader>r", "<F2>" }, vim.lsp.buf.rename, opts)
+ map("n", { "gA", "<F4>" }, vim.lsp.buf.code_action, opts)
+
+ -- Diagnostics
+ map("n", "[d", function()
+ vim.diagnostic.jump({ count = -1 })
+ end, opts)
+ map("n", "]d", function()
+ vim.diagnostic.jump({ count = 1 })
+ end, opts)
+ end
+ })
+end
+
+return M
diff --git a/lua/core/lsp/functions.lua b/lua/core/lsp/functions.lua
deleted file mode 100644
index 4591205..0000000
--- a/lua/core/lsp/functions.lua
+++ /dev/null
@@ -1,100 +0,0 @@
-local misc = require("core.misc")
-local map, auto = misc.map, misc.auto
-
-local M = {}
-
--- TODO: find a way to make the qflist current item be the one closest to the
--- cursor whenever we open it
-local function on_list(opts)
- vim.fn.setqflist({}, "r", opts)
- if #opts.items > 1 then
- vim.cmd.copen()
- end
- vim.cmd(".cc! 1")
-end
-
----@type vim.lsp.util.open_floating_preview.Opts
-local popup_opts = {
- border = vim.g.border_style
-}
----@type vim.lsp.buf.hover.Opts
----@diagnostic disable-next-line: assign-type-mismatch
-local hover_opts = vim.tbl_deep_extend("force", popup_opts, {})
-
----@type vim.lsp.buf.signature_help.Opts
----@diagnostic disable-next-line: assign-type-mismatch
-local signature_opts = vim.tbl_deep_extend("force", popup_opts, {})
-
----@type vim.lsp.ListOpts
-local list_opts = {
- on_list = on_list
-}
-
----@type vim.lsp.LocationOpts
----@diagnostic disable-next-line: assign-type-mismatch
-local location_opts = vim.tbl_deep_extend("force", list_opts, {})
-
--- disable the default keybinds (they're bad)
-for _, bind in ipairs({ "grn", "gra", "gri", "grr" }) do
- pcall(vim.keymap.del, "n", bind)
-end
-
---- setup basic options on lsp attach
----@param bufnr number buffer number
-local function attach(bufnr)
- local opts = { buffer = bufnr, nowait = true }
-
- -- LSP actions
- map("n", "K", function() vim.lsp.buf.hover(hover_opts) end, opts)
- map("n", "gd", function() vim.lsp.buf.definition(location_opts) end, opts)
- map("n", "gD", function() vim.lsp.buf.declaration(location_opts) end, opts)
- map("n", "gi", function() vim.lsp.buf.implementation(location_opts) end, opts)
- map("n", "gy", function() vim.lsp.buf.type_definition(location_opts) end, opts)
- map("n", "gr", function() vim.lsp.buf.references(nil, list_opts) end, opts)
- map("n", "<S-Tab>", function() vim.lsp.buf.signature_help(signature_opts) end, opts)
- map("n", { "<leader>r", "<F2>" }, vim.lsp.buf.rename, opts)
- map("n", { "gA", "<F4>" }, vim.lsp.buf.code_action, opts)
-
- -- Diagnostics
- map("n", "[d", function()
- vim.diagnostic.jump({ count = -1 })
- end, opts)
- map("n", "]d", function()
- vim.diagnostic.jump({ count = 1 })
- end, opts)
-end
-
---- setup vim lsp options
-function M.setup()
- vim.diagnostic.config {
- virtual_text = false,
- virtual_lines = {
- current_line = true
- },
- update_in_insert = false,
- underline = true,
- severity_sort = true,
- signs = {
- text = {
- [vim.diagnostic.severity.ERROR] = "x",
- [vim.diagnostic.severity.WARN] = "!",
- [vim.diagnostic.severity.INFO] = "i",
- [vim.diagnostic.severity.HINT] = "h"
- }
- }
- }
-
- -- set default capabilities and attach function
- vim.lsp.config['*'] = {
- capabilities = vim.lsp.protocol.make_client_capabilities()
- }
-
- -- make my attach function always run
- auto("LspAttach", {
- callback = function(event)
- attach(event.buf)
- end
- })
-end
-
-return M