mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
feat(extras): Added angularls lsp configuration
This commit is contained in:
parent
ac27fcf4df
commit
ce13ca1a72
1 changed files with 37 additions and 55 deletions
|
|
@ -1,79 +1,61 @@
|
|||
local goto_template_file = function()
|
||||
local params = vim.lsp.util.make_position_params(0)
|
||||
vim.lsp.buf_request(0, "angular/getTemplateLocationForComponent", params, function(_, result)
|
||||
if result then
|
||||
vim.lsp.util.jump_to_location(result, "utf-8")
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local goto_component_file = function()
|
||||
local params = vim.lsp.util.make_position_params(0)
|
||||
vim.lsp.buf_request(0, "angular/getComponentsWithTemplateFile", params, function(_, result)
|
||||
if result then
|
||||
if #result == 1 then
|
||||
vim.lsp.util.jump_to_location(result[1], "utf-8")
|
||||
else
|
||||
vim.fn.setqflist({}, " ", {
|
||||
title = "Angular Language Server",
|
||||
items = vim.lsp.util.locations_to_items(result, "utf-8"),
|
||||
})
|
||||
vim.cmd.copen()
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
---@param id string
|
||||
---@param cmd string | function
|
||||
---@param desc string
|
||||
local create_cmd = function(id, cmd, desc)
|
||||
vim.api.nvim_create_user_command(string.format("Ng%s", id), cmd, {
|
||||
desc = string.format("Angular » %s", desc),
|
||||
})
|
||||
end
|
||||
|
||||
return {
|
||||
recommended = function()
|
||||
return LazyVim.extras.wants({
|
||||
ft = { "html", "typescript" },
|
||||
root = {
|
||||
"angular.json",
|
||||
"nx.json", --support for nx workspace
|
||||
},
|
||||
})
|
||||
end,
|
||||
|
||||
{
|
||||
"nvim-treesitter",
|
||||
optional = true,
|
||||
opts = function(_, opts)
|
||||
if type(opts.ensure_installed) == "table" then
|
||||
vim.list_extend(opts.ensure_installed, { "angular" })
|
||||
vim.list_extend(opts.ensure_installed, { "angular", "scss" })
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
-- angularls depends on typescript
|
||||
{ import = "lazyvim.plugins.extras.lang.typescript" },
|
||||
|
||||
-- LSP Servers
|
||||
{
|
||||
"nvim-lspconfig",
|
||||
"neovim/nvim-lspconfig",
|
||||
opts = {
|
||||
servers = {
|
||||
angularls = {
|
||||
root_dir = function(fname)
|
||||
local util = require("lspconfig").util
|
||||
local original = util.root_pattern("angular.json", "project.json")(fname)
|
||||
-- set fallback for nx workspace support
|
||||
local nx_fallback = util.root_pattern("nx.json", "workspace.json")(fname)
|
||||
local git_fallback = util.root_pattern(".git")(fname)
|
||||
return original or nx_fallback or git_fallback
|
||||
end,
|
||||
},
|
||||
angularls = {},
|
||||
},
|
||||
setup = {
|
||||
angularls = function()
|
||||
require("lazyvim.util").lsp.on_attach(function(client)
|
||||
LazyVim.lsp.on_attach(function(client)
|
||||
if client.name == "angularls" then
|
||||
-- disable lsp rename to not conflicting with tsserver
|
||||
--HACK: disable angular renaming capability due to duplicate rename popping up
|
||||
client.server_capabilities.renameProvider = false
|
||||
-- run :Ngc to go to the component of the current template buffer
|
||||
create_cmd("c", goto_component_file, "Go to component file")
|
||||
-- run :Ngt to go to the template of the current component
|
||||
create_cmd("t", goto_template_file, "Go to template file")
|
||||
end
|
||||
end)
|
||||
return false
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
-- Configure tsserver plugin
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
opts = function(_, opts)
|
||||
LazyVim.extend(opts.servers.vtsls, "settings.vtsls.tsserver.globalPlugins", {
|
||||
{
|
||||
name = "@angular/language-server",
|
||||
location = LazyVim.get_pkg_path(
|
||||
"angular-language-server",
|
||||
"/node_modules/@angular/language-server",
|
||||
{ warn = false }
|
||||
),
|
||||
enableForWorkspaceTypeScriptVersions = true,
|
||||
},
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue