Skip to content

Commit 937e452

Browse files
committed
language server protocol has been added...
- [ Plugins Added ]: - cmp-nvim-lsp: bridge for nvim-lspconfig and nvim-cmp. - nvim-lspconfig: quick setup for builtin lsp. - mason: package manager for lsp. - mason-lspconfig: bridge for mason and nvim-lspconfig. - now CTRL+f will used to fold all codes in one shortcut key. - now CTRL+j will used to unfold all codes in one shortcut key. - Quit all shortcut has been shifted from CTRL+Shift+q to ALT+q in NormalMode.
1 parent 901385d commit 937e452

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

lazy-lock.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"bufferline.nvim": { "branch": "main", "commit": "73540cb95f8d95aa1af3ed57713c6720c78af915" },
44
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
55
"cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" },
6+
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
67
"cmp-nvim-lsp-signature-help": { "branch": "main", "commit": "3d8912ebeb56e5ae08ef0906e3a54de1c66b92f1" },
78
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
89
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
@@ -11,8 +12,11 @@
1112
"indent-blankline.nvim": { "branch": "master", "commit": "3d08501caef2329aba5121b753e903904088f7e6" },
1213
"lazy.nvim": { "branch": "main", "commit": "758bb5de98b805acc5eeed8cdc8ac7f0bc4b0b86" },
1314
"lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" },
15+
"mason-lspconfig.nvim": { "branch": "main", "commit": "9ae570e206360e47d30b4c35a4550c165f4ea7b7" },
16+
"mason.nvim": { "branch": "main", "commit": "49ff59aded1047a773670651cfa40e76e63c6377" },
1417
"nvim-autopairs": { "branch": "master", "commit": "14e97371b2aab6ee70054c1070a123dfaa3e217e" },
1518
"nvim-cmp": { "branch": "main", "commit": "24122371810089d390847d8ba66325c1f1aa64c0" },
19+
"nvim-lspconfig": { "branch": "master", "commit": "a27179f56c6f98a4cdcc79ee2971b514815a4940" },
1620
"nvim-tree.lua": { "branch": "master", "commit": "78c4c083ed5d47e7fab7627d78ce33d3bcfb88f0" },
1721
"nvim-web-devicons": { "branch": "master", "commit": "5b9067899ee6a2538891573500e8fd6ff008440f" }
1822
}

lua/plugins/lsp_config.lua

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
return {
2+
"neovim/nvim-lspconfig",
3+
event = { "BufReadPre", "BufNewFile" },
4+
dependencies = {
5+
"williamboman/mason.nvim",
6+
"williamboman/mason-lspconfig.nvim",
7+
"hrsh7th/cmp-nvim-lsp",
8+
},
9+
config = function()
10+
-- plugins localization --
11+
local lspconfig = require("lspconfig")
12+
local cmp_nvim_lsp = require("cmp_nvim_lsp")
13+
local mason = require("mason")
14+
local mason_lspconfig = require("mason-lspconfig")
15+
-- language server protocol configration --
16+
local keymap = vim.keymap -- for conciseness
17+
-- lsp keybinds
18+
vim.api.nvim_create_autocmd("LspAttach", {
19+
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
20+
callback = function(ev)
21+
-- see :help vim.lsp.*
22+
local opts = { buffer = ev.buf, silent = true }
23+
-- see :help vim.lsp.buf
24+
opts.desc = "Show LSP definitions"
25+
keymap.set("n", "<CR>", vim.lsp.buf.definition, opts)
26+
opts.desc = "Show documentation for what is under cursor"
27+
keymap.set("n", "<CR>", vim.lsp.buf.hover, opts)
28+
end,
29+
})
30+
-- used to enable autocompletion (assign to every lsp server config)
31+
local capabilities = cmp_nvim_lsp.default_capabilities()
32+
-- vim diagnostic settings
33+
local diagnostic_config = {
34+
virtual_text = true,
35+
update_in_insert = true,
36+
float = {
37+
focusable = false,
38+
border = "rounded",
39+
},
40+
}
41+
vim.diagnostic.config(diagnostic_config)
42+
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
43+
border = "rounded",
44+
})
45+
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
46+
border = "rounded",
47+
})
48+
-- mason-lspconfig servers handler
49+
mason_lspconfig.setup_handlers({
50+
-- default handler for installed servers
51+
function(server_name)
52+
lspconfig[server_name].setup({
53+
capabilities = capabilities,
54+
})
55+
end,
56+
})
57+
-- mason package manager --
58+
local servers = {
59+
"bashls",
60+
"tsserver",
61+
"cssls",
62+
"html",
63+
"jsonls",
64+
"pyright",
65+
}
66+
mason.setup({
67+
ui = {
68+
icons = {
69+
package_installed = "",
70+
package_pending = "",
71+
package_uninstalled = ""
72+
},
73+
},
74+
})
75+
mason_lspconfig.setup({
76+
ensure_installed = servers,
77+
automatic_installation = false,
78+
})
79+
end,
80+
}

lua/user/keymaps.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ end
1010

1111
-- pre defined vscode key shortcuts.
1212
nmap("f","zc")
13+
nmap("<C-f>","zM")
14+
nmap("<C-j>","zR")
1315
nmap("<C-e>","<Esc>:NvimTreeFindFile<CR>")
1416
nmap("<C-q>","<Esc>:q!<CR>")
15-
nmap("<C-Q>","<Esc>:qall!<CR>")
17+
nmap("<M-q>","<Esc>:qall!<CR>")
1618
imap("<C-q>","<Esc>:wq<CR>i")
1719
imap("<C-s>","<Esc>:w<CR>i")
1820
imap("<C-d>","<Esc>:t.<CR>i")

0 commit comments

Comments
 (0)