nvim 0.13 lsp
lsp ?
I am assuming you dont try out new langs on a daily and dont need mason.
-
First ensure you have downloaded the lsp for your lang of choice.
-
Then, go to: https://github.com/...lspconfig.nvim go into the /lsp directory and find the file corresponding to the name of your lsp. So for rust you would find the rust-analyzer file for go you would find gopls and so on.
-
Then copy the contents of that file into ~/.config/nvim/lsp/<YOUR_FILE_HERE> name this file accoring to the language its for (rust.lua, go.lua, etc,.).
-
Then go into your init.lua, (this is the entry point for nvim) usually at ~/.config/nvim/init.lua and write:
vim.lsp.enable({
'rust'
-- 'lua' THESE ARE THE FILE NAMES IN THE LSP DIRECTORY
-- 'go'
})
then below that add:
-- LspAttatch just means that whenever a lsp is being used
--run the stuff inside this block
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("lsp", { clear = true }),
callback = function(args)
local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
local bufnr = args.buf
--this is a thing for specific lsp i lwk dont know why i even have this
if client then client.server_capabilities.semanticTokensProvider = nil end
local function map(mode, lhs, rhs, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, lhs, rhs, opts)
end
-- START: This is where you define the keymaps,
--these are technicaly all set by default
--but I find setting then with somthing
--comon like "gr" and then the specific command
--makes it easier to remmeber.
-- there are more but you can figure that out yourself.
-- Also shift + k lets you see documentation of the thing
--your cursor is on
map('n', 'grD', vim.lsp.buf.declaration)
map('n', 'gri', vim.lsp.buf.implementation)
map('n', 'grd', vim.lsp.buf.definition)
map('n', 'grn', vim.lsp.buf.rename)
-- END
-- START: This block lets you format on save
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
callback = function()
vim.lsp.buf.format { async = false, id = client.id }
end,
})
-- END
end,
})
you now should be getting lsp working!