Highlight the erroneous line

Hi Team,
Im new to IntelliJ plugin development. Im developing a plugin which is facilitate highlighting error lines in a source code.

Scenario: There's a grid which has source code errors and grid contains file name, file path, line number also. When user click the row, plugin should be able to select errornous line accordingly.

Is there any sample tutorial I can go through with? Please help me with this.

Thank you,
Navin

0
14 comments

There is no sample tutorial that explains exactly that scenario. You can find general plugin development documentation here: https://confluence.jetbrains.com/display/IDEADEV/PluginDevelopment

Which part of the scenario exactly is difficult for you?

0
Avatar
Permanently deleted user

Im stuck with highlighting the erroneous line in a source file part. Im trying to achiev same capability as it is in Eclipse plugin we developed. Eclipse provide ITextEditor, IDocumentProvider, IDocument...etc to achiev mention capability. By parsing line number to ITextEditor we can highlighted the line programmatically. If you can send me the matching classes for the following from IntelliJ side, that will be greatful too.

  • IWorkspaceRoot
  • IPath
  • Path
  • IWorkspaceRoot
  • IProject
  • IFile
  • IDocumentProvider
  • ITextEditor


Thanks for the prompt reply.

Navin

0

To highlight a line in an editor, use Editor.getMarkupModel().getRangeHighlighter().

I'm not familiar with Eclipse plugin development and I don't know what these classes in the Eclipse API do. To familiarize yourself with the core classes involved in IntelliJ plugin development, please refer to https://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Architectural+Overview

0
Avatar
Permanently deleted user

Thanks Dimitry. Could you pleas tell me the flow of opening a source file (java file) from Editor programatically.

0

What do you mean "open a file from editor"? To open a file in the editor, use: new OpenFileDescriptor(project, file).navigate(true)

0
Avatar
Permanently deleted user

Thanks again Dimitry, I followed your steps and able to open a file in the editor. But line highlighting part didn't work as expected. Here is the sample code I implemented with, What did i do wrong?

        Project project = anActionEvent.getProject();
        File file = new File("/home/namarasiri/IdeaProjects/TestPlugin/src/com/test/Test.java");
        VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file);
        PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
        OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(project, virtualFile);
        openFileDescriptor.navigate(true);

        Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
        int x =  editor.getDocument().getLineCount();
        editor.getMarkupModel().addLineHighlighter(1, 20, null);//addRangeHighlighter(1, 20, (HighlighterLayer.SELECTION - 100), new TextAttributes(), HighlighterTargetArea.EXACT_RANGE);


Thanks,
Navin
0

So what did you expect to happen? You're specifying null as the attributes for highlighting. This creates a highlighter with no attributes - in other words, an invisible highlighter. If you want your highlighter to be visible, you need to tell IntelliJ IDEA how it should look like.

0
Avatar
Permanently deleted user

Thanks again, I able to resolve that by parsing "editor.getCaretModel().getTextAttributes()" which I guess default attributes. Thanks again... :). I didn't know that "null" acting as a invisible highlighter.

0

There is no such thing as "default attributes". CaretModel.getTextAttributes() returns the background color of the caret, which is not intended to be used for highlighting things which are not the caret.

0
Avatar
Permanently deleted user

What is the preferd way to highlight line in a code programatically.

0

The preferred way is to figure out the color with which you want the line to be highlighted, and then pass that color as the TextAttributes parameter.

0
Avatar
Permanently deleted user

Thanks Dimitry.

0
Avatar
Permanently deleted user

Hi Dimitry,
  Do you know how to set couser to selected line or set foucus to the given line?

0
0

Please sign in to leave a comment.