Skip to content

Commit

Permalink
attempt at fixing and improving issues with inlay hints
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Apr 11, 2024
1 parent 3fbe5fa commit 8d95226
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static void handleCaptureVarDeclarationHints(@NotNull PsiElement element

if (!result.isUnknown() && !result.getType().isInvalid()) {
int offset = varDeclaration.getComponentName().getTextRange().getEndOffset();
InlineInlayPosition position = new InlineInlayPosition(offset, false, 0);
InlineInlayPosition position = new InlineInlayPosition(offset, true, 0);
sink.addPresentation(position, null, null, false, appendTypeTextToBuilder(result)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static void handleEnumArgumentExtractorHints(@NotNull InlayTreeSink sink
if (children[i] instanceof HaxeEnumExtractedValue enumExtractedValue) {
int offset = enumExtractedValue.getTextRange().getEndOffset();

InlineInlayPosition position = new InlineInlayPosition(offset, false, 0);
InlineInlayPosition position = new InlineInlayPosition(offset, true, 0);
if (extractedValueList.size() > i) {
ResultHolder type = HaxeExpressionEvaluator.evaluate(extractedValueList.get(i), null).result;
sink.addPresentation(position, null, null, false, appendTypeTextToBuilder(type));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static void handleFieldDeclarationHints(@NotNull PsiElement element,
else {
offset = field.getPsiField().getComponentName().getTextRange().getEndOffset();
}
InlineInlayPosition position = new InlineInlayPosition(offset, false, 0);
InlineInlayPosition position = new InlineInlayPosition(offset, true, 0);
sink.addPresentation(position, null, null, false, appendTypeTextToBuilder(type)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static void handleForEachHints(@NotNull PsiElement element,
private static void createInlayHint(@NotNull HaxeComponentName componentName,@NotNull InlayTreeSink sink, ResultHolder type ) {
if (!type.isUnknown() && !type.getType().isInvalid()) {
int offset = componentName.getTextRange().getEndOffset();
InlineInlayPosition position = new InlineInlayPosition(offset, false, 0);
InlineInlayPosition position = new InlineInlayPosition(offset, true, 0);
sink.addPresentation(position, null, null, false, appendTypeTextToBuilder(type)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ 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);
InlineInlayPosition position = new InlineInlayPosition(offset, true, 0);
sink.addPresentation(position, null, null, false, appendTypeTextToBuilder(type));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void handleFunctionDeclarationHints(InlayTreeSink sink, HaxeLocalFunctio
if (paramListEnd == null) return;
int offset = paramListEnd.getTextRange().getEndOffset();
if (!returnType.isUnknown() && !returnType.getType().isInvalid()) {
InlineInlayPosition position = new InlineInlayPosition(offset, false, 0);
InlineInlayPosition position = new InlineInlayPosition(offset, true, 0);
sink.addPresentation(position, null, null, false, appendTypeTextToBuilder(returnType));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static void handleUntypedParameterHints(@NotNull HaxeParameter parameter

if (!result.isUnknown() && !result.getType().isInvalid()) {
int offset = parameter.getComponentName().getTextRange().getEndOffset();
InlineInlayPosition position = new InlineInlayPosition(offset, false, 0);
InlineInlayPosition position = new InlineInlayPosition(offset, true, 0);
sink.addPresentation(position, null, null, false, appendTypeTextToBuilder(result)
);
}
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/intellij/plugins/haxe/lang/psi/HaxeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,16 @@ private List<? extends PsiElement> checkEnumMemberHints(HaxeReference reference)
return findEnumMember(reference, typeReference);
}
}
if (field.getVarInit() != null) {
ResultHolder type = HaxeTypeResolver.getPsiElementType(field.getVarInit(), null);
if (type.getClassType() != null) {
SpecificTypeReference typeReference = type.getClassType().fullyResolveTypeDefAndUnwrapNullTypeReference();
return findEnumMember(reference, typeReference);
HaxeVarInit init = field.getVarInit();
if (init != null) {
// check if reference is part of init expression and if so skip to avoid circular resolve
HaxeVarInit referenceInitParent = PsiTreeUtil.getParentOfType(reference, HaxeVarInit.class);
if (referenceInitParent == null || referenceInitParent != init) {
ResultHolder type = HaxeTypeResolver.getPsiElementType(init, null);
if (type.getClassType() != null) {
SpecificTypeReference typeReference = type.getClassType().fullyResolveTypeDefAndUnwrapNullTypeReference();
return findEnumMember(reference, typeReference);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,10 @@ public void useHaxeToolkit(String version) {
}




protected void doTest(InlayHintsProvider inlayHintsProvider, String... additionalFiles)
throws Exception {
String testFile = getTestName(false) + ".hx";
myFixture.setTestDataPath(getTestDataPath());
myFixture.configureByFiles(ArrayUtil.mergeArrays(new String[]{testFile}, additionalFiles));
protected void doTest(InlayHintsProvider inlayHintsProvider) throws Exception {

String name = getTestDataPath() + getTestName(false) + ".hx";
String data = Files.readString(Path.of(name));

doTestProvider("testFile.hx", data, inlayHintsProvider, Map.of(), false);
}
}

0 comments on commit 8d95226

Please sign in to comment.