Skip to content
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

fix(57348): Auto-complete on satisfies auto-imports satisfies #57364

Merged
merged 4 commits into from
Feb 26, 2024

Conversation

a-tarasyuk
Copy link
Contributor

Fixes #57348

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Feb 10, 2024
@@ -4004,7 +4005,9 @@ function getCompletionData(
if (!isIdentifierText(symbolName, getEmitScriptTarget(host.getCompilationSettings()))) return false;
if (!detailsEntryId && isStringANonContextualKeyword(symbolName)) return false;
if (!isTypeOnlyLocation && !importStatementCompletion && !(targetFlags & SymbolFlags.Value)) return false;
if (!isTypeOnlyLocation && contextToken && isExpression(contextToken) && contains([SyntaxKind.AsKeyword, SyntaxKind.SatisfiesKeyword], stringToToken(symbolName))) return false;
Copy link
Member

Choose a reason for hiding this comment

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

Special-casing just these two feels off - why can't we just return both the auto-import and the keyword? For example, if you have a module like this:

namespace foo {
    export function await() {

    }
}

export = foo;

Both the keyword and auto-import are available in other files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I understand it, this "special-casing" should apply in cases where the user is in a "casting/satisfies" position.

1 a/**/
1 sati/**/
// should we suggest auto-import here?

Copy link
Member

Choose a reason for hiding this comment

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

I suppose that's fine - in which case, at the very least that you need to check for no line terminator before the position, right?

Copy link
Member

Choose a reason for hiding this comment

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

Isn’t the keyword supposed to be present and sorted above the auto-import? Here’s async, for example:

image

In a position like 1 satisf/**/, it’s true that an identifier would be invalid, so we could consider blocking all auto-imports there. However, I sometimes find myself wanting completions in the middle of a messy edit:

const x = someFn bla/**/, foo); // going to backtrack and add the missing `(`

so I’m hesitant to block completions based on relying too much on the current state of the parse tree. It feels to me like the bug is just that the keywords don’t show up here, even though they’re valid:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2024-02-14 at 03 42 12 Screenshot 2024-02-14 at 03 42 26

This comment was marked as duplicate.

@andrewbranch
Copy link
Member

Thanks @a-tarasyuk!

@andrewbranch andrewbranch merged commit 65812bf into microsoft:main Feb 26, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto-complete on satisfies auto-imports satisfies
5 participants