diff --git a/src/server/server.ts b/src/server/server.ts index 767793024c2..efd01741f86 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -14,12 +14,14 @@ namespace ts.server { }); class Logger implements ts.server.Logger { - fd = -1; - seq = 0; - inGroup = false; - firstInGroup = true; + private fd = -1; + private seq = 0; + private inGroup = false; + private firstInGroup = true; - constructor(public logFilename: string, public level: string) { + constructor(private readonly logFilename: string, + private readonly traceToConsole: boolean, + private readonly level: string) { } static padStringRight(str: string, padding: string) { @@ -52,7 +54,7 @@ namespace ts.server { } loggingEnabled() { - return !!this.logFilename; + return !!this.logFilename || this.traceToConsole; } isVerbose() { @@ -66,7 +68,7 @@ namespace ts.server { this.fd = fs.openSync(this.logFilename, "w"); } } - if (this.fd >= 0) { + if (this.fd >= 0 || this.traceToConsole) { s = s + "\n"; const prefix = Logger.padStringRight(type + " " + this.seq.toString(), " "); if (this.firstInGroup) { @@ -78,7 +80,13 @@ namespace ts.server { this.firstInGroup = true; } const buf = new Buffer(s); - fs.writeSync(this.fd, buf, 0, buf.length, null); + if (this.fd >= 0) { + fs.writeSync(this.fd, buf, 0, buf.length, null); + } + if (this.traceToConsole) + { + console.warn(s); + } } } } @@ -109,6 +117,7 @@ namespace ts.server { interface LogOptions { file?: string; detailLevel?: string; + traceToConsole?: boolean; } function parseLoggingEnvironmentString(logEnvStr: string): LogOptions { @@ -125,6 +134,9 @@ namespace ts.server { case "-level": logEnv.detailLevel = value; break; + case "-traceToConsole": + logEnv.traceToConsole = value.toLowerCase() === "true"; + break; } } } @@ -135,6 +147,7 @@ namespace ts.server { function createLoggerFromEnv() { let fileName: string = undefined; let detailLevel = "normal"; + let traceToConsole = false; const logEnvStr = process.env["TSS_LOG"]; if (logEnvStr) { const logEnv = parseLoggingEnvironmentString(logEnvStr); @@ -147,8 +160,9 @@ namespace ts.server { if (logEnv.detailLevel) { detailLevel = logEnv.detailLevel; } + traceToConsole = logEnv.traceToConsole; } - return new Logger(fileName, detailLevel); + return new Logger(fileName, traceToConsole, detailLevel); } // This places log file in the directory containing editorServices.js // TODO: check that this location is writable diff --git a/src/server/session.ts b/src/server/session.ts index 5119e536f72..a20ef018a87 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -118,6 +118,7 @@ namespace ts.server { export const DocumentHighlights = "documentHighlights"; export const Open = "open"; export const Quickinfo = "quickinfo"; + export const QuickinfoFull = "quickinfo-full"; export const References = "references"; export const Reload = "reload"; export const Rename = "rename"; @@ -608,7 +609,7 @@ namespace ts.server { } } - private getQuickInfo(args: protocol.FileLocationRequestArgs): protocol.QuickInfoResponseBody { + private getQuickInfoWorker(args: protocol.FileLocationRequestArgs, simplified: boolean): protocol.QuickInfoResponseBody | QuickInfo { const file = ts.normalizePath(args.file); const project = this.projectService.getProjectForFile(file); if (!project) { @@ -621,21 +622,22 @@ namespace ts.server { if (!quickInfo) { return undefined; } - if (args.position !== undefined) { - // TODO: fixme - return quickInfo; - } - const displayString = ts.displayPartsToString(quickInfo.displayParts); - const docString = ts.displayPartsToString(quickInfo.documentation); - return { - kind: quickInfo.kind, - kindModifiers: quickInfo.kindModifiers, - start: scriptInfo.positionToLineOffset(quickInfo.textSpan.start), - end: scriptInfo.positionToLineOffset(ts.textSpanEnd(quickInfo.textSpan)), - displayString: displayString, - documentation: docString, - }; + if (simplified) { + const displayString = ts.displayPartsToString(quickInfo.displayParts); + const docString = ts.displayPartsToString(quickInfo.documentation); + return { + kind: quickInfo.kind, + kindModifiers: quickInfo.kindModifiers, + start: scriptInfo.positionToLineOffset(quickInfo.textSpan.start), + end: scriptInfo.positionToLineOffset(ts.textSpanEnd(quickInfo.textSpan)), + displayString: displayString, + documentation: docString, + }; + } + else { + return quickInfo; + } } private getFormattingEditsForRange(line: number, offset: number, endLine: number, endOffset: number, fileName: string): protocol.CodeEdit[] { @@ -1112,7 +1114,10 @@ namespace ts.server { return this.notRequired(); }, [CommandNames.Quickinfo]: (request: protocol.QuickInfoRequest) => { - return this.requiredResponse(this.getQuickInfo(request.arguments)); + return this.requiredResponse(this.getQuickInfoWorker(request.arguments, /*simplified*/ true)); + }, + [CommandNames.QuickinfoFull]: (request: protocol.QuickInfoRequest) => { + return this.requiredResponse(this.getQuickInfoWorker(request.arguments, /*simplified*/ false)); }, [CommandNames.Format]: (request: protocol.Request) => { const formatArgs = request.arguments;