Skip to content

Expose base type of enumeration#39

Merged
rchl merged 1 commit intomainfrom
feat/enumeration-base-type
Apr 22, 2026
Merged

Expose base type of enumeration#39
rchl merged 1 commit intomainfrom
feat/enumeration-base-type

Conversation

@rchl
Copy link
Copy Markdown
Member

@rchl rchl commented Apr 20, 2026

Enumerations that specify supportsCustomValues now get the base type (str or int) included where those are referenced.

It solves the use case that #37 was solving but in a different way.

Note that root_symbol_name was unused.

@rchl rchl force-pushed the feat/enumeration-base-type branch from 7aa44a7 to a057c2f Compare April 20, 2026 20:22
Comment thread generated/lsp_types.py
@since 3.17.0 support for relative patterns.
"""
kind: NotRequired['WatchKind']
kind: NotRequired[Union[Uint, WatchKind]]
Copy link
Copy Markdown
Member Author

@rchl rchl Apr 20, 2026

Choose a reason for hiding this comment

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

From the spec perspective it is probably correct because the value is a bitwise flag so not necessarily the exact value that matches one of the enums.

Copy link
Copy Markdown
Member

@jwortmann jwortmann Apr 22, 2026

Choose a reason for hiding this comment

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

I've probably should have written this before approving/merge, but didn't pay close attention to this comment.

Actually the type of a bitwise combination of IntFlag members is also considered to by that IntFlag. So unless WatchKind also supports custom values, this UInt is probably not needed.

Copy link
Copy Markdown
Member Author

@rchl rchl Apr 22, 2026

Choose a reason for hiding this comment

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

It doesn't work to directly assign a number (even if its the value of one of the IntFlag's):

Screenshot 2026-04-22 at 17 53 35

But of course it works to combine enum flags so in theory we could do without int... It would have to be then special-cased in generator.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's true, but I would say that is a good thing, because we should only use predefined values or combinations of the predefined values from the WatchKind IntFlag in the code.

Copy link
Copy Markdown
Member

@jwortmann jwortmann Apr 22, 2026

Choose a reason for hiding this comment

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

There are only two types from the LSP specs that use IntFlag in the generated types: WatchKind and ApplyKind.

{
"name": "WatchKind",
"type": {
"kind": "base",
"name": "uinteger"
},
"values": [
{
"name": "Create",
"value": 1,
"documentation": "Interested in create events."
},
{
"name": "Change",
"value": 2,
"documentation": "Interested in change events"
},
{
"name": "Delete",
"value": 4,
"documentation": "Interested in delete events"
}
],
"supportsCustomValues": true
},

{
"name": "ApplyKind",
"type": {
"kind": "base",
"name": "uinteger"
},
"values": [
{
"name": "Replace",
"value": 1,
"documentation": "The value from the individual item (if provided and not `null`) will be\nused instead of the default."
},
{
"name": "Merge",
"value": 2,
"documentation": "The value from the item will be merged with the default.\n\nThe specific rules for mergeing values are defined against each field\nthat supports merging."
}
],
"documentation": "Defines how values from a set of defaults and an individual item will be\nmerged.\n\n@since 3.18.0",
"since": "3.18.0"
},

But it seems that ApplyKind is not actually used as a bitwise flag, so that could be a bug in the generator? It also does not have supportsCustomValues set in the metaModel.

I would say the generator should not produce the union type for IntFlag, even if supportsCustomValues is set.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Follow-up in #40

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But it seems that ApplyKind is not actually used as a bitwise flag, so that could be a bug in the generator?

Not sure what would you consider a bug. That we don't create an union or that we use IntEnum for it?

It also does not have supportsCustomValues set in the metaModel.

We only create union when supportsCustomValues is true.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No, the bug is that we don't use IntEnum for it.

Currently it is IntFlag, but that is wrong:
https://github.com/sublimelsp/LSP/blob/50fa4b40a970e7e8e6f62520aba66c47bf4bb7fb/protocol/__init__.py#L733

It should be IntEnum instead.

Copy link
Copy Markdown
Member Author

@rchl rchl Apr 22, 2026

Choose a reason for hiding this comment

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

We had an override for it - addressed in #40
Also tested that LSP code base has no type issues with that change.

@rchl rchl changed the title Feat/enumeration base type Expose base type of enumeration Apr 20, 2026
@rchl rchl requested a review from jwortmann April 21, 2026 20:28
@rchl rchl merged commit 8c62a64 into main Apr 22, 2026
1 check passed
@rchl rchl deleted the feat/enumeration-base-type branch April 22, 2026 15:30
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