Created
November 7, 2021 13:45
-
-
Save AlixShahid/2dc12ac46b53416be726b8334fc22f9b to your computer and use it in GitHub Desktop.
Medium-Setting Up Neovim for Web Development - 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- options for lsp diagnostic | |
| vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( | |
| vim.lsp.diagnostic.on_publish_diagnostics, { | |
| underline = true, | |
| signs = true, | |
| update_in_insert = true, | |
| virtual_text = { | |
| true, | |
| spacing = 6, | |
| --severity_limit='Error' -- Only show virtual text on error | |
| }, | |
| } | |
| ) | |
| -- se LSP diagnostic symbols/signs | |
| vim.api.nvim_command [[ sign define LspDiagnosticsSignError text=✗ texthl=LspDiagnosticsSignError linehl= numhl= ]] | |
| vim.api.nvim_command [[ sign define LspDiagnosticsSignWarning text=⚠ texthl=LspDiagnosticsSignWarning linehl= numhl= ]] | |
| vim.api.nvim_command [[ sign define LspDiagnosticsSignInformation text= texthl=LspDiagnosticsSignInformation linehl= numhl= ]] | |
| vim.api.nvim_command [[ sign define LspDiagnosticsSignHint text= texthl=LspDiagnosticsSignHint linehl= numhl= ]] | |
| -- Use an on_attach function to only map the following keys | |
| -- after the language server attaches to the current buffer | |
| On_attach = function(client, bufnr) | |
| local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end | |
| local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end | |
| -- Enable completion triggered by <c-x><c-o> | |
| buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') | |
| -- Mappings. | |
| local opts = { noremap=true, silent=true } | |
| -- See `:help vim.lsp.*` for documentation on any of the below functions | |
| --─────────────────────────────────────────────────-- | |
| buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts) | |
| buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts) | |
| buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts) | |
| buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) | |
| buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts) | |
| buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts) | |
| buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts) | |
| buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts) | |
| buf_set_keymap('n', '[ls', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) | |
| buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) | |
| buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | |
| buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) | |
| buf_set_keymap("n", "<space>f", '<cmd>lua vim.lsp.buf.formatting()<CR>', opts) | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setting Up Neovim for Web Development
https://xlwe.medium.com/setting-up-neovim-for-web-development-70c57c3d7d61