diff --git a/server/src/e2e/tolk/testcases/references/basic.test b/server/src/e2e/tolk/testcases/references/basic.test index b9c5008e..c07d7443 100644 --- a/server/src/e2e/tolk/testcases/references/basic.test +++ b/server/src/e2e/tolk/testcases/references/basic.test @@ -278,7 +278,7 @@ fun test2() { } ------------------------------------------------------------------------ References: [3:8, 4:14, 9:8, 10:14] -Scope: GlobalSearchScope +Scope: GlobalSearchScope{test.tolk} ======================================================================== Function references @@ -292,7 +292,7 @@ fun test2() { } ------------------------------------------------------------------------ References: [3:4, 4:4, 5:4] -Scope: GlobalSearchScope +Scope: GlobalSearchScope{test.tolk} ======================================================================== Static method references @@ -306,7 +306,7 @@ fun test2() { } ------------------------------------------------------------------------ References: [5:8] -Scope: GlobalSearchScope +Scope: GlobalSearchScope{test.tolk} ======================================================================== Instance method references @@ -321,7 +321,7 @@ fun test2() { } ------------------------------------------------------------------------ References: [6:8] -Scope: GlobalSearchScope +Scope: GlobalSearchScope{test.tolk} ======================================================================== Instance method references via alias @@ -338,7 +338,7 @@ fun test2() { } ------------------------------------------------------------------------ References: [8:8] -Scope: GlobalSearchScope +Scope: GlobalSearchScope{test.tolk} ======================================================================== Constant references @@ -352,7 +352,7 @@ fun test2() { } ------------------------------------------------------------------------ References: [3:8, 4:14] -Scope: GlobalSearchScope +Scope: GlobalSearchScope{test.tolk} ======================================================================== Type alias references @@ -366,7 +366,7 @@ struct Foo { fun test2(a: Int): Int {} ------------------------------------------------------------------------ References: [3:11, 6:13, 6:19] -Scope: GlobalSearchScope +Scope: GlobalSearchScope{test.tolk} ======================================================================== Type alias references from usage @@ -380,7 +380,7 @@ struct Foo { fun test2(a: Int): Int {} ------------------------------------------------------------------------ References: [3:11, 6:13, 6:19] -Scope: GlobalSearchScope +Scope: GlobalSearchScope{test.tolk} ======================================================================== Struct references @@ -395,7 +395,7 @@ fun test2(a: Foo): Foo { } ------------------------------------------------------------------------ References: [4:13, 4:19, 5:13, 6:14] -Scope: GlobalSearchScope +Scope: GlobalSearchScope{test.tolk} ======================================================================== Struct keyword references @@ -421,7 +421,7 @@ fun test() { } ------------------------------------------------------------------------ References: [3:4] -Scope: GlobalSearchScope +Scope: GlobalSearchScope{test.tolk} ======================================================================== Do while references @@ -437,3 +437,24 @@ Scope: LocalSearchScope: do { var a = 10; } while (a) + +======================================================================== +Struct references with generic type +======================================================================== +struct Config {} + +struct Storage { + config: Cell +} + +fun Storage.load() { + return Storage.fromCell(contract.getData()) +} + +fun name() { + var st = Storage.load(); + val config = st.config.load(); +} +------------------------------------------------------------------------ +References: [3:15] +Scope: GlobalSearchScope{test.tolk} diff --git a/server/src/languages/tolk/intentions/index.ts b/server/src/languages/tolk/intentions/index.ts index 6290f5ca..72b9aeb4 100644 --- a/server/src/languages/tolk/intentions/index.ts +++ b/server/src/languages/tolk/intentions/index.ts @@ -1,6 +1,6 @@ import * as lsp from "vscode-languageserver" import {findTolkFile, TOLK_PARSED_FILES_CACHE} from "@server/files" -import {LocalSearchScope, Referent} from "@server/languages/tolk/psi/Referent" +import {GlobalSearchScope, LocalSearchScope, Referent} from "@server/languages/tolk/psi/Referent" import {File} from "@server/psi/File" import type {Node as SyntaxNode} from "web-tree-sitter" import {asParserPoint} from "@server/utils/position" @@ -50,7 +50,14 @@ export async function provideExecuteTolkCommand( if (!scope) return "Scope not found" if (scope instanceof LocalSearchScope) return scope.toString() - return "GlobalSearchScope" + if (scope instanceof GlobalSearchScope) { + if (scope.files.length > 10) { + return "GlobalSearchScope{...}" + } + + return `GlobalSearchScope{${scope.files.map(it => it.name + ".tolk").join(", ")}}` + } + return "Unknown" } if (params.command === "tolk.getUnresolvedIdentifiers") { diff --git a/server/src/languages/tolk/psi/Referent.ts b/server/src/languages/tolk/psi/Referent.ts index 1f98fdc4..9b16f3e3 100644 --- a/server/src/languages/tolk/psi/Referent.ts +++ b/server/src/languages/tolk/psi/Referent.ts @@ -216,8 +216,11 @@ export class Referent { } if (node.type === "type_identifier" && parent.type === "instantiationT_list") { - // T in `fun Foo.bar() {}` - return true + const grand = parent.parent?.parent + if (grand?.type === "method_receiver") { + // T in `fun Foo.bar() {}` + return true + } } if (