Skip to content

Commit 9962e25

Browse files
authored
fix(angularls): pass --angularCoreVersion for backwards compatibility #3592
1 parent 1f941b3 commit 9962e25

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lua/lspconfig/configs/angularls.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,27 @@ local function get_probe_dir(root_dir)
99
return project_root and (project_root .. '/node_modules') or ''
1010
end
1111

12+
local function get_angular_core_version(root_dir)
13+
local project_root = vim.fs.dirname(vim.fs.find('node_modules', { path = root_dir, upward = true })[1])
14+
15+
local package_json = project_root .. '/package.json'
16+
if not vim.loop.fs_stat(package_json) then
17+
return ''
18+
end
19+
20+
local contents = io.open(package_json):read '*a'
21+
local json = vim.json.decode(contents)
22+
if not json.dependencies then
23+
return ''
24+
end
25+
26+
local angular_core_version = json.dependencies['@angular/core']
27+
28+
return angular_core_version
29+
end
30+
1231
local default_probe_dir = get_probe_dir(vim.fn.getcwd())
32+
local default_angular_core_version = get_angular_core_version(vim.fn.getcwd())
1333

1434
return {
1535
default_config = {
@@ -20,6 +40,8 @@ return {
2040
default_probe_dir,
2141
'--ngProbeLocations',
2242
default_probe_dir,
43+
'--angularCoreVersion',
44+
default_angular_core_version,
2345
},
2446
filetypes = { 'typescript', 'html', 'typescriptreact', 'typescript.tsx', 'htmlangular' },
2547
-- Check for angular.json since that is the root of the project.
@@ -29,6 +51,7 @@ return {
2951
},
3052
on_new_config = function(new_config, new_root_dir)
3153
local new_probe_dir = get_probe_dir(new_root_dir)
54+
local angular_core_version = get_angular_core_version(new_root_dir)
3255

3356
-- We need to check our probe directories because they may have changed.
3457
new_config.cmd = {
@@ -38,6 +61,8 @@ return {
3861
new_probe_dir,
3962
'--ngProbeLocations',
4063
new_probe_dir,
64+
'--angularCoreVersion',
65+
angular_core_version,
4166
}
4267
end,
4368
docs = {

0 commit comments

Comments
 (0)