Skip to content

Commit d1d57eb

Browse files
author
Keen Yee Liau
committed
feat: Allow users to set log verbosity in editor
This commit adds a config `angular.log` that mirrors `typescript.tsserver.log` for setting log verbosity. This allows users to turn on verbose logging for debugging / diagnostic purpose. It would also help us gather much more info when users report errors. The default value is set to 'terse', which is minimal logging.
1 parent efaeef4 commit d1d57eb

File tree

2 files changed

+48
-26
lines changed

2 files changed

+48
-26
lines changed

client/src/extension.ts

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,13 @@ import {registerCommands} from './commands';
1414
import {projectLoadingNotification} from './protocol';
1515

1616
export function activate(context: vscode.ExtensionContext) {
17-
// Log file does not yet exist on disk. It is up to the server to create the
18-
// file.
19-
const logFile = path.join(context.logPath, 'nglangsvc.log');
20-
const ngProbeLocations = getProbeLocations('angular.ngdk', context.asAbsolutePath('server'));
21-
const tsProbeLocations = getProbeLocations('typescript.tsdk', context.extensionPath);
2217
// If the extension is launched in debug mode then the debug server options are used
2318
// Otherwise the run options are used
2419
const serverOptions: lsp.ServerOptions = {
2520
run: {
2621
module: context.asAbsolutePath(path.join('server')),
2722
transport: lsp.TransportKind.ipc,
28-
args: [
29-
'--logFile',
30-
logFile,
31-
// TODO: Might want to turn off logging completely.
32-
'--ngProbeLocations',
33-
ngProbeLocations.join(','),
34-
'--tsProbeLocations',
35-
tsProbeLocations.join(','),
36-
],
23+
args: constructArgs(context, false /* debug */),
3724
options: {
3825
env: {
3926
// Force TypeScript to use the non-polling version of the file watchers.
@@ -44,16 +31,7 @@ export function activate(context: vscode.ExtensionContext) {
4431
debug: {
4532
module: context.asAbsolutePath(path.join('server', 'out', 'server.js')),
4633
transport: lsp.TransportKind.ipc,
47-
args: [
48-
'--logFile',
49-
logFile,
50-
'--logVerbosity',
51-
'verbose',
52-
'--ngProbeLocations',
53-
ngProbeLocations.join(','),
54-
'--tsProbeLocations',
55-
tsProbeLocations.join(','),
56-
],
34+
args: constructArgs(context, true /* debug */),
5735
options: {
5836
env: {
5937
// Force TypeScript to use the non-polling version of the file watchers.
@@ -127,10 +105,15 @@ export function activate(context: vscode.ExtensionContext) {
127105
});
128106
}
129107

130-
function getProbeLocations(configName: string, bundled: string): string[] {
108+
/**
109+
* Return the paths for the module that corresponds to the specified `configValue`,
110+
* and use the specified `bundled` as fallback if none is provided.
111+
* @param configName
112+
* @param bundled
113+
*/
114+
function getProbeLocations(configValue: string|null, bundled: string): string[] {
131115
const locations = [];
132116
// Always use config value if it's specified
133-
const configValue = vscode.workspace.getConfiguration().get(configName);
134117
if (configValue) {
135118
locations.push(configValue as string);
136119
}
@@ -143,3 +126,31 @@ function getProbeLocations(configName: string, bundled: string): string[] {
143126
locations.push(bundled);
144127
return locations;
145128
}
129+
130+
/**
131+
* Construct the arguments that's used to spawn the server process.
132+
* @param ctx vscode extension context
133+
* @param debug true if debug mode is on
134+
*/
135+
function constructArgs(ctx: vscode.ExtensionContext, debug: boolean): string[] {
136+
const config = vscode.workspace.getConfiguration();
137+
const args: string[] = [];
138+
139+
const ngLog: string = config.get('angular.log', 'off');
140+
if (ngLog !== 'off') {
141+
// Log file does not yet exist on disk. It is up to the server to create the file.
142+
const logFile = path.join(ctx.logPath, 'nglangsvc.log');
143+
args.push('--logFile', logFile);
144+
args.push('--logVerbosity', debug ? 'verbose' : ngLog);
145+
}
146+
147+
const ngdk: string|null = config.get('angular.ngdk', null);
148+
const ngProbeLocations = getProbeLocations(ngdk, ctx.asAbsolutePath('server'));
149+
args.push('--ngProbeLocations', ngProbeLocations.join(','));
150+
151+
const tsdk: string|null = config.get('typescript.tsdk', null);
152+
const tsProbeLocations = getProbeLocations(tsdk, ctx.extensionPath);
153+
args.push('--tsProbeLocations', tsProbeLocations.join(','));
154+
155+
return args;
156+
}

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@
3131
"type": ["string", "null"],
3232
"default": null,
3333
"description": "Specifies the folder path to @angular/language-service."
34+
},
35+
"angular.log": {
36+
"type": "string",
37+
"enum": [
38+
"off",
39+
"terse",
40+
"normal",
41+
"verbose"
42+
],
43+
"default": "terse",
44+
"description": "Enables logging of the Angular server to a file. This log can be used to diagnose Angular Server issues. The log may contain file paths, source code, and other potentially sensitive information from your project."
3445
}
3546
}
3647
}

0 commit comments

Comments
 (0)