Best way to create code completion (DSL) support in IntelliJ?

Hi all,

I've got a small question: we've got an internally developed configuration language, which has some keywords and parameters, a bit like the following:

expect mode=ALL match=TEXT api.returnCode=OK securityproxy.resultCode=OK

Where 'expect' is the keyword, and then followed by some key/value pairs, which are always in this format.

I thought it would be nice if I could use something like GroovyDSL to create some code completion for this. At least for the keywords, but possibly also for the key/value pairs.

I was wondering if something like this was possible in IntelliJ, and, if so, what the best way forward is.

Suggestions welcome!

Kind regards,

Erik pragt

5 comments

Hi Erik,

No Groovy DSL, sorry.

The most usual way is to write a custom language plugin (http://confluence.jetbrains.net/display/IDEADEV/Developing+Custom+Language+Plugins+for+IntelliJ+IDEA) which implies having a lexer, a parser, syntactic tree, references and, finally, completion.

If you want only completion, and the format is very simple, then I can imagine an easier way, which, alas, also involves plugin creation but can be done quite easily.
You register your file type as a text and register a CompletionContributor extension for plain text files.
When this extension is called (fillCompletionVariants), you check that it's the file of "your" type, analyze the current line contents (CompletionParameters will help you) and provide the appropriate variants (CompletionResultSet#addElement(LookupElementBuilder.create(...)).

Hope this helps.

0

Hi Peter,

That certainly helps! What I actually want, which I think of now, is two things:
1) code completion
2) syntax highlighting (for example, highlight the keywords)

Can both be done using the CompletionContributor, or do I need something else (HighlightContributor??) for this?

Thanks,

Erik

0

It depends on the kind of syntax highlighting that you need.
If you need to just highlight several words known in advance, custom file types are the best solution.
Otherwise, normally you need to create your own language with a lexer (and highlighting lexer).
You can also highlight plain text file via Annotator, although that will work a bit slower and annotators are usually reserved for error or warning highlighting, not syntax. But it's possible.

0

Is this answer still totally relevant for IntelliJ IDEA 2018 Ultimate ? I'm thinking of giving Groovy-based DSL a try in order to get rid of cumbersome 3rd party proprietary configuration scripts, and would like to have yummy IDE features available, (syntax validation, code completion, etc) as that would help a lot with pushing this idea on a management level. If anything has changed in regards to this, please share it.

Thanks

0

Please sign in to leave a comment.