Syntax highlighting
Hi,
I am developing a custom language pluggin for intellij. I want to highlight the syntax of a custome language for which I have generated java class using Jflex and done upto the implementation of SyntaxHighlighterBase implementation. But How to link that with the editor?
Thanks..!1
请先登录再写评论。
Hi Amila,
You should have a look here.
Denis
Did you follow steps from http://confluence.jetbrains.net/display/IDEADEV/Developing+Custom+Language+Plugins+for+IntelliJ+IDEA#DevelopingCustomLanguagePluginsforIntelliJIDEA-SyntaxHighlightingandErrorHighlighting?
If yes, could you post/link your code to help you debug?
Hi,
Thank You for replying. Here is my syntaxhighlighting class. I did not follow the steps mentioned in 'Implementing a Parser and PSI'. Since I am new to this I created this code snippets to see how the system works.
package newair.org;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.editor.SyntaxHighlighterColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.tree.IElementType;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
/**
* Created with IntelliJ IDEA.
* User: amila
* Date: 6/8/12
* Time: 1:00 PM
* To change this template use File | Settings | File Templates.
*/
public class SyntaxHighlightHandler extends SyntaxHighlighterBase {
@NotNull
@Override
public Lexer getHighlightingLexer() {
return new JaggeryHighlightingLexer(); //To change body of implemented methods use File | Settings | File Templates.
}
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType iElementType) {
return pack(keys1.get(iElementType),keys2.get(iElementType)); //To change body of implemented methods use File | Settings | File Templates.
}
public static final TextAttributesKey JAGGERY_KEY = TextAttributesKey.createTextAttributesKey(
"JAGGERY.KEY",
SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()
);
public static final TextAttributesKey JAGGERY_VALUE = TextAttributesKey.createTextAttributesKey(
"JAGGERY.VALUE",
SyntaxHighlighterColors.STRING.getDefaultAttributes()
);
public static final TextAttributesKey JAGGERY_DOCCOMMENT = TextAttributesKey.createTextAttributesKey(
"JAGGERY.DOCCOMMENT",
SyntaxHighlighterColors.DOC_COMMENT.getDefaultAttributes()
);
private static THashMap<IElementType,TextAttributesKey> keys1;
private static THashMap<IElementType,TextAttributesKey> keys2;
static {
keys1.put(JaggeryTokenTypes.KEY_CHARACTERS, JAGGERY_KEY);
keys1.put(JaggeryTokenTypes.VALUE_CHARACTERS, JAGGERY_VALUE);
}
Here is the class which extends flexAdapter.
File type implementation.
I just tested with javascript before the real imlementation here is the .java file generated by Jflex.
please make the whole project available for checkout/download
Here is the link. Sorry for confusion of so many classes. Up to now I have implemented the file type recognition part. It shows in the File type with the icon. But in the tutorial there is no clear step to be implemented as how to invoke the editor. Is it by the FileEditorProvider or anything else?
Your help is kindly appreciated...!!
Thanx.!!
I meant, though it is shown in the File type I cannot open in an editor.
ex:-
new--> file---->file name given-----> File type is chosen (ok) --------> but no empty editor is opened.
what is the procedure to get the editor?
Thanks..!!
There is no special procedure or need for FileEditorProvider for your usecase.
Since I cannot compile your project fully, I can only give you some hints:
- please remove/comment out everything from plugin.xml you don't need, you don't need to assign "id" to every extension either
- in newair.org.SyntaxHighlightHandler "keys1" and "keys2" are not initialized and class initialization is thus bound to fail in its static initializer
Please follow instructions step-by-step and have a look at other simple highlight-only language plugins (there's plenty in plugin repository, also http://git.jetbrains.org/?p=idea/contrib.git;a=tree;f=typoScript;h=fd072e0a387dba678ceeac0cd01fe2694f954eeb;hb=HEAD TypoScript is a good example).