Skip to content

Commit 4680b0b

Browse files
authored
fix(tolk): don't show private fields in completion (#231)
1 parent 6a79fa3 commit 4680b0b

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

server/src/e2e/tolk/testcases/completion/fields.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,21 @@ struct Foo {
177177
------------------------------------------------------------------------
178178
13 private
179179
13 readonly
180+
181+
========================================================================
182+
Struct fields completion with private
183+
========================================================================
184+
struct Foo {
185+
first: int,
186+
private second: slice,
187+
}
188+
189+
fun main() {
190+
val foo = Foo {};
191+
foo.<caret>;
192+
}
193+
------------------------------------------------------------------------
194+
9 first: int of Foo
195+
1 forceLoadLazyObject(self): slice
196+
1 stackMoveToTop(mutate self): void
197+
1 toCell(self, options: PackOptions = {}): Cell<T>

server/src/languages/tolk/completion/ReferenceCompletionProcessor.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ export class ReferenceCompletionProcessor implements ScopeProcessor {
7171
// since structs can be created like `Foo{}` we allow them
7272
if (node instanceof Struct) return true
7373
if (node instanceof Enum) return true // for Color.Red
74+
75+
if (node instanceof Field) {
76+
if (node.isPrivate()) return false
77+
}
78+
7479
return true
7580
}
7681

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,12 @@ export class Field extends NamedNode {
491491
return new Struct(ownerNode, this.file)
492492
}
493493

494+
public isPrivate(): boolean {
495+
const modifiers = this.node.childForFieldName("modifiers")
496+
if (!modifiers) return false
497+
return modifiers.children.some(it => it?.text === "private")
498+
}
499+
494500
public modifiers(): string[] {
495501
const modifiers = this.node.childForFieldName("modifiers")
496502
if (!modifiers) return []

0 commit comments

Comments
 (0)