Cannot resolve language with id "kotlin"

已回答

Hello, 

I was trying to create a plugin that adds line markers to both Java and Kotlin PSI elements. I posted it yesterday and tried to solve the problem. But 'kotlin' language is not resolved yet. Still can't figure out why this problem is happening. I am a student and a beginner for this problem. Please help for understanding why this problem occurs and how to solve it. 

Unresolved code is marked below <<not solved>>

<codeInsight.lineMarkerProvider language="kotlin" <<not solved>>
implementationClass="de.example.iem.LineMarker.RandomLineMarker"/>

Besides, I still couldn't show the line marker to kotlin files. I don't know what is the issue. Can you please have a look?

package de.example.iem.LineMarker;

import com.intellij.codeHighlighting.Pass;
import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.codeInsight.daemon.LineMarkerProvider;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.markup.GutterIconRenderer;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Set;

public class RandomLineMarker implements LineMarkerProvider {

@Override
public @Nullable LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) {
if(psiElement instanceof PsiStatement){
return CreateNewMarker(psiElement);
}
else{
return null;
}
}
private LineMarkerInfo CreateNewMarker(PsiElement psiElement){
return new LineMarkerInfo(psiElement, psiElement.getTextRange(), IconLoader.getIcon("/icons/cognicrypt.png"), Pass.LINE_MARKERS,null, null, GutterIconRenderer.Alignment.LEFT);
}
}

This is my working repository: https://github.com/Projucti/LineMarker.git

0

Please read instructions here https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_dependencies.html :

1. Your main plugin.xml needs additional
<depends>org.jetbrains.kotlin</depends>

2. remove this line from build.gradle

compile "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"


3. withKotlin.xml must have root tag <idea-plugin> just like plugin.xml

1

Thanks for the answer. I followed all the steps written in the documentation. I also followed your steps and still language 'kotlin' is not resolving. 
Can we have a direct meeting/discussion for this problem?

0

Please try reimporting Gradle project.

1

Thank you. Re-importing the project resolved 'kotlin' language tag. But line marker isn't showing in the kotlin files. What is this problem happening?

0

PsiStatement is Java specific PSI and will never be present in Kotlin files. You must target Kotlin specific PSI, use PsiViewer to investigate https://plugins.jetbrains.com/plugin/227-psiviewer

0

Is there any documentation or guideline where I can learn more specifically about kotlin PSI elements?

0

Thank you. Investigating this way is definitely hard and very confusing for Beginners/Students.

Can I request to JetBrains for proper documentation of Kotlin PSI structures, naming convention with examples or can you please forward my request?

0

Depending on specific use case, some of Java PSI API can also be used (anyway it is very similar and much better documented). I'll try to find more sources for docs

0

Thank you. Looking forward to more sources.

0

How to configure Kotlin support using plugin.xml ? (not Gradle)

Just adding

<depends>org.jetbrains.kotlin</depends>

does not work. I failed to find any working tutorial on this. 

0

already studied - does not help. It literally says "If a plugin processes Kotlin code (e.g., providing inspections), it needs to add a dependency on the Kotlin plugin (Plugin ID org.jetbrains.kotlin) itself." 

So that is what I am doing - adding dependency to plugin.xml. It does not work - dependency not recognized. 

0

As stated in the documentation - you have to use Gradle for such integration. If you have any troubles with that, check our template repository: Using GitHub Template

0

This is not explicitely stated in documentation. 

0

请先登录再写评论。