Skip to content

Commit 381dd84

Browse files
author
Armando Aguirre
committed
Removed TextRange and added FileRangeRequestArgs
1 parent 090b38d commit 381dd84

File tree

7 files changed

+183
-198
lines changed

7 files changed

+183
-198
lines changed

src/harness/fourslashImpl.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,7 +3190,7 @@ namespace FourSlash {
31903190

31913191
this.raiseError(
31923192
`Expected to find a fix with the name '${fixName}', but none exists.` +
3193-
availableFixes.length
3193+
availableFixes.length
31943194
? ` Available fixes: ${availableFixes.map(fix => `${fix.fixName} (${fix.fixId ? "with" : "without"} fix-all)`).join(", ")}`
31953195
: ""
31963196
);
@@ -3429,13 +3429,13 @@ namespace FourSlash {
34293429

34303430
const incomingCalls =
34313431
direction === CallHierarchyItemDirection.Outgoing ? { result: "skip" } as const :
3432-
alreadySeen ? { result: "seen" } as const :
3433-
{ result: "show", values: this.languageService.provideCallHierarchyIncomingCalls(callHierarchyItem.file, callHierarchyItem.selectionSpan.start) } as const;
3432+
alreadySeen ? { result: "seen" } as const :
3433+
{ result: "show", values: this.languageService.provideCallHierarchyIncomingCalls(callHierarchyItem.file, callHierarchyItem.selectionSpan.start) } as const;
34343434

34353435
const outgoingCalls =
34363436
direction === CallHierarchyItemDirection.Incoming ? { result: "skip" } as const :
3437-
alreadySeen ? { result: "seen" } as const :
3438-
{ result: "show", values: this.languageService.provideCallHierarchyOutgoingCalls(callHierarchyItem.file, callHierarchyItem.selectionSpan.start) } as const;
3437+
alreadySeen ? { result: "seen" } as const :
3438+
{ result: "show", values: this.languageService.provideCallHierarchyOutgoingCalls(callHierarchyItem.file, callHierarchyItem.selectionSpan.start) } as const;
34393439

34403440
let text = "";
34413441
text += `${prefix}╭ name: ${callHierarchyItem.name}\n`;
@@ -3446,7 +3446,7 @@ namespace FourSlash {
34463446
text += `${prefix}├ selectionSpan:\n`;
34473447
text += this.formatCallHierarchyItemSpan(file, callHierarchyItem.selectionSpan, `${prefix}│ `,
34483448
incomingCalls.result !== "skip" || outgoingCalls.result !== "skip" ? `${prefix}│ ` :
3449-
`${trailingPrefix}╰ `);
3449+
`${trailingPrefix}╰ `);
34503450

34513451
if (incomingCalls.result === "seen") {
34523452
if (outgoingCalls.result === "skip") {
@@ -3475,8 +3475,8 @@ namespace FourSlash {
34753475
text += `${prefix}│ ├ fromSpans:\n`;
34763476
text += this.formatCallHierarchyItemSpans(file, incomingCall.fromSpans, `${prefix}│ │ `,
34773477
i < incomingCalls.values.length - 1 ? `${prefix}│ ╰ ` :
3478-
outgoingCalls.result !== "skip" ? `${prefix}│ ╰ ` :
3479-
`${trailingPrefix}╰ ╰ `);
3478+
outgoingCalls.result !== "skip" ? `${prefix}│ ╰ ` :
3479+
`${trailingPrefix}╰ ╰ `);
34803480
}
34813481
}
34823482
}
@@ -3497,7 +3497,7 @@ namespace FourSlash {
34973497
text += `${prefix}│ ├ fromSpans:\n`;
34983498
text += this.formatCallHierarchyItemSpans(file, outgoingCall.fromSpans, `${prefix}│ │ `,
34993499
i < outgoingCalls.values.length - 1 ? `${prefix}│ ╰ ` :
3500-
`${trailingPrefix}╰ ╰ `);
3500+
`${trailingPrefix}╰ ╰ `);
35013501
}
35023502
}
35033503
}
@@ -3659,20 +3659,22 @@ namespace FourSlash {
36593659
}
36603660

