Skip to content

Commit 10e6996

Browse files
authored
feat(tolk): don't show .acton imports in contract/ import completion (#296)
1 parent 67483fb commit 10e6996

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

server/src/languages/tolk/completion/providers/ImportPathCompletionProvider.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ export class ImportPathCompletionProvider implements CompletionProvider<Completi
6565

6666
if (actonToml) {
6767
const mappings = actonToml.getMappings()
68-
for (const key of mappings.keys()) {
68+
for (const [key, value] of mappings.entries()) {
69+
const mappingDir = path.resolve(actonToml.workingDir, value)
70+
if (file.shouldHideActonImportCompletion(mappingDir)) {
71+
continue
72+
}
73+
6974
result.add({
7075
label: `@${key}/`,
7176
kind: CompletionItemKind.Folder,
@@ -83,9 +88,16 @@ export class ImportPathCompletionProvider implements CompletionProvider<Completi
8388
result: CompletionResult,
8489
): void {
8590
const [actualDir, namePrefix] = this.splitPath(dir)
91+
if (file.shouldHideActonImportCompletion(actualDir)) {
92+
return
93+
}
8694

8795
const files = this.files(actualDir, file)
8896
for (const name of files) {
97+
if (file.shouldHideActonImportCompletion(path.join(actualDir, name))) {
98+
continue
99+
}
100+
89101
if (namePrefix && !name.startsWith(namePrefix)) {
90102
// for "./bar/some"
91103
// filter all files that do not start with `some`
@@ -98,6 +110,10 @@ export class ImportPathCompletionProvider implements CompletionProvider<Completi
98110

99111
const dirs = this.dirs(actualDir)
100112
for (const name of dirs) {
113+
if (file.shouldHideActonImportCompletion(path.join(actualDir, name))) {
114+
continue
115+
}
116+
101117
if (namePrefix && !name.startsWith(namePrefix)) {
102118
// for "./bar/some"
103119
// filter all dirs that do not start with `some`

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ export class TolkFile extends File {
5252
return relative === "contracts" || relative.startsWith("contracts/")
5353
}
5454

55+
public shouldHideActonImportCompletion(candidatePath: string): boolean {
56+
if (!this.isInContractsDir) return false
57+
58+
const actonToml = ActonToml.discover(this.uri)
59+
if (!actonToml) return false
60+
61+
const relative = path.relative(actonToml.workingDir, candidatePath).replace(/\\/g, "/")
62+
return relative === ".acton" || relative.startsWith(".acton/")
63+
}
64+
5565
public symbolAt(offset: number): string {
5666
return this.content[offset] ?? ""
5767
}

0 commit comments

Comments
 (0)