From d2712dd793db7032b11e5ef71c1f4a4ee06131b2 Mon Sep 17 00:00:00 2001 From: steveluc Date: Mon, 16 Feb 2015 23:43:05 -0800 Subject: [PATCH] Removed file mapping compression technique due to brittleness of approach. As necessary, will substitute grouping or paging approaches. --- src/server/client.ts | 24 ++++-------------------- src/server/protocol.d.ts | 40 ++++------------------------------------ src/server/session.ts | 30 +++++++----------------------- 3 files changed, 15 insertions(+), 79 deletions(-) diff --git a/src/server/client.ts b/src/server/client.ts index 22b346aa3ec..a3b32be31ed 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -69,22 +69,6 @@ module ts.server { }; } - private decodeEncodedFileId(fileId: ts.server.protocol.EncodedFile): string { - var fileName: string; - if (typeof fileId === "object") { - fileName = (fileId).file; - this.fileMapping[(fileId).id] = fileName; - } - else if (typeof fileId === "number") { - fileName = ts.lookUp(this.fileMapping, fileId.toString()); - Debug.assert(!!fileName, "Did not find filename in previous fileID mappings."); - } - else { - Debug.fail("Got unexpedted fileId type."); - } - return fileName; - } - private processRequest(command: string, arguments?: any): T { var request: ts.server.protocol.Request = { seq: this.sequence++, @@ -232,7 +216,7 @@ module ts.server { var response = this.processResponse(request); return response.body.map(entry => { - var fileName = this.decodeEncodedFileId(entry.file); + var fileName = entry.file; var start = this.lineColToPosition(fileName, entry.start); var end = this.lineColToPosition(fileName, entry.end); @@ -299,7 +283,7 @@ module ts.server { var response = this.processResponse(request); return response.body.map(entry => { - var fileName = this.decodeEncodedFileId(entry.file); + var fileName = entry.file; var start = this.lineColToPosition(fileName, entry.start); var end = this.lineColToPosition(fileName, entry.end); return { @@ -325,7 +309,7 @@ module ts.server { var response = this.processResponse(request); return response.body.refs.map(entry => { - var fileName = this.decodeEncodedFileId(entry.file); + var fileName = entry.file; var start = this.lineColToPosition(fileName, entry.start); var end = this.lineColToPosition(fileName, entry.end); return { @@ -378,7 +362,7 @@ module ts.server { findInStrings: findInStrings, findInComments: findInComments, locations: response.body.locs.map((entry) => { - var fileName = this.decodeEncodedFileId(entry.file); + var fileName = entry.file; var start = this.lineColToPosition(fileName, entry.start); var end = this.lineColToPosition(fileName, entry.end); return { diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index e3433e24690..06974b58cb3 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -153,11 +153,9 @@ declare module ts.server.protocol { */ export interface CodeSpan extends TextSpan { /** - * File containing the definition; the value of this - * field will always be a string, number of a mapping between - * a string and a number. + * File containing text span. */ - file: EncodedFile; + file: string; } /** @@ -675,11 +673,9 @@ declare module ts.server.protocol { kindModifiers?: string; /** - * The file in which the symbol is found; the value of this - * field will always be a string, number of a mapping between - * a string and a number. + * The file in which the symbol is found. */ - file: EncodedFile; + file: string; /** * The location within file at which the symbol is found. @@ -736,34 +732,6 @@ declare module ts.server.protocol { arguments: ChangeRequestArgs; } - /** - * If an object of this type is returned in place of a string as - * the value of a file field in a response message, add the - * mapping id => file to the client's cache of file id mappings, - * and interpret the value as if it was the string in the 'file' - * field. - */ - export interface IdFile { - /** - * Id to assign to file. - */ - id: number; - - /** - * File name that will correspond to id. - */ - file: string; - } - - /** - * The type of an encoded file name. If of type number, the value - * is a file id. If of type IdFile, the value is interpreted as - * 'file' and in addition the mapping 'id' to 'file' is - * established. If of type string, the value is simply the file - * name. - */ - export type EncodedFile = number | IdFile | string; - /** * Response to "brace" request. */ diff --git a/src/server/session.ts b/src/server/session.ts index e88932dcb77..812d2fc6c15 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -5,10 +5,6 @@ /// module ts.server { - var paddedLength = 8; - - var typeNames = ["interface", "class", "enum", "module", "alias", "type"]; - var spaceCache = [" ", " ", " ", " "]; interface StackTraceError extends Error { @@ -27,7 +23,7 @@ module ts.server { } interface FileStart { - file: ts.server.protocol.EncodedFile; + file: string; start: ILineInfo; } @@ -204,18 +200,6 @@ module ts.server { this.send(res); } - encodeFileName(fileName: string): ts.server.protocol.EncodedFile { - var id = ts.lookUp(this.fileHash, fileName); - if (!id) { - id = this.nextFileId++; - this.fileHash[fileName] = id; - return { id: id, file: fileName }; - } - else { - return id; - } - } - output(body: any, commandName: string, requestSequence = 0, errorMessage?: string) { this.response(body, commandName, requestSequence, errorMessage); } @@ -224,7 +208,7 @@ module ts.server { var diags = project.compilerService.languageService.getSemanticDiagnostics(file); if (diags) { var bakedDiags = diags.map((diag) => formatDiag(file, project, diag)); - this.event({ file: this.encodeFileName(file), diagnostics: bakedDiags }, "semanticDiag"); + this.event({ file: file, diagnostics: bakedDiags }, "semanticDiag"); } } @@ -232,7 +216,7 @@ module ts.server { var diags = project.compilerService.languageService.getSyntacticDiagnostics(file); if (diags) { var bakedDiags = diags.map((diag) => formatDiag(file, project, diag)); - this.event({ file: this.encodeFileName(file), diagnostics: bakedDiags }, "syntaxDiag"); + this.event({ file: file, diagnostics: bakedDiags }, "syntaxDiag"); } } @@ -293,7 +277,7 @@ module ts.server { } return definitions.map(def => ({ - file: this.encodeFileName(def.fileName), + file: def.fileName, start: compilerService.host.positionToLineCol(def.fileName, def.textSpan.start), end: compilerService.host.positionToLineCol(def.fileName, ts.textSpanEnd(def.textSpan)) })); @@ -326,7 +310,7 @@ module ts.server { } var bakedRenameLocs = renameLocations.map(location => ({ - file: this.encodeFileName(location.fileName), + file: location.fileName, start: compilerService.host.positionToLineCol(location.fileName, location.textSpan.start), end: compilerService.host.positionToLineCol(location.fileName, ts.textSpanEnd(location.textSpan)), })); @@ -366,7 +350,7 @@ module ts.server { var snap = compilerService.host.getScriptSnapshot(ref.fileName); var lineText = snap.getText(refLineSpan.start, ts.textSpanEnd(refLineSpan)).replace(/\r|\n/g, ""); return { - file: this.encodeFileName(ref.fileName), + file: ref.fileName, start: start, lineText: lineText, end: compilerService.host.positionToLineCol(ref.fileName, ts.textSpanEnd(ref.textSpan)), @@ -633,7 +617,7 @@ module ts.server { var bakedItem: ts.server.protocol.NavtoItem = { name: navItem.name, kind: navItem.kind, - file: this.encodeFileName(navItem.fileName), + file: navItem.fileName, start: start, end: end, };