Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 31 additions & 10 deletions server/src/e2e/tolk/testcases/references/basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ fun test2() {
}
------------------------------------------------------------------------
References: [3:8, 4:14, 9:8, 10:14]
Scope: GlobalSearchScope
Scope: GlobalSearchScope{test.tolk}

========================================================================
Function references
Expand All @@ -292,7 +292,7 @@ fun test2() {
}
------------------------------------------------------------------------
References: [3:4, 4:4, 5:4]
Scope: GlobalSearchScope
Scope: GlobalSearchScope{test.tolk}

========================================================================
Static method references
Expand All @@ -306,7 +306,7 @@ fun test2() {
}
------------------------------------------------------------------------
References: [5:8]
Scope: GlobalSearchScope
Scope: GlobalSearchScope{test.tolk}

========================================================================
Instance method references
Expand All @@ -321,7 +321,7 @@ fun test2() {
}
------------------------------------------------------------------------
References: [6:8]
Scope: GlobalSearchScope
Scope: GlobalSearchScope{test.tolk}

========================================================================
Instance method references via alias
Expand All @@ -338,7 +338,7 @@ fun test2() {
}
------------------------------------------------------------------------
References: [8:8]
Scope: GlobalSearchScope
Scope: GlobalSearchScope{test.tolk}

========================================================================
Constant references
Expand All @@ -352,7 +352,7 @@ fun test2() {
}
------------------------------------------------------------------------
References: [3:8, 4:14]
Scope: GlobalSearchScope
Scope: GlobalSearchScope{test.tolk}

========================================================================
Type alias references
Expand All @@ -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
Expand All @@ -380,7 +380,7 @@ struct Foo {
fun test2(a: <caret>Int): Int {}
------------------------------------------------------------------------
References: [3:11, 6:13, 6:19]
Scope: GlobalSearchScope
Scope: GlobalSearchScope{test.tolk}

========================================================================
Struct references
Expand All @@ -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
Expand All @@ -421,7 +421,7 @@ fun test() {
}
------------------------------------------------------------------------
References: [3:4]
Scope: GlobalSearchScope
Scope: GlobalSearchScope{test.tolk}

========================================================================
Do while references
Expand All @@ -437,3 +437,24 @@ Scope: LocalSearchScope:
do {
var a = 10;
} while (a)

========================================================================
Struct references with generic type
========================================================================
struct <caret>Config {}

struct Storage {
config: Cell<Config>
}

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}
11 changes: 9 additions & 2 deletions server/src/languages/tolk/intentions/index.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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") {
Expand Down
7 changes: 5 additions & 2 deletions server/src/languages/tolk/psi/Referent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,11 @@ export class Referent {
}

if (node.type === "type_identifier" && parent.type === "instantiationT_list") {
// T in `fun Foo<T>.bar() {}`
return true
const grand = parent.parent?.parent
if (grand?.type === "method_receiver") {
// T in `fun Foo<T>.bar() {}`
return true
}
}

if (
Expand Down