Skip to content

Commit

Permalink
release 1.4.15-223
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Oct 8, 2023
1 parent 1272ba3 commit ee938b1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 58 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<PresentationTreeBuilder, Unit> appendTypeTextToBuilder(ResultHolder type) {
return builder -> {
builder.text(":" + type.toPresentationString(), null);
return null;
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,57 @@
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;
import com.intellij.plugins.haxe.model.type.HaxeTypeResolver;
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) {
Expand All @@ -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<PresentationTreeBuilder, Unit> appendTypeTextToBuilder(ResultHolder type) {
return builder -> {
builder.text(":" + type.toPresentationString(), null);
return null;
};
}
}
}

0 comments on commit ee938b1

Please sign in to comment.