Skip to content

Commit

Permalink
aya: remove DeclCollector
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Nov 19, 2024
1 parent 2b784a4 commit eecce40
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
6 changes: 4 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ plugins {
// Java support
java
// Kotlin support
kotlin("jvm") version "2.0.0"
kotlin("jvm") version "2.0.21"
// https://github.com/JetBrains/gradle-intellij-plugin
id("org.jetbrains.intellij") version "1.17.3"
// https://github.com/JetBrains/gradle-changelog-plugin
id("org.jetbrains.changelog") version "2.2.0"
id("org.jetbrains.changelog") version "2.2.1"
// https://github.com/JetBrains/gradle-grammar-kit-plugin
id("org.jetbrains.grammarkit") version "2022.3.2.2"
}
Expand Down Expand Up @@ -199,10 +199,12 @@ dependencies {
implementation("org.aya-prover", "producer", ayaVersion) {
exclude("org.aya-prover.upstream", "ij-parsing-core")
exclude("org.aya-prover.upstream", "ij-util-text")
exclude("org.aya-prover.upstream", "lang-syntax")
}
implementation("org.aya-prover", "ide-lsp", ayaVersion) {
exclude("org.aya-prover.upstream", "ij-parsing-core")
exclude("org.aya-prover.upstream", "ij-util-text")
exclude("org.aya-prover.upstream", "lang-syntax")
}
testImplementation(kotlin("test-junit"))
}
36 changes: 8 additions & 28 deletions src/main/java/org/aya/intellij/actions/lsp/AyaLsp.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.intellij.openapi.vfs.newvfs.events.*;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import kala.collection.SeqLike;
import kala.collection.SeqView;
import kala.collection.immutable.ImmutableMap;
import kala.collection.immutable.ImmutableSeq;
Expand All @@ -35,10 +34,8 @@
import org.aya.lsp.server.AyaLanguageClient;
import org.aya.lsp.server.AyaLanguageServer;
import org.aya.lsp.utils.Log;
import org.aya.resolve.context.Candidate;
import org.aya.syntax.GenericAyaParser;
import org.aya.syntax.concrete.stmt.Command;
import org.aya.syntax.concrete.stmt.Stmt;
import org.aya.syntax.concrete.stmt.decl.Decl;
import org.aya.syntax.ref.AnyVar;
import org.aya.syntax.ref.DefVar;
import org.aya.tyck.error.Goal;
Expand Down Expand Up @@ -310,15 +307,13 @@ public boolean isInLibrary(@Nullable VirtualFile file) {
public @NotNull SeqView<DefVar<?, ?>> symbolsInFile(@NotNull AyaPsiFile file) {
var source = sourceFileOf(file);
if (source == null) return SeqView.empty();
// TODO: consider the following code
// return source.resolveInfo().get().thisModule().definitions()
// .valuesView()
// .flatMap(MapLike::valuesView)
// .filterIsInstance(DefVar.class)
// .toImmutableSeq();
var collector = new DeclCollector(MutableList.create());
collector.visit(source.program().get());
return collector.decls.view().flatMap(Resolver::withChildren);
var list = MutableList.<DefVar<?, ?>>create();
source.resolveInfo().get().thisModule().symbols()
.view()
.valuesView()
.flatMap(Candidate::getAll)
.filterIsInstanceTo(list, DefVar.class);
return list.view();
}

@Override public void publishAyaProblems(
Expand Down Expand Up @@ -348,19 +343,4 @@ public boolean isInLibrary(@Nullable VirtualFile file) {
@Override public @NotNull GenericAyaParser createParser(@NotNull Reporter reporter) {
return new AyaIJParserImpl(project, reporter);
}

private record DeclCollector(@NotNull MutableList<Decl> decls) {
public void visit(@Nullable SeqLike<Stmt> stmts) {
if (stmts == null) return;
stmts.forEach(this::visit);
}

public void visit(@NotNull Stmt stmt) {
switch (stmt) {
case Command.Module mod -> visit(mod.contents());
case Decl decl -> decls.append(decl);
default -> {}
}
}
}
}

0 comments on commit eecce40

Please sign in to comment.