Questions about language plugin

Hi,

i'm writing a plugin for a language. the documentation and example on jetbrains.com is good, but leaves some questions open.

in a string can be escaped chars like \n, \t etc. how can i mark these as highlighted?

the language has a lot of libraries for special extensions. the lexer only recognizes an identifier and the parser marks functioncalls, if identifier() is entered. how can i detect the library-functions and how can i display these functions in a special way, like italic. the problem is, that i can't add all library-functions to the lexer, because there are too much of them and the count of functions depends on the installed libraries. i'd like to make the developer decide, which libraries are installed, so these kind of parsing and syntax-highlighting must be a step past the lexer.

how do i create a quick-list with these functions? and a online-help for the parameters of a function? this must be a standard-problem, so i think, there is an easy solution with some classes or interfaces. :)

these are the first questions for now. to be continued.... :) I hope, my english is good enough to understand.

thanks for the help,

michael

10 comments
Comment actions Permalink

I know nothing about programming plug-ins for IDEA, but I do know that the proper place for discussing their programming is the "Open API" forum.

Randall Schulz

0
Comment actions Permalink

Hmm, should I post this thread there again? Some user would note this as a kind of spam.

0
Comment actions Permalink

Well, I still go by the classic definition of spam: "Unsolicited commercial email," so your post is by no means spam, but it is off-topic here.

So yes, I'd post it again on the Open UI forum.


Randall Schulz

0
Comment actions Permalink

Hello Michael,

in a string can be escaped chars like \n, \t etc. how can i mark these
as highlighted?


You need to implement a separate lexer for contents of string literals. You
can look at the sources of the JavaScript plugin, for example, to see examples
of how this is implemented.

the language has a lot of libraries for special extensions. the lexer
only recognizes an identifier and the parser marks functioncalls, if
identifier() is entered. how can i detect the library-functions
and how can i display these functions in a special way, like italic.
the problem is, that i can't add all library-functions to the lexer,
because there are too much of them and the count of functions depends
on the installed libraries. i'd like to make the developer decide,
which libraries are installed, so these kind of parsing and
syntax-highlighting must be a step past the lexer.


This kind of highlighting is usually performed by an annotator. Again, you
can find examples of annotators in any custom language plugin.

how do i create a quick-list with these functions?


Do you mean code completion? You can find some information on implementing
code completion in the "Developing custom language plugins" document. Essentially
you will need to return the functions from the getVariants() method of your
PsiReference implementation.

and a online-help for the parameters of a function?


You'll need to provide implementations of DocumentationProvider (for Ctrl-Q)
and ParameterInfoHandler (for Ctrl-P).

this must be a standard-problem, so
i think, there is an easy solution with some classes or interfaces.
:)


Well, any problem can be solved with some classes or interfaces. :) But if
the only thing you now have is a lexer, there's still a long way to go before
you'll have a complete custom language plugin.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

hi!

1. to highlight escape sequences in strings you have to return tokens for them from the lexer
you can do it either by modifying your lexer or by wrapping your lexer in LayeredLexer


2. to highlight something after lexer you need to implement Annotator for your language, then create info annotation on AnnotationHolder and then apply your text attributes to it.
See http://www.jetbrains.com/idea/plugins/developing_custom_language_plugins.html#syntax_highlighting

0
Comment actions Permalink

Thanks for this help, I'll have a look for this and will set this question as answered after that.
In the example, I'll see only the java-code, not the code for jflex, can you or anybody else create a link to the flex-code from the documentation?

at the moment, i have a lot more: the lexer parses all keywords and symbols, the syntax-highlighter for the normal code works, the statement- and expression-parser works, so i have a psi-tree. the code-folding and spacing do the most of if it's work and i have some code for the annotation to check the for the correct syntax.

0
Comment actions Permalink

Hi Jay,

this works. Thanks :)

Michael

0
Comment actions Permalink

you're welcome ;)

