Skip to content

Path completions for import types #23082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ namespace ts.Completions {
// }
// let x: Foo["/*completion position*/"]
return stringLiteralCompletionsFromProperties(typeChecker.getTypeFromTypeNode((node.parent.parent as IndexedAccessTypeNode).objectType));
case SyntaxKind.ImportTypeNode:
return { kind: StringLiteralCompletionKind.Paths, paths: PathCompletions.getStringLiteralCompletionsFromModuleNames(sourceFile, node, compilerOptions, host, typeChecker) };
default:
return undefined;
}
Expand Down
8 changes: 0 additions & 8 deletions tests/cases/fourslash/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,6 @@ declare namespace FourSlashInterface {
assertHasRanges(ranges: Range[]): void;
caretAtMarker(markerName?: string): void;
completionsAt(markerName: string | ReadonlyArray<string>, completions: ReadonlyArray<string | { name: string, insertText?: string, replacementSpan?: Range }>, options?: CompletionsAtOptions): void;
completionsAndDetailsAt(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this from the fourslash .d.ts because I tried to use it then discovered that it doesn't exist at runtime - the verify class doesn't have this member (any more?).

markerName: string,
completions: {
excludes?: ReadonlyArray<string>,
//TODO: better type
entries: ReadonlyArray<{ entry: any, details: any }>,
},
): void; //TODO: better type
applyCodeActionFromCompletion(markerName: string, options: {
name: string,
source?: string,
Expand Down
13 changes: 13 additions & 0 deletions tests/cases/fourslash/importTypeModuleCompletions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// <reference path="fourslash.ts" />

// @moduleResolution: node

// @Filename: /ns.ts
////file content not read
// @Filename: /node_modules/package/index.ts
////file content not read
// @Filename: /usage.ts
////type A = typeof import("p/*1*/");
////type B = typeof import(".//*2*/");
verify.completionsAt("1", ["package"], { isNewIdentifierLocation: true });
verify.completionsAt("2", ["lib", "ns", "node_modules"], { isNewIdentifierLocation: true });