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

feat(language-server): Resolve paths for imports #1079

Merged
merged 12 commits into from
Feb 20, 2024

Conversation

DieMyst
Copy link
Member

@DieMyst DieMyst commented Feb 16, 2024

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

  • Corresponding issue has been created and linked in PR title.
  • Proposed changes are covered by tests.
  • Documentation has been updated to reflect the changes (if applicable).
  • I have self-reviewed my code and ensured its quality.
  • I have added/updated necessary comments to aid understanding.

Reviewer Checklist

  • Tests have been reviewed and are sufficient to validate the changes.
  • Documentation has been reviewed and is up to date.
  • Any questions or concerns have been addressed.

Copy link

linear bot commented Feb 16, 2024

@DieMyst DieMyst added the e2e Run e2e workflow label Feb 16, 2024
@DieMyst DieMyst marked this pull request as ready for review February 16, 2024 12:16
@@ -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
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

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)
}

Copy link
Contributor

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? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, you are right

Copy link
Member Author

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 {
Copy link
Contributor

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)
Copy link
Contributor

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))))
Copy link
Contributor

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(...))

@DieMyst DieMyst enabled auto-merge (squash) February 20, 2024 10:59
@DieMyst DieMyst merged commit 245f664 into main Feb 20, 2024
10 checks passed
@DieMyst DieMyst deleted the LNG-309-go-to-definition-on-import-paths branch February 20, 2024 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Run e2e workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants