Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types to symbol outline #398

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions effekt/jvm/src/main/scala/effekt/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import kiama.output.PrettyPrinterTypes.Document
import org.eclipse.lsp4j.{ Diagnostic, DocumentSymbol, SymbolKind, SymbolTag, ExecuteCommandParams }

import scala.jdk.CollectionConverters._
import effekt.context.Annotations

/**
* effekt.Intelligence <--- gathers information -- LSPServer --- provides LSP interface ---> kiama.Server
Expand Down Expand Up @@ -135,6 +136,12 @@ trait LSPServer extends kiama.util.Server[Tree, EffektConfig, EffektError] with

override def getSymbols(source: Source): Option[Vector[DocumentSymbol]] =
context.compiler.runFrontend(source)(using context).map { module =>
for {
scope <- context.annotationOption(Annotations.ScopesForFile, source).getOrElse(Nil)
} yield {
val BindingInfo(importedTerms, importedTypes, terms, types) = allBindings(scope)(using context)
}

val fileStart = convertRange(kiama.util.Range(kiama.util.Position(1, 1, source), kiama.util.Position(1, 1, source)))
val root = DocumentSymbol(module.namespace.head, SymbolKind.Namespace, fileStart, fileStart)

Expand Down Expand Up @@ -164,8 +171,6 @@ trait LSPServer extends kiama.util.Server[Tree, EffektConfig, EffektError] with
case (_, tpe) => TypePrinter.show(tpe)
}



override def getReferences(position: Position, includeDecl: Boolean): Option[Vector[Tree]] =
for {
(tree, sym) <- getSymbolAt(position)(context)
Expand Down
3 changes: 3 additions & 0 deletions effekt/shared/src/main/scala/effekt/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,9 @@ trait NamerOps extends ContextOps { Context: Context =>
}

private[namer] def scoped[R](block: => R): R = Context in {
val src = module.source
val scopesSoFar = annotationOption(Annotations.ScopesForFile, src).getOrElse(Nil)
annotate(Annotations.ScopesForFile, src, scopesSoFar :+ (scope.scope))
scope.scoped { block }
}

Expand Down
8 changes: 8 additions & 0 deletions effekt/shared/src/main/scala/effekt/context/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ object Annotations {
"all inferred captures for file"
)

/**
* Used by LSP to list all scopes
*/
val ScopesForFile = Annotation[kiama.util.Source, List[symbols.scopes.Scope]](
"ScopesForFile",
"all scopes for file"
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might lead to a lot of allocation, but this is a general problem.


/**
* The module a given symbol is defined in
*
Expand Down
Loading