From bdadba7103ca3752352fdb8633cb680767a7a7d2 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Wed, 18 Dec 2024 20:35:52 +0100 Subject: [PATCH] Configure Angular --- install.sh | 7 +++++- lua/core/keymap.lua | 14 +++++++++++ lua/toolchain/angular.lua | 49 +++++++++++++++++++++++++-------------- 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/install.sh b/install.sh index 6dbcc84..ea9194c 100755 --- a/install.sh +++ b/install.sh @@ -45,4 +45,9 @@ command -v stylelint &>/dev/null || volta install stylelint command -v prettierd &>/dev/null || volta install @fsouza/prettierd # Angular -command -v ng &>/dev/null || volta install @angular/cli +command -v ng &>/dev/null || volta install @angular/cli +command -v ngserver &>/dev/null || { + volta install @angular/language-server + volta install @angular/language-service + volta install typescript +} diff --git a/lua/core/keymap.lua b/lua/core/keymap.lua index 1e3023d..2b4da97 100644 --- a/lua/core/keymap.lua +++ b/lua/core/keymap.lua @@ -182,4 +182,18 @@ K.CODE = { }, } +--[[ Angular ]] +K.ANGULAR = { + TEMPLATE = { + mode = 'n', + shortcut = 'at', + description = 'Go to Angular Template', + }, + COMPONENT = { + mode = 'n', + shortcut = 'ac', + description = 'Go to Angular Component', + }, +} + return K diff --git a/lua/toolchain/angular.lua b/lua/toolchain/angular.lua index abb6baf..706f3f8 100644 --- a/lua/toolchain/angular.lua +++ b/lua/toolchain/angular.lua @@ -1,5 +1,6 @@ local T = require('toolchain') local M = {} +local K = require('core.keymap') function M.setup() T.add_highlighter_autoinstalls('angular') @@ -18,33 +19,47 @@ function M.setup() T.add_lsp_autoinstalls('angularls') T.add_lsps(function(lspconfig, capabilities) - local config = { capabilities = capabilities } - lspconfig.html.setup(config) - lspconfig.emmet_ls.setup(config) - lspconfig.cssls.setup(config) - lspconfig.tailwindcss.setup(config) - lspconfig.ts_ls.setup(config) - lspconfig.eslint.setup(config) + local cmd = { + vim.env.VOLTA_HOME .. '/bin/ngserver', + '--stdio', + '--tsProbeLocations', + vim.env.VOLTA_HOME, + '--ngProbeLocations', + vim.env.VOLTA_HOME, + } + lspconfig.angularls.setup({ + capabilities = capabilities, + cmd = cmd, + on_new_config = function(new_config, _new_root_dir) + new_config.cmd = cmd + end, + }) end) T.add_plugins({ 'joeveiga/ng.nvim', config = function() - local opts = { noremap = true, silent = true } local ng = require('ng') vim.keymap.set( - 'n', - 'at', - ng.goto_template_for_component, - opts + K.ANGULAR.COMPONENT.mode, + K.ANGULAR.COMPONENT.shortcut, + ng.goto_component_with_template_file, + { + noremap = true, + silent = true, + desc = K.ANGULAR.COMPONENT.description, + } ) vim.keymap.set( - 'n', - 'ac', - ng.goto_component_with_template_file, - opts + K.ANGULAR.TEMPLATE.mode, + K.ANGULAR.TEMPLATE.shortcut, + ng.goto_template_for_component, + { + noremap = true, + silent = true, + desc = K.ANGULAR.TEMPLATE.description, + } ) - vim.keymap.set('n', 'aT', ng.get_template_tcb, opts) end, }) end