Fix LSP setup on MacOS
This commit is contained in:
parent
91aa6f9c8a
commit
ca62386d97
26
dot_config/nvim/after/ftplugin/tex.lua
Normal file
26
dot_config/nvim/after/ftplugin/tex.lua
Normal file
@ -0,0 +1,26 @@
|
||||
vim.g.tex_flavor = "latex"
|
||||
|
||||
vim.opt_local.conceallevel = 2
|
||||
-- vim.opt_local.spell = true
|
||||
vim.opt_local.wrap = true
|
||||
|
||||
require("nvim-surround").buffer_setup({
|
||||
surrounds = {
|
||||
['"'] = {
|
||||
add = { "``", "''" },
|
||||
find = "``.-''",
|
||||
delete = "^(``)().-('')()$",
|
||||
},
|
||||
["$"] = {
|
||||
add = { "\\(", "\\)" },
|
||||
find = "\\%(.-\\%)",
|
||||
delete = "^(\\%()().-(\\%))()$",
|
||||
change = {
|
||||
target = "^\\(%()().-(\\%))()$",
|
||||
replacement = function()
|
||||
return { { "[", "\t" }, { "", "\\]" } }
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
@ -1,93 +0,0 @@
|
||||
local ok, lsp = pcall(require, 'lspconfig')
|
||||
if not ok then
|
||||
return
|
||||
end
|
||||
|
||||
local sign = function(opts)
|
||||
-- See :help sign_define()
|
||||
vim.fn.sign_define(opts.name, {
|
||||
texthl = opts.name,
|
||||
text = opts.text,
|
||||
numhl = ''
|
||||
})
|
||||
end
|
||||
|
||||
sign({name = 'DiagnosticSignError', text = '✘'})
|
||||
sign({name = 'DiagnosticSignWarn', text = '▲'})
|
||||
sign({name = 'DiagnosticSignHint', text = '⚑'})
|
||||
sign({name = 'DiagnosticSignInfo', text = ''})
|
||||
|
||||
vim.diagnostic.config({
|
||||
virtual_text = false,
|
||||
severity_sort = true,
|
||||
float = {
|
||||
border = 'rounded',
|
||||
source = 'always',
|
||||
header = '',
|
||||
prefix = '',
|
||||
},
|
||||
})
|
||||
|
||||
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(
|
||||
vim.lsp.handlers.hover,
|
||||
{border = 'rounded'}
|
||||
)
|
||||
|
||||
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(
|
||||
vim.lsp.handlers.signature_help,
|
||||
{border = 'rounded'}
|
||||
)
|
||||
|
||||
vim.lsp.handlers["workspace/diagnostic/refresh"] = function(_, _, ctx)
|
||||
local ns = vim.lsp.diagnostic.get_namespace(ctx.client_id)
|
||||
pcall(vim.diagnostic.reset, ns)
|
||||
return true
|
||||
end
|
||||
|
||||
require("lsp-format").setup {}
|
||||
|
||||
local on_attach = function(client)
|
||||
local bufmap = function(mode, lhs, rhs)
|
||||
local opts = {buffer = true}
|
||||
vim.keymap.set(mode, lhs, rhs, opts)
|
||||
end
|
||||
require("lsp-format").on_attach(client)
|
||||
|
||||
bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>')
|
||||
bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>')
|
||||
bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>')
|
||||
bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>')
|
||||
bufmap('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>')
|
||||
bufmap('n', 'gA', '<cmd>Telescope diagnostics<cr>')
|
||||
bufmap('n', 'gr', '<cmd>Telescope lsp_references<cr>')
|
||||
bufmap('n', 'gi', '<cmd>Telescope lsp_implementations<cr>')
|
||||
bufmap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>')
|
||||
bufmap('n', '<F3>', '<cmd>lua vim.lsp.buf.format({async = true})<cr>')
|
||||
bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>')
|
||||
bufmap('x', '<F4>', '<cmd>lua vim.lsp.buf.range_code_action()<cr>')
|
||||
bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>')
|
||||
bufmap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
|
||||
bufmap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>')
|
||||
end
|
||||
|
||||
lsp.gopls.setup { on_attach = on_attach }
|
||||
lsp.clangd.setup { on_attach = on_attach }
|
||||
lsp.ltex.setup { on_attach = on_attach }
|
||||
lsp.svelte.setup { on_attach = on_attach }
|
||||
lsp.tsserver.setup { on_attach = on_attach }
|
||||
lsp.lua_ls.setup {
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = {
|
||||
globals = { 'vim' }
|
||||
},
|
||||
-- workspace = {
|
||||
-- library = vim.api.nvim_get_runtime_file("", true),
|
||||
-- },
|
||||
-- telemetry = {
|
||||
-- enable = false,
|
||||
-- },
|
||||
}
|
||||
},
|
||||
on_attach = on_attach
|
||||
}
|
176
dot_config/nvim/after/plugin/lsp.lua.tmpl
Normal file
176
dot_config/nvim/after/plugin/lsp.lua.tmpl
Normal file
@ -0,0 +1,176 @@
|
||||
local ok, lsp = pcall(require, 'lspconfig')
|
||||
if not ok then
|
||||
return
|
||||
end
|
||||
|
||||
{{- if ne .chezmoi.os "openbsd" }}
|
||||
-- See :help mason-settings
|
||||
require('mason').setup({
|
||||
ui = { border = 'rounded' }
|
||||
})
|
||||
|
||||
-- See :help mason-lspconfig-settings
|
||||
require('mason-lspconfig').setup({
|
||||
ensure_installed = {
|
||||
'clangd',
|
||||
'gopls',
|
||||
'ltex',
|
||||
'svelte',
|
||||
'tsserver',
|
||||
'eslint',
|
||||
'html',
|
||||
'cssls',
|
||||
'lua_ls'
|
||||
}
|
||||
})
|
||||
{{- end }}
|
||||
|
||||
local lsp_defaults = lsp.util.default_config
|
||||
|
||||
lsp_defaults.capabilities = vim.tbl_deep_extend(
|
||||
'force',
|
||||
lsp_defaults.capabilities,
|
||||
require('cmp_nvim_lsp').default_capabilities()
|
||||
)
|
||||
|
||||
local sign = function(opts)
|
||||
-- See :help sign_define()
|
||||
vim.fn.sign_define(opts.name, {
|
||||
texthl = opts.name,
|
||||
text = opts.text,
|
||||
numhl = ''
|
||||
})
|
||||
end
|
||||
|
||||
sign({ name = 'DiagnosticSignError', text = '✘' })
|
||||
sign({ name = 'DiagnosticSignWarn', text = '▲' })
|
||||
sign({ name = 'DiagnosticSignHint', text = '⚑' })
|
||||
sign({ name = 'DiagnosticSignInfo', text = '' })
|
||||
|
||||
vim.diagnostic.config({
|
||||
virtual_text = false,
|
||||
severity_sort = true,
|
||||
float = {
|
||||
border = 'rounded',
|
||||
source = 'always',
|
||||
header = '',
|
||||
prefix = '',
|
||||
},
|
||||
})
|
||||
|
||||
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(
|
||||
vim.lsp.handlers.hover,
|
||||
{ border = 'rounded' }
|
||||
)
|
||||
|
||||
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(
|
||||
vim.lsp.handlers.signature_help,
|
||||
{ border = 'rounded' }
|
||||
)
|
||||
|
||||
vim.lsp.handlers["workspace/diagnostic/refresh"] = function(_, _, ctx)
|
||||
local ns = vim.lsp.diagnostic.get_namespace(ctx.client_id)
|
||||
pcall(vim.diagnostic.reset, ns)
|
||||
return true
|
||||
end
|
||||
|
||||
require("lsp-format").setup {}
|
||||
|
||||
{{- if ne .chezmoi.os "openbsd" }}
|
||||
local group = vim.api.nvim_create_augroup('lsp_cmds', { clear = true })
|
||||
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
group = group,
|
||||
desc = 'LSP actions',
|
||||
callback = function(args)
|
||||
local bufmap = function(mode, lhs, rhs)
|
||||
local opts = { buffer = true }
|
||||
vim.keymap.set(mode, lhs, rhs, opts)
|
||||
end
|
||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||
require("lsp-format").on_attach(client)
|
||||
|
||||
bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>')
|
||||
bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>')
|
||||
bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>')
|
||||
bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>')
|
||||
bufmap('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>')
|
||||
bufmap('n', 'gA', '<cmd>Telescope diagnostics<cr>')
|
||||
bufmap('n', 'gr', '<cmd>Telescope lsp_references<cr>')
|
||||
bufmap('n', 'gi', '<cmd>Telescope lsp_implementations<cr>')
|
||||
bufmap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>')
|
||||
bufmap('n', '<F3>', '<cmd>lua vim.lsp.buf.format({async = true})<cr>')
|
||||
bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>')
|
||||
bufmap('x', '<F4>', '<cmd>lua vim.lsp.buf.range_code_action()<cr>')
|
||||
bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>')
|
||||
bufmap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
|
||||
bufmap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>')
|
||||
end
|
||||
})
|
||||
|
||||
require('mason-lspconfig').setup_handlers({
|
||||
function(server)
|
||||
lsp[server].setup({})
|
||||
end,
|
||||
['tsserver'] = function()
|
||||
lsp.tsserver.setup({
|
||||
settings = {
|
||||
completions = {
|
||||
completeFunctionCalls = true
|
||||
}
|
||||
}
|
||||
})
|
||||
end,
|
||||
['lua_ls'] = function()
|
||||
lsp.lua_ls.setup({
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = {
|
||||
globals = { 'vim' }
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
})
|
||||
{{- else }}
|
||||
local on_attach = function(client)
|
||||
local bufmap = function(mode, lhs, rhs)
|
||||
local opts = {buffer = true}
|
||||
vim.keymap.set(mode, lhs, rhs, opts)
|
||||
end
|
||||
require("lsp-format").on_attach(client)
|
||||
|
||||
bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>')
|
||||
bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>')
|
||||
bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>')
|
||||
bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>')
|
||||
bufmap('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>')
|
||||
bufmap('n', 'gA', '<cmd>Telescope diagnostics<cr>')
|
||||
bufmap('n', 'gr', '<cmd>Telescope lsp_references<cr>')
|
||||
bufmap('n', 'gi', '<cmd>Telescope lsp_implementations<cr>')
|
||||
bufmap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>')
|
||||
bufmap('n', '<F3>', '<cmd>lua vim.lsp.buf.format({async = true})<cr>')
|
||||
bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>')
|
||||
bufmap('x', '<F4>', '<cmd>lua vim.lsp.buf.range_code_action()<cr>')
|
||||
bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>')
|
||||
bufmap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
|
||||
bufmap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>')
|
||||
end
|
||||
|
||||
lsp.gopls.setup { on_attach = on_attach }
|
||||
lsp.clangd.setup { on_attach = on_attach }
|
||||
lsp.ltex.setup { on_attach = on_attach }
|
||||
lsp.svelte.setup { on_attach = on_attach }
|
||||
lsp.tsserver.setup { on_attach = on_attach }
|
||||
lsp.lua_ls.setup {
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = {
|
||||
globals = { 'vim' }
|
||||
},
|
||||
}
|
||||
},
|
||||
on_attach = on_attach
|
||||
}
|
||||
{{- end }}
|
@ -11,14 +11,20 @@ require "paq" {
|
||||
"nvim-treesitter/nvim-treesitter";
|
||||
"nvim-treesitter/nvim-treesitter-textobjects";
|
||||
|
||||
-- Theming
|
||||
"ellisonleao/gruvbox.nvim";
|
||||
"nvim-lualine/lualine.nvim";
|
||||
"nvim-tree/nvim-web-devicons";
|
||||
"lukas-reineke/indent-blankline.nvim";
|
||||
|
||||
-- LSP support
|
||||
"onsails/lspkind.nvim";
|
||||
"lukas-reineke/lsp-format.nvim";
|
||||
"neovim/nvim-lspconfig";
|
||||
-- "williamboman/mason.nvim";
|
||||
-- "williamboman/mason-lspconfig.nvim";
|
||||
{{- if ne .chezmoi.os "openbsd" }}
|
||||
"williamboman/mason.nvim";
|
||||
"williamboman/mason-lspconfig.nvim";
|
||||
{{- end }}
|
||||
|
||||
-- Autocomplete
|
||||
"hrsh7th/nvim-cmp";
|
||||
@ -56,8 +62,6 @@ require "paq" {
|
||||
"nvim-lua/plenary.nvim";
|
||||
"akinsho/toggleterm.nvim";
|
||||
|
||||
"nvim-lualine/lualine.nvim";
|
||||
"ellisonleao/gruvbox.nvim";
|
||||
}
|
||||
|
||||
require('nvim-web-devicons').setup {}
|
||||
@ -88,6 +92,14 @@ require('lualine').setup {
|
||||
}
|
||||
}
|
||||
|
||||
require('indent_blankline').setup({
|
||||
char = '▏',
|
||||
show_trailing_blankline_indent = false,
|
||||
show_first_indent_level = false,
|
||||
use_treesitter = true,
|
||||
show_current_context = false
|
||||
})
|
||||
|
||||
require('toggleterm').setup({
|
||||
open_mapping = '<C-g>',
|
||||
direction = 'horizontal',
|
Loading…
Reference in New Issue
Block a user