Skip to content

Commit 73bf268

Browse files
committed
Rename to use contextSpan
1 parent da2aa97 commit 73bf268

File tree

353 files changed

+935
-935
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

353 files changed

+935
-935
lines changed

src/harness/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,12 @@ namespace ts.server {
395395
const locations: RenameLocation[] = [];
396396
for (const entry of body.locs) {
397397
const fileName = entry.file;
398-
for (const { start, end, declarationStart, declarationEnd, ...prefixSuffixText } of entry.locs) {
398+
for (const { start, end, contextStart, contextEnd, ...prefixSuffixText } of entry.locs) {
399399
locations.push({
400400
textSpan: this.decodeSpan({ start, end }, fileName),
401401
fileName,
402-
...(declarationStart !== undefined ?
403-
{ declarationSpan: this.decodeSpan({ start: declarationStart, end: declarationEnd! }, fileName) } :
402+
...(contextStart !== undefined ?
403+
{ contextSpan: this.decodeSpan({ start: contextStart, end: contextEnd! }, fileName) } :
404404
undefined),
405405
...prefixSuffixText
406406
});

src/harness/fourslash.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -956,14 +956,14 @@ namespace FourSlash {
956956
const fullExpected = ts.map<FourSlashInterface.ReferenceGroup, ReferenceGroupJson>(parts, ({ definition, ranges }) => ({
957957
definition: typeof definition === "string" ? definition : { ...definition, range: ts.createTextSpanFromRange(definition.range) },
958958
references: ranges.map<ts.ReferenceEntry>(r => {
959-
const { isWriteAccess = false, isDefinition = false, isInString, declarationRangeIndex } = (r.marker && r.marker.data || {}) as { isWriteAccess?: boolean, isDefinition?: boolean, isInString?: true, declarationRangeIndex?: number };
959+
const { isWriteAccess = false, isDefinition = false, isInString, contextRangeIndex } = (r.marker && r.marker.data || {}) as { isWriteAccess?: boolean, isDefinition?: boolean, isInString?: true, contextRangeIndex?: number };
960960
return {
961961
fileName: r.fileName,
962962
textSpan: ts.createTextSpanFromRange(r),
963963
isWriteAccess,
964964
isDefinition,
965-
...(declarationRangeIndex !== undefined ?
966-
{ declarationSpan: ts.createTextSpanFromRange(this.getRanges()[declarationRangeIndex]) } :
965+
...(contextRangeIndex !== undefined ?
966+
{ contextSpan: ts.createTextSpanFromRange(this.getRanges()[contextRangeIndex]) } :
967967
undefined),
968968
...(isInString ? { isInString: true } : undefined),
969969
};
@@ -1193,12 +1193,12 @@ Actual: ${stringify(fullActual)}`);
11931193
locations && ts.sort(locations, (r1, r2) => ts.compareStringsCaseSensitive(r1.fileName, r2.fileName) || r1.textSpan.start - r2.textSpan.start);
11941194
assert.deepEqual(sort(references), sort(ranges.map((rangeOrOptions): ts.RenameLocation => {
11951195
const { range, ...prefixSuffixText } = "range" in rangeOrOptions ? rangeOrOptions : { range: rangeOrOptions };
1196-
const { declarationRangeIndex } = (range.marker && range.marker.data || {}) as { declarationRangeIndex?: number; };
1196+
const { contextRangeIndex } = (range.marker && range.marker.data || {}) as { contextRangeIndex?: number; };
11971197
return {
11981198
fileName: range.fileName,
11991199
textSpan: ts.createTextSpanFromRange(range),
1200-
...(declarationRangeIndex !== undefined ?
1201-
{ declarationSpan: ts.createTextSpanFromRange(this.getRanges()[declarationRangeIndex]) } :
1200+
...(contextRangeIndex !== undefined ?
1201+
{ contextSpan: ts.createTextSpanFromRange(this.getRanges()[contextRangeIndex]) } :
12021202
undefined),
12031203
...prefixSuffixText
12041204
};

src/server/protocol.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -872,24 +872,24 @@ namespace ts.server.protocol {
872872
file: string;
873873
}
874874

875-
export interface DeclarationTextSpan extends TextSpan {
876-
declarationStart?: Location;
877-
declarationEnd?: Location;
875+
export interface TextSpanWithContext extends TextSpan {
876+
contextStart?: Location;
877+
contextEnd?: Location;
878878
}
879879

880-
export interface DeclarationFileSpan extends FileSpan, DeclarationTextSpan {
880+
export interface FileSpanWithContext extends FileSpan, TextSpanWithContext {
881881
}
882882

883883
export interface DefinitionInfoAndBoundSpan {
884-
definitions: ReadonlyArray<DeclarationFileSpan>;
884+
definitions: ReadonlyArray<FileSpanWithContext>;
885885
textSpan: TextSpan;
886886
}
887887

888888
/**
889889
* Definition response message. Gives text range for definition.
890890
*/
891891
export interface DefinitionResponse extends Response {
892-
body?: DeclarationFileSpan[];
892+
body?: FileSpanWithContext[];
893893
}
894894

895895
export interface DefinitionInfoAndBoundSpanReponse extends Response {
@@ -900,14 +900,14 @@ namespace ts.server.protocol {
900900
* Definition response message. Gives text range for definition.
901901
*/
902902
export interface TypeDefinitionResponse extends Response {
903-
body?: DeclarationFileSpan[];
903+
body?: FileSpanWithContext[];
904904
}
905905

906906
/**
907907
* Implementation response message. Gives text range for implementations.
908908
*/
909909
export interface ImplementationResponse extends Response {
910-
body?: DeclarationFileSpan[];
910+
body?: FileSpanWithContext[];
911911
}
912912

913913
/**
@@ -950,7 +950,7 @@ namespace ts.server.protocol {
950950
}
951951

952952
/** @deprecated */
953-
export interface OccurrencesResponseItem extends DeclarationFileSpan {
953+
export interface OccurrencesResponseItem extends FileSpanWithContext {
954954
/**
955955
* True if the occurrence is a write location, false otherwise.
956956
*/
@@ -980,7 +980,7 @@ namespace ts.server.protocol {
980980
/**
981981
* Span augmented with extra information that denotes the kind of the highlighting to be used for span.
982982
*/
983-
export interface HighlightSpan extends DeclarationTextSpan {
983+
export interface HighlightSpan extends TextSpanWithContext {
984984
kind: HighlightSpanKind;
985985
}
986986

@@ -1015,7 +1015,7 @@ namespace ts.server.protocol {
10151015
command: CommandTypes.References;
10161016
}
10171017

1018-
export interface ReferencesResponseItem extends DeclarationFileSpan {
1018+
export interface ReferencesResponseItem extends FileSpanWithContext {
10191019
/** Text of line containing the reference. Including this
10201020
* with the response avoids latency of editor loading files
10211021
* to show text of reference line (the server already has
@@ -1158,7 +1158,7 @@ namespace ts.server.protocol {
11581158
locs: RenameTextSpan[];
11591159
}
11601160

1161-
export interface RenameTextSpan extends DeclarationTextSpan {
1161+
export interface RenameTextSpan extends TextSpanWithContext {
11621162
readonly prefixText?: string;
11631163
readonly suffixText?: string;
11641164
}

src/server/session.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ namespace ts.server {
362362
...outputReferencedSymbol.definition,
363363
textSpan: createTextSpan(mappedDefinitionFile.pos, outputReferencedSymbol.definition.textSpan.length),
364364
fileName: mappedDefinitionFile.fileName,
365-
declarationSpan: getMappedDeclarationSpan(outputReferencedSymbol.definition, project)
365+
contextSpan: getMappedContextSpan(outputReferencedSymbol.definition, project)
366366
};
367367

368368
let symbolToAddTo = find(outputs, o => documentSpansEqual(o.definition, definition));
@@ -501,22 +501,22 @@ namespace ts.server {
501501
},
502502
originalFileName: documentSpan.fileName,
503503
originalTextSpan: documentSpan.textSpan,
504-
declarationSpan: getMappedDeclarationSpan(documentSpan, project),
505-
originalDeclarationSpan: documentSpan.declarationSpan
504+
contextSpan: getMappedContextSpan(documentSpan, project),
505+
originalContextSpan: documentSpan.contextSpan
506506
};
507507
}
508508

509-
function getMappedDeclarationSpan(documentSpan: DocumentSpan, project: Project): TextSpan | undefined {
510-
const declarationSpanStart = documentSpan.declarationSpan && getMappedLocation(
511-
{ fileName: documentSpan.fileName, pos: documentSpan.declarationSpan.start },
509+
function getMappedContextSpan(documentSpan: DocumentSpan, project: Project): TextSpan | undefined {
510+
const contextSpanStart = documentSpan.contextSpan && getMappedLocation(
511+
{ fileName: documentSpan.fileName, pos: documentSpan.contextSpan.start },
512512
project
513513
);
514-
const declarationSpanEnd = documentSpan.declarationSpan && getMappedLocation(
515-
{ fileName: documentSpan.fileName, pos: documentSpan.declarationSpan.start + documentSpan.declarationSpan.length },
514+
const contextSpanEnd = documentSpan.contextSpan && getMappedLocation(
515+
{ fileName: documentSpan.fileName, pos: documentSpan.contextSpan.start + documentSpan.contextSpan.length },
516516
project
517517
);
518-
return declarationSpanStart && declarationSpanEnd ?
519-
{ start: declarationSpanStart.pos, length: declarationSpanEnd.pos - declarationSpanStart.pos } :
518+
return contextSpanStart && contextSpanEnd ?
519+
{ start: contextSpanStart.pos, length: contextSpanEnd.pos - contextSpanStart.pos } :
520520
undefined;
521521
}
522522

@@ -971,7 +971,7 @@ namespace ts.server {
971971
: diagnostics.map(d => formatDiag(file, project, d));
972972
}
973973

974-
private getDefinition(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.DeclarationFileSpan> | ReadonlyArray<DefinitionInfo> {
974+
private getDefinition(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.FileSpanWithContext> | ReadonlyArray<DefinitionInfo> {
975975
const { file, project } = this.getFileAndProject(args);
976976
const position = this.getPositionInFile(args, file);
977977
const definitions = this.mapDefinitionInfoLocations(project.getLanguageService().getDefinitionAtPosition(file, position) || emptyArray, project);
@@ -1026,8 +1026,8 @@ namespace ts.server {
10261026
return project.getLanguageService().getEmitOutput(file);
10271027
}
10281028

1029-
private mapDefinitionInfo(definitions: ReadonlyArray<DefinitionInfo>, project: Project): ReadonlyArray<protocol.DeclarationFileSpan> {
1030-
return definitions.map(def => this.toDeclarationFileSpan(def.fileName, def.textSpan, def.declarationSpan, project));
1029+
private mapDefinitionInfo(definitions: ReadonlyArray<DefinitionInfo>, project: Project): ReadonlyArray<protocol.FileSpanWithContext> {
1030+
return definitions.map(def => this.toFileSpanWithContext(def.fileName, def.textSpan, def.contextSpan, project));
10311031
}
10321032

10331033
/*
@@ -1046,8 +1046,8 @@ namespace ts.server {
10461046
textSpan: def.originalTextSpan,
10471047
targetFileName: def.fileName,
10481048
targetTextSpan: def.textSpan,
1049-
declarationSpan: def.originalDeclarationSpan,
1050-
targetDeclarationSpan: def.declarationSpan
1049+
contextSpan: def.originalContextSpan,
1050+
targetContextSpan: def.contextSpan
10511051
};
10521052
}
10531053
return def;
@@ -1065,15 +1065,15 @@ namespace ts.server {
10651065
};
10661066
}
10671067

1068-
private toDeclarationFileSpan(fileName: string, textSpan: TextSpan, declarationSpan: TextSpan | undefined, project: Project): protocol.DeclarationFileSpan {
1068+
private toFileSpanWithContext(fileName: string, textSpan: TextSpan, contextSpan: TextSpan | undefined, project: Project): protocol.FileSpanWithContext {
10691069
const fileSpan = this.toFileSpan(fileName, textSpan, project);
1070-
const declaration = declarationSpan && this.toFileSpan(fileName, declarationSpan, project);
1071-
return declaration ?
1072-
{ ...fileSpan, declarationStart: declaration.start, declarationEnd: declaration.end } :
1070+
const context = contextSpan && this.toFileSpan(fileName, contextSpan, project);
1071+
return context ?
1072+
{ ...fileSpan, contextStart: context.start, contextEnd: context.end } :
10731073
fileSpan;
10741074
}
10751075

1076-
private getTypeDefinition(args: protocol.FileLocationRequestArgs): ReadonlyArray<protocol.DeclarationFileSpan> {
1076+
private getTypeDefinition(args: protocol.FileLocationRequestArgs): ReadonlyArray<protocol.FileSpanWithContext> {
10771077
const { file, project } = this.getFileAndProject(args);
10781078
const position = this.getPositionInFile(args, file);
10791079

@@ -1092,12 +1092,12 @@ namespace ts.server {
10921092
});
10931093
}
10941094

1095-
private getImplementation(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.DeclarationFileSpan> | ReadonlyArray<ImplementationLocation> {
1095+
private getImplementation(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.FileSpanWithContext> | ReadonlyArray<ImplementationLocation> {
10961096
const { file, project } = this.getFileAndProject(args);
10971097
const position = this.getPositionInFile(args, file);
10981098
const implementations = this.mapImplementationLocations(project.getLanguageService().getImplementationAtPosition(file, position) || emptyArray, project);
10991099
return simplifiedResult ?
1100-
implementations.map(({ fileName, textSpan, declarationSpan }) => this.toDeclarationFileSpan(fileName, textSpan, declarationSpan, project)) :
1100+
implementations.map(({ fileName, textSpan, contextSpan }) => this.toFileSpanWithContext(fileName, textSpan, contextSpan, project)) :
11011101
implementations.map(Session.mapToOriginalLocation);
11021102
}
11031103

@@ -1107,10 +1107,10 @@ namespace ts.server {
11071107
const occurrences = project.getLanguageService().getOccurrencesAtPosition(file, position);
11081108
return occurrences ?
11091109
occurrences.map<protocol.OccurrencesResponseItem>(occurrence => {
1110-
const { fileName, isWriteAccess, textSpan, isInString, declarationSpan } = occurrence;
1110+
const { fileName, isWriteAccess, textSpan, isInString, contextSpan } = occurrence;
11111111
const scriptInfo = project.getScriptInfo(fileName)!;
11121112
return {
1113-
...toProtocolDeclarationTextSpan(textSpan, declarationSpan, scriptInfo),
1113+
...toProtocolTextSpanWithContext(textSpan, contextSpan, scriptInfo),
11141114
file: fileName,
11151115
isWriteAccess,
11161116
...(isInString ? { isInString } : undefined)
@@ -1166,8 +1166,8 @@ namespace ts.server {
11661166
const scriptInfo = project.getScriptInfo(fileName)!;
11671167
return {
11681168
file: fileName,
1169-
highlightSpans: highlightSpans.map(({ textSpan, kind, declarationSpan }) => ({
1170-
...toProtocolDeclarationTextSpan(textSpan, declarationSpan, scriptInfo),
1169+
highlightSpans: highlightSpans.map(({ textSpan, kind, contextSpan }) => ({
1170+
...toProtocolTextSpanWithContext(textSpan, contextSpan, scriptInfo),
11711171
kind
11721172
}))
11731173
};
@@ -1273,11 +1273,11 @@ namespace ts.server {
12731273

12741274
private toSpanGroups(locations: ReadonlyArray<RenameLocation>): ReadonlyArray<protocol.SpanGroup> {
12751275
const map = createMap<protocol.SpanGroup>();
1276-
for (const { fileName, textSpan, declarationSpan, originalDeclarationSpan: _2, originalTextSpan: _, originalFileName: _1, ...prefixSuffixText } of locations) {
1276+
for (const { fileName, textSpan, contextSpan, originalContextSpan: _2, originalTextSpan: _, originalFileName: _1, ...prefixSuffixText } of locations) {
12771277
let group = map.get(fileName);
12781278
if (!group) map.set(fileName, group = { file: fileName, locs: [] });
12791279
const scriptInfo = Debug.assertDefined(this.projectService.getScriptInfo(fileName));
1280-
group.locs.push({ ...toProtocolDeclarationTextSpan(textSpan, declarationSpan, scriptInfo), ...prefixSuffixText });
1280+
group.locs.push({ ...toProtocolTextSpanWithContext(textSpan, contextSpan, scriptInfo), ...prefixSuffixText });
12811281
}
12821282
return arrayFrom(map.values());
12831283
}
@@ -1302,9 +1302,9 @@ namespace ts.server {
13021302
const symbolStartOffset = nameSpan ? scriptInfo.positionToLineOffset(nameSpan.start).offset : 0;
13031303
const symbolName = nameSpan ? scriptInfo.getSnapshot().getText(nameSpan.start, textSpanEnd(nameSpan)) : "";
13041304
const refs: ReadonlyArray<protocol.ReferencesResponseItem> = flatMap(references, referencedSymbol =>
1305-
referencedSymbol.references.map(({ fileName, textSpan, declarationSpan, isWriteAccess, isDefinition }): protocol.ReferencesResponseItem => {
1305+
referencedSymbol.references.map(({ fileName, textSpan, contextSpan, isWriteAccess, isDefinition }): protocol.ReferencesResponseItem => {
13061306
const scriptInfo = Debug.assertDefined(this.projectService.getScriptInfo(fileName));
1307-
const span = toProtocolDeclarationTextSpan(textSpan, declarationSpan, scriptInfo);
1307+
const span = toProtocolTextSpanWithContext(textSpan, contextSpan, scriptInfo);
13081308
const lineSpan = scriptInfo.lineToTextSpan(span.start.line - 1);
13091309
const lineText = scriptInfo.getSnapshot().getText(lineSpan.start, textSpanEnd(lineSpan)).replace(/\r|\n/g, "");
13101310
return {
@@ -2565,11 +2565,11 @@ namespace ts.server {
25652565
};
25662566
}
25672567

2568-
function toProtocolDeclarationTextSpan(span: TextSpan, declarationSpan: TextSpan | undefined, scriptInfo: ScriptInfo): protocol.DeclarationTextSpan {
2568+
function toProtocolTextSpanWithContext(span: TextSpan, contextSpan: TextSpan | undefined, scriptInfo: ScriptInfo): protocol.TextSpanWithContext {
25692569
const textSpan = toProcolTextSpan(span, scriptInfo);
2570-
const declarationTextSpan = declarationSpan && toProcolTextSpan(declarationSpan, scriptInfo);
2571-
return declarationTextSpan ?
2572-
{ ...textSpan, declarationStart: declarationTextSpan.start, declarationEnd: declarationTextSpan.end } :
2570+
const contextTextSpan = contextSpan && toProcolTextSpan(contextSpan, scriptInfo);
2571+
return contextTextSpan ?
2572+
{ ...textSpan, contextStart: contextTextSpan.start, contextEnd: contextTextSpan.end } :
25732573
textSpan;
25742574
}
25752575

0 commit comments

Comments
 (0)