Skip to content

Conversation

@Andarist
Copy link
Contributor

@Andarist Andarist commented Feb 6, 2023

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Feb 6, 2023
case StringLiteralCompletionKind.Types:
return find(completion.types, t => t.value === name) ? createCompletionDetails(name, ScriptElementKindModifier.none, ScriptElementKind.typeElement, [textPart(name)]) : undefined;
case StringLiteralCompletionKind.Cases:
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure what kind of details should be returned here.

Copy link
Member

@gabritto gabritto Feb 6, 2023

Choose a reason for hiding this comment

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

I think you should do something like the above case for StringLiteralCompletionKind.Types, except I don't think the kind should be ScriptElementKind.typeElement, it should be ScriptElementKind.string instead. Not related to your PR: I don't know why the call above is using ScriptElementKind.typeElement, it looks weird to me that the kind in the CompletionEntry and CompletionEntryDetails return two different things for StringLiteralCompletionKind.Types case, do you know why that is @andrewbranch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I came to the conclusion - that perhaps I don't need a completely separate type and I can just use .Types. At first, I wasn't sure what .Types is supposed to resolve so I was afraid of reusing it. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

I don’t know the answer to @gabritto’s question, but I do think you can just use .Types for this.

Copy link
Member

Choose a reason for hiding this comment

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

I think you can reuse it and fix the CompletionEntryDetails.kind weirdness. With any luck, if this turns out to be wrong for some reason, a test will break 😅

Copy link
Member

Choose a reason for hiding this comment

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

AFAIK that property only controls the icon displayed in editors, and the editors map our categories onto their own, so there’s not really a right or wrong answer.

hasValue(value: string | number | PseudoBigInt): boolean;
}

function newCaseClauseTracker(checker: TypeChecker, clauses: readonly (CaseClause | DefaultClause)[]): CaseClauseTracker {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it makes sense to move this out to a shared space so both completions and stringCompletions can use it - but if you prefer some other solution, let me know.

@Andarist Andarist marked this pull request as draft February 6, 2023 15:44
@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Feb 6, 2023
//// case /*2*/
//// }
//// declare const f2: 'foo' | 'bar' | 'baz';
//// switch (f) {
Copy link
Member

Choose a reason for hiding this comment

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

I think you meant to switch (f2) here instead of switch (f).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, definitely - this was a late copy-paste from a separate file in which I was originally testing it 😅 gonna amend that soon

case StringLiteralCompletionKind.Types:
return find(completion.types, t => t.value === name) ? createCompletionDetails(name, ScriptElementKindModifier.none, ScriptElementKind.typeElement, [textPart(name)]) : undefined;
case StringLiteralCompletionKind.Cases:
return;
Copy link
Member

@gabritto gabritto Feb 6, 2023

Choose a reason for hiding this comment

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

I think you should do something like the above case for StringLiteralCompletionKind.Types, except I don't think the kind should be ScriptElementKind.typeElement, it should be ScriptElementKind.string instead. Not related to your PR: I don't know why the call above is using ScriptElementKind.typeElement, it looks weird to me that the kind in the CompletionEntry and CompletionEntryDetails return two different things for StringLiteralCompletionKind.Types case, do you know why that is @andrewbranch?

@jakebailey
Copy link
Member

@Andarist FYI you may want to recopy the settings from settings.template.json to get the organize import settings in the repo (+ use the nightly TS extension), which should make thinkgs like auto-imports produce a more linter-friendly result.

@Andarist Andarist marked this pull request as ready for review February 6, 2023 20:39
@gabritto gabritto merged commit 6b43f82 into microsoft:main Feb 6, 2023
@Andarist Andarist deleted the fix/filter-out-existing-cases-from-string-completions branch February 7, 2023 09:27
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch case completion filtering doesn’t work inside string literal quotes

5 participants