Skip to content

Commit 7a8c102

Browse files
authored
fix(tolk/references): fix reference handling for Foo<Bar> (#8)
1 parent e7f8957 commit 7a8c102

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

server/src/e2e/tolk/testcases/references/basic.test

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ fun test2() {
278278
}
279279
------------------------------------------------------------------------
280280
References: [3:8, 4:14, 9:8, 10:14]
281-
Scope: GlobalSearchScope
281+
Scope: GlobalSearchScope{test.tolk}
282282

283283
========================================================================
284284
Function references
@@ -292,7 +292,7 @@ fun test2() {
292292
}
293293
------------------------------------------------------------------------
294294
References: [3:4, 4:4, 5:4]
295-
Scope: GlobalSearchScope
295+
Scope: GlobalSearchScope{test.tolk}
296296

297297
========================================================================
298298
Static method references
@@ -306,7 +306,7 @@ fun test2() {
306306
}
307307
------------------------------------------------------------------------
308308
References: [5:8]
309-
Scope: GlobalSearchScope
309+
Scope: GlobalSearchScope{test.tolk}
310310

311311
========================================================================
312312
Instance method references
@@ -321,7 +321,7 @@ fun test2() {
321321
}
322322
------------------------------------------------------------------------
323323
References: [6:8]
324-
Scope: GlobalSearchScope
324+
Scope: GlobalSearchScope{test.tolk}
325325

326326
========================================================================
327327
Instance method references via alias
@@ -338,7 +338,7 @@ fun test2() {
338338
}
339339
------------------------------------------------------------------------
340340
References: [8:8]
341-
Scope: GlobalSearchScope
341+
Scope: GlobalSearchScope{test.tolk}
342342

343343
========================================================================
344344
Constant references
@@ -352,7 +352,7 @@ fun test2() {
352352
}
353353
------------------------------------------------------------------------
354354
References: [3:8, 4:14]
355-
Scope: GlobalSearchScope
355+
Scope: GlobalSearchScope{test.tolk}
356356

357357
========================================================================
358358
Type alias references
@@ -366,7 +366,7 @@ struct Foo {
366366
fun test2(a: Int): Int {}
367367
------------------------------------------------------------------------
368368
References: [3:11, 6:13, 6:19]
369-
Scope: GlobalSearchScope
369+
Scope: GlobalSearchScope{test.tolk}
370370

371371
========================================================================
372372
Type alias references from usage
@@ -380,7 +380,7 @@ struct Foo {
380380
fun test2(a: <caret>Int): Int {}
381381
------------------------------------------------------------------------
382382
References: [3:11, 6:13, 6:19]
383-
Scope: GlobalSearchScope
383+
Scope: GlobalSearchScope{test.tolk}
384384

385385
========================================================================
386386
Struct references
@@ -395,7 +395,7 @@ fun test2(a: Foo): Foo {
395395
}
396396
------------------------------------------------------------------------
397397
References: [4:13, 4:19, 5:13, 6:14]
398-
Scope: GlobalSearchScope
398+
Scope: GlobalSearchScope{test.tolk}
399399

400400
========================================================================
401401
Struct keyword references
@@ -421,7 +421,7 @@ fun test() {
421421
}
422422
------------------------------------------------------------------------
423423
References: [3:4]
424-
Scope: GlobalSearchScope
424+
Scope: GlobalSearchScope{test.tolk}
425425

426426
========================================================================
427427
Do while references
@@ -437,3 +437,24 @@ Scope: LocalSearchScope:
437437
do {
438438
var a = 10;
439439
} while (a)
440+
441+
========================================================================
442+
Struct references with generic type
443+
========================================================================
444+
struct <caret>Config {}
445+
446+
struct Storage {
447+
config: Cell<Config>
448+
}
449+
450+
fun Storage.load() {
451+
return Storage.fromCell(contract.getData())
452+
}
453+
454+
fun name() {
455+
var st = Storage.load();
456+
val config = st.config.load();
457+
}
458+
------------------------------------------------------------------------
459+
References: [3:15]
460+
Scope: GlobalSearchScope{test.tolk}

server/src/languages/tolk/intentions/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as lsp from "vscode-languageserver"
22
import {findTolkFile, TOLK_PARSED_FILES_CACHE} from "@server/files"
3-
import {LocalSearchScope, Referent} from "@server/languages/tolk/psi/Referent"
3+
import {GlobalSearchScope, LocalSearchScope, Referent} from "@server/languages/tolk/psi/Referent"
44
import {File} from "@server/psi/File"
55
import type {Node as SyntaxNode} from "web-tree-sitter"
66
import {asParserPoint} from "@server/utils/position"
@@ -50,7 +50,14 @@ export async function provideExecuteTolkCommand(
5050
if (!scope) return "Scope not found"
5151

5252
if (scope instanceof LocalSearchScope) return scope.toString()
53-
return "GlobalSearchScope"
53+
if (scope instanceof GlobalSearchScope) {
54+
if (scope.files.length > 10) {
55+
return "GlobalSearchScope{...}"
56+
}
57+
58+
return `GlobalSearchScope{${scope.files.map(it => it.name + ".tolk").join(", ")}}`
59+
}
60+
return "Unknown"
5461
}
5562

5663
if (params.command === "tolk.getUnresolvedIdentifiers") {

server/src/languages/tolk/psi/Referent.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,11 @@ export class Referent {
216216
}
217217

218218
if (node.type === "type_identifier" && parent.type === "instantiationT_list") {
219-
// T in `fun Foo<T>.bar() {}`
220-
return true
219+
const grand = parent.parent?.parent
220+
if (grand?.type === "method_receiver") {
221+
// T in `fun Foo<T>.bar() {}`
222+
return true
223+
}
221224
}
222225

223226
if (

0 commit comments

Comments
 (0)