Update lsp settings for Go and fix ls_emmet config
This commit is contained in:
@@ -107,7 +107,8 @@ autocmd FileType go set noexpandtab
|
|||||||
|
|
||||||
vim.g.mapleader = " "
|
vim.g.mapleader = " "
|
||||||
|
|
||||||
vim.cmd([[autocmd BufWritePre * Neoformat]])
|
vim.cmd(
|
||||||
|
[[autocmd BufWritePre *.js,*.jsx,*.ts,*.tsx,*.html,*.css,*.scss,*.json,*.lua silent Neoformat]])
|
||||||
|
|
||||||
require("lsp")
|
require("lsp")
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local lsp_installer = require("nvim-lsp-installer")
|
local lsp_installer = require("nvim-lsp-installer")
|
||||||
local cmp = require("cmp")
|
local cmp = require("cmp")
|
||||||
local configs = require("lspconfig/configs")
|
local configs = require("lspconfig.configs")
|
||||||
local nvim_lsp = require("lspconfig")
|
local nvim_lsp = require("lspconfig")
|
||||||
|
|
||||||
local kind_icons = {
|
local kind_icons = {
|
||||||
@@ -42,7 +42,13 @@ cmp.setup({
|
|||||||
["<C-k>"] = cmp.mapping.select_prev_item({
|
["<C-k>"] = cmp.mapping.select_prev_item({
|
||||||
behavior = cmp.SelectBehavior.Select
|
behavior = cmp.SelectBehavior.Select
|
||||||
}),
|
}),
|
||||||
["<C-space>"] = cmp.mapping.complete(),
|
["<C-space>"] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.close()
|
||||||
|
else
|
||||||
|
cmp.complete()
|
||||||
|
end
|
||||||
|
end),
|
||||||
-- ["<CR>"] = cmp.mapping.confirm({
|
-- ["<CR>"] = cmp.mapping.confirm({
|
||||||
-- select = true,
|
-- select = true,
|
||||||
-- behavior = cmp.SelectBehavior.Insert
|
-- behavior = cmp.SelectBehavior.Insert
|
||||||
@@ -59,7 +65,10 @@ cmp.setup({
|
|||||||
completion = {completeopt = "menu,menuone,noselect,noinsert,preview"},
|
completion = {completeopt = "menu,menuone,noselect,noinsert,preview"},
|
||||||
experimental = {ghost_text = true},
|
experimental = {ghost_text = true},
|
||||||
sorting = {
|
sorting = {
|
||||||
comparators = {cmp.config.compare.sort_text, cmp.config.compare.kind}
|
comparators = {
|
||||||
|
cmp.config.compare.score, cmp.config.compare.sort_text,
|
||||||
|
cmp.config.compare.kind
|
||||||
|
}
|
||||||
},
|
},
|
||||||
documentation = {
|
documentation = {
|
||||||
border = {"╭", "─", "╮", "│", "╯", "─", "╰", "│"},
|
border = {"╭", "─", "╮", "│", "╯", "─", "╰", "│"},
|
||||||
@@ -125,17 +134,20 @@ lsp_installer.on_server_ready(function(server)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
-- Use this emmet lsp - https://github.com/pedro757/emmet
|
-- Use this emmet lsp - https://github.com/pedro757/emmet
|
||||||
|
if not configs.ls_emmet then
|
||||||
configs.ls_emmet = {
|
configs.ls_emmet = {
|
||||||
default_config = {
|
default_config = {
|
||||||
cmd = {'ls_emmet', '--stdio'},
|
cmd = {'ls_emmet', '--stdio'},
|
||||||
filetypes = {
|
filetypes = {
|
||||||
'html', 'css', 'scss', 'javascriptreact', 'typescriptreact', 'haml',
|
'html', 'css', 'scss', 'javascriptreact', 'typescriptreact',
|
||||||
'xml', 'xsl', 'pug', 'slim', 'sass', 'stylus', 'less', 'sss'
|
'haml', 'xml', 'xsl', 'pug', 'slim', 'sass', 'stylus', 'less',
|
||||||
|
'sss'
|
||||||
},
|
},
|
||||||
root_dir = function(fname) return vim.loop.cwd() end,
|
root_dir = function(fname) return vim.loop.cwd() end,
|
||||||
settings = {}
|
settings = {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
end
|
||||||
nvim_lsp.ls_emmet.setup({capabilities = capabilities})
|
nvim_lsp.ls_emmet.setup({capabilities = capabilities})
|
||||||
|
|
||||||
nvim_lsp.gopls.setup({
|
nvim_lsp.gopls.setup({
|
||||||
@@ -150,6 +162,40 @@ nvim_lsp.gopls.setup({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function goimports(timeout_ms)
|
||||||
|
local context = {only = {"source.organizeImports"}}
|
||||||
|
vim.validate {context = {context, "t", true}}
|
||||||
|
|
||||||
|
local params = vim.lsp.util.make_range_params()
|
||||||
|
params.context = context
|
||||||
|
|
||||||
|
-- See the implementation of the textDocument/codeAction callback
|
||||||
|
-- (lua/vim/lsp/handler.lua) for how to do this properly.
|
||||||
|
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction",
|
||||||
|
params, timeout_ms)
|
||||||
|
if not result or next(result) == nil then return end
|
||||||
|
local actions = result[1].result
|
||||||
|
if not actions then return end
|
||||||
|
local action = actions[1]
|
||||||
|
|
||||||
|
-- textDocument/codeAction can return either Command[] or CodeAction[]. If it
|
||||||
|
-- is a CodeAction, it can have either an edit, a command or both. Edits
|
||||||
|
-- should be executed first.
|
||||||
|
if action.edit or type(action.command) == "table" then
|
||||||
|
if action.edit then
|
||||||
|
vim.lsp.util.apply_workspace_edit(action.edit)
|
||||||
|
end
|
||||||
|
if type(action.command) == "table" then
|
||||||
|
vim.lsp.buf.execute_command(action.command)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
vim.lsp.buf.execute_command(action)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.cmd([[autocmd BufWritePre *.go lua vim.lsp.buf.formatting()]])
|
||||||
|
vim.cmd([[autocmd BufWritePre *.go lua goimports(1000)]])
|
||||||
|
|
||||||
require("luasnip/loaders/from_vscode").load({
|
require("luasnip/loaders/from_vscode").load({
|
||||||
include = {"javascript", "typescript", "go", "html"}
|
include = {"javascript", "typescript", "go", "html"}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user