Skip to content

Commit e192c2c

Browse files
author
Andy Hanson
committed
Code review
1 parent 9a9a38a commit e192c2c

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

src/server/session.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,11 +1837,7 @@ namespace ts.server {
18371837
}
18381838

18391839
private mapTextChangeToCodeEdit(change: FileTextChanges): protocol.FileCodeEdits {
1840-
return mapTextChangesToCodeEdits(change, this.projectService.getScriptInfoOrConfig(this.normalizePath(change.fileName)));
1841-
}
1842-
1843-
private normalizePath(fileName: string) {
1844-
return normalizedPathToPath(toNormalizedPath(fileName), this.host.getCurrentDirectory(), fileName => this.getCanonicalFileName(fileName));
1840+
return mapTextChangesToCodeEdits(change, this.projectService.getScriptInfoOrConfig(change.fileName));
18451841
}
18461842

18471843
private convertTextChangeToCodeEdit(change: TextChange, scriptInfo: ScriptInfo): protocol.CodeEdit {

src/testRunner/unittests/tsserverProjectSystem.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,10 @@ namespace ts.projectSystem {
515515
return session.executeCommand(makeSessionRequest(command, args)).response as TResponse["body"];
516516
}
517517

518+
export function executeSessionRequestNoResponse<TRequest extends protocol.Request>(session: server.Session, command: TRequest["command"], args: TRequest["arguments"]): void {
519+
session.executeCommand(makeSessionRequest(command, args));
520+
}
521+
518522
export function openFilesForSession(files: ReadonlyArray<File | { readonly file: File | string, readonly projectRootPath: string }>, session: server.Session): void {
519523
for (const file of files) {
520524
session.executeCommand(makeSessionRequest<protocol.OpenRequestArgs>(CommandNames.Open,
@@ -9256,6 +9260,50 @@ export function Test2() {
92569260
});
92579261
});
92589262

9263+
describe("Untitled files", () => {
9264+
it("Can convert positions to locations", () => {
9265+
const aTs: File = { path: "/proj/a.ts", content: "" };
9266+
const tsconfig: File = { path: "/proj/tsconfig.json", content: "{}" };
9267+
const session = createSession(createServerHost([aTs, tsconfig]));
9268+
9269+
openFilesForSession([aTs], session);
9270+
9271+
const untitledFile = "untitled:^Untitled-1";
9272+
executeSessionRequestNoResponse<protocol.OpenRequest>(session, protocol.CommandTypes.Open, {
9273+
file: untitledFile,
9274+
fileContent: "let foo = 1;\nfooo/**/",
9275+
scriptKindName: "TS",
9276+
projectRootPath: "/proj",
9277+
});
9278+
9279+
const response = executeSessionRequest<protocol.CodeFixRequest, protocol.CodeFixResponse>(session, protocol.CommandTypes.GetCodeFixes, {
9280+
file: untitledFile,
9281+
startLine: 2,
9282+
startOffset: 1,
9283+
endLine: 2,
9284+
endOffset: 5,
9285+
errorCodes: [Diagnostics.Cannot_find_name_0_Did_you_mean_1.code],
9286+
});
9287+
assert.deepEqual<ReadonlyArray<protocol.CodeFixAction> | undefined>(response, [
9288+
{
9289+
description: "Change spelling to 'foo'",
9290+
fixAllDescription: "Fix all detected spelling errors",
9291+
fixId: "fixSpelling",
9292+
fixName: "spelling",
9293+
changes: [{
9294+
fileName: untitledFile,
9295+
textChanges: [{
9296+
start: { line: 2, offset: 1 },
9297+
end: { line: 2, offset: 5 },
9298+
newText: "foo",
9299+
}],
9300+
}],
9301+
commands: undefined,
9302+
},
9303+
]);
9304+
});
9305+
});
9306+
92599307
function makeReferenceItem(file: File, isDefinition: boolean, text: string, lineText: string, options?: SpanFromSubstringOptions): protocol.ReferencesResponseItem {
92609308
return {
92619309
...protocolFileSpanFromSubstring(file, text, options),

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8893,7 +8893,6 @@ declare namespace ts.server {
88938893
private mapCodeFixAction;
88948894
private mapTextChangesToCodeEdits;
88958895
private mapTextChangeToCodeEdit;
8896-
private normalizePath;
88978896
private convertTextChangeToCodeEdit;
88988897
private getBraceMatching;
88998898
private getDiagnosticsForProject;

0 commit comments

Comments
 (0)