Skip to content

Don't generate union for IntEnums#40

Merged
rchl merged 3 commits intomainfrom
fix/intenum
Apr 22, 2026
Merged

Don't generate union for IntEnums#40
rchl merged 3 commits intomainfrom
fix/intenum

Conversation

@rchl
Copy link
Copy Markdown
Member

@rchl rchl commented Apr 22, 2026

Address #39 (comment)

Also remove IntFlag override for ApplyKind since it's not a bitwise flag. (see #39 (comment))

@jwortmann
Copy link
Copy Markdown
Member

jwortmann commented Apr 22, 2026

I would change the condition so that the type union is not produced for supportsCustomValues if the resulting type is IntFlag. Custom values could be allowed for IntEnum (and in contrary to IntFlag it would be necessary to use Union[int, ...] in that case for proper typing).

The only places where this seems to be in the metaModel currently is for ErrorCodes and LSPErrorCodes. But neither of them are referenced in any other LSP type, so technically no lint error would occur at the moment. That is because ResponseError doesn't seem to be part of the metaModel (and doesn't directly reference the ErrorCodes in the specs, so we have the code already typed as int in a custom type defintion at https://github.com/sublimelsp/LSP/blob/50fa4b40a970e7e8e6f62520aba66c47bf4bb7fb/plugin/core/protocol.py#L437).

But if there would be another IntEnum type with custom values in the future, the type union might also be needed for proper lint checks.


So something like this (untested):

    if (
            (enum := context['enumerations'].get(literal_symbol_name))
            and enum.get('supportsCustomValues')
            and ENUM_OVERRIDES.get(literal_symbol_name) != 'IntFlag'   # only for string enums and int enums, bitwise combinations of IntFlag are handled fine
        ):

@rchl
Copy link
Copy Markdown
Member Author

rchl commented Apr 22, 2026

We didn't have ENUM_OVERRIDES in this context so did a refactor to pass it.

EDIT: Well, we could have imported it but it's not how the code wanted to do things.

@rchl rchl merged commit ed09589 into main Apr 22, 2026
1 check passed
@rchl rchl deleted the fix/intenum branch April 22, 2026 22:25
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.

3 participants