From 978c5be06e3d2c80453ad2958a17f0c955eb6503 Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Wed, 15 Jan 2025 21:53:03 +0100 Subject: [PATCH] fixing issue where untyped parameters in methods did not resolve type correctly. --- .../evaluator/HaxeExpressionEvaluator.java | 4 +- .../HaxeExpressionEvaluatorHandlers.java | 6 ++- .../ide/inlay/all/AllInlayHintsProvider.java | 38 +++++++++++++++++++ .../haxe/ide/inlay/all/HaxeAllInlayTest.java | 27 +++++++++++++ .../testData/inlay/all/ParameterMonomorph.hx | 12 ++++++ 5 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/intellij/plugins/haxe/ide/inlay/all/AllInlayHintsProvider.java create mode 100644 src/test/java/com/intellij/plugins/haxe/ide/inlay/all/HaxeAllInlayTest.java create mode 100644 src/test/resources/testData/inlay/all/ParameterMonomorph.hx diff --git a/src/main/java/com/intellij/plugins/haxe/model/evaluator/HaxeExpressionEvaluator.java b/src/main/java/com/intellij/plugins/haxe/model/evaluator/HaxeExpressionEvaluator.java index 9c756158b..f45faacb9 100644 --- a/src/main/java/com/intellij/plugins/haxe/model/evaluator/HaxeExpressionEvaluator.java +++ b/src/main/java/com/intellij/plugins/haxe/model/evaluator/HaxeExpressionEvaluator.java @@ -659,7 +659,7 @@ private static ResultHolder checkSearchResult(HaxeExpressionEvaluatorContext con } return null; }); - if(result != null) return result; + return result; } } } @@ -715,7 +715,7 @@ private static ResultHolder checkSearchResult(HaxeExpressionEvaluatorContext con } } } - return null; + return createUnknown(reference.getElement()); } diff --git a/src/main/java/com/intellij/plugins/haxe/model/evaluator/HaxeExpressionEvaluatorHandlers.java b/src/main/java/com/intellij/plugins/haxe/model/evaluator/HaxeExpressionEvaluatorHandlers.java index 1aa5eea60..195354355 100644 --- a/src/main/java/com/intellij/plugins/haxe/model/evaluator/HaxeExpressionEvaluatorHandlers.java +++ b/src/main/java/com/intellij/plugins/haxe/model/evaluator/HaxeExpressionEvaluatorHandlers.java @@ -249,7 +249,11 @@ static ResultHolder handleReferenceExpression( HaxeExpressionEvaluatorContext co } } - if (access != null) typeHolder = access; + if (access != null){ + typeHolder = access; + }else { + typeHolder = createUnknown(child); + } } } diff --git a/src/test/java/com/intellij/plugins/haxe/ide/inlay/all/AllInlayHintsProvider.java b/src/test/java/com/intellij/plugins/haxe/ide/inlay/all/AllInlayHintsProvider.java new file mode 100644 index 000000000..789f83df7 --- /dev/null +++ b/src/test/java/com/intellij/plugins/haxe/ide/inlay/all/AllInlayHintsProvider.java @@ -0,0 +1,38 @@ +package com.intellij.plugins.haxe.ide.inlay.all; + +import com.intellij.codeInsight.hints.declarative.InlayHintsCollector; +import com.intellij.codeInsight.hints.declarative.InlayHintsProvider; +import com.intellij.codeInsight.hints.declarative.SharedBypassCollector; +import com.intellij.openapi.editor.Editor; +import com.intellij.plugins.haxe.ide.hint.types.*; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class AllInlayHintsProvider implements InlayHintsProvider { + + List inlayHintsProviders = List.of( + new HaxeInlayCaptureVariableHintsProvider(), + new HaxeInlayEnumExtractorHintsProvider(), + new HaxeInlayFieldHintsProvider(), + new HaxeInlayForLoopHintsProvider(), + new HaxeInlayLocalVariableHintsProvider(), + new HaxeInlayReturnTypeHintsProvider(), + new HaxeInlayUntypedParameterHintsProvider() + ); + + @Override + public @Nullable InlayHintsCollector createCollector(@NotNull PsiFile psiFile, @NotNull Editor editor) { + List inlayHintsCollectors = inlayHintsProviders.stream() + .map(inlayHintsProvider -> inlayHintsProvider.createCollector(psiFile, editor)) + .map(HaxeSharedBypassCollector.class::cast) + .toList(); + + return (SharedBypassCollector) (psiElement, inlayTreeSink) -> { + inlayHintsCollectors.forEach(collector -> collector.collectFromElement(psiElement, inlayTreeSink)); + }; + + } +} diff --git a/src/test/java/com/intellij/plugins/haxe/ide/inlay/all/HaxeAllInlayTest.java b/src/test/java/com/intellij/plugins/haxe/ide/inlay/all/HaxeAllInlayTest.java new file mode 100644 index 000000000..6cb81fb4a --- /dev/null +++ b/src/test/java/com/intellij/plugins/haxe/ide/inlay/all/HaxeAllInlayTest.java @@ -0,0 +1,27 @@ +package com.intellij.plugins.haxe.ide.inlay.all; + +import com.intellij.codeInsight.hints.declarative.InlayHintsProvider; +import com.intellij.plugins.haxe.ide.inlay.HaxeInlayTestBase; +import org.junit.Test; + +public class HaxeAllInlayTest extends HaxeInlayTestBase { + + InlayHintsProvider hintsProvider = new AllInlayHintsProvider(); + + @Override + protected String getBasePath() { + return "/inlay/all/"; + } + + @Override + public void setUp() throws Exception { + useHaxeToolkit(); + super.setUp(); + setTestStyleSettings(2); + } + + @Test + public void testParameterMonomorph() throws Exception { + doTest(hintsProvider); + } +} diff --git a/src/test/resources/testData/inlay/all/ParameterMonomorph.hx b/src/test/resources/testData/inlay/all/ParameterMonomorph.hx new file mode 100644 index 000000000..94b5b35ab --- /dev/null +++ b/src/test/resources/testData/inlay/all/ParameterMonomorph.hx @@ -0,0 +1,12 @@ +class ParameterMonomorph { + + public function new() { + var test/*<# :String #>*/ = testFunction(null); + } + function testFunction(?p)/*<# :String #>*/ { + if (p == null) { + p = "string"; + } + return p; + } +} \ No newline at end of file