Skip to content

Commit 4d18f93

Browse files
author
Andy Hanson
committed
Change name to getJsxClosingTagAtPosition and return an object
1 parent f76f10b commit 4d18f93

File tree

12 files changed

+58
-37
lines changed

12 files changed

+58
-37
lines changed

src/harness/fourslash.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,10 +2743,10 @@ Actual: ${stringify(fullActual)}`);
27432743
}
27442744
}
27452745

2746-
public verifyAutoCloseTag(map: { [markerName: string]: string | undefined }): void {
2746+
public verifyJsxClosingTag(map: { [markerName: string]: ts.JsxClosingTagInfo | undefined }): void {
27472747
for (const markerName in map) {
27482748
this.goToMarker(markerName);
2749-
const actual = this.languageService.getAutoCloseTagAtPosition(this.activeFile.fileName, this.currentCaretPosition);
2749+
const actual = this.languageService.getJsxClosingTagAtPosition(this.activeFile.fileName, this.currentCaretPosition);
27502750
assert.equal(actual, map[markerName]);
27512751
}
27522752
}
@@ -4087,8 +4087,8 @@ namespace FourSlashInterface {
40874087
this.state.verifyBraceCompletionAtPosition(this.negative, openingBrace);
40884088
}
40894089

4090-
public autoCloseTag(map: { [markerName: string]: string | undefined }): void {
4091-
this.state.verifyAutoCloseTag(map);
4090+
public jsxClosingTag(map: { [markerName: string]: ts.JsxClosingTagInfo | undefined }): void {
4091+
this.state.verifyJsxClosingTag(map);
40924092
}
40934093

40944094
public isInCommentAtPosition(onlyMultiLineDiverges?: boolean) {

src/harness/harnessLanguageService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ namespace Harness.LanguageService {
509509
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean {
510510
return unwrapJSONCallResult(this.shim.isValidBraceCompletionAtPosition(fileName, position, openingBrace));
511511
}
512-
getAutoCloseTagAtPosition(): string | undefined {
512+
getJsxClosingTagAtPosition(): never {
513513
throw new Error("Not supported on the shim.");
514514
}
515515
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): ts.TextSpan {

src/harness/unittests/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ namespace ts.server {
188188

189189
describe("onMessage", () => {
190190
const allCommandNames: CommandNames[] = [
191-
CommandNames.AutoCloseTag,
192191
CommandNames.Brace,
193192
CommandNames.BraceFull,
194193
CommandNames.BraceCompletion,
@@ -225,6 +224,7 @@ namespace ts.server {
225224
CommandNames.Occurrences,
226225
CommandNames.DocumentHighlights,
227226
CommandNames.DocumentHighlightsFull,
227+
CommandNames.JsxClosingTag,
228228
CommandNames.Open,
229229
CommandNames.Quickinfo,
230230
CommandNames.QuickinfoFull,

src/server/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ namespace ts.server {
552552
return notImplemented();
553553
}
554554

555-
getAutoCloseTagAtPosition(_fileName: string, _position: number): string | undefined {
555+
getJsxClosingTagAtPosition(_fileName: string, _position: number): never {
556556
return notImplemented();
557557
}
558558

src/server/protocol.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace ts.server.protocol {
77
// NOTE: If updating this, be sure to also update `allCommandNames` in `harness/unittests/session.ts`.
88
export const enum CommandTypes {
9-
AutoCloseTag = "autoCloseTag",
9+
JsxClosingTag = "jsxClosingTag",
1010
Brace = "brace",
1111
/* @internal */
1212
BraceFull = "brace-full",
@@ -891,14 +891,14 @@ namespace ts.server.protocol {
891891
openingBrace: string;
892892
}
893893

894-
export interface AutoCloseTagRequest extends FileLocationRequest {
895-
readonly command: CommandTypes.AutoCloseTag;
896-
readonly arguments: AutoCloseTagRequestArgs;
894+
export interface JsxClosingTagRequest extends FileLocationRequest {
895+
readonly command: CommandTypes.JsxClosingTag;
896+
readonly arguments: JsxClosingTagRequestArgs;
897897
}
898898

899-
export interface AutoCloseTagRequestArgs extends FileLocationRequestArgs {}
899+
export interface JsxClosingTagRequestArgs extends FileLocationRequestArgs {}
900900

901-
export interface AutoCloseTagResponse extends Response {
901+
export interface JsxClosingTagResponse extends Response {
902902
readonly body: TextInsertion;
903903
}
904904

src/server/session.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -818,11 +818,11 @@ namespace ts.server {
818818
return this.getDiagnosticsWorker(args, /*isSemantic*/ true, (project, file) => project.getLanguageService().getSuggestionDiagnostics(file), !!args.includeLinePosition);
819819
}
820820

821-
private getAutoCloseTag(args: protocol.AutoCloseTagRequestArgs): TextInsertion | undefined {
821+
private getJsxClosingTag(args: protocol.JsxClosingTagRequestArgs): TextInsertion | undefined {
822822
const { file, project } = this.getFileAndProject(args);
823823
const position = this.getPositionInFile(args, file);
824-
const tag = project.getLanguageService().getAutoCloseTagAtPosition(file, position);
825-
return tag === undefined ? undefined : { newText: tag, caretOffset: 0 };
824+
const tag = project.getLanguageService().getJsxClosingTagAtPosition(file, position);
825+
return tag === undefined ? undefined : { newText: tag.newText, caretOffset: 0 };
826826
}
827827

828828
private getDocumentHighlights(args: protocol.DocumentHighlightsRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.DocumentHighlightsItem> | ReadonlyArray<DocumentHighlights> {
@@ -2137,8 +2137,8 @@ namespace ts.server {
21372137
this.projectService.reloadProjects();
21382138
return this.notRequired();
21392139
},
2140-
[CommandNames.AutoCloseTag]: (request: protocol.AutoCloseTagRequest) => {
2141-
return this.requiredResponse(this.getAutoCloseTag(request.arguments));
2140+
[CommandNames.JsxClosingTag]: (request: protocol.JsxClosingTagRequest) => {
2141+
return this.requiredResponse(this.getJsxClosingTag(request.arguments));
21422142
},
21432143
[CommandNames.GetCodeFixes]: (request: protocol.CodeFixRequest) => {
21442144
return this.requiredResponse(this.getCodeFixes(request.arguments, /*simplifiedResult*/ true));

src/services/services.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,15 +2051,14 @@ namespace ts {
20512051
return true;
20522052
}
20532053

2054-
function getAutoCloseTagAtPosition(fileName: string, position: number): string | undefined {
2054+
function getJsxClosingTagAtPosition(fileName: string, position: number): JsxClosingTagInfo | undefined {
20552055
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
20562056
const token = findPrecedingToken(position, sourceFile);
20572057
if (!token) return undefined;
2058-
const element = token.kind === SyntaxKind.GreaterThanToken
2059-
? isJsxOpeningElement(token.parent) ? token.parent.parent : undefined
2058+
const element = token.kind === SyntaxKind.GreaterThanToken && isJsxOpeningElement(token.parent) ? token.parent.parent
20602059
: isJsxText(token) ? token.parent : undefined;
20612060
if (element && !tagNamesAreEquivalent(element.openingElement.tagName, element.closingElement.tagName)) {
2062-
return `</${element.openingElement.tagName.getText(sourceFile)}>`;
2061+
return { newText: `</${element.openingElement.tagName.getText(sourceFile)}>` };
20632062
}
20642063
}
20652064

@@ -2295,7 +2294,7 @@ namespace ts {
22952294
getFormattingEditsAfterKeystroke,
22962295
getDocCommentTemplateAtPosition,
22972296
isValidBraceCompletionAtPosition,
2298-
getAutoCloseTagAtPosition,
2297+
getJsxClosingTagAtPosition,
22992298
getSpanOfEnclosingComment,
23002299
getCodeFixesAtPosition,
23012300
getCombinedCodeFix,

src/services/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,11 @@ namespace ts {
323323
getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion | undefined;
324324

325325
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
326-
getAutoCloseTagAtPosition(fileName: string, position: number): string | undefined;
326+
/**
327+
* This will return a defined result if the position is after the `>` of the opening tag, or somewhere in the text, of a JSXElement with no closing tag.
328+
* Editors should call this after `>` is typed.
329+
*/
330+
getJsxClosingTagAtPosition(fileName: string, position: number): JsxClosingTagInfo | undefined;
327331

328332
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan | undefined;
329333

@@ -360,6 +364,10 @@ namespace ts {
360364
dispose(): void;
361365
}
362366

367+
export interface JsxClosingTagInfo {
368+
readonly newText: string;
369+
}
370+
363371
export interface CombinedCodeFixScope { type: "file"; fileName: string; }
364372

365373
export type OrganizeImportsScope = CombinedCodeFixScope;

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4556,7 +4556,11 @@ declare namespace ts {
45564556
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[];
45574557
getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion | undefined;
45584558
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
4559-
getAutoCloseTagAtPosition(fileName: string, position: number): string | undefined;
4559+
/**
4560+
* This will return a defined result if the position is after the `>` of the opening tag, or somewhere in the text, of a JSXElement with no closing tag.
4561+
* Editors should call this after `>` is typed.
4562+
*/
4563+
getJsxClosingTagAtPosition(fileName: string, position: number): JsxClosingTagInfo | undefined;
45604564
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan | undefined;
45614565
toLineColumnOffset?(fileName: string, position: number): LineAndCharacter;
45624566
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings, preferences: UserPreferences): ReadonlyArray<CodeFixAction>;
@@ -4578,6 +4582,9 @@ declare namespace ts {
45784582
getProgram(): Program | undefined;
45794583
dispose(): void;
45804584
}
4585+
interface JsxClosingTagInfo {
4586+
readonly newText: string;
4587+
}
45814588
interface CombinedCodeFixScope {
45824589
type: "file";
45834590
fileName: string;
@@ -5507,7 +5514,7 @@ declare namespace ts.server {
55075514
*/
55085515
declare namespace ts.server.protocol {
55095516
enum CommandTypes {
5510-
AutoCloseTag = "autoCloseTag",
5517+
JsxClosingTag = "jsxClosingTag",
55115518
Brace = "brace",
55125519
BraceCompletion = "braceCompletion",
55135520
GetSpanOfEnclosingComment = "getSpanOfEnclosingComment",
@@ -6177,13 +6184,13 @@ declare namespace ts.server.protocol {
61776184
*/
61786185
openingBrace: string;
61796186
}
6180-
interface AutoCloseTagRequest extends FileLocationRequest {
6181-
readonly command: CommandTypes.AutoCloseTag;
6182-
readonly arguments: AutoCloseTagRequestArgs;
6187+
interface JsxClosingTagRequest extends FileLocationRequest {
6188+
readonly command: CommandTypes.JsxClosingTag;
6189+
readonly arguments: JsxClosingTagRequestArgs;
61836190
}
6184-
interface AutoCloseTagRequestArgs extends FileLocationRequestArgs {
6191+
interface JsxClosingTagRequestArgs extends FileLocationRequestArgs {
61856192
}
6186-
interface AutoCloseTagResponse extends Response {
6193+
interface JsxClosingTagResponse extends Response {
61876194
readonly body: TextInsertion;
61886195
}
61896196
/**
@@ -8474,7 +8481,7 @@ declare namespace ts.server {
84748481
private getSyntacticDiagnosticsSync;
84758482
private getSemanticDiagnosticsSync;
84768483
private getSuggestionDiagnosticsSync;
8477-
private getAutoCloseTag;
8484+
private getJsxClosingTag;
84788485
private getDocumentHighlights;
84798486
private setCompilerOptionsForInferredProjects;
84808487
private getProjectInfo;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4556,7 +4556,11 @@ declare namespace ts {
45564556
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[];
45574557
getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion | undefined;
45584558
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
4559-
getAutoCloseTagAtPosition(fileName: string, position: number): string | undefined;
4559+
/**
4560+
* This will return a defined result if the position is after the `>` of the opening tag, or somewhere in the text, of a JSXElement with no closing tag.
4561+
* Editors should call this after `>` is typed.
4562+
*/
4563+
getJsxClosingTagAtPosition(fileName: string, position: number): JsxClosingTagInfo | undefined;
45604564
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan | undefined;
45614565
toLineColumnOffset?(fileName: string, position: number): LineAndCharacter;
45624566
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings, preferences: UserPreferences): ReadonlyArray<CodeFixAction>;
@@ -4578,6 +4582,9 @@ declare namespace ts {
45784582
getProgram(): Program | undefined;
45794583
dispose(): void;
45804584
}
4585+
interface JsxClosingTagInfo {
4586+
readonly newText: string;
4587+
}
45814588
interface CombinedCodeFixScope {
45824589
type: "file";
45834590
fileName: string;

0 commit comments

Comments
 (0)