mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
update external files api
This commit is contained in:
1 parent
6bc5ef3474
commit
9050d0fdf8
2 files changed
+15
-14
No files matched your search
@@ -12,7 +12,7 @@ namespace ts.codefix {
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions(context) {
|
||||
const info = getInfo(context.sourceFile, context.span.start, context.program.getTypeChecker());
|
||||
const info = getInfo(context.sourceFile, context.span.start, context.program.getTypeChecker(), context.program);
|
||||
if (!info) return undefined;
|
||||
|
||||
if (info.kind === InfoKind.Enum) {
|
||||
@@ -37,7 +37,7 @@ namespace ts.codefix {
|
||||
|
||||
return createCombinedCodeActions(textChanges.ChangeTracker.with(context, changes => {
|
||||
eachDiagnostic(context, errorCodes, diag => {
|
||||
const info = getInfo(diag.file, diag.start, checker);
|
||||
const info = getInfo(diag.file, diag.start, checker, context.program);
|
||||
if (!info || !addToSeen(seen, getNodeId(info.parentDeclaration) + "#" + info.token.text)) {
|
||||
return;
|
||||
}
|
||||
@@ -113,12 +113,7 @@ namespace ts.codefix {
|
||||
}
|
||||
type Info = EnumInfo | ClassOrInterfaceInfo;
|
||||
|
||||
function isInNodeModulesDeclarationFile(node: Node) {
|
||||
const sourceFile = getSourceFileOfNode(node);
|
||||
return sourceFile.isDeclarationFile && startsWith(sourceFile.resolvedPath, "node_modules/") || sourceFile.resolvedPath.indexOf("/node_modules/") !== -1;
|
||||
}
|
||||
|
||||
function getInfo(tokenSourceFile: SourceFile, tokenPos: number, checker: TypeChecker): Info | undefined {
|
||||
function getInfo(tokenSourceFile: SourceFile, tokenPos: number, checker: TypeChecker, program: Program): Info | undefined {
|
||||
// The identifier of the missing property. eg:
|
||||
// this.missing = 1;
|
||||
// ^^^^^^^
|
||||
@@ -136,7 +131,7 @@ namespace ts.codefix {
|
||||
|
||||
// Prefer to change the class instead of the interface if they are merged
|
||||
const classOrInterface = find(symbol.declarations, isClassLike) || find(symbol.declarations, isInterfaceDeclaration);
|
||||
if (classOrInterface && !isInNodeModulesDeclarationFile(classOrInterface)) {
|
||||
if (classOrInterface && !program.isSourceFileFromExternalLibrary(classOrInterface.getSourceFile())) {
|
||||
const makeStatic = ((leftExpressionType as TypeReference).target || leftExpressionType) !== checker.getDeclaredTypeOfSymbol(symbol);
|
||||
const declSourceFile = classOrInterface.getSourceFile();
|
||||
const inJs = isSourceFileJS(declSourceFile);
|
||||
@@ -144,7 +139,7 @@ namespace ts.codefix {
|
||||
return { kind: InfoKind.ClassOrInterface, token, parentDeclaration: classOrInterface, makeStatic, declSourceFile, inJs, call };
|
||||
}
|
||||
const enumDeclaration = find(symbol.declarations, isEnumDeclaration);
|
||||
if (enumDeclaration && !isInNodeModulesDeclarationFile(enumDeclaration)) {
|
||||
if (enumDeclaration && !program.isSourceFileFromExternalLibrary(enumDeclaration.getSourceFile())) {
|
||||
return { kind: InfoKind.Enum, token, parentDeclaration: enumDeclaration };
|
||||
}
|
||||
return undefined;
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @Filename: /node_modules/foo/declarations.d.ts
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
|
||||
// @Filename: /node_modules/foo/types.d.ts
|
||||
//// interface Response {}
|
||||
|
||||
// @Filename: foo.ts
|
||||
//// import '/node_modules/foo/declarations.d.ts'
|
||||
// @Filename: /node_modules/foo/package.json
|
||||
//// { "types": "types.d.ts" }
|
||||
|
||||
// @Filename: /foo.ts
|
||||
//// import { Response } from 'foo'
|
||||
//// declare const resp: Response
|
||||
//// resp.test()
|
||||
|
||||
goTo.file('foo.ts')
|
||||
goTo.file('/foo.ts')
|
||||
|
||||
verify.not.codeFixAvailable()
|
||||
Reference in new issue
Block a user