diff --git a/gradle.properties b/gradle.properties index df04c130d..64c51942b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ pluginName = Haxe Toolkit Support pluginRepositoryUrl = https://github.com/HaxeFoundation/intellij-haxe # SemVer format -> https://semver.org -pluginVersion = 1.4.14-223 +pluginVersion = 1.4.15-223 # IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties platformType = IU diff --git a/src/main/java/com/intellij/plugins/haxe/ide/hint/types/HaxeInlayFieldHintsProvider.java b/src/main/java/com/intellij/plugins/haxe/ide/hint/types/HaxeInlayFieldHintsProvider.java index 8f37d830e..af4dce74b 100644 --- a/src/main/java/com/intellij/plugins/haxe/ide/hint/types/HaxeInlayFieldHintsProvider.java +++ b/src/main/java/com/intellij/plugins/haxe/ide/hint/types/HaxeInlayFieldHintsProvider.java @@ -1,7 +1,10 @@ package com.intellij.plugins.haxe.ide.hint.types; -import com.intellij.codeInsight.hints.declarative.*; +import com.intellij.codeInsight.hints.InlayHintsCollector; +import com.intellij.codeInsight.hints.InlayHintsSink; +import com.intellij.codeInsight.hints.NoSettings; import com.intellij.openapi.editor.Editor; +import com.intellij.plugins.haxe.HaxeHintBundle; import com.intellij.plugins.haxe.lang.psi.HaxeExpression; import com.intellij.plugins.haxe.lang.psi.HaxeFieldDeclaration; import com.intellij.plugins.haxe.model.HaxeFieldModel; @@ -11,65 +14,64 @@ 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.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class HaxeInlayFieldHintsProvider implements InlayHintsProvider { +public class HaxeInlayFieldHintsProvider extends HaxeInlayHintProvider { @Nullable @Override - public InlayHintsCollector createCollector(@NotNull PsiFile file, @NotNull Editor editor) { - return new TypeCollector(); + public InlayHintsCollector getCollectorFor(@NotNull PsiFile file, + @NotNull Editor editor, + @NotNull NoSettings settings, + @NotNull InlayHintsSink sink) { + return new InlayCollector(editor); } - private static class TypeCollector implements SharedBypassCollector { + @Nls(capitalization = Nls.Capitalization.Sentence) + @NotNull + @Override + public String getName() { + return HaxeHintBundle.message("haxe.field.hint.name"); + } + + private static class InlayCollector extends HaxeInlayHintsFactory { + public InlayCollector(@NotNull Editor editor) { + super(editor); + } @Override - public void collectFromElement(@NotNull PsiElement element, @NotNull InlayTreeSink sink) { + public boolean collect(@NotNull PsiElement element, @NotNull Editor editor, @NotNull InlayHintsSink sink) { if (element instanceof HaxeFieldDeclaration fieldDeclaration) { handleFieldDeclarationHints(element, sink, fieldDeclaration); } + return true; } - private static void handleFieldDeclarationHints(@NotNull PsiElement element, - @NotNull InlayTreeSink sink, - HaxeFieldDeclaration fieldDeclaration) { + private void handleFieldDeclarationHints(@NotNull PsiElement element, + @NotNull InlayHintsSink sink, + HaxeFieldDeclaration fieldDeclaration) { HaxeFieldModel field = new HaxeFieldModel(fieldDeclaration); - - if (!field.hasTypeTag()) { - + if (!field.hasTypeTag() && field.getInitializerExpression() != null) { HaxeExpression expression = field.getInitializerExpression(); - if (expression != null) { - HaxeGenericResolver resolver = HaxeGenericResolverUtil.generateResolverFromScopeParents(expression); - ResultHolder type = HaxeTypeResolver.getPsiElementType(expression, element, resolver); + HaxeGenericResolver resolver = HaxeGenericResolverUtil.generateResolverFromScopeParents(expression); + ResultHolder type = HaxeTypeResolver.getPsiElementType(expression, element, resolver); - if (!type.isUnknown() && !type.getType().isInvalid()) { - int offset; - if (fieldDeclaration.getPropertyDeclaration() != null) { - offset = fieldDeclaration.getPropertyDeclaration().getTextRange().getEndOffset(); - } - else { - offset = field.getPsiField().getComponentName().getTextRange().getEndOffset(); - } - InlineInlayPosition position = new InlineInlayPosition(offset, false, 0); - sink.addPresentation(position, null, null, false, appendTypeTextToBuilder(type) - ); + if (!type.isUnknown() && !type.getType().isInvalid()) { + int offset = -1; + if (fieldDeclaration.getPropertyDeclaration() != null) { + offset = fieldDeclaration.getPropertyDeclaration().getTextRange().getEndOffset(); } + else { + offset = field.getPsiField().getComponentName().getTextRange().getEndOffset(); + } + + addInsert(offset, sink, ":" + type.toPresentationString()); } } } - - - @NotNull - private static Function1 appendTypeTextToBuilder(ResultHolder type) { - return builder -> { - builder.text(":" + type.toPresentationString(), null); - return null; - }; - } } } diff --git a/src/main/java/com/intellij/plugins/haxe/ide/hint/types/HaxeInlayLocalVariableHintsProvider.java b/src/main/java/com/intellij/plugins/haxe/ide/hint/types/HaxeInlayLocalVariableHintsProvider.java index 5719c61f6..f37b65101 100644 --- a/src/main/java/com/intellij/plugins/haxe/ide/hint/types/HaxeInlayLocalVariableHintsProvider.java +++ b/src/main/java/com/intellij/plugins/haxe/ide/hint/types/HaxeInlayLocalVariableHintsProvider.java @@ -1,7 +1,10 @@ package com.intellij.plugins.haxe.ide.hint.types; -import com.intellij.codeInsight.hints.declarative.*; +import com.intellij.codeInsight.hints.InlayHintsCollector; +import com.intellij.codeInsight.hints.InlayHintsSink; +import com.intellij.codeInsight.hints.NoSettings; import com.intellij.openapi.editor.Editor; +import com.intellij.plugins.haxe.HaxeHintBundle; import com.intellij.plugins.haxe.lang.psi.*; import com.intellij.plugins.haxe.model.type.HaxeGenericResolver; import com.intellij.plugins.haxe.model.type.HaxeGenericResolverUtil; @@ -9,31 +12,46 @@ 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.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class HaxeInlayLocalVariableHintsProvider implements InlayHintsProvider { +public class HaxeInlayLocalVariableHintsProvider extends HaxeInlayHintProvider { @Nullable @Override - public InlayHintsCollector createCollector(@NotNull PsiFile file, @NotNull Editor editor) { - return new TypeCollector(); + public InlayHintsCollector getCollectorFor(@NotNull PsiFile file, + @NotNull Editor editor, + @NotNull NoSettings settings, + @NotNull InlayHintsSink sink) { + return new InlayCollector(editor); } - private static class TypeCollector implements SharedBypassCollector { + @Nls(capitalization = Nls.Capitalization.Sentence) + @NotNull + @Override + public String getName() { + return HaxeHintBundle.message("haxe.local.variable.hint.name"); + } + + private static class InlayCollector extends HaxeInlayHintsFactory { + public InlayCollector(@NotNull Editor editor) { + super(editor); + } @Override - public void collectFromElement(@NotNull PsiElement element, @NotNull InlayTreeSink sink) { + public boolean collect(@NotNull PsiElement element, @NotNull Editor editor, @NotNull InlayHintsSink sink) { if (element instanceof HaxeLocalVarDeclaration varDeclaration) { - handleLocalVarDeclarationHints(sink, varDeclaration); + handleLocalVarDeclarationHints(element, sink, varDeclaration); } + return true; } - private static void handleLocalVarDeclarationHints(@NotNull InlayTreeSink sink, @NotNull HaxeLocalVarDeclaration varDeclaration) { + private void handleLocalVarDeclarationHints(@NotNull PsiElement element, + @NotNull InlayHintsSink sink, + HaxeLocalVarDeclaration varDeclaration) { HaxeTypeTag tag = varDeclaration.getTypeTag(); if (tag == null) { @@ -49,18 +67,9 @@ private static void handleLocalVarDeclarationHints(@NotNull InlayTreeSink sink, if (!type.isUnknown() && !type.getType().isInvalid()) { int offset = varDeclaration.getComponentName().getTextRange().getEndOffset(); - InlineInlayPosition position = new InlineInlayPosition(offset, false, 0); - sink.addPresentation(position, null, null, false, appendTypeTextToBuilder(type)); + addInsert(offset, sink, ":" + type.toPresentationString()); } } } - - @NotNull - private static Function1 appendTypeTextToBuilder(ResultHolder type) { - return builder -> { - builder.text(":" + type.toPresentationString(), null); - return null; - }; - } } }