36613661
public toggleLineComment(newFileContent: string): void {
3662-
const ranges = this.getRanges();
3663-
assert(ranges.length);
3664-
const changes = this.languageService.toggleLineComment(this.activeFile.fileName, ranges);
3665-
3662+
let changes: ts.TextChange[] = [];
3663+
for (let range of this.getRanges()) {
3664+
changes.push.apply(changes, this.languageService.toggleLineComment(this.activeFile.fileName, range));
3665+
}
3666+
36663667
this.applyEdits(this.activeFile.fileName, changes);
36673668

36683669
this.verifyCurrentFileContent(newFileContent);
36693670
}
36703671

36713672
public toggleMultilineComment(newFileContent: string): void {
3672-
const ranges = this.getRanges();
3673-
assert(ranges.length);
3674-
const changes = this.languageService.toggleMultilineComment(this.activeFile.fileName, ranges);
3675-
3673+
let changes: ts.TextChange[] = [];
3674+
for (let range of this.getRanges()) {
3675+
changes.push.apply(changes, this.languageService.toggleMultilineComment(this.activeFile.fileName, range));
3676+
}
3677+
36763678
this.applyEdits(this.activeFile.fileName, changes);
36773679

36783680
this.verifyCurrentFileContent(newFileContent);

src/harness/harnessLanguageService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,11 +600,11 @@ namespace Harness.LanguageService {
600600
clearSourceMapperCache(): never {
601601
return ts.notImplemented();
602602
}
603-
toggleLineComment(fileName: string, textRanges: ts.TextRange[]): ts.TextChange[] {
604-
return unwrapJSONCallResult(this.shim.toggleLineComment(fileName, textRanges));
603+
toggleLineComment(fileName: string, textRange: ts.TextRange): ts.TextChange[] {
604+
return unwrapJSONCallResult(this.shim.toggleLineComment(fileName, textRange));
605605
}
606-
toggleMultilineComment(fileName: string, textRanges: ts.TextRange[]): ts.TextChange[] {
607-
return unwrapJSONCallResult(this.shim.toggleMultilineComment(fileName, textRanges));
606+
toggleMultilineComment(fileName: string, textRange: ts.TextRange): ts.TextChange[] {
607+
return unwrapJSONCallResult(this.shim.toggleMultilineComment(fileName, textRange));
608608
}
609609
dispose(): void { this.shim.dispose({}); }
610610
}

src/server/protocol.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -923,18 +923,6 @@ namespace ts.server.protocol {
923923
end: Location;
924924
}
925925

926-
export interface TextRange {
927-
/**
928-
* Position of the first character.
929-
*/
930-
pos: number;
931-
932-
/**
933-
* Position of the last character.
934-
*/
935-
end: number;
936-
}
937-
938926
/**
939927
* Object found in response messages defining a span of text in a specific source file.
940928
*/
@@ -1551,20 +1539,12 @@ namespace ts.server.protocol {
15511539

15521540
export interface ToggleLineCommentRequest extends FileRequest {
15531541
command: CommandTypes.ToggleLineComment;
1554-
arguments: ToggleLineCommentRequestArgs;
1555-
}
1556-
1557-
export interface ToggleLineCommentRequestArgs extends FileRequestArgs {
1558-
textRanges: TextRange[];
1542+
arguments: FileRangeRequestArgs;
15591543
}
15601544

15611545
export interface ToggleMultilineCommentRequest extends FileRequest {
15621546
command: CommandTypes.ToggleMultilineComment;
1563-
arguments: ToggleMultilineCommentRequestArgs;
1564-
}
1565-
1566-
export interface ToggleMultilineCommentRequestArgs extends FileRequestArgs {
1567-
textRanges: TextRange[];
1547+
arguments: FileRangeRequestArgs;
15681548
}
15691549

15701550
/**

src/server/session.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,8 +1957,7 @@ namespace ts.server {
19571957
position = getPosition(args);
19581958
}
19591959
else {
1960-
const { startPosition, endPosition } = this.getStartAndEndPosition(args, scriptInfo);
1961-
textRange = { pos: startPosition, end: endPosition };
1960+
textRange = this.getRange(args, scriptInfo);
19621961
}
19631962
return Debug.checkDefined(position === undefined ? textRange : position);
19641963

@@ -1967,6 +1966,12 @@ namespace ts.server {
19671966
}
19681967
}
19691968

1969+
private getRange(args: protocol.FileRangeRequestArgs, scriptInfo: ScriptInfo): TextRange {
1970+
const { startPosition, endPosition } = this.getStartAndEndPosition(args, scriptInfo);
1971+
1972+
return { pos: startPosition, end: endPosition };
1973+
}
1974+
19701975
private getApplicableRefactors(args: protocol.GetApplicableRefactorsRequestArgs): protocol.ApplicableRefactorInfo[] {
19711976
const { file, project } = this.getFileAndProject(args);
19721977
const scriptInfo = project.getScriptInfoForNormalizedPath(file)!;
@@ -2196,10 +2201,12 @@ namespace ts.server {
21962201
});
21972202
}
21982203

2199-
private toggleLineComment(args: protocol.ToggleLineCommentRequestArgs, simplifiedResult: boolean): TextChange[] | protocol.CodeEdit[] {
2204+
private toggleLineComment(args: protocol.FileRangeRequestArgs, simplifiedResult: boolean): TextChange[] | protocol.CodeEdit[] {
22002205
const { file, project } = this.getFileAndProject(args);
2206+
const scriptInfo = project.getScriptInfoForNormalizedPath(file)!;
2207+
const textRange = this.getRange(args, scriptInfo);
22012208

2202-
const textChanges = project.getLanguageService().toggleLineComment(file, args.textRanges);
2209+
const textChanges = project.getLanguageService().toggleLineComment(file, textRange);
22032210

22042211
if (simplifiedResult) {
22052212
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!;
@@ -2210,10 +2217,12 @@ namespace ts.server {
22102217
return textChanges;
22112218
}
22122219

2213-
private toggleMultilineComment(args: protocol.ToggleMultilineCommentRequestArgs, simplifiedResult: boolean): TextChange[] | protocol.CodeEdit[] {
2220+
private toggleMultilineComment(args: protocol.FileRangeRequestArgs, simplifiedResult: boolean): TextChange[] | protocol.CodeEdit[] {
22142221
const { file, project } = this.getFileAndProject(args);
2222+
const scriptInfo = project.getScriptInfoForNormalizedPath(file)!;
2223+
const textRange = this.getRange(args, scriptInfo);
22152224

2216-
const textChanges = project.getLanguageService().toggleMultilineComment(file, args.textRanges);
2225+
const textChanges = project.getLanguageService().toggleMultilineComment(file, textRange);
22172226

22182227
if (simplifiedResult) {
22192228
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!;
@@ -2678,7 +2687,7 @@ namespace ts.server {
26782687
[CommandNames.ToggleMultilineComment]: (request: protocol.ToggleMultilineCommentRequest) => {
26792688
return this.requiredResponse(this.toggleMultilineComment(request.arguments, /*simplifiedResult*/true));
26802689
},
2681-
[CommandNames.ToggleMultilineComment]: (request: protocol.ToggleMultilineCommentRequest) => {
2690+
[CommandNames.ToggleMultilineCommentFull]: (request: protocol.ToggleMultilineCommentRequest) => {
26822691
return this.requiredResponse(this.toggleMultilineComment(request.arguments, /*simplifiedResult*/false));
26832692
},
26842693
});

0 commit comments

Comments
 (0)