Skip to content

Commit

Permalink
[core hacking] Don't complain about re-declarations
Browse files Browse the repository at this point in the history
Another stopgap. This one should be properly fixed by
addressing whatever is tripping up the re-declaration
detector.

For now though, it makes tons of "errors" disappear
while hacking on the CORE.setting, so it's worth the
fiddliness of the solution.
  • Loading branch information
ab5tract committed Sep 15, 2024
1 parent 8752876 commit 731ffeb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder hold
if (routineDecl.getRoutineKind().equals("method"))
holder.newAnnotation(HighlightSeverity.WARNING,
String.format("%s should be declared as a submethod", name))
.withFix(new MakeSubmethodFix(routineDecl))
.range(routineDecl.getDeclaratorNode()).create();
.withFix(new MakeSubmethodFix(routineDecl))
.range(routineDecl.getDeclaratorNode()).create();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@

public class UndeclaredAttributeAnnotator implements Annotator {

// TODO: Replace this with a project-level setting or something else more robust
private Boolean PROJECT_IS_RAKUDO = null;

private boolean isProjectRakudo() {
if (PROJECT_IS_RAKUDO == null) {
PROJECT_IS_RAKUDO = Objects.requireNonNull(ProjectManager.getInstance().getOpenProjects()[0].getBasePath()).endsWith("rakudo");
}
return PROJECT_IS_RAKUDO;
}

@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
// Filter out anything except attribute usages.
Expand Down Expand Up @@ -58,4 +48,13 @@ public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder hold
.range(element).create();
}
}

// TODO: Replace this with a project-level setting or something else more robust
private Boolean PROJECT_IS_RAKUDO = null;
private boolean isProjectRakudo() {
if (PROJECT_IS_RAKUDO == null) {
PROJECT_IS_RAKUDO = Objects.requireNonNull(ProjectManager.getInstance().getOpenProjects()[0].getBasePath()).endsWith("rakudo");
}
return PROJECT_IS_RAKUDO;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder hold
if (results.length == 0) {
AnnotationBuilder annBuilder = holder.newAnnotation(HighlightSeverity.ERROR,
String.format("Subroutine %s is not declared", subName))
.withFix(new StubMissingSubroutineFix())
.range(element);
.withFix(new StubMissingSubroutineFix())
.range(element);
if (subName.equals("const") &&
(PsiTreeUtil.skipWhitespacesForward(call) instanceof RakuVariable ||
PsiTreeUtil.skipWhitespacesForward(call) instanceof RakuInfixApplication)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder hold
// Straight resolution failure
holder.newAnnotation(HighlightSeverity.ERROR,
String.format("Variable %s is not declared", variableName))
.range(element).create();
.range(element).create();
}
}
else {
Expand All @@ -81,7 +81,7 @@ public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder hold
if (psi != null && psi.getContainingFile() == variable.getContainingFile() && psi.getTextOffset() > variable.getTextOffset())
holder.newAnnotation(HighlightSeverity.ERROR,
String.format("Variable %s is not declared in this scope yet", variableName))
.range(element).create();
.range(element).create();
}
}
}
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/org/raku/comma/highlighter/RakuHighlightVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.intellij.openapi.extensions.InternalIgnoreDependencyViolation;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
Expand Down Expand Up @@ -368,17 +369,26 @@ private HighlightInfo getDuplicateHighlightInfo(RakuPsiElement originalDecl,
PsiElement currentDecl,
TextRange range,
String name, HighlightInfoType infoType) {
if (!originalDecl.isValid())
return null;
if (!currentDecl.getContainingFile().equals(myFile))
return null;
if (! originalDecl.isValid()) return null;
if (! currentDecl.getContainingFile().equals(myFile)) return null;
if (isProjectRakudo()) return null;

PsiFile containingFile = originalDecl.getContainingFile();
String previousPos = containingFile.getName() +
":" +
(StringUtil.offsetToLineNumber(containingFile.getText(), originalDecl.getTextOffset()) + 1);
return HighlightInfo.newHighlightInfo(infoType)
.range(range)
.descriptionAndTooltip(String.format("Re-declaration of %s from %s", name, previousPos))
.create();
.range(range)
.descriptionAndTooltip(String.format("Re-declaration of %s from %s", name, previousPos))
.create();
}

// TODO: Replace this with a project-level setting or something else more robust
private Boolean PROJECT_IS_RAKUDO = null;
private boolean isProjectRakudo() {
if (PROJECT_IS_RAKUDO == null) {
PROJECT_IS_RAKUDO = Objects.requireNonNull(ProjectManager.getInstance().getOpenProjects()[0].getBasePath()).endsWith("rakudo");
}
return PROJECT_IS_RAKUDO;
}
}

0 comments on commit 731ffeb

Please sign in to comment.