Added base folke setup
This commit is contained in:
26
lua/plugins/lsp/diagnostics.lua
Normal file
26
lua/plugins/lsp/diagnostics.lua
Normal file
@@ -0,0 +1,26 @@
|
||||
local M = {}
|
||||
|
||||
M.signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
|
||||
|
||||
function M.setup()
|
||||
-- Automatically update diagnostics
|
||||
vim.diagnostic.config({
|
||||
underline = true,
|
||||
update_in_insert = false,
|
||||
virtual_text = { spacing = 4, prefix = "●" },
|
||||
severity_sort = true,
|
||||
})
|
||||
|
||||
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
|
||||
|
||||
for type, icon in pairs(M.signs) do
|
||||
local hl = "DiagnosticSign" .. type
|
||||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
59
lua/plugins/lsp/formatting.lua
Normal file
59
lua/plugins/lsp/formatting.lua
Normal file
@@ -0,0 +1,59 @@
|
||||
local util = require("util")
|
||||
|
||||
local M = {}
|
||||
|
||||
-- vim.lsp.handlers["textDocument/hover"] = function(_, method, result)
|
||||
-- print(vim.inspect(result))
|
||||
-- end
|
||||
|
||||
M.autoformat = true
|
||||
|
||||
function M.toggle()
|
||||
M.autoformat = not M.autoformat
|
||||
if M.autoformat then
|
||||
util.info("enabled format on save", "Formatting")
|
||||
else
|
||||
util.warn("disabled format on save", "Formatting")
|
||||
end
|
||||
end
|
||||
|
||||
function M.format()
|
||||
if M.autoformat then
|
||||
if vim.lsp.buf.format then
|
||||
vim.lsp.buf.format()
|
||||
else
|
||||
vim.lsp.buf.formatting_sync()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(client, buf)
|
||||
local ft = vim.api.nvim_buf_get_option(buf, "filetype")
|
||||
local nls = require("plugins.null-ls")
|
||||
|
||||
local enable = false
|
||||
if nls.has_formatter(ft) then
|
||||
enable = client.name == "null-ls"
|
||||
else
|
||||
enable = not (client.name == "null-ls")
|
||||
end
|
||||
|
||||
if client.name == "tsserver" then
|
||||
enable = false
|
||||
end
|
||||
|
||||
-- util.info(client.name .. " " .. (enable and "yes" or "no"), "format")
|
||||
|
||||
client.server_capabilities.documentFormattingProvider = enable
|
||||
-- format on save
|
||||
if client.server_capabilities.documentFormattingProvider then
|
||||
vim.cmd([[
|
||||
augroup LspFormat
|
||||
autocmd! * <buffer>
|
||||
autocmd BufWritePre <buffer> lua require("plugins.lsp.formatting").format()
|
||||
augroup END
|
||||
]])
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
91
lua/plugins/lsp/init.lua
Normal file
91
lua/plugins/lsp/init.lua
Normal file
@@ -0,0 +1,91 @@
|
||||
local M = {
|
||||
event = "BufReadPre"
|
||||
}
|
||||
|
||||
function M.config()
|
||||
require("lua-dev").setup({
|
||||
library = {
|
||||
runtime = "~/projects/neovim/runtime/"
|
||||
}
|
||||
})
|
||||
require("mason")
|
||||
require("plugins.lsp.diagnostics").setup()
|
||||
require("fidget").setup({text = {spinner = "dots"} })
|
||||
local function on_attach(client, bufnr)
|
||||
--require("nvim-navic").attach(client, bufnr)
|
||||
require("plugins.lsp.formatting").setup(client, bufnr)
|
||||
--require("plugins.lsp.keys").setup(client, bufnr)
|
||||
end
|
||||
|
||||
---@type lspconfig.options
|
||||
local servers = {
|
||||
sumneko_lua = {
|
||||
single_file_support = true,
|
||||
settings = {
|
||||
Lua = {
|
||||
workspace = {
|
||||
checkThirdParty = false,
|
||||
},
|
||||
completion = {
|
||||
workspaceWord = false,
|
||||
},
|
||||
misc = {
|
||||
parameters = {
|
||||
"--log-level=trace",
|
||||
},
|
||||
},
|
||||
diagnostics = {
|
||||
groupFileStatus = {
|
||||
["ambiguity"] = "Opened",
|
||||
["await"] = "Opened",
|
||||
["codestyle"] = "None",
|
||||
["duplicate"] = "Opened",
|
||||
["global"] = "Opened",
|
||||
["luadoc"] = "Opened",
|
||||
["redefined"] = "Opened",
|
||||
["strict"] = "Opened",
|
||||
["strong"] = "Opened",
|
||||
["type-check"] = "Opened",
|
||||
["unbalanced"] = "Opened",
|
||||
["unused"] = "Opened",
|
||||
},
|
||||
unusedLocalExclude = { "_*" },
|
||||
},
|
||||
format = {
|
||||
enable = false,
|
||||
defaultConfig = {
|
||||
indent_style = "space",
|
||||
indent_size = "2",
|
||||
continuation_indent_size = "2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
vimls = {},
|
||||
}
|
||||
local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||
capabilities.textDocument.foldingRange = {
|
||||
dymanicRegistration = false,
|
||||
lineFoldingOnly = true,
|
||||
}
|
||||
|
||||
---@type _.lspconfig.options
|
||||
local options = {
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
flags = {
|
||||
debounce_text_change = 150,
|
||||
}
|
||||
}
|
||||
|
||||
for server, opts in pairs(servers) do
|
||||
opts = vim.tbl_deep_extend("force", {}, options, opts or {})
|
||||
require("lspconfig")[server].setup(opts)
|
||||
end
|
||||
|
||||
require("plugins.null-ls").setup(options)
|
||||
|
||||
end
|
||||
|
||||
return M
|
36
lua/plugins/lsp/kind.lua
Normal file
36
lua/plugins/lsp/kind.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
local M = {}
|
||||
|
||||
M.icons = {
|
||||
Class = " ",
|
||||
Color = " ",
|
||||
Constant = " ",
|
||||
Constructor = " ",
|
||||
Enum = "了 ",
|
||||
EnumMember = " ",
|
||||
Field = " ",
|
||||
File = " ",
|
||||
Folder = " ",
|
||||
Function = " ",
|
||||
Interface = "ﰮ ",
|
||||
Keyword = " ",
|
||||
Method = "ƒ ",
|
||||
Module = " ",
|
||||
Property = " ",
|
||||
Snippet = " ",
|
||||
Struct = " ",
|
||||
Text = " ",
|
||||
Unit = " ",
|
||||
Value = " ",
|
||||
Variable = " ",
|
||||
}
|
||||
|
||||
function M.cmp_format()
|
||||
return function(_entry, vim_item)
|
||||
if M.icons[vim_item.kind] then
|
||||
vim_item.kind = M.icons[vim_item.kind] .. vim_item.kind
|
||||
end
|
||||
return vim_item
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
Reference in New Issue
Block a user