Skip to content

Commit 4e570f0

Browse files
Andymhegazy
authored andcommitted
Revert public API changes to logger (#17901)
1 parent b326ac6 commit 4e570f0

File tree

6 files changed

+52
-39
lines changed

6 files changed

+52
-39
lines changed

src/harness/harnessLanguageService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ namespace Harness.LanguageService {
686686
this.host.log(message);
687687
}
688688

689-
err(message: string): void {
689+
msg(message: string): void {
690690
this.host.log(message);
691691
}
692692

@@ -702,7 +702,8 @@ namespace Harness.LanguageService {
702702
return false;
703703
}
704704

705-
group() { throw ts.notImplemented(); }
705+
startGroup() { throw ts.notImplemented(); }
706+
endGroup() { throw ts.notImplemented(); }
706707

707708
perftrc(message: string): void {
708709
return this.host.log(message);

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ namespace ts.projectSystem {
3939
loggingEnabled: () => false,
4040
perftrc: noop,
4141
info: noop,
42-
err: noop,
43-
group: noop,
42+
msg: noop,
43+
startGroup: noop,
44+
endGroup: noop,
4445
getLogFileName: (): string => undefined
4546
};
4647

src/server/editorServices.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -958,28 +958,28 @@ namespace ts.server {
958958
return;
959959
}
960960

961-
this.logger.group(info => {
962-
let counter = 0;
963-
counter = printProjects(this.externalProjects, info, counter);
964-
counter = printProjects(this.configuredProjects, info, counter);
965-
printProjects(this.inferredProjects, info, counter);
966-
967-
info("Open files: ");
968-
for (const rootFile of this.openFiles) {
969-
info(`\t${rootFile.fileName}`);
970-
}
971-
});
972-
973-
function printProjects(projects: Project[], info: (msg: string) => void, counter: number): number {
961+
this.logger.startGroup();
962+
let counter = 0;
963+
const printProjects = (projects: Project[], counter: number): number => {
974964
for (const project of projects) {
975965
project.updateGraph();
976-
info(`Project '${project.getProjectName()}' (${ProjectKind[project.projectKind]}) ${counter}`);
977-
info(project.filesToString());
978-
info("-----------------------------------------------");
966+
this.logger.info(`Project '${project.getProjectName()}' (${ProjectKind[project.projectKind]}) ${counter}`);
967+
this.logger.info(project.filesToString());
968+
this.logger.info("-----------------------------------------------");
979969
counter++;
980970
}
981971
return counter;
972+
};
973+
counter = printProjects(this.externalProjects, counter);
974+
counter = printProjects(this.configuredProjects, counter);
975+
printProjects(this.inferredProjects, counter);
976+
977+
this.logger.info("Open files: ");
978+
for (const rootFile of this.openFiles) {
979+
this.logger.info(`\t${rootFile.fileName}`);
982980
}
981+
982+
this.logger.endGroup();
983983
}
984984

985985
private findConfiguredProjectByProjectName(configFileName: NormalizedPath) {

src/server/server.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ namespace ts.server {
140140
class Logger implements server.Logger {
141141
private fd = -1;
142142
private seq = 0;
143+
private inGroup = false;
144+
private firstInGroup = true;
143145

144146
constructor(private readonly logFilename: string,
145147
private readonly traceToConsole: boolean,
@@ -169,24 +171,24 @@ namespace ts.server {
169171
}
170172

171173
perftrc(s: string) {
172-
this.msg(s, "Perf");
174+
this.msg(s, Msg.Perf);
173175
}
174176

175177
info(s: string) {
176-
this.msg(s, "Info");
178+
this.msg(s, Msg.Info);
177179
}
178180

179181
err(s: string) {
180-
this.msg(s, "Err");
182+
this.msg(s, Msg.Err);
181183
}
182184

183-
group(logGroupEntries: (log: (msg: string) => void) => void) {
184-
let firstInGroup = false;
185-
logGroupEntries(s => {
186-
this.msg(s, "Info", /*inGroup*/ true, firstInGroup);
187-
firstInGroup = false;
188-
});
189-
this.seq++;
185+
startGroup() {
186+
this.inGroup = true;
187+
this.firstInGroup = true;
188+
}
189+
190+
endGroup() {
191+
this.inGroup = false;
190192
}
191193

192194
loggingEnabled() {
@@ -197,16 +199,16 @@ namespace ts.server {
197199
return this.loggingEnabled() && this.level >= level;
198200
}
199201

200-
private msg(s: string, type: string, inGroup = false, firstInGroup = false) {
202+
msg(s: string, type: Msg.Types = Msg.Err) {
201203
if (!this.canWrite) return;
202204

203205
s = `[${nowString()}] ${s}\n`;
204-
if (!inGroup || firstInGroup) {
206+
if (!this.inGroup || this.firstInGroup) {
205207
const prefix = Logger.padStringRight(type + " " + this.seq.toString(), " ");
206208
s = prefix + s;
207209
}
208210
this.write(s);
209-
if (!inGroup) {
211+
if (!this.inGroup) {
210212
this.seq++;
211213
}
212214
}

src/server/session.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ namespace ts.server {
368368
msg += "\n" + (<StackTraceError>err).stack;
369369
}
370370
}
371-
this.logger.err(msg);
371+
this.logger.msg(msg, Msg.Err);
372372
}
373373

374374
public send(msg: protocol.Message) {
@@ -1950,7 +1950,7 @@ namespace ts.server {
19501950
return this.executeWithRequestId(request.seq, () => handler(request));
19511951
}
19521952
else {
1953-
this.logger.err(`Unrecognized JSON command: ${JSON.stringify(request)}`);
1953+
this.logger.msg(`Unrecognized JSON command: ${JSON.stringify(request)}`, Msg.Err);
19541954
this.output(undefined, CommandNames.Unknown, request.seq, `Unrecognized JSON command: ${request.command}`);
19551955
return { responseRequired: false };
19561956
}

src/server/utilities.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,22 @@ namespace ts.server {
1717
loggingEnabled(): boolean;
1818
perftrc(s: string): void;
1919
info(s: string): void;
20-
err(s: string): void;
21-
group(logGroupEntries: (log: (msg: string) => void) => void): void;
20+
startGroup(): void;
21+
endGroup(): void;
22+
msg(s: string, type?: Msg.Types): void;
2223
getLogFileName(): string;
2324
}
2425

26+
export namespace Msg {
27+
export type Err = "Err";
28+
export const Err: Err = "Err";
29+
export type Info = "Info";
30+
export const Info: Info = "Info";
31+
export type Perf = "Perf";
32+
export const Perf: Perf = "Perf";
33+
export type Types = Err | Info | Perf;
34+
}
35+
2536
function getProjectRootPath(project: Project): Path {
2637
switch (project.projectKind) {
2738
case ProjectKind.Configured:
@@ -115,9 +126,7 @@ namespace ts.server {
115126
}
116127

117128
export function createNormalizedPathMap<T>(): NormalizedPathMap<T> {
118-
/* tslint:disable:no-null-keyword */
119129
const map = createMap<T>();
120-
/* tslint:enable:no-null-keyword */
121130
return {
122131
get(path) {
123132
return map.get(path);

0 commit comments

Comments
 (0)