Skip to content

Commit ac94769

Browse files
committed
Even more lsp configuration for nvim
1 parent ce336e3 commit ac94769

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

nvim/.config/nvim/.luarc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"runtime.version": "LuaJIT",
3+
"runtime.path": [
4+
"lua/?.lua",
5+
"lua/?/init.lua"
6+
],
7+
"diagnostics.globals": ["vim"],
8+
"workspace.checkThirdParty": false,
9+
"workspace.library": [
10+
"$VIMRUNTIME"
11+
]
12+
}

nvim/.config/nvim/plugin/lsp.lua

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
-- Reserve a space in the gutter to avoid layout shift
2+
vim.opt.signcolumn = "yes"
3+
4+
-- Add cmp_nvim_lsp capabilities settings to lspconfig
5+
-- This should be executed before you configure any language server
6+
local lspconfig_defaults = require("lspconfig").util.default_config
7+
lspconfig_defaults.capabilities =
8+
vim.tbl_deep_extend("force", lspconfig_defaults.capabilities, require("cmp_nvim_lsp").default_capabilities())
9+
10+
-- Configuration for when a language server is active in the file
11+
vim.api.nvim_create_autocmd("LspAttach", {
12+
desc = "LSP actions",
13+
callback = function(event)
14+
local opts = { buffer = event.buf }
15+
16+
vim.keymap.set("n", "K", "<cmd>lua vim.lsp.buf.hover()<cr>", opts)
17+
vim.keymap.set("n", "gd", "<cmd>lua vim.lsp.buf.definition()<cr>", opts)
18+
vim.keymap.set("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<cr>", opts)
19+
vim.keymap.set("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<cr>", opts)
20+
vim.keymap.set("n", "go", "<cmd>lua vim.lsp.buf.type_definition()<cr>", opts)
21+
vim.keymap.set("n", "gr", "<cmd>lua vim.lsp.buf.references()<cr>", opts)
22+
vim.keymap.set("n", "gs", "<cmd>lua vim.lsp.buf.signature_help()<cr>", opts)
23+
vim.keymap.set("n", "<F2>", "<cmd>lua vim.lsp.buf.rename()<cr>", opts)
24+
vim.keymap.set({ "n", "x" }, "<F3>", "<cmd>lua vim.lsp.buf.format({async = true})<cr>", opts)
25+
vim.keymap.set("n", "<F4>", "<cmd>lua vim.lsp.buf.code_action()<cr>", opts)
26+
end,
27+
})
28+
29+
local cmp = require("cmp")
30+
31+
cmp.setup({
32+
sources = {
33+
{ name = "nvim_lsp" },
34+
},
35+
window = {
36+
completion = cmp.config.window.bordered(),
37+
documentation = cmp.config.window.bordered(),
38+
},
39+
mapping = cmp.mapping.preset.insert({
40+
-- Carriage return complete (usually Enter)
41+
["<CR>"] = cmp.mapping.confirm({ select = true }),
42+
-- Simple tab complete
43+
["<Tab>"] = cmp.mapping(function(fallback)
44+
local col = vim.fn.col(".") - 1
45+
46+
if cmp.visible() then
47+
cmp.select_next_item({ behavior = "select" })
48+
elseif col == 0 or vim.fn.getline("."):sub(col, col):match("%s") then
49+
fallback()
50+
else
51+
cmp.complete()
52+
end
53+
end, { "i", "s" }),
54+
55+
-- Go to previous item
56+
["<S-Tab>"] = cmp.mapping.select_prev_item({ behavior = "select" }),
57+
}),
58+
preselect = "item",
59+
completion = {
60+
completeopt = "menu,menuone,noinsert",
61+
},
62+
})
63+
64+
-- Borders for help windows
65+
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" })
66+
67+
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" })
68+
69+
-- Vim scripting
70+
require("lspconfig").lua_ls.setup({})
71+
72+
-- Web development
73+
require("lspconfig").cssls.setup({})
74+
require("lspconfig").jsonls.setup({})
75+
require("lspconfig").html.setup({})
76+
require("lspconfig").denols.setup({})
77+
78+
-- LaTeX
79+
require("lspconfig").texlab.setup({
80+
settings = {
81+
texlab = {
82+
build = {
83+
args = { "-pdf", "-interaction=nonstopmode", "-synctex=1", "-outdir=out", "%f" },
84+
},
85+
chktex = {
86+
onOpenAndSave = true,
87+
},
88+
},
89+
},
90+
})
91+
92+
vim.g.markdown_fenced_languages = {
93+
"ts=typescript",
94+
}

0 commit comments

Comments
 (0)