Skip to content

Commit

Permalink
feat: Allow users to set @angular/language-service from vscode (angul…
Browse files Browse the repository at this point in the history
…ar#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.
  • Loading branch information
Keen Yee Liau authored and ayazhafiz committed Oct 11, 2019
1 parent 20625ca commit 156e723
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
28 changes: 19 additions & 9 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,8 @@ export function activate(context: vscode.ExtensionContext) {
// Log file does not yet exist on disk. It is up to the server to create the
// file.
const logFile = path.join(context.logPath, 'nglangsvc.log');
const ngProbeLocations = [
process.cwd(), // workspace version
context.asAbsolutePath('server'), // bundled version
];
const tsProbeLocations = [
process.cwd(), // workspace version
context.extensionPath, // bundled version
];

const ngProbeLocations = getProbeLocations('angular.ngdk', context.asAbsolutePath('server'));
const tsProbeLocations = getProbeLocations('typescript.tsdk', context.extensionPath);
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
const serverOptions: lsp.ServerOptions = {
Expand Down Expand Up @@ -133,3 +126,20 @@ export function activate(context: vscode.ExtensionContext) {
});
});
}

function getProbeLocations(configName: string, bundled: string): string[] {
const locations = [];
// Always use config value if it's specified
const configValue = vscode.workspace.getConfiguration().get(configName);
if (configValue) {
locations.push(configValue as string);
}
// If not, look in workspaces currently open
const workspaceFolders = vscode.workspace.workspaceFolders || [];
for (const folder of workspaceFolders) {
locations.push(folder.uri.fsPath);
}
// If all else fails, load the bundled version
locations.push(bundled);
return locations;
}
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@
"title": "Restart Angular Language server",
"category": "Angular"
}
]
],
"configuration": {
"title": "Angular Language Service",
"properties": {
"angular.ngdk": {
"type": ["string", "null"],
"default": null,
"description": "Specifies the folder path to @angular/language-service."
}
}
}
},
"activationEvents": [
"onLanguage:html",
Expand Down

0 comments on commit 156e723

Please sign in to comment.