feat: LSP for Luau and diagnostics keymap
This commit is contained in:
parent
5fe1909b08
commit
57216b2013
3 changed files with 110 additions and 1 deletions
|
@ -7,6 +7,7 @@
|
||||||
"indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" },
|
"indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" },
|
||||||
"lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" },
|
"lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" },
|
||||||
"lualine.nvim": { "branch": "master", "commit": "0c6cca9f2c63dadeb9225c45bc92bb95a151d4af" },
|
"lualine.nvim": { "branch": "master", "commit": "0c6cca9f2c63dadeb9225c45bc92bb95a151d4af" },
|
||||||
|
"luau-lsp.nvim": { "branch": "main", "commit": "f81c6c713e4598abc484cbeabca918475d176c54" },
|
||||||
"mason-lspconfig.nvim": { "branch": "main", "commit": "87888865fa1ce1928a25b9abbea8c8f7839bf522" },
|
"mason-lspconfig.nvim": { "branch": "main", "commit": "87888865fa1ce1928a25b9abbea8c8f7839bf522" },
|
||||||
"mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" },
|
"mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" },
|
||||||
"neo-tree.nvim": { "branch": "v3.x", "commit": "f481de16a0eb59c985abac8985e3f2e2f75b4875" },
|
"neo-tree.nvim": { "branch": "v3.x", "commit": "f481de16a0eb59c985abac8985e3f2e2f75b4875" },
|
||||||
|
|
57
.config/nvim/lua/null/lsp-diagnostics.lua
Normal file
57
.config/nvim/lua/null/lsp-diagnostics.lua
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
-- REF: https://github.com/lukas-reineke/dotfiles/blob/master/vim/lua/lsp/diagnostics.lua
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local serverity_map = {
|
||||||
|
"DiagnosticError",
|
||||||
|
"DiagnosticWarn",
|
||||||
|
"DiagnosticInfo",
|
||||||
|
"DiagnosticHint",
|
||||||
|
}
|
||||||
|
local icon_map = {
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
" ",
|
||||||
|
}
|
||||||
|
|
||||||
|
local function source_string(source, code)
|
||||||
|
if code then
|
||||||
|
return string.format(" [%s %s]", source, code)
|
||||||
|
else
|
||||||
|
return string.format(" [%s]", source)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
M.line_diagnostics = function()
|
||||||
|
local bufnr, lnum = unpack(vim.fn.getcurpos())
|
||||||
|
local diagnostics = vim.diagnostic.get(bufnr, { lnum = lnum - 1, })
|
||||||
|
if vim.tbl_isempty(diagnostics) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local lines = {}
|
||||||
|
|
||||||
|
for _, diagnostic in ipairs(diagnostics) do
|
||||||
|
table.insert(
|
||||||
|
lines,
|
||||||
|
icon_map[diagnostic.severity]
|
||||||
|
.. " "
|
||||||
|
.. diagnostic.message:gsub("\n", " ")
|
||||||
|
.. source_string(diagnostic.source, diagnostic.code)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
local floating_bufnr, _ = vim.lsp.util.open_floating_preview(lines, "plaintext", {
|
||||||
|
border = vim.g.floating_window_border_dark,
|
||||||
|
focus_id = "line",
|
||||||
|
})
|
||||||
|
|
||||||
|
for i, diagnostic in ipairs(diagnostics) do
|
||||||
|
local message_length = #lines[i] - #source_string(diagnostic.source, diagnostic.code)
|
||||||
|
vim.api.nvim_buf_add_highlight(floating_bufnr, -1, serverity_map[diagnostic.severity], i - 1, 0, message_length)
|
||||||
|
vim.api.nvim_buf_add_highlight(floating_bufnr, -1, "DiagnosticSource", i - 1, message_length, -1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
|
@ -1,3 +1,5 @@
|
||||||
|
local map = require("null.util").map
|
||||||
|
|
||||||
require("null.util").lazy_file()
|
require("null.util").lazy_file()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -43,10 +45,20 @@ return {
|
||||||
require("mason-lspconfig").setup(opts)
|
require("mason-lspconfig").setup(opts)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"lopi-py/luau-lsp.nvim",
|
||||||
|
lazy = true,
|
||||||
|
opts = {
|
||||||
|
},
|
||||||
|
dependencies = {
|
||||||
|
"nvim-lua/plenary.nvim",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
lazy = true,
|
lazy = true,
|
||||||
dependencies = {
|
dependencies = {
|
||||||
|
"lopi-py/luau-lsp.nvim",
|
||||||
"mason-org/mason-lspconfig.nvim",
|
"mason-org/mason-lspconfig.nvim",
|
||||||
},
|
},
|
||||||
opts = function()
|
opts = function()
|
||||||
|
@ -69,10 +81,20 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
capabilities = {
|
||||||
|
workspace = {
|
||||||
|
didChangeWatchedFiles = {
|
||||||
|
dynamicRegistration = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
vim.diagnostic.config(vim.deepcopy(opts.diagnostics))
|
vim.diagnostic.config(vim.deepcopy(opts.diagnostics))
|
||||||
|
local on_attach = function(client, bufnr)
|
||||||
|
map("n", "<Space><CR>", require("null.lsp-diagnostics").line_diagnostics, { buffer = bufnr })
|
||||||
|
end
|
||||||
|
|
||||||
-- Setup lspconfig
|
-- Setup lspconfig
|
||||||
local has_cmp, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
local has_cmp, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
||||||
|
@ -115,7 +137,36 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
vim.lsp.enable("emmylua_ls")
|
-- vim.lsp.enable("emmylua_ls")
|
||||||
|
require("luau-lsp").setup {
|
||||||
|
platform = {
|
||||||
|
type = "roblox",
|
||||||
|
},
|
||||||
|
types = {
|
||||||
|
roblox_security_level = "PluginSecurity",
|
||||||
|
},
|
||||||
|
sourcemap = {
|
||||||
|
enabled = true,
|
||||||
|
autogenerate = true, -- automatic generation when the server is attached
|
||||||
|
rojo_project_file = "default.project.json",
|
||||||
|
sourcemap_file = "sourcemap.json",
|
||||||
|
},
|
||||||
|
server = {
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
settings = {
|
||||||
|
-- https://github.com/folke/neoconf.nvim/blob/main/schemas/luau_lsp.json
|
||||||
|
["luau-lsp"] = {
|
||||||
|
completion = {
|
||||||
|
imports = {
|
||||||
|
enabled = true, -- enable auto imports
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
-- vim.lsp.enable("luau_lsp")
|
||||||
vim.lsp.config["rust_analyzer"] = {
|
vim.lsp.config["rust_analyzer"] = {
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
settings = {
|
settings = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue