How to get CSharp References comment

Answered

Many people have asked me to support Rider, and I have been researching for a long time.

Other languages can obtain comments using psiElement.getReferences().resolve().

C # does not have an object that can getReferences().

how should I obtain reference comments?

My Plugins: https://plugins.jetbrains.com/plugin/18553-show-comment

 

My Code: https://github.com/LinWanCen/show-comment/blob/baa2fe1dfc55ccc69141afef765ed042d9565b58/src/main/java/io/github/linwancen/plugin/show/lang/base/BaseLangDoc.java#L147-L157

    @Nullable
    protected String refDoc(@NotNull LineInfo info, @NotNull PsiElement ref) {
        // kotlin ref.getReference() == null but ref.getReferences().length == 2
        @NotNull PsiReference[] references = ref.getReferences();
        if (references.length < 1) {
            return null;
        }
        for (@NotNull PsiReference reference : references) {
            @Nullable PsiElement resolve;
            try {
                resolve = reference.resolve();

 

https://github.com/LinWanCen/show-comment/blob/baa2fe1dfc55ccc69141afef765ed042d9565b58/src/main/java/io/github/linwancen/plugin/show/lang/JsLangDoc.java#L22-L25

    @Override
    public @NotNull List<Class<? extends PsiElement>> getRefClass() {
        return List.of(JSPsiReferenceElement.class);
    }

 

1
3 comments

Hi,

Rider doesn't operate on a real PSI tree, and all PSI-related operations should be implemented in the Rider part of the plugin. See:

0

Can you give me some code references or class names? After reading the content in the link, I still don't know how to do it.

0

Hi linwancheng ,

Rider uses the ReSharper SDK (i.e., not the IntelliJ SDK) to parse C# syntax. Therefore, expect to write C#/.NET to support your feature. I think the inspections sample project could be helpful to get started with how things are working. Since I expect you also want to use some of your existing infrastructure, you must send data between C# and Kotlin code. For that, I recommend looking into the protocol sample project (check the README).

 

0

Please sign in to leave a comment.