Skip to content
This repository was archived by the owner on Nov 21, 2025. It is now read-only.

Commit e75e7d4

Browse files
committed
refactor: use Session.info/error to log to console and output
This is a follow-up to #962 We should always call `Session.info()` or `Session.error()` to log entries so that console entries also show up in log file.
1 parent e7143d7 commit e75e7d4

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

server/src/session.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export class Session {
210210
const {configFileName} = this.projectService.openClientFile(scriptInfo.fileName);
211211
if (!configFileName) {
212212
// Failed to find a config file. There is nothing we could do.
213-
this.connection.console.error(`No config file for ${scriptInfo.fileName}`);
213+
this.error(`No config file for ${scriptInfo.fileName}`);
214214
return;
215215
}
216216
project = this.projectService.findProject(configFileName);
@@ -270,7 +270,7 @@ export class Session {
270270
const {configFileName, configFileErrors} = result;
271271
if (configFileErrors && configFileErrors.length) {
272272
// configFileErrors is an empty array even if there's no error, so check length.
273-
this.connection.console.error(configFileErrors.map(e => e.messageText).join('\n'));
273+
this.error(configFileErrors.map(e => e.messageText).join('\n'));
274274
}
275275
if (!configFileName) {
276276
// It is not really an error if there is no config file, because the
@@ -284,7 +284,7 @@ export class Session {
284284
}
285285
const project = this.projectService.findProject(configFileName);
286286
if (!project) {
287-
this.connection.console.error(`Failed to find project for ${filePath}`);
287+
this.error(`Failed to find project for ${filePath}`);
288288
return;
289289
}
290290
if (project.languageServiceEnabled) {
@@ -319,7 +319,7 @@ export class Session {
319319
}
320320
const scriptInfo = this.projectService.getScriptInfo(filePath);
321321
if (!scriptInfo) {
322-
this.connection.console.log(`Failed to get script info for ${filePath}`);
322+
this.error(`Failed to get script info for ${filePath}`);
323323
return;
324324
}
325325
for (const change of contentChanges) {
@@ -415,7 +415,7 @@ export class Session {
415415
const filePath = uriToFilePath(textDocument.uri);
416416
const scriptInfo = this.projectService.getScriptInfo(filePath);
417417
if (!scriptInfo) {
418-
this.connection.console.log(`Script info not found for ${filePath}`);
418+
this.error(`Script info not found for ${filePath}`);
419419
return;
420420
}
421421

@@ -528,35 +528,30 @@ export class Session {
528528
const NG_CORE = '@angular/core/core.d.ts';
529529
const {projectName} = project;
530530
if (!project.languageServiceEnabled) {
531-
const msg = `Language service is already disabled for ${projectName}. ` +
531+
this.info(`Language service is already disabled for ${projectName}. ` +
532532
`This could be due to non-TS files that exceeded the size limit (${
533533
ts.server.maxProgramSizeForNonTsFiles} bytes).` +
534-
`Please check log file for details.`;
535-
this.connection.console.info(msg); // log to remote console to inform users
536-
project.log(msg); // log to file, so that it's easier to correlate with ts entries
534+
`Please check log file for details.`);
537535

538536
return;
539537
}
540538
if (!isAngularProject(project, NG_CORE)) {
541539
project.disableLanguageService();
542-
const msg =
540+
this.info(
543541
`Disabling language service for ${projectName} because it is not an Angular project ` +
544542
`('${NG_CORE}' could not be found). ` +
545-
`If you believe you are seeing this message in error, please reinstall the packages in your package.json.`;
546-
this.connection.console.info(msg);
547-
project.log(msg);
543+
`If you believe you are seeing this message in error, please reinstall the packages in your package.json.`);
544+
548545
if (project.getExcludedFiles().some(f => f.endsWith(NG_CORE))) {
549-
const msg =
550-
`Please check your tsconfig.json to make sure 'node_modules' directory is not excluded.`;
551-
this.connection.console.info(msg);
552-
project.log(msg);
546+
this.info(
547+
`Please check your tsconfig.json to make sure 'node_modules' directory is not excluded.`);
553548
}
554549

555550
return;
556551
}
557552

558553
// The language service should be enabled at this point.
559-
this.connection.console.info(`Enabling language service for ${projectName}.`);
554+
this.info(`Enabling language service for ${projectName}.`);
560555
}
561556
}
562557

0 commit comments

Comments
 (0)