Custom langugage: Autocomplete based on grammar?

Answered

I'm currently working on custom language support. I was able to get a (mostly) working BNF and generate a lexer from it. The language looks about like this:

```

State A {

goto B and call someService

}

State B {

}

```

 

I've managed to "Jump to" for references and implement autocompletion so that when you enter `goto ` you get a list of all the states. Now you would need to enter `call <someService>` and when it's missing you get an error message "WorkflowTokenType.and expected, got '}". So the program knows that `and` is missing.

Now my question is: Do I actually have to implement autocomplete for every part of the grammar? Shouldn't it be possible to suggest `and` at this point as the software knows it's missing?

The language is a bit more complex than stated in the example and with my improper error recovery it's a bit of a hassle to get the completion working. It would be quite a bit of work to get the completion to work for any statement / token contained in the language.

 

4 comments
Comment actions Permalink

See com.intellij.sh.completion.ShCommandCompletionContributor in IntelliJ Community sources as sample

0
Comment actions Permalink

Thank you Yann.

I think this ignores the context of the completion and always suggests any of the keywords. I tried the same approach as used in the CustomFileTypeCompletionContributor which basically does the same. I though it should be possible to query the grammar for the completion.

I managed to get about half of the required words being suggested but it's a lot of busy work. It'll have to to I guess.

0
Comment actions Permalink

FTR most language plugins I'm aware of do not reuse Grammar for keyword completion, but implement it fully "manually"

0
Comment actions Permalink

Alright, thanks for the response anyway. It's a bit more ardous in my case because I can't get the grammar and recoverWhile and stuff like that to work properly so getting the context is hard. But it works, that's what's important.

0

Please sign in to leave a comment.