fix(angularls): cannot require() angularls.lua

The config makes too many assumptions and will just throw if those
assumptions don't hold...
This commit is contained in:
Justin M. Keyes 2025-04-18 17:49:34 +02:00
parent f8b5cbe631
commit e8963b5b0b

View File

@ -1,7 +1,8 @@
-- Angular requires a node_modules directory to probe for @angular/language-service and typescript
-- in order to use your projects configured versions.
local root_dir = vim.fn.getcwd()
local project_root = vim.fs.dirname(vim.fs.find('node_modules', { path = root_dir, upward = true })[1])
local node_modules_dir = vim.fs.find('node_modules', { path = root_dir, upward = true })[1]
local project_root = node_modules_dir and vim.fs.dirname(node_modules_dir) or '?'
local function get_probe_dir()
return project_root and (project_root .. '/node_modules') or ''
@ -40,7 +41,8 @@ local default_angular_core_version = get_angular_core_version()
-- - bin
-- - ngserver
-- - typescript
local ngserver_path = vim.fs.dirname(vim.uv.fs_realpath(vim.fn.exepath('ngserver')))
local ngserver_exe = vim.fn.exepath('ngserver')
local ngserver_path = #(ngserver_exe or '') > 0 and vim.fs.dirname(vim.uv.fs_realpath(ngserver_exe)) or '?'
local extension_path = vim.fs.normalize(vim.fs.joinpath(ngserver_path, '../../../'))
-- angularls will get module by `require.resolve(PROBE_PATH, MODULE_NAME)` of nodejs