Saturday, July 16, 2022

[FIXED] How to display a warning at a specific line

Issue

Quick Intellij plugin Development question.

Can somebody show me a snippet of code on how to display a warning at a specific line?

I want to display a yellow bulb and be able to alt enter.

I don't know if the yellow bulb is part of a warning or just a hint but i would very much appreciate if somebody would show me how to do it.

I tried to find it on idea plugin development but didn't have any luck

private List<PsiFile> psiFiles = new ArrayList<PsiFile>();
   public void actionPerformed(AnActionEvent e) {
   PsiManager psiManager=PsiManager.getInstance(e.getProject());
   Project project = e.getProject();
    VirtualFile srcFile;
        if(e.getProject().getBaseDir().findChild("src") == null)
            return;
        else
        {
            srcFile = e.getProject().getBaseDir().findChild("src");
        }
      //using the buildFilesList i get all the .java files
      buildFilesList(psiManager,srcFile);
     for(PsiFile file : psiFiles)
        //here i would want for a psiFile a warning to be displayed at a specific line
        System.out.println(file);

}


Solution

What you need to write is an inspection. You don't need to enumerate the files in the project; IntelliJ IDEA will take care of calling your API at the correct moment. You can find a simple example of a plugin that implements an inspection here.



Answered By - yole
Answer Checked By - Mary Flores (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.