From 3e9d3856685f74a6be5d0aa288cd7e4f95010901 Mon Sep 17 00:00:00 2001 From: Dima Date: Mon, 26 Feb 2024 16:00:25 +0300 Subject: [PATCH] fix(language-server): Name clashing in LSP [LNG-342] (#1089) --- .github/workflows/e2e.yml | 8 ++-- aqua-src/antithesis.aqua | 33 ++++--------- aqua-src/hack.aqua | 21 ++------ .../main/scala/aqua/lsp/LspSemantics.scala | 7 --- .../src/test/scala/aqua/lsp/AquaLSPSpec.scala | 48 +++++++++++++++++++ .../aqua/semantics/expr/func/FuncSem.scala | 2 +- 6 files changed, 66 insertions(+), 53 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 49dbee5a..fea9df5a 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -48,7 +48,7 @@ jobs: with: aqua-snapshots: "${{ needs.aqua.outputs.aqua-snapshots }}" - registry: - needs: - - fcli-snapshot - uses: fluencelabs/registry/.github/workflows/tests.yml@main + # registry: + # needs: + # - fcli-snapshot + # uses: fluencelabs/registry/.github/workflows/tests.yml@main diff --git a/aqua-src/antithesis.aqua b/aqua-src/antithesis.aqua index 6ba99770..0f3ce6a5 100644 --- a/aqua-src/antithesis.aqua +++ b/aqua-src/antithesis.aqua @@ -1,29 +1,12 @@ -aqua A +aqua Job declares * -export haveFun +import someString from "hack" +use timeout, someString from "hack.aqua" as P -ability Compute: - job() -> string +export timeout -func lift() -> Compute: - job = () -> string: - <- "job done" - <- Compute(job) - -ability Function: - run() -> string - -func roundtrip{Function}() -> string: - res <- Function.run() - <- res - -func disjoint_run{Compute}() -> Function: - run = func () -> string: - <- Compute.job() - <- Function(run = run) - -func haveFun() -> string: - comp = lift() - fn = disjoint_run{comp}() - res <- roundtrip{fn}() +func timeout() -> string: + res <- P.timeout() + b = someString() + a = P.someString() <- res \ No newline at end of file diff --git a/aqua-src/hack.aqua b/aqua-src/hack.aqua index c0b2ac2c..22f77978 100644 --- a/aqua-src/hack.aqua +++ b/aqua-src/hack.aqua @@ -1,18 +1,7 @@ -service Peer("peer"): - hodes: -> []string - timeout: i32, string -> string +aqua B declares timeout, someString -func test_timeout() -> string: - on HOST_PEER_ID: - nodes <- Peer.hodes() - results: *string +func timeout() -> string: + <- "hack file" - for node <- nodes par: - on node: - results <<- node - - timeout: *string - join results[999] - par join results[123] - - <- timeout! \ No newline at end of file +func someString() -> string: + <- "sssss" \ No newline at end of file diff --git a/language-server/language-server-api/src/main/scala/aqua/lsp/LspSemantics.scala b/language-server/language-server-api/src/main/scala/aqua/lsp/LspSemantics.scala index 9ea6dbbc..92a0bc5c 100644 --- a/language-server/language-server-api/src/main/scala/aqua/lsp/LspSemantics.scala +++ b/language-server/language-server-api/src/main/scala/aqua/lsp/LspSemantics.scala @@ -41,13 +41,6 @@ class LspSemantics[S[_]] extends Semantics[S, LspContext[S]] { val rawState = CompilerState.init[S](init.raw) val initState = rawState.copy( - names = rawState.names.copy( - rootArrows = rawState.names.rootArrows ++ init.rootArrows, - constants = rawState.names.constants ++ init.constants - ), - abilities = rawState.abilities.copy( - definitions = rawState.abilities.definitions ++ init.abDefinitions - ), locations = rawState.locations.copy( variables = rawState.locations.variables ++ init.variables ) diff --git a/language-server/language-server-api/src/test/scala/aqua/lsp/AquaLSPSpec.scala b/language-server/language-server-api/src/test/scala/aqua/lsp/AquaLSPSpec.scala index 60123550..da3612a6 100644 --- a/language-server/language-server-api/src/test/scala/aqua/lsp/AquaLSPSpec.scala +++ b/language-server/language-server-api/src/test/scala/aqua/lsp/AquaLSPSpec.scala @@ -455,4 +455,52 @@ class AquaLSPSpec extends AnyFlatSpec with Matchers with Inside { res.checkLocations("Srv", 0, n, main) shouldBe true } } + + it should "return right tokens with no errors when using different file" in { + val main = + """aqua Import declares * + | + |use timeout, someString from "export2.aqua" as Export + |import someString from "export2.aqua" + | + |export timeout + | + |func timeout() -> string: + | res <- Export.timeout() + | b = someString() + | a = Export.someString() + | <- res + | + |""".stripMargin + val src = Map( + "index.aqua" -> main + ) + + val firstImport = + """aqua B declares timeout, someString + | + |func timeout() -> string: + | <- "hack file" + | + |func someString() -> string: + | <- "sssss" + | + |""".stripMargin + + val imports = Map( + "export2.aqua" -> + firstImport + ) + + val res = compile(src, imports).toOption.get.values.head + + res.errors shouldBe empty + res.checkLocations("timeout", 1, 0, firstImport, Some(main)) shouldBe true + res.checkLocations("timeout", 1, 1, firstImport, Some(main)) shouldBe false + res.checkLocations("timeout", 1, 2, firstImport, Some(main)) shouldBe false + res.checkLocations("timeout", 1, 3, firstImport, Some(main)) shouldBe true + res.checkLocations("someString", 1, 0, firstImport, Some(main)) shouldBe true + res.checkLocations("someString", 1, 2, firstImport, Some(main)) shouldBe true + res.checkLocations("someString", 1, 3, firstImport, Some(main)) shouldBe true + } } diff --git a/semantics/src/main/scala/aqua/semantics/expr/func/FuncSem.scala b/semantics/src/main/scala/aqua/semantics/expr/func/FuncSem.scala index a9652045..11c0962d 100644 --- a/semantics/src/main/scala/aqua/semantics/expr/func/FuncSem.scala +++ b/semantics/src/main/scala/aqua/semantics/expr/func/FuncSem.scala @@ -21,7 +21,7 @@ class FuncSem[S[_]](val expr: FuncExpr[S]) extends AnyVal { case arrow: ArrowRaw => N.defineArrow(expr.name, arrow.`type`, isRoot = true) as FuncRaw(expr.name.value, arrow) - case m => + case _ => Raw.error("Func must continue with an arrow definition").pure[Alg] }