summaryrefslogtreecommitdiff
path: root/after/plugin
diff options
context:
space:
mode:
authortalha <talha@talhaamir.xyz>2024-04-23 20:04:41 +0500
committertalha <talha@talhaamir.xyz>2024-04-23 20:04:41 +0500
commit440cc9de7021c7059523b6dafbf02f247291f160 (patch)
tree60b5c23063ea53f6a315fa9ce15c609ec8719e8e /after/plugin
parentbca3805fdea8f92253a3710dd01f4c8d9908c2ee (diff)
Added notes, updated keymaps
Diffstat (limited to 'after/plugin')
-rw-r--r--after/plugin/lsp.lua48
1 files changed, 44 insertions, 4 deletions
diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua
index 63c369f..b0977c1 100644
--- a/after/plugin/lsp.lua
+++ b/after/plugin/lsp.lua
@@ -1,10 +1,42 @@
local lsp = require('lsp-zero').preset({})
+-- @notes on Lsp and Cmp configs here:
+--[[
+
+# LSP
+1. Renamed the keymaps to what I use
+2. Added a custom handler for formatting files.
+ It checks the explicitly defined language servers passed and if they allow formatting, only then will it attempt
+ to format the buffer
+3. Since python lsp does not come with formatting, we need to handle that separately
+
+## Formatting
+1. This is handled in 2 ways:
+ a. By the lsp using vlf (for vl(LSP)f(Format))
+ b. By some tool, then defined in the specific language server by using vcf (for vc(Custom)f(Format)
+
+# Complete
+Completion is done by nvim-cmp. The setup for that does a few things.
+1. Defines the sources to use for autocompletion:
+ a. LSP server
+ b. nvim-lua: only active in lua file I think
+ c. buffer: uses the current file for auto-completion (similar to default nvim behavior)
+2. By default it pops up a list for auto-completion, we have that disabled.
+3. When having auto-complete disabled, it takes extra steps to trigger autocomplete, due
+ to this we need to have it preselect the first item upon triggering autocomplete.
+4. We define some custom mappings
+--]]
+
+local function allow_format(servers)
+ return function(client) return vim.tbl_contains(servers, client.name) end
+end
+
lsp.on_attach(function(client, bufnr)
-- see :help lsp-zero-keybindings
-- to learn the available actions
local opts = {buffer = bufnr, remap = false}
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
+ vim.keymap.set("n", "gD", function() vim.lsp.buf.declaration() end, opts)
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
@@ -13,16 +45,22 @@ lsp.on_attach(function(client, bufnr)
vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, opts)
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts)
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
- vim.keymap.set("n", "<leader>vbf", function() vim.lsp.buf.format() end, opts)
- vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, {buffer = bfnr})
+ vim.keymap.set("n", "<leader>vlf", function()
+ vim.lsp.buf.format({
+ async = false,
+ timeout_ms = 10000,
+ filter = allow_format({'rust_analyzer', 'tsserver'}),
+ })
+ end, opts)
+ vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
end)
-- specific setup for python as it's lsp does not come with formatting
require('lspconfig').pyright.setup({
single_file_support = false,
on_attach = function(client, bufnr)
- local opts = {buffer = bfnr}
- vim.keymap.set({'n', 'x'}, '<leader>vpf', function()
+ local opts = {buffer = bfnr, remap = false}
+ vim.keymap.set({'n', 'x'}, '<leader>vcf', function()
local filename = GetCurrFileName()
vim.cmd(":silent !autopep8 -i " .. filename)
vim.cmd(":silent !isort " .. filename)
@@ -32,6 +70,8 @@ require('lspconfig').pyright.setup({
lsp.setup()
+-- @todo: Look at luasnip and why I would require it
+
local cmp = require('cmp')
local cmp_action = require('lsp-zero').cmp_action()