-
Hello, I've added classes to my language, and now want to add some constructor-logic to them. This is how the class is defined in the grammar:
VariableDeclaration would then become:
I then took the Expression-logic from the lox-sampe, and it works pretty nicely for assigning variables. In my case i need to be able to have this syntax:
This means that i need to have a constructors with the same name as the class. I initially thought I could edit the Class to have this grammar:
Which would make it possible to create some 'special classes' like this:
The completionItems gets filtered to only show one of them, thought, so is there something i can override to show them all? And when making validations for this, is it possible to 'fetch' the parameters from the Class, and from that validate that the parameters passed inn is of valid type? I'm open to reworking this as well, if there are better/other options for how to solve this :) /e |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
After taking a closer look i figured its better to not have multiple completionitems with the same name, and just do validations of the parameters instead. The documentation/comment can explain the overloads. Was able to add/inject them through the defaultcompletionsprovider/getcompletion(), but it behaved differently depending on position so it seems safer to avoid going down this path. |
Beta Was this translation helpful? Give feedback.
I was about to write, that it's likely not a good idea to have different overloads of the same name in the completion. Instead, you can use the LSP
SignatureHelpProvider
(andAbstractSignatureHelpProvider
) to provide all the different overloads of your constructors to the user:langium/packages/langium/src/lsp/signature-help-provider.ts
Lines 17 to 26 in 68c0fa3