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

Add string Literal types #16

Closed
wants to merge 6 commits into from
Closed

Conversation

predragnikolic
Copy link
Member

No description provided.

@predragnikolic
Copy link
Member Author

predragnikolic commented Apr 16, 2024

I think that the String Literal types might be useful instead of StrEnum.
Both types will exist. And we can use what ever type that has more sense in the code context.

@predragnikolic
Copy link
Member Author

Now,
there will be MonikerKind (StrEnum) and MonikerKindLiteral type.
SemanticTokenTypes (StrEnum) and SemanticTokenTypesLiteral
and so on.

Each StrEnum will have its Literal type alternative.

@jwortmann
Copy link
Member

I don't really understand how this is supposed to be used in the code.
Currently we can use for example

if params['kind'] == CodeActionKind.QuickFix:

and it gives autocompletions for the members when typing the dot.
Or in the type annotations we can use CodeActionKind directly, which is the name from the LSP specs.

Where would we use the Literal types?

@predragnikolic
Copy link
Member Author

Thanks for the look.

Well it is technically adding Literal Types is not necessary.
I will close this PR, because I would rather not add more code.

One pro where Literals shine over enums can be seen in this example:
Screenshot 2024-04-17 at 15 23 26

If pyright strict mode is enabled, pyright will report the correct error for the Literal example,
while for the enum example, it will not.
not sure if it is something that needs to be reported to pyright.

@jwortmann
Copy link
Member

I see. But this would only help against typos, and ideally we always want to use the enum constants in the code, instead of writing the string literal directly.

And various of the enums allow additional custom values defined by the server; for example the SemanticTokenTypes, or the FoldingRangeKind. So this would even be wrong to restrict the allowed values for those enums.

So I guess it was the right choice to close this for now :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants