summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.lua25
-rw-r--r--lsp/clangd.lua30
-rw-r--r--lsp/css.lua12
-rw-r--r--lsp/go.lua18
-rw-r--r--lsp/html.lua11
-rw-r--r--lsp/javascript.lua36
-rw-r--r--lsp/json.lua8
-rw-r--r--lsp/lua.lua24
-rw-r--r--lsp/markdown.lua6
-rw-r--r--lsp/odin.lua17
-rw-r--r--lsp/ruby.lua14
-rw-r--r--lsp/yaml.lua7
-rw-r--r--lsp/zig.lua9
-rw-r--r--lua/config/lsp.lua82
-rw-r--r--lua/config/plugins/completion.lua29
-rw-r--r--lua/config/plugins/lsp.lua106
16 files changed, 285 insertions, 149 deletions
diff --git a/init.lua b/init.lua
index 43b2eb7..c939de3 100644
--- a/init.lua
+++ b/init.lua
@@ -1,5 +1,6 @@
require("config.lazy")
require("config.terminal")
+require("config.lsp")
vim.g.have_nerd_font = true
vim.g.loaded_node_provider = 0
@@ -52,7 +53,6 @@ vim.opt.shiftwidth = 2
vim.keymap.set("n", "<ESC>", "<CMD>nohlsearch<CR>")
-vim.keymap.set("n", "<Leader>s", "<CMD>wall<CR>", { desc = "Save all changed buffers" })
vim.keymap.set("n", "<Leader>s", function()
vim.cmd[[wall]]
vim.notify("Changed buffers saved.")
@@ -74,18 +74,15 @@ vim.keymap.set("n", "<Leader>q", "<CMD>bprevious | bdelete #<CR>", { desc = "Clo
vim.keymap.set("n", "<A-p>", "<CMD>bprevious<CR>", { desc = "Previous buffer" })
vim.keymap.set("n", "<A-n>", "<CMD>bnext<CR>", { desc = "Next buffer" })
-vim.keymap.set("n", "<C-s>", "<CMD>silent! update | redraw<CR>", { desc = "Save" })
-vim.keymap.set({ "i", "x" }, "<C-s>", "<ESC><CMD>silent! update | redraw<CR>", { desc = "Save and go to Normal mode" })
-
vim.keymap.set("n", "<Leader>-", "<CMD>Oil<CR>", { desc = "Open Oil" })
-- Quickfix and location list navigation.
vim.keymap.set("n", "<C-d>", "<C-d>zz")
vim.keymap.set("n", "<C-u>", "<C-u>zz")
-vim.keymap.set("n", "<C-k>", "<cmd>cnext<CR>zz")
-vim.keymap.set("n", "<C-j>", "<cmd>cprev<CR>zz")
-vim.keymap.set("n", "<Leader>k", "<CMD>lnext<CR>zz")
-vim.keymap.set("n", "<Leader>j", "<CMD>lprev<CR>zz")
+vim.keymap.set("n", "<C-j>", "<cmd>cnext<CR>zz")
+vim.keymap.set("n", "<C-k>", "<cmd>cprev<CR>zz")
+vim.keymap.set("n", "<Leader>j", "<CMD>lnext<CR>zz", { desc = "Next location list item" })
+vim.keymap.set("n", "<Leader>k", "<CMD>lprev<CR>zz", { desc = "Previous location list item" })
vim.api.nvim_create_autocmd("TextYankPost", { desc = "Highlight when yanking text",
group = vim.api.nvim_create_augroup("highlight-yank", { clear = true }),
@@ -94,9 +91,9 @@ vim.api.nvim_create_autocmd("TextYankPost", { desc = "Highlight when yanking tex
end,
})
-vim.api.nvim_create_user_command("CopyPath", function()
- local path = vim.fn.expand("%:p")
- vim.fn.setreg("+", path)
- vim.notify("Copied '" .. path .. "' to the clipboard.")
-end, { desc = "Copy current buffer file path to the clipboard." })
-vim.keymap.set("n", "<C-c>", "<CMD>CopyPath<CR>")
+vim.keymap.set("n", "<C-c>", function()
+ local path = vim.fn.expand("%:~:.")
+ local line = vim.fn.line(".")
+ vim.fn.setreg("+", path .. ":" .. line)
+ vim.notify("Copied '" .. path .. "' line " .. line .. " to the clipboard.")
+end, { desc = 'Copy relative file path with current line number to clipboard.' })
diff --git a/lsp/clangd.lua b/lsp/clangd.lua
new file mode 100644
index 0000000..c2deb96
--- /dev/null
+++ b/lsp/clangd.lua
@@ -0,0 +1,30 @@
+return {
+ cmd = {
+ "clangd",
+ "--header-insertion=iwyu",
+ "--background-index",
+ "--clang-tidy",
+ "--log=verbose",
+ },
+ filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto" },
+ root_markers = {
+ ".clangd",
+ ".clang-tidy",
+ ".clang-format",
+ "compile_commands.json",
+ "compile_flags.txt",
+ "configure.ac",
+ "Makefile",
+ "CMakeLists.txt",
+ ".git",
+ },
+ single_file_support = true,
+ flags = {
+ debounce_text_changes = 20,
+ },
+ capabilities = {
+ textDocument = {
+ completion = { editsNearCursor = true }
+ },
+ }
+}
diff --git a/lsp/css.lua b/lsp/css.lua
new file mode 100644
index 0000000..01b4b77
--- /dev/null
+++ b/lsp/css.lua
@@ -0,0 +1,12 @@
+return {
+ cmd = { "vscode-css-language-server", "--stdio" },
+ filetypes = { "css", "scss", "less" },
+ root_markers = { "package.json", ".git" },
+ single_file_support = true,
+ init_options = { provideFormatter = true },
+ settings = {
+ css = { validate = true },
+ scss = { validate = true },
+ less = { validate = true },
+ },
+}
diff --git a/lsp/go.lua b/lsp/go.lua
new file mode 100644
index 0000000..e57d880
--- /dev/null
+++ b/lsp/go.lua
@@ -0,0 +1,18 @@
+return {
+ cmd = { "gopls" },
+ filetypes = { "go", "gomod", "gowork", "gosum" },
+ root_markers = { ".git" },
+ settings = {
+ autoformat = true,
+ gopls = {
+ analyses = {
+ unusedparams = true,
+ unusedwrite = true,
+ nilness = true,
+ },
+ gofumpt = true,
+ semanticTokens = true,
+ staticcheck = true,
+ },
+ },
+}
diff --git a/lsp/html.lua b/lsp/html.lua
new file mode 100644
index 0000000..f601246
--- /dev/null
+++ b/lsp/html.lua
@@ -0,0 +1,11 @@
+return {
+ cmd = { "vscode-html-language-server", "--stdio" },
+ filetypes = { "html" },
+ root_markers = { "package.json", ".git" },
+ single_file_support = true,
+ init_options = {
+ provideFormatter = true,
+ embeddedLanguages = { css = true, javascript = true },
+ configurationSection = { "html", "css", "javascript" },
+ },
+}
diff --git a/lsp/javascript.lua b/lsp/javascript.lua
new file mode 100644
index 0000000..6d8e9f8
--- /dev/null
+++ b/lsp/javascript.lua
@@ -0,0 +1,36 @@
+return {
+ cmd = {
+ "typescript-language-server",
+ "--stdio",
+ },
+ filetypes = { "javascript", "typescript" },
+ -- disable_formatting = true,
+ root_markers = { "yarn.lock", "tsconfig.json", "jsconfig.json", "package.json", ".git" },
+ single_file_support = true,
+
+ settings = {
+ javascript = {
+ inlayHints = {
+ includeInlayEnumMemberValueHints = true,
+ includeInlayFunctionLikeReturnTypeHints = true,
+ includeInlayFunctionParameterTypeHints = true,
+ includeInlayParameterNameHints = "all", -- "none" | "literals" | "all";
+ includeInlayParameterNameHintsWhenArgumentMatchesName = true,
+ includeInlayPropertyDeclarationTypeHints = true,
+ includeInlayVariableTypeHints = true,
+ },
+ },
+
+ typescript = {
+ inlayHints = {
+ includeInlayEnumMemberValueHints = true,
+ includeInlayFunctionLikeReturnTypeHints = true,
+ includeInlayFunctionParameterTypeHints = true,
+ includeInlayParameterNameHints = "all", -- "none" | "literals" | "all";
+ includeInlayParameterNameHintsWhenArgumentMatchesName = true,
+ includeInlayPropertyDeclarationTypeHints = true,
+ includeInlayVariableTypeHints = true,
+ },
+ },
+ },
+}
diff --git a/lsp/json.lua b/lsp/json.lua
new file mode 100644
index 0000000..8b2a8cf
--- /dev/null
+++ b/lsp/json.lua
@@ -0,0 +1,8 @@
+return {
+ cmd = { "vscode-json-language-server", "--stdio" },
+ filetypes = { "json", "jsonc" },
+ root_markers = { ".git" },
+ init_options = {
+ provideFormatter = true,
+ },
+}
diff --git a/lsp/lua.lua b/lsp/lua.lua
new file mode 100644
index 0000000..4d3e241
--- /dev/null
+++ b/lsp/lua.lua
@@ -0,0 +1,24 @@
+return {
+ cmd = { "lua-language-server" },
+ filetypes = { "lua" },
+ root_markers = { ".luarc.json" },
+ settings = {
+ Lua = {
+ runtime = {
+ version = "LuaJIT",
+ },
+ diagnostics = {
+ globals = {
+ "vim",
+ "require",
+ },
+ },
+ workspace = {
+ library = vim.api.nvim_get_runtime_file("", true),
+ },
+ telemetry = {
+ enable = false,
+ },
+ },
+ },
+}
diff --git a/lsp/markdown.lua b/lsp/markdown.lua
new file mode 100644
index 0000000..05fd268
--- /dev/null
+++ b/lsp/markdown.lua
@@ -0,0 +1,6 @@
+return {
+ cmd = { "marksman", "server" },
+ filetypes = { "markdown", "markdown.mdx" },
+ root_markers = { ".marksman.toml", ".git" },
+ single_file_support = true,
+}
diff --git a/lsp/odin.lua b/lsp/odin.lua
new file mode 100644
index 0000000..ee6ced4
--- /dev/null
+++ b/lsp/odin.lua
@@ -0,0 +1,17 @@
+return {
+ cmd = { "ols" },
+ filetypes = { "odin" },
+ root_markers = { "ols.json", ".git", "*.odin" },
+ single_file_support = true,
+ init_options = {
+ checker_args = "-strict-style",
+ init_options = {
+ schema = "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/odinfmt.schema.json",
+ checker_args = "-strict-style",
+ enable_semantic_tokens = false,
+ enable_document_symbols = true,
+ enable_hover = true,
+ enable_snippets = true,
+ },
+ },
+}
diff --git a/lsp/ruby.lua b/lsp/ruby.lua
new file mode 100644
index 0000000..07c64a5
--- /dev/null
+++ b/lsp/ruby.lua
@@ -0,0 +1,14 @@
+return {
+ cmd = {
+ vim.fn.expand("~/.local/share/nvim/mason/bin/solargraph"),
+ "stdio",
+ },
+ filetypes = { "ruby" },
+ root_markers = { "Gemfile", ".git" },
+ init_options = { formatting = true },
+ settings = {
+ solargraph = {
+ diagnostics = true,
+ },
+ },
+}
diff --git a/lsp/yaml.lua b/lsp/yaml.lua
new file mode 100644
index 0000000..3725843
--- /dev/null
+++ b/lsp/yaml.lua
@@ -0,0 +1,7 @@
+return {
+ cmd = {
+ "yaml-language-server",
+ "--stdio",
+ },
+ filetypes = { "yaml" },
+}
diff --git a/lsp/zig.lua b/lsp/zig.lua
new file mode 100644
index 0000000..c48b2a4
--- /dev/null
+++ b/lsp/zig.lua
@@ -0,0 +1,9 @@
+return {
+ cmd = { "zls" },
+ filetypes = { "zig" },
+ root_markers = { "build.zig" },
+ single_file_support = true,
+ settings = {
+ autoformat = true,
+ },
+}
diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua
new file mode 100644
index 0000000..ebb779f
--- /dev/null
+++ b/lua/config/lsp.lua
@@ -0,0 +1,82 @@
+vim.o.completeopt = "menuone,noselect,noinsert,popup,fuzzy"
+
+vim.diagnostic.config({
+ underline = true,
+ virtual_lines = { current_line = true },
+ signs = {
+ text = {
+ [vim.diagnostic.severity.ERROR] = "",
+ [vim.diagnostic.severity.WARN] = "",
+ [vim.diagnostic.severity.INFO] = "",
+ [vim.diagnostic.severity.HINT] = "",
+ },
+ },
+})
+
+vim.lsp.config("*", {
+ capabilities = {
+ textDocument = {
+ semanticTokens = {
+ multilineTokenSupport = true,
+ },
+ completion = {
+ completionItem = {
+ snippetSupport = true,
+ commitCharactersSupport = true,
+ deprecatedSupport = true,
+ preselectSupport = true,
+ insertReplaceSupport = true,
+ labelDetailsSupport = true,
+ resolveSupport = {
+ properties = {
+ "documentation",
+ "detail",
+ "additionalTextEdits",
+ },
+ },
+ },
+ },
+ },
+ },
+
+ on_attach = function(client, bufnr)
+ if client:supports_method('textDocument/completion') then
+ vim.lsp.completion.enable(true, client.id, bufnr, { autotrigger = true })
+ vim.keymap.set("i", "<M-Space>", vim.lsp.completion.get, { buffer = bufnr })
+ end
+
+ if client:supports_method('textDocument/definition') then
+ vim.keymap.set("n", "grd", vim.lsp.buf.definition, { desc = "Jumps to definition", buffer = bufnr })
+ end
+ if client:supports_method('textDocument/declaration') then
+ vim.keymap.set("n", "grD", vim.lsp.buf.declaration, { desc = "Jumps to declaration", buffer = bufnr })
+ end
+
+ if client:supports_method("textDocument/inlayHint") then
+ vim.lsp.inlay_hint.enable(true, { bufnr })
+ end
+
+ if client:supports_method("textDocument/formatting") then
+ local description = "LSP: Formats the current buffer"
+ local format_buffer = function()
+ vim.lsp.buf.format({ async = true, buffer = bufnr })
+ end
+ vim.keymap.set("n", "<Leader>cf", format_buffer, { desc = description })
+ vim.keymap.set("v", "<C-f>", format_buffer, { desc = description })
+ end
+ end,
+})
+
+vim.lsp.enable({
+ "clangd",
+ "css",
+ "go",
+ "html",
+ "javascript",
+ "json",
+ "lua",
+ "markdown",
+ "odin",
+ "ruby",
+ "yaml",
+})
diff --git a/lua/config/plugins/completion.lua b/lua/config/plugins/completion.lua
deleted file mode 100644
index f8cc602..0000000
--- a/lua/config/plugins/completion.lua
+++ /dev/null
@@ -1,29 +0,0 @@
-return {
- {
- "saghen/blink.cmp",
- dependencies = "rafamadriz/friendly-snippets",
-
- version = "v0.13.1",
-
- opts = {
- keymap = {
- preset = "default",
- -- The default `<C-Space>` is my tmux prefix.
- ["<M-Space>"] = { "show", "show_documentation", "hide_documentation" },
- },
-
- appearance = {
- use_nvim_cmp_as_default = true,
- nerd_font_variant = 'mono'
- },
-
- sources = {
- min_keyword_length = 2,
- default = { "lsp", "path", "snippets", "buffer" },
- },
-
- signature = { enabled = true },
- },
- opts_extend = { "sources.default" }
- }
-}
diff --git a/lua/config/plugins/lsp.lua b/lua/config/plugins/lsp.lua
deleted file mode 100644
index 16e785d..0000000
--- a/lua/config/plugins/lsp.lua
+++ /dev/null
@@ -1,106 +0,0 @@
-return {
- {
- "neovim/nvim-lspconfig",
- dependencies = {
- "saghen/blink.cmp",
- },
- opts = {
- servers = {
- clangd = {
- cmd = {
- "clangd",
- "--header-insertion=iwyu",
- "--background-index",
- "--clang-tidy",
- "--log=verbose",
- },
- filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto" },
- single_file_support = true,
- },
- cssls = {},
- html = {},
- jsonls = {},
- lua_ls = {
- settings = {
- Lua = {
- runtime = {
- version = "LuaJIT",
- },
- diagnostics = {
- globals = {
- "vim",
- "require",
- },
- },
- workspace = {
- library = vim.api.nvim_get_runtime_file("", true),
- },
- telemetry = {
- enable = false,
- },
- },
- },
- },
- marksman = {},
- solargraph = {
- cmd = {
- vim.fn.expand('~/.local/share/nvim/mason/bin/solargraph'),
- 'stdio',
- },
- },
- ts_ls = {},
- },
- },
-
- config = function(_, opts)
- local lspconfig = require("lspconfig")
- local blink = require("blink.cmp")
-
- for server, config in pairs(opts.servers) do
- config.capabilities = blink.get_lsp_capabilities()
- lspconfig[server].setup(config)
- end
-
- vim.api.nvim_create_autocmd("LspAttach", {
- callback = function(args)
- local client = vim.lsp.get_client_by_id(args.data.client_id)
- if not client then return end
-
- vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "Jumps to definition", buffer = args.buf })
- vim.keymap.set("n", "gD", vim.lsp.buf.declaration, { desc = "Jumps to declaration", buffer = args.buf })
- vim.keymap.set("n", "gi", vim.lsp.buf.implementation, { desc = "Lists all implementations", buffer = args.buf })
-
- vim.keymap.set("n", "<Leader>cf", function() vim.lsp.buf.format({ async = true, buffer = args.buf }) end,
- { desc = "Formats a buffer", buffer = args.buf })
- vim.keymap.set("v", "<C-f>", function() vim.lsp.buf.format({ async = true, buffer = args.buf }) end,
- { desc = "Formats a buffer", buffer = args.buf })
-
- -- Disabled, kept temporarily here just for reference
- if false and vim.bo.filetype == "lua" then
- if client.supports_method("textDocument/formatting") then
- vim.api.nvim_create_autocmd("BufWritePre", {
- buffer = args.buf,
- callback = function()
- vim.lsp.buf.format({ bufnr = args.buf, id = client.id })
- end,
- })
- end
- end
- end
- })
-
- vim.diagnostic.config({
- underline = true,
- virtual_text = { prefix = " ●", },
- signs = {
- text = {
- [vim.diagnostic.severity.ERROR] = "",
- [vim.diagnostic.severity.WARN] = "",
- [vim.diagnostic.severity.INFO] = "",
- [vim.diagnostic.severity.HINT] = "",
- },
- },
- })
- end,
- },
-}