0
Comment actions Permalink

Hi Dmitry,

this has helped me, but I have the following problems:

how do i create a quick-list with these functions?


Do you mean code completion? You can find some
information on implementing
code completion in the "Developing custom language
plugins" document. Essentially
you will need to return the functions from the
getVariants() method of your
PsiReference implementation.


Ok, i've implemented a ResefrenceExpression, like the example, but the code won't be called. For example, when I type "my" and press Ctrl-Space a tooltip "No suggetions" appears and none of my breakpoints will be used. Maybe I habe forgotten some code, but it's hard to compare, because in the JS-example i can have one Java-Class as a HTML-Code in the example and can't search for usages (I love this feature in Idea :) ).

While debugging, i've found, that sometimes the PsiBuilder has a TokenText of "IntellijIdeaRulezzz". Does this mark the current Cursor-Position?

and a online-help for the parameters of a function?


You'll need to provide implementations of
DocumentationProvider (for Ctrl-Q)
and ParameterInfoHandler (for Ctrl-P).


I haven't found these Interfaces. Maybe I have an older version of the API, I use Idea 5.1 and the documentation of the plugin links to the JavaDoc of V5.0 (http://www.jetbrains.com/idea/openapi/5.0/). Which Interfaces do I have to use now?

The next thing, I haven't understood, is the IChameleonType. In the example, I haven't found, where the ElementType EMBEDDED_CONTENT is set (again: searching in the HTML-Code is not possible :) ). You only define a constant in JSElementType of the type IChameleonType but wrote, that it method parseContents() must be overwritten. There is no example and i don't understand, how to write this method.

Michael

0
Comment actions Permalink

Hello Michael,

this has helped me, but I have the following problems:

>>> how do i create a quick-list with these functions?
>>>
>> Do you mean code completion? You can find some
>> information on implementing
>> code completion in the "Developing custom language
>> plugins" document. Essentially
>> you will need to return the functions from the
>> getVariants() method of your
>> PsiReference implementation.

Ok, i've implemented a ResefrenceExpression, like the example, but the
code won't be called. For example, when I type "my" and press
Ctrl-Space a tooltip "No suggetions" appears and none of my
breakpoints will be used. Maybe I habe forgotten some code, but it's
hard to compare, because in the JS-example i can have one Java-Class
as a HTML-Code in the example and can't search for usages (I love this
feature in Idea :) ).


Please ensure that your PsiReference implementation follows the requirements
described in the "Developing Custom Language Plugins" document.

While debugging, i've found, that sometimes the PsiBuilder has a
TokenText of "IntellijIdeaRulezzz". Does this mark the current
Cursor-Position?


You could say so. :) The completion inserts this identifier at the cursor
position, tries to detect a reference at that location and shows the completion
list produced by getVariants() of this reference.

>>> and a online-help for the parameters of a function?
>>>
>> You'll need to provide implementations of
>> DocumentationProvider (for Ctrl-Q)
>> and ParameterInfoHandler (for Ctrl-P).

I haven't found these Interfaces. Maybe I have an older version of the
API, I use Idea 5.1 and the documentation of the plugin links to the
JavaDoc of V5.0 (http://www.jetbrains.com/idea/openapi/5.0/). Which
Interfaces do I have to use now?


These APIs are new in 7.0. Parameter Info is not pluggable in earlier IDEA
versions.

The next thing, I haven't understood, is the IChameleonType. In the
example, I haven't found, where the ElementType EMBEDDED_CONTENT is
set (again: searching in the HTML-Code is not possible :) ). You only
define a constant in JSElementType of the type IChameleonType but
wrote, that it method parseContents() must be overwritten. There is no
example and i don't understand, how to write this method.


Why do you need chameleons? If you need to implement mixed language documents,
it is strongly recommended to upgrade to IDEA 6.0 or (preferably) 7.0 and
use language injection instead of chameleons.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.