-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Enable auto imports in member snippet completions #46592
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -942,7 +942,7 @@ namespace FourSlash { | |
expected = typeof expected === "string" ? { name: expected } : expected; | ||
|
||
if (actual.insertText !== expected.insertText) { | ||
this.raiseError(`Expected completion insert text to be ${expected.insertText}, got ${actual.insertText}`); | ||
this.raiseError(`Completion insert text did not match: ${showTextDiff(expected.insertText || "", actual.insertText || "")}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's awesome, I've been needing this for a while There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I usually try to fix things that annoy me about fourslash, it has definitely paid off even if I were the only person using it 😅 |
||
} | ||
const convertedReplacementSpan = expected.replacementSpan && ts.createTextSpanFromRange(expected.replacementSpan); | ||
if (convertedReplacementSpan?.length) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
// @newline: LF | ||
|
||
// @Filename: /types1.ts | ||
//// export interface I { foo: string } | ||
|
||
// @Filename: /types2.ts | ||
//// import { I } from "./types1"; | ||
//// export interface Base { method(p: I): void } | ||
|
||
// @Filename: /index.ts | ||
//// import { Base } from "./types2"; | ||
//// export class C implements Base { | ||
//// /**/ | ||
//// } | ||
|
||
goTo.marker(""); | ||
verify.completions({ | ||
marker: "", | ||
isNewIdentifierLocation: true, | ||
preferences: { | ||
includeCompletionsWithInsertText: true, | ||
includeCompletionsWithSnippetText: false, | ||
includeCompletionsWithClassMemberSnippets: true, | ||
}, | ||
includes: [{ | ||
name: "method", | ||
sortText: completion.SortText.LocationPriority, | ||
replacementSpan: { | ||
fileName: "", | ||
pos: 0, | ||
end: 0, | ||
}, | ||
insertText: "method(p: I): void {\n}\n", | ||
hasAction: true, | ||
source: completion.CompletionSource.ClassMemberSnippet, | ||
}], | ||
}); | ||
|
||
verify.applyCodeActionFromCompletion("", { | ||
preferences: { | ||
includeCompletionsWithInsertText: true, | ||
includeCompletionsWithSnippetText: false, | ||
includeCompletionsWithClassMemberSnippets: true, | ||
}, | ||
name: "method", | ||
source: completion.CompletionSource.ClassMemberSnippet, | ||
description: "Includes imports of types referenced by 'method'", | ||
newFileContent: | ||
`import { I } from "./types1"; | ||
import { Base } from "./types2"; | ||
export class C implements Base { | ||
|
||
}` | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is never surfaced by the VS Code UI 🤷
I think that's totally fine, I only made it because the protocol made me have a message to go along with the fix