Skip to content

Commit 156e723

Browse files
Keen Yee Liauayazhafiz
authored andcommitted
feat: Allow users to set @angular/language-service from vscode (#415)
This PR allows users to change the version of typescript and @angular/language-service used by the server from vscode. Instead of using process.cwd() (which is a very bad idea), the extension client should instead look for typescript and @angular/language-service in the workspace folders. If there's no workspace folder, fallback to the bundled version.
1 parent 20625ca commit 156e723

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

client/src/extension.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,8 @@ export function activate(context: vscode.ExtensionContext) {
1717
// Log file does not yet exist on disk. It is up to the server to create the
1818
// file.
1919
const logFile = path.join(context.logPath, 'nglangsvc.log');
20-
const ngProbeLocations = [
21-
process.cwd(), // workspace version
22-
context.asAbsolutePath('server'), // bundled version
23-
];
24-
const tsProbeLocations = [
25-
process.cwd(), // workspace version
26-
context.extensionPath, // bundled version
27-
];
28-
20+
const ngProbeLocations = getProbeLocations('angular.ngdk', context.asAbsolutePath('server'));
21+
const tsProbeLocations = getProbeLocations('typescript.tsdk', context.extensionPath);
2922
// If the extension is launched in debug mode then the debug server options are used
3023
// Otherwise the run options are used
3124
const serverOptions: lsp.ServerOptions = {
@@ -133,3 +126,20 @@ export function activate(context: vscode.ExtensionContext) {
133126
});
134127
});
135128
}
129+
130+
function getProbeLocations(configName: string, bundled: string): string[] {
131+
const locations = [];
132+
// Always use config value if it's specified
133+
const configValue = vscode.workspace.getConfiguration().get(configName);
134+
if (configValue) {
135+
locations.push(configValue as string);
136+
}
137+
// If not, look in workspaces currently open
138+
const workspaceFolders = vscode.workspace.workspaceFolders || [];
139+
for (const folder of workspaceFolders) {
140+
locations.push(folder.uri.fsPath);
141+
}
142+
// If all else fails, load the bundled version
143+
locations.push(bundled);
144+
return locations;
145+
}

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,17 @@
2323
"title": "Restart Angular Language server",
2424
"category": "Angular"
2525
}
26-
]
26+
],
27+
"configuration": {
28+
"title": "Angular Language Service",
29+
"properties": {
30+
"angular.ngdk": {
31+
"type": ["string", "null"],
32+
"default": null,
33+
"description": "Specifies the folder path to @angular/language-service."
34+
}
35+
}
36+
}
2737
},
2838
"activationEvents": [
2939
"onLanguage:html",

0 commit comments

Comments
 (0)