Rename to use contextSpan

This commit is contained in:
Sheetal Nandi
2019-06-13 12:25:02 -07:00
parent da2aa9781e
commit 73bf2684ac
353 changed files with 935 additions and 935 deletions

View File

@@ -3,15 +3,15 @@ namespace ts.projectSystem {
file: File;
text: string;
options?: SpanFromSubstringOptions;
declarationText?: string;
declarationOptions?: SpanFromSubstringOptions;
contextText?: string;
contextOptions?: SpanFromSubstringOptions;
}
function documentSpanFromSubstring({ file, text, declarationText, options, declarationOptions }: DocumentSpanFromSubstring): DocumentSpan {
const declarationSpan = declarationText !== undefined ? documentSpanFromSubstring({ file, text: declarationText, options: declarationOptions }) : undefined;
function documentSpanFromSubstring({ file, text, contextText, options, contextOptions }: DocumentSpanFromSubstring): DocumentSpan {
const contextSpan = contextText !== undefined ? documentSpanFromSubstring({ file, text: contextText, options: contextOptions }) : undefined;
return {
fileName: file.path,
textSpan: textSpanFromSubstring(file.content, text, options),
...declarationSpan && { declarationSpan: declarationSpan.textSpan }
...contextSpan && { contextSpan: contextSpan.textSpan }
};
}
@@ -25,7 +25,7 @@ namespace ts.projectSystem {
}
function makeReferenceItem({ isDefinition, lineText, ...rest }: MakeReferenceItem): protocol.ReferencesResponseItem {
return {
...protocolDeclarationFileSpanFromSubstring(rest),
...protocolFileSpanWithContextFromSubstring(rest),
isDefinition,
isWriteAccess: isDefinition,
lineText,
@@ -206,10 +206,10 @@ namespace ts.projectSystem {
const session = makeSampleProjects();
const response = executeSessionRequest<protocol.DefinitionRequest, protocol.DefinitionResponse>(session, protocol.CommandTypes.Definition, protocolFileLocationFromSubstring(userTs, "fnA()"));
assert.deepEqual(response, [
protocolDeclarationFileSpanFromSubstring({
protocolFileSpanWithContextFromSubstring({
file: aTs,
text: "fnA",
declarationText: "export function fnA() {}"
contextText: "export function fnA() {}"
})
]);
verifySingleInferredProject(session);
@@ -221,10 +221,10 @@ namespace ts.projectSystem {
assert.deepEqual(response, {
textSpan: protocolTextSpanFromSubstring(userTs.content, "fnA"),
definitions: [
protocolDeclarationFileSpanFromSubstring({
protocolFileSpanWithContextFromSubstring({
file: aTs,
text: "fnA",
declarationText: "export function fnA() {}"
contextText: "export function fnA() {}"
})
],
});
@@ -237,10 +237,10 @@ namespace ts.projectSystem {
assert.deepEqual(response, {
textSpan: protocolTextSpanFromSubstring(userTs.content, "fnA"),
definitions: [
protocolDeclarationFileSpanFromSubstring({
protocolFileSpanWithContextFromSubstring({
file: aTs,
text: "fnA",
declarationText: "export function fnA() {}"
contextText: "export function fnA() {}"
})
],
});
@@ -264,10 +264,10 @@ namespace ts.projectSystem {
const session = makeSampleProjects();
const response = executeSessionRequest<protocol.TypeDefinitionRequest, protocol.TypeDefinitionResponse>(session, protocol.CommandTypes.TypeDefinition, protocolFileLocationFromSubstring(userTs, "instanceA"));
assert.deepEqual(response, [
protocolDeclarationFileSpanFromSubstring({
protocolFileSpanWithContextFromSubstring({
file: aTs,
text: "IfaceA",
declarationText: "export interface IfaceA {}"
contextText: "export interface IfaceA {}"
})
]);
verifySingleInferredProject(session);
@@ -277,10 +277,10 @@ namespace ts.projectSystem {
const session = makeSampleProjects();
const response = executeSessionRequest<protocol.ImplementationRequest, protocol.ImplementationResponse>(session, protocol.CommandTypes.Implementation, protocolFileLocationFromSubstring(userTs, "fnA()"));
assert.deepEqual(response, [
protocolDeclarationFileSpanFromSubstring({
protocolFileSpanWithContextFromSubstring({
file: aTs,
text: "fnA",
declarationText: "export function fnA() {}"
contextText: "export function fnA() {}"
})]);
verifySingleInferredProject(session);
});
@@ -290,10 +290,10 @@ namespace ts.projectSystem {
const response = executeSessionRequest<protocol.DefinitionRequest, protocol.DefinitionResponse>(session, CommandNames.Definition, protocolFileLocationFromSubstring(userTs, "fnB()"));
// bTs does not exist, so stick with bDts
assert.deepEqual(response, [
protocolDeclarationFileSpanFromSubstring({
protocolFileSpanWithContextFromSubstring({
file: bDts,
text: "fnB",
declarationText: "export declare function fnB(): void;"
contextText: "export declare function fnB(): void;"
})
]);
verifySingleInferredProject(session);
@@ -345,7 +345,7 @@ namespace ts.projectSystem {
file: aTs,
isDefinition: true,
text: "fnA",
declarationText: "export function fnA() {}",
contextText: "export function fnA() {}",
lineText: "export function fnA() {}"
});
const referencesUserTs = (userTs: File): ReadonlyArray<protocol.ReferencesResponseItem> => [
@@ -398,7 +398,7 @@ namespace ts.projectSystem {
...documentSpanFromSubstring({
file: aTs,
text: "fnA",
declarationText: "export function fnA() {}"
contextText: "export function fnA() {}"
}),
kind: ScriptElementKind.functionElement,
name: "function fnA(): void",
@@ -417,7 +417,7 @@ namespace ts.projectSystem {
},
references: [
makeReferenceEntry({ file: userTs, /*isDefinition*/ isDefinition: false, text: "fnA" }),
makeReferenceEntry({ file: aTs, /*isDefinition*/ isDefinition: true, text: "fnA", declarationText: "export function fnA() {}" }),
makeReferenceEntry({ file: aTs, /*isDefinition*/ isDefinition: true, text: "fnA", contextText: "export function fnA() {}" }),
],
},
]);
@@ -452,7 +452,7 @@ namespace ts.projectSystem {
file: aTs,
text: "f",
options: { index: 1 },
declarationText: "function f() {}"
contextText: "function f() {}"
}),
containerKind: ScriptElementKind.unknown,
containerName: "",
@@ -481,7 +481,7 @@ namespace ts.projectSystem {
file: aTs,
text: "f",
options: { index: 1 },
declarationText: "function f() {}",
contextText: "function f() {}",
isDefinition: true
})
],
@@ -499,7 +499,7 @@ namespace ts.projectSystem {
file: bDts,
isDefinition: true,
text: "fnB",
declarationText: "export declare function fnB(): void;",
contextText: "export declare function fnB(): void;",
lineText: "export declare function fnB(): void;"
}),
makeReferenceItem({
@@ -522,7 +522,7 @@ namespace ts.projectSystem {
protocolRenameSpanFromSubstring({
fileText: aTs.content,
text: "fnA",
declarationText: "export function fnA() {}"
contextText: "export function fnA() {}"
})
],
});
@@ -578,7 +578,7 @@ namespace ts.projectSystem {
const response = executeSessionRequest<protocol.RenameFullRequest, protocol.RenameFullResponse>(session, protocol.CommandTypes.RenameLocationsFull, protocolFileLocationFromSubstring(userTs, "fnA()"));
assert.deepEqual<ReadonlyArray<RenameLocation>>(response, [
renameLocation({ file: userTs, text: "fnA" }),
renameLocation({ file: aTs, text: "fnA", declarationText: "export function fnA() {}" }),
renameLocation({ file: aTs, text: "fnA", contextText: "export function fnA() {}" }),
]);
verifyATsConfigOriginalProject(session);
});
@@ -603,7 +603,7 @@ namespace ts.projectSystem {
protocolRenameSpanFromSubstring({
fileText: bDts.content,
text: "fnB",
declarationText: "export declare function fnB(): void;"
contextText: "export declare function fnB(): void;"
})
],
},

View File

@@ -514,49 +514,49 @@ namespace ts.projectSystem {
return { file: file.path, ...protocolTextSpanFromSubstring(file.content, text, options) };
}
interface DeclarationFileSpanFromSubString {
interface FileSpanWithContextFromSubString {
file: File;
text: string;
options?: SpanFromSubstringOptions;
declarationText?: string;
declarationOptions?: SpanFromSubstringOptions;
contextText?: string;
contextOptions?: SpanFromSubstringOptions;
}
export function protocolDeclarationFileSpanFromSubstring({ declarationText, declarationOptions, ...rest }: DeclarationFileSpanFromSubString): protocol.DeclarationFileSpan {
export function protocolFileSpanWithContextFromSubstring({ contextText, contextOptions, ...rest }: FileSpanWithContextFromSubString): protocol.FileSpanWithContext {
const result = protocolFileSpanFromSubstring(rest);
const declarationSpan = declarationText !== undefined ?
protocolFileSpanFromSubstring({ file: rest.file, text: declarationText, options: declarationOptions }) :
const contextSpan = contextText !== undefined ?
protocolFileSpanFromSubstring({ file: rest.file, text: contextText, options: contextOptions }) :
undefined;
return declarationSpan ?
return contextSpan ?
{
...result,
declarationStart: declarationSpan.start,
declarationEnd: declarationSpan.end
contextStart: contextSpan.start,
contextEnd: contextSpan.end
} :
result;
}
export interface ProtocolDeclarationTextSpanFromString {
export interface ProtocolTextSpanWithContextFromString {
fileText: string;
text: string;
options?: SpanFromSubstringOptions;
declarationText?: string;
declarationOptions?: SpanFromSubstringOptions;
contextText?: string;
contextOptions?: SpanFromSubstringOptions;
}
export function protocolDeclarationTextSpanFromSubstring({ fileText, text, options, declarationText, declarationOptions }: ProtocolDeclarationTextSpanFromString): protocol.DeclarationTextSpan {
export function protocolTextSpanWithContextFromSubstring({ fileText, text, options, contextText, contextOptions }: ProtocolTextSpanWithContextFromString): protocol.TextSpanWithContext {
const span = textSpanFromSubstring(fileText, text, options);
const toLocation = protocolToLocation(fileText);
const declarationSpan = declarationText !== undefined ? textSpanFromSubstring(fileText, declarationText, declarationOptions) : undefined;
const contextSpan = contextText !== undefined ? textSpanFromSubstring(fileText, contextText, contextOptions) : undefined;
return {
start: toLocation(span.start),
end: toLocation(textSpanEnd(span)),
...declarationSpan && {
declarationStart: toLocation(declarationSpan.start),
declarationEnd: toLocation(textSpanEnd(declarationSpan))
...contextSpan && {
contextStart: toLocation(contextSpan.start),
contextEnd: toLocation(textSpanEnd(contextSpan))
}
};
}
export interface ProtocolRenameSpanFromSubstring extends ProtocolDeclarationTextSpanFromString {
export interface ProtocolRenameSpanFromSubstring extends ProtocolTextSpanWithContextFromString {
prefixSuffixText?: {
readonly prefixText?: string;
readonly suffixText?: string;
@@ -564,7 +564,7 @@ namespace ts.projectSystem {
}
export function protocolRenameSpanFromSubstring({ prefixSuffixText, ...rest }: ProtocolRenameSpanFromSubstring): protocol.RenameTextSpan {
return {
...protocolDeclarationTextSpanFromSubstring(rest),
...protocolTextSpanWithContextFromSubstring(rest),
...prefixSuffixText
};
}

View File

@@ -78,10 +78,10 @@ namespace ts.projectSystem {
arguments: { file: myConstFile, ...myConstStart }
}).response as protocol.RenameResponseBody;
const locationOfMyConstInLib = protocolDeclarationFileSpanFromSubstring({
const locationOfMyConstInLib = protocolFileSpanWithContextFromSubstring({
file: containerLib[1],
text: "myConst",
declarationText: "export const myConst = 30;"
contextText: "export const myConst = 30;"
});
const { file: _, ...renameTextOfMyConstInLib } = locationOfMyConstInLib;
assert.deepEqual(response.locs, [
@@ -191,8 +191,8 @@ fn5();
file: dtsPath,
start: { line: fn, offset: definition.start.offset + declareSpaceLength },
end: { line: fn, offset: definition.end.offset + declareSpaceLength },
declarationStart: { line: fn, offset: 1 },
declarationEnd: { line: fn, offset: 37 }
contextStart: { line: fn, offset: 1 },
contextEnd: { line: fn, offset: 37 }
}],
textSpan
},
@@ -204,20 +204,20 @@ fn5();
};
}
function declarationSpan(fn: number): protocol.DeclarationTextSpan {
function declarationSpan(fn: number): protocol.TextSpanWithContext {
return {
start: { line: fn, offset: 17 },
end: { line: fn, offset: 20 },
declarationStart: { line: fn, offset: 1 },
declarationEnd: { line: fn, offset: 26 }
contextStart: { line: fn, offset: 1 },
contextEnd: { line: fn, offset: 26 }
};
}
function importSpan(fn: number): protocol.DeclarationTextSpan {
function importSpan(fn: number): protocol.TextSpanWithContext {
return {
start: { line: fn + 1, offset: 5 },
end: { line: fn + 1, offset: 8 },
declarationStart: { line: 1, offset: 1 },
declarationEnd: { line: 7, offset: 27 }
contextStart: { line: 1, offset: 1 },
contextEnd: { line: 7, offset: 27 }
};
}
function usageSpan(fn: number): protocol.TextSpan {
@@ -226,7 +226,7 @@ fn5();
function renameFromDependencyTs(fn: number): SessionAction<protocol.RenameRequest, protocol.RenameResponseBody> {
const defSpan = declarationSpan(fn);
const { declarationStart: _, declarationEnd: _1, ...triggerSpan } = defSpan;
const { contextStart: _, contextEnd: _1, ...triggerSpan } = defSpan;
return {
reqName: "rename",
request: {

View File

@@ -20,7 +20,7 @@ namespace ts.projectSystem {
protocolRenameSpanFromSubstring({
fileText: bTs.content,
text: "./a",
declarationText: bTs.content
contextText: bTs.content
})
]
}],
@@ -45,7 +45,7 @@ namespace ts.projectSystem {
protocolRenameSpanFromSubstring({
fileText: bTs.content,
text: "./a",
declarationText: bTs.content
contextText: bTs.content
})
]
}],
@@ -71,7 +71,7 @@ namespace ts.projectSystem {
protocolRenameSpanFromSubstring({
fileText: bTs.content,
text: "./a",
declarationText: bTs.content
contextText: bTs.content
})
]
}],
@@ -103,7 +103,7 @@ namespace ts.projectSystem {
protocolRenameSpanFromSubstring({
fileText: aTs.content,
text: "x",
declarationText: "const x = 0;"
contextText: "const x = 0;"
}),
protocolRenameSpanFromSubstring({
fileText: aTs.content,
@@ -135,7 +135,7 @@ namespace ts.projectSystem {
protocolRenameSpanFromSubstring({
fileText: aTs.content,
text: "x",
declarationText: "const x = 0;"
contextText: "const x = 0;"
}),
protocolRenameSpanFromSubstring({
fileText: aTs.content,
@@ -169,7 +169,7 @@ namespace ts.projectSystem {
protocolRenameSpanFromSubstring({
fileText: aTs.content,
text: "x",
declarationText: "const x = 0;"
contextText: "const x = 0;"
}),
protocolRenameSpanFromSubstring({
fileText: aTs.content,
@@ -210,13 +210,13 @@ namespace ts.projectSystem {
protocolRenameSpanFromSubstring({
fileText: aTs.content,
text: "x",
declarationText: "const x = 1;"
contextText: "const x = 1;"
}),
protocolRenameSpanFromSubstring({
fileText: aTs.content,
text: "x",
options: { index: 2 },
declarationText: "export { x };",
contextText: "export { x };",
prefixSuffixText: { suffixText: " as x" }
}),
],
@@ -243,7 +243,7 @@ namespace ts.projectSystem {
protocolRenameSpanFromSubstring({
fileText: bTs.content,
text: "x",
declarationText: `import { x } from "./a";`
contextText: `import { x } from "./a";`
}),
protocolRenameSpanFromSubstring({
fileText: bTs.content,
@@ -258,13 +258,13 @@ namespace ts.projectSystem {
protocolRenameSpanFromSubstring({
fileText: aTs.content,
text: "x",
declarationText: "const x = 1;"
contextText: "const x = 1;"
}),
protocolRenameSpanFromSubstring({
fileText: aTs.content,
text: "x",
options: { index: 2 },
declarationText: "export { x };",
contextText: "export { x };",
}),
],
},

View File

@@ -61,7 +61,7 @@ namespace ts.projectSystem {
protocolRenameSpanFromSubstring({
fileText: aFile.content,
text: "C",
declarationText: `import {C} from "./c/fc";`
contextText: `import {C} from "./c/fc";`
}),
protocolRenameSpanFromSubstring({
fileText: aFile.content,
@@ -72,7 +72,7 @@ namespace ts.projectSystem {
const span = protocolRenameSpanFromSubstring({
fileText: cFile.content,
text: "C",
declarationText: "export const C = 8"
contextText: "export const C = 8"
});
const cLocs: protocol.RenameTextSpan[] = [span];
assert.deepEqual<protocol.RenameResponseBody | undefined>(response, {