-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,147 @@ | ||
local nvim_lsp = require('lspconfig') | ||
local protocol = require('vim.lsp.protocol') | ||
local protocol = require'vim.lsp.protocol' | ||
|
||
local 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 | ||
|
||
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') | ||
|
||
local opts = { noremap=true, silent=true } | ||
|
||
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('i', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) | ||
buf_set_keymap('n', '<leader>lwa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) | ||
buf_set_keymap('n', '<leader>lwr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts) | ||
buf_set_keymap('n', '<leader>lwl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts) | ||
buf_set_keymap('n', '<leader>lD', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) | ||
buf_set_keymap('n', '<leader>lrn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | ||
buf_set_keymap('n', '<leader>lca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts) | ||
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) | ||
buf_set_keymap('n', '<leader>le', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts) | ||
--buf_set_keymap('n', '<C-j>', '<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', '<leader>lq', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) | ||
buf_set_keymap("n", "<leader>lf", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts) | ||
|
||
-- formatting | ||
if client.resolved_capabilities.document_formatting then | ||
vim.api.nvim_command [[augroup Format]] | ||
vim.api.nvim_command [[autocmd! * <buffer>]] | ||
vim.api.nvim_command [[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()]] | ||
vim.api.nvim_command [[augroup END]] | ||
end | ||
|
||
require'completion'.on_attach(client, bufnr) | ||
|
||
--protocol.SymbolKind = { } | ||
protocol.CompletionItemKind = { | ||
'', -- Text | ||
'', -- Method | ||
'', -- Function | ||
'', -- Constructor | ||
'', -- Field | ||
'', -- Variable | ||
'', -- Class | ||
'ﰮ', -- Interface | ||
'', -- Module | ||
'', -- Property | ||
'', -- Unit | ||
'', -- Value | ||
'', -- Enum | ||
'', -- Keyword | ||
'', -- Snippet | ||
'', -- Color | ||
'', -- File | ||
'', -- Reference | ||
'', -- Folder | ||
'', -- EnumMember | ||
'', -- Constant | ||
'', -- Struct | ||
'', -- Event | ||
'ﬦ', -- Operator | ||
'', -- TypeParameter | ||
} | ||
end | ||
|
||
nvim_lsp.flow.setup { | ||
on_attach = on_attach | ||
} | ||
|
||
nvim_lsp.tsserver.setup { | ||
on_attach = on_attach, | ||
filetypes = { "typescript", "typescriptreact", "typescript.tsx" } | ||
} | ||
|
||
nvim_lsp.diagnosticls.setup { | ||
on_attach = on_attach, | ||
filetypes = { 'javascript', 'javascriptreact', 'json', 'typescript', 'typescriptreact', 'css', 'less', 'scss', 'markdown', 'pandoc' }, | ||
init_options = { | ||
linters = { | ||
eslint = { | ||
command = 'eslint_d', | ||
rootPatterns = { '.git' }, | ||
debounce = 100, | ||
args = { '--stdin', '--stdin-filename', '%filepath', '--format', 'json' }, | ||
sourceName = 'eslint_d', | ||
parseJson = { | ||
errorsRoot = '[0].messages', | ||
line = 'line', | ||
column = 'column', | ||
endLine = 'endLine', | ||
endColumn = 'endColumn', | ||
message = '[eslint] ${message} [${ruleId}]', | ||
security = 'severity' | ||
}, | ||
securities = { | ||
[2] = 'error', | ||
[1] = 'warning' | ||
} | ||
}, | ||
}, | ||
filetypes = { | ||
javascript = 'eslint', | ||
javascriptreact = 'eslint', | ||
typescript = 'eslint', | ||
typescriptreact = 'eslint', | ||
}, | ||
formatters = { | ||
eslint_d = { | ||
command = 'eslint_d', | ||
args = { '--stdin', '--stdin-filename', '%filename', '--fix-to-stdout' }, | ||
rootPatterns = { '.git' }, | ||
}, | ||
prettier = { | ||
command = 'prettier', | ||
args = { '--stdin-filepath', '%filename' } | ||
} | ||
}, | ||
formatFiletypes = { | ||
css = 'prettier', | ||
javascript = 'eslint_d', | ||
javascriptreact = 'eslint_d', | ||
json = 'prettier', | ||
scss = 'prettier', | ||
less = 'prettier', | ||
json = 'prettier', | ||
typescript = 'eslint_d', | ||
typescriptreact = 'eslint_d', | ||
markdown = 'prettier', | ||
} | ||
} | ||
} | ||
|
||
-- icon | ||
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( | ||
vim.lsp.diagnostic.on_publish_diagnostics, { | ||
underline = true, | ||
-- This sets the spacing and the prefix, obviously. | ||
virtual_text = { | ||
spacing = 4, | ||
prefix = '' | ||
} | ||
} | ||
) |