Skip to content

Commit

Permalink
show declearingCLass for enumValues when showing inlay hints
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Apr 17, 2024
1 parent e4bfc82 commit cd66569
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.intellij.plugins.haxe.model.type.*;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -20,7 +18,7 @@ public InlayHintsCollector createCollector(@NotNull PsiFile file, @NotNull Edito
return new TypeCollector();
}

private static class TypeCollector implements SharedBypassCollector {
private static class TypeCollector extends HaxeSharedBypassCollector {

@Override
public void collectFromElement(@NotNull PsiElement element, @NotNull InlayTreeSink sink) {
Expand All @@ -44,13 +42,5 @@ private static void handleCaptureVarDeclarationHints(@NotNull PsiElement element
}
}
}

@NotNull
private static Function1<PresentationTreeBuilder, Unit> appendTypeTextToBuilder(ResultHolder type) {
return builder -> {
builder.text(":" + type.toPresentationString(), null);
return null;
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
import com.intellij.plugins.haxe.lang.psi.HaxeEnumExtractedValue;
import com.intellij.plugins.haxe.lang.psi.HaxeEnumValueDeclaration;
import com.intellij.plugins.haxe.lang.psi.HaxeParameterList;
import com.intellij.plugins.haxe.model.HaxeParameterModel;
import com.intellij.plugins.haxe.model.type.*;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -25,7 +22,7 @@ public InlayHintsCollector createCollector(@NotNull PsiFile file, @NotNull Edito
return new TypeCollector();
}

private static class TypeCollector implements SharedBypassCollector {
private static class TypeCollector extends HaxeSharedBypassCollector {

@Override
public void collectFromElement(@NotNull PsiElement element, @NotNull InlayTreeSink sink) {
Expand Down Expand Up @@ -57,20 +54,5 @@ private static void handleEnumArgumentExtractorHints(@NotNull InlayTreeSink sink
}
}
}


@NotNull
private static List<HaxeParameterModel> MapParametersToModel(HaxeParameterList parameterList) {
return parameterList.getParameterList().stream().map(HaxeParameterModel::new).toList();
}


@NotNull
private static Function1<PresentationTreeBuilder, Unit> appendTypeTextToBuilder(ResultHolder type) {
return builder -> {
builder.text(":" + type.toPresentationString(), null);
return null;
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import com.intellij.plugins.haxe.model.type.ResultHolder;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -24,7 +22,7 @@ public InlayHintsCollector createCollector(@NotNull PsiFile file, @NotNull Edito
return new TypeCollector();
}

private static class TypeCollector implements SharedBypassCollector {
private static class TypeCollector extends HaxeSharedBypassCollector {

@Override
public void collectFromElement(@NotNull PsiElement element, @NotNull InlayTreeSink sink) {
Expand Down Expand Up @@ -62,14 +60,5 @@ private static void handleFieldDeclarationHints(@NotNull PsiElement element,
}
}
}


@NotNull
private static Function1<PresentationTreeBuilder, Unit> appendTypeTextToBuilder(ResultHolder type) {
return builder -> {
builder.text(":" + type.toPresentationString(), null);
return null;
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import com.intellij.codeInsight.hints.declarative.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.plugins.haxe.lang.psi.*;
import com.intellij.plugins.haxe.model.HaxeMethodModel;
import com.intellij.plugins.haxe.model.type.*;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -20,7 +17,7 @@ public InlayHintsCollector createCollector(@NotNull PsiFile file, @NotNull Edito
return new TypeCollector();
}

private static class TypeCollector implements SharedBypassCollector {
private static class TypeCollector extends HaxeSharedBypassCollector {

@Override
public void collectFromElement(@NotNull PsiElement element, @NotNull InlayTreeSink sink) {
Expand Down Expand Up @@ -69,13 +66,5 @@ private static void createInlayHint(@NotNull HaxeComponentName componentName,@No
);
}
}

@NotNull
private static Function1<PresentationTreeBuilder, Unit> appendTypeTextToBuilder(ResultHolder type) {
return builder -> {
builder.text( ":"+type.toPresentationString(), null);
return null;
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.intellij.plugins.haxe.model.type.*;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -20,7 +18,7 @@ public InlayHintsCollector createCollector(@NotNull PsiFile file, @NotNull Edito
return new TypeCollector();
}

private static class TypeCollector implements SharedBypassCollector {
private static class TypeCollector extends HaxeSharedBypassCollector {

@Override
public void collectFromElement(@NotNull PsiElement element, @NotNull InlayTreeSink sink) {
Expand All @@ -44,13 +42,5 @@ private static void handleLocalVarDeclarationHints(@NotNull InlayTreeSink sink,
}
}
}

@NotNull
private static Function1<PresentationTreeBuilder, Unit> appendTypeTextToBuilder(ResultHolder type) {
return builder -> {
builder.text(":" + type.toPresentationString(), null);
return null;
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import com.intellij.plugins.haxe.util.UsefulPsiTreeUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -22,7 +20,7 @@ public InlayHintsCollector createCollector(@NotNull PsiFile file, @NotNull Edito
return new TypeCollector();
}

private static class TypeCollector implements SharedBypassCollector {
private static class TypeCollector extends HaxeSharedBypassCollector {

@Override
public void collectFromElement(@NotNull PsiElement element, @NotNull InlayTreeSink sink) {
Expand Down Expand Up @@ -68,12 +66,8 @@ private void handleMethodDeclarationHints(InlayTreeSink sink, HaxeMethodDeclarat
}


@NotNull
private static Function1<PresentationTreeBuilder, Unit> appendTypeTextToBuilder(ResultHolder type) {
return builder -> {
builder.text(":" + type.toPresentationString(), null);
return null;
};
}



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import com.intellij.plugins.haxe.model.type.ResultHolder;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -23,7 +21,7 @@ public InlayHintsCollector createCollector(@NotNull PsiFile file, @NotNull Edito
return new TypeCollector();
}

private static class TypeCollector implements SharedBypassCollector {
private static class TypeCollector extends HaxeSharedBypassCollector {

@Override
public void collectFromElement(@NotNull PsiElement element, @NotNull InlayTreeSink sink) {
Expand All @@ -48,13 +46,5 @@ private static void handleUntypedParameterHints(@NotNull HaxeParameter parameter
}
}
}

@NotNull
private static Function1<PresentationTreeBuilder, Unit> appendTypeTextToBuilder(ResultHolder type) {
return builder -> {
builder.text(":" + type.toPresentationString(), null);
return null;
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.intellij.plugins.haxe.ide.hint.types;

import com.intellij.codeInsight.hints.declarative.PresentationTreeBuilder;
import com.intellij.codeInsight.hints.declarative.SharedBypassCollector;
import com.intellij.plugins.haxe.model.type.ResultHolder;
import com.intellij.plugins.haxe.model.type.SpecificEnumValueReference;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;

public abstract class HaxeSharedBypassCollector implements SharedBypassCollector {

@NotNull
protected static Function1<PresentationTreeBuilder, Unit> appendTypeTextToBuilder(ResultHolder type) {
return builder -> {
builder.text(":" + getPresentationText(type), null);
return null;
};
}


protected static String getPresentationText(ResultHolder returnType) {
// we dont want to show enumValues as type info in inlays as its not an assignable type.
if (returnType.getType() instanceof SpecificEnumValueReference enumValueReference) {
return enumValueReference.getEnumClass().toPresentationString();
}else {
return returnType.getType().toPresentationString();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ private static HaxeClass tryResolveClassByQNameWhenGetQNameFail(@NotNull PsiElem
}
}
}
if (result == null) result = matchesInImport.get(0);
if (result == null && !matchesInImport.isEmpty()) result = matchesInImport.get(0);
}
}
if (result == null) result = searchInSamePackage(fileModel, className, false);
Expand Down

0 comments on commit cd66569

Please sign in to comment.