Skip to content

Commit ac9717d

Browse files
committed
use Logger directly
1 parent 09a9785 commit ac9717d

5 files changed

Lines changed: 41 additions & 35 deletions

File tree

src/server/editorServices.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ namespace ts.server {
8686
// if the ref count for this directory watcher drops to 0, it's time to close it
8787
this.directoryWatchersRefCount[directory]--;
8888
if (this.directoryWatchersRefCount[directory] === 0) {
89-
this.projectService.log(`Close directory watcher for: ${directory}`);
89+
this.projectService.logger.info(`Close directory watcher for: ${directory}`);
9090
this.directoryWatchersForTsconfig[directory].close();
9191
delete this.directoryWatchersForTsconfig[directory];
9292
}
@@ -97,7 +97,7 @@ namespace ts.server {
9797
let parentPath = getDirectoryPath(currentPath);
9898
while (currentPath != parentPath) {
9999
if (!this.directoryWatchersForTsconfig[currentPath]) {
100-
this.projectService.log(`Add watcher for: ${currentPath}`);
100+
this.projectService.logger.info(`Add watcher for: ${currentPath}`);
101101
this.directoryWatchersForTsconfig[currentPath] = this.projectService.host.watchDirectory(currentPath, callback);
102102
this.directoryWatchersRefCount[currentPath] = 1;
103103
}
@@ -279,7 +279,7 @@ namespace ts.server {
279279
return;
280280
}
281281

282-
this.log(`Detected source file changes: ${fileName}`);
282+
this.logger.info(`Detected source file changes: ${fileName}`);
283283
this.throttledOperations.schedule(
284284
project.configFileName,
285285
/*delay*/250,
@@ -306,7 +306,7 @@ namespace ts.server {
306306
}
307307

308308
private onConfigChangedForConfiguredProject(project: ConfiguredProject) {
309-
this.log(`Config file changed: ${project.configFileName}`);
309+
this.logger.info(`Config file changed: ${project.configFileName}`);
310310
this.updateConfiguredProject(project);
311311
this.refreshInferredProjects();
312312
}
@@ -317,11 +317,11 @@ namespace ts.server {
317317
private onConfigFileAddedForInferredProject(fileName: string) {
318318
// TODO: check directory separators
319319
if (getBaseFileName(fileName) != "tsconfig.json") {
320-
this.log(`${fileName} is not tsconfig.json`);
320+
this.logger.info(`${fileName} is not tsconfig.json`);
321321
return;
322322
}
323323

324-
this.log(`Detected newly added tsconfig file: ${fileName}`);
324+
this.logger.info(`Detected newly added tsconfig file: ${fileName}`);
325325
this.reloadProjects();
326326
}
327327

@@ -331,7 +331,7 @@ namespace ts.server {
331331
}
332332

333333
private removeProject(project: Project) {
334-
this.log(`remove project: ${project.getRootFiles().toString()}`);
334+
this.logger.info(`remove project: ${project.getRootFiles().toString()}`);
335335

336336
project.close();
337337

@@ -460,16 +460,16 @@ namespace ts.server {
460460
*/
461461
private openOrUpdateConfiguredProjectForFile(fileName: NormalizedPath): OpenConfiguredProjectResult {
462462
const searchPath = getDirectoryPath(fileName);
463-
this.log(`Search path: ${searchPath}`, "Info");
463+
this.logger.info(`Search path: ${searchPath}`);
464464

465465
// check if this file is already included in one of external projects
466466
const configFileName = this.findConfigFile(asNormalizedPath(searchPath));
467467
if (!configFileName) {
468-
this.log("No config files found.");
468+
this.logger.info("No config files found.");
469469
return {};
470470
}
471471

472-
this.log(`Config file name: ${configFileName}`, "Info");
472+
this.logger.info(`Config file name: ${configFileName}`);
473473

474474
const project = this.findConfiguredProjectByProjectName(configFileName);
475475
if (!project) {
@@ -480,7 +480,7 @@ namespace ts.server {
480480

481481
// even if opening config file was successful, it could still
482482
// contain errors that were tolerated.
483-
this.log(`Opened configuration file ${configFileName}`, "Info");
483+
this.logger.info(`Opened configuration file ${configFileName}`);
484484
if (errors && errors.length > 0) {
485485
return { configFileName, configFileErrors: errors };
486486
}
@@ -737,7 +737,7 @@ namespace ts.server {
737737

738738
private updateConfiguredProject(project: ConfiguredProject) {
739739
if (!this.host.fileExists(project.configFileName)) {
740-
this.log("Config file deleted");
740+
this.logger.info("Config file deleted");
741741
this.removeProject(project);
742742
return;
743743
}
@@ -835,26 +835,22 @@ namespace ts.server {
835835
return this.filenameToScriptInfo.get(fileName);
836836
}
837837

838-
log(msg: string, type = "Err") {
839-
this.logger.msg(msg, type);
840-
}
841-
842838
setHostConfiguration(args: protocol.ConfigureRequestArguments) {
843839
if (args.file) {
844840
const info = this.getScriptInfoForNormalizedPath(toNormalizedPath(args.file));
845841
if (info) {
846842
info.setFormatOptions(args.formatOptions);
847-
this.log(`Host configuration update for file ${args.file}`, "Info");
843+
this.logger.info(`Host configuration update for file ${args.file}`);
848844
}
849845
}
850846
else {
851847
if (args.hostInfo !== undefined) {
852848
this.hostConfiguration.hostInfo = args.hostInfo;
853-
this.log(`Host information ${args.hostInfo}`, "Info");
849+
this.logger.info(`Host information ${args.hostInfo}`);
854850
}
855851
if (args.formatOptions) {
856852
mergeMaps(this.hostConfiguration.formatCodeOptions, args.formatOptions);
857-
this.log("Format host information updated", "Info");
853+
this.logger.info("Format host information updated");
858854
}
859855
}
860856
}
@@ -867,7 +863,7 @@ namespace ts.server {
867863
* This function rebuilds the project for every file opened by the client
868864
*/
869865
reloadProjects() {
870-
this.log("reload projects.");
866+
this.logger.info("reload projects.");
871867
// try to reload config file for all open files
872868
for (const info of this.openFiles) {
873869
this.openOrUpdateConfiguredProjectForFile(info.fileName);
@@ -881,7 +877,7 @@ namespace ts.server {
881877
* up to date.
882878
*/
883879
refreshInferredProjects() {
884-
this.log("updating project structure from ...", "Info");
880+
this.logger.info("updating project structure from ...");
885881
this.printProjects();
886882

887883
const orphantedFiles: ScriptInfo[] = [];

src/server/project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ namespace ts.server {
406406
}
407407

408408
const directoryToWatch = getDirectoryPath(this.configFileName);
409-
this.projectService.log(`Add recursive watcher for: ${directoryToWatch}`);
409+
this.projectService.logger.info(`Add recursive watcher for: ${directoryToWatch}`);
410410
this.directoryWatcher = this.projectService.host.watchDirectory(directoryToWatch, path => callback(this, path), /*recursive*/ true);
411411
}
412412

@@ -418,7 +418,7 @@ namespace ts.server {
418418
this.directoriesWatchedForWildcards = reduceProperties(this.wildcardDirectories, (watchers, flag, directory) => {
419419
if (comparePaths(configDirectoryPath, directory, ".", !this.projectService.host.useCaseSensitiveFileNames) !== Comparison.EqualTo) {
420420
const recursive = (flag & WatchDirectoryFlags.Recursive) !== 0;
421-
this.projectService.log(`Add ${recursive ? "recursive " : ""}watcher for: ${directory}`);
421+
this.projectService.logger.info(`Add ${recursive ? "recursive " : ""}watcher for: ${directory}`);
422422
watchers[directory] = this.projectService.host.watchDirectory(
423423
directory,
424424
path => callback(this, path),

src/server/server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ namespace ts.server {
4444
}
4545

4646
perftrc(s: string) {
47-
this.msg(s, "Perf");
47+
this.msg(s, Msg.Perf);
4848
}
4949

5050
info(s: string) {
51-
this.msg(s, "Info");
51+
this.msg(s, Msg.Info);
5252
}
5353

5454
startGroup() {
@@ -71,7 +71,7 @@ namespace ts.server {
7171
}
7272

7373

74-
msg(s: string, type = "Err") {
74+
msg(s: string, type: Msg.Types = Msg.Err) {
7575
if (this.fd < 0) {
7676
if (this.logFilename) {
7777
this.fd = fs.openSync(this.logFilename, "w");
@@ -105,7 +105,7 @@ namespace ts.server {
105105
}
106106

107107
exit() {
108-
this.projectService.log("Exiting...", "Info");
108+
this.logger.info("Exiting...");
109109
this.projectService.closeLog();
110110
process.exit(0);
111111
}

src/server/session.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ namespace ts.server {
164164
private maxUncompressedMessageSize: number,
165165
private compress: (s: string) => CompressedData,
166166
private hrtime: (start?: number[]) => number[],
167-
private logger: Logger) {
167+
protected logger: Logger) {
168168
this.projectService =
169169
new ProjectService(host, logger, cancellationToken, useSingleInferredProject, (eventName, project, fileName) => {
170170
this.handleEvent(eventName, project, fileName);
@@ -173,7 +173,7 @@ namespace ts.server {
173173

174174
private handleEvent(eventName: string, project: Project, fileName: NormalizedPath) {
175175
if (eventName == "context") {
176-
this.projectService.log("got context event, updating diagnostics for" + fileName, "Info");
176+
this.logger.info("got context event, updating diagnostics for" + fileName);
177177
this.updateErrorCheck([{ fileName, project }], this.changeSeq,
178178
(n) => n === this.changeSeq, 100);
179179
}
@@ -187,7 +187,7 @@ namespace ts.server {
187187
msg += "\n" + (<StackTraceError>err).stack;
188188
}
189189
}
190-
this.projectService.log(msg);
190+
this.logger.msg(msg, Msg.Err);
191191
}
192192

193193
public send(msg: protocol.Message, canCompressResponse: boolean) {
@@ -334,7 +334,7 @@ namespace ts.server {
334334
if (!projects) {
335335
return;
336336
}
337-
this.projectService.log(`cleaning ${caption}`);
337+
this.logger.info(`cleaning ${caption}`);
338338
for (const p of projects) {
339339
p.languageService.cleanupSemanticCache();
340340
}
@@ -345,7 +345,7 @@ namespace ts.server {
345345
this.cleanProjects("configured projects", this.projectService.configuredProjects);
346346
this.cleanProjects("external projects", this.projectService.externalProjects);
347347
if (typeof global !== "undefined" && global.gc) {
348-
this.projectService.log(`global.gc()`);
348+
this.logger.info(`global.gc()`);
349349
global.gc();
350350
global.gc();
351351
global.gc();
@@ -1451,8 +1451,8 @@ namespace ts.server {
14511451
return handler(request);
14521452
}
14531453
else {
1454-
this.projectService.log("Unrecognized JSON command: " + JSON.stringify(request));
1455-
this.output(undefined, CommandNames.Unknown, /*canCompressResponse*/ false, request.seq, "Unrecognized JSON command: " + request.command);
1454+
this.logger.msg(`Unrecognized JSON command: ${JSON.stringify(request)}`, Msg.Err);
1455+
this.output(undefined, CommandNames.Unknown, /*canCompressResponse*/ false, request.seq, `Unrecognized JSON command: ${request.command}`);
14561456
return { responseRequired: false };
14571457
}
14581458
}

src/server/utilities.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ namespace ts.server {
99
info(s: string): void;
1010
startGroup(): void;
1111
endGroup(): void;
12-
msg(s: string, type?: string): void;
12+
msg(s: string, type?: Msg.Types): void;
13+
}
14+
15+
export namespace Msg {
16+
export type Err = "Err";
17+
export const Err: Err = "Err";
18+
export type Info = "Info";
19+
export const Info: Info = "Info";
20+
export type Perf = "Perf";
21+
export const Perf: Perf = "Perf";
22+
export type Types = Err | Info | Perf;
1323
}
1424

1525
export function getDefaultFormatCodeSettings(host: ServerHost): FormatCodeSettings {

0 commit comments

Comments
 (0)