-
Notifications
You must be signed in to change notification settings - Fork 24
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
feat(language-server): Resolve paths for imports #1079
Conversation
@@ -22,7 +22,8 @@ case class LspContext[S[_]]( | |||
variables: List[VariableInfo[S]] = Nil, | |||
importTokens: List[LiteralToken[S]] = Nil, | |||
errors: List[SemanticError[S]] = Nil, | |||
warnings: List[SemanticWarning[S]] = Nil | |||
warnings: List[SemanticWarning[S]] = Nil, | |||
importPaths: Map[String, String] = Map.empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not merge it together with importTokens
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they are gathered from different sources
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So? I think it is much more clear to do something like
case class Import[S[_]](
token: LiteralToken[S],
resolution: Option[String] = None
) {
def resolve(resolution: String): Import[S] = copy(resolution = resolution.some)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, what will happen, if two files are compiled as dependencies, both have import "some.aqua"
, but imports are resolved to different paths? importPaths
map is just concatenated when merging two contexts. However, this should not affect anything as this info is used only for the file being viewed? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you are right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So? I think it is much more clear to do something like
case class Import[S[_]]( token: LiteralToken[S], resolution: Option[String] = None ) { def resolve(resolution: String): Import[S] = copy(resolution = resolution.some) }
i don't like it. I should work with options two times (in setImportPaths and in converting imports to JS) instead of merge two fields at the end (ResultHelper) once.
trait FileId[I] extends Show[I] with Order[I] | ||
|
||
object FileId { | ||
given FileId[String] with { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets define it only in tests? Seems like it is not used in code
@@ -1,7 +1,7 @@ | |||
package aqua.linker | |||
|
|||
case class AquaModule[I, E, T](id: I, imports: Map[String, I], dependsOn: Map[I, E], body: T) { | |||
def map[TT](f: T => TT): AquaModule[I, E, TT] = copy(body = f(body)) | |||
def map[TT](f: AquaModule[I, E, T] => AquaModule[I, E, TT]): AquaModule[I, E, TT] = f(this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe delete this method at this point? The next one is useless too.
transpiled = modules.map(body => transpile(body)) | ||
transpiled = modules.map { m => | ||
val importIds = m.imports.view.mapValues(_.show).toMap | ||
m.copy(body = transpile(m.body).map(_.map(_.setImportPaths(importIds)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Maybe pass imports to transpile
and set them there instead of map(_.map(...))
Co-authored-by: InversionSpaces <[email protected]>
Description
Resolve paths for imports to make it possible to implement go-to-definition on import paths.
Proposed Changes
Add import paths to CompilationResult
Checklist
Reviewer Checklist