Skip to content

Commit 527de9b

Browse files
authoredFeb 14, 2025
fix(inspections): don't warn on symbols with several declarations (#232)
Fixes #223 Fixes #224 Fixes #144
1 parent 0d25fa4 commit 527de9b

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed
 

‎server/src/indexes/index.ts

+23
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,29 @@ export class GlobalIndex {
190190
}
191191
return null
192192
}
193+
194+
public hasSeveralDeclarations(name: string): boolean {
195+
let seen = false
196+
for (const value of this.files.values()) {
197+
const element =
198+
value.elementByName(IndexKey.Funs, name) ??
199+
value.elementByName(IndexKey.Contracts, name) ??
200+
value.elementByName(IndexKey.Constants, name) ??
201+
value.elementByName(IndexKey.Structs, name) ??
202+
value.elementByName(IndexKey.Messages, name) ??
203+
value.elementByName(IndexKey.Traits, name) ??
204+
value.elementByName(IndexKey.Primitives, name)
205+
206+
if (element && seen) {
207+
return true
208+
}
209+
210+
if (element) {
211+
seen = true
212+
}
213+
}
214+
return false
215+
}
193216
}
194217

195218
export const index = new GlobalIndex()

‎server/src/inspections/NotImportedSymbolInspection.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import {asLspRange} from "@server/utils/position"
44
import {RecursiveVisitor} from "@server/psi/RecursiveVisitor"
55
import {Reference} from "@server/psi/Reference"
66
import {NamedNode} from "@server/psi/Node"
7-
import {Contract, Primitive} from "@server/psi/Decls"
7+
import {Contract, Field, Primitive} from "@server/psi/Decls"
88
import {Inspection, InspectionIds} from "./Inspection"
9+
import {index} from "@server/indexes"
910

1011
export class NotImportedSymbolInspection implements Inspection {
1112
public readonly id: "not-imported-symbol" = InspectionIds.NOT_IMPORTED_SYMBOL
@@ -18,7 +19,13 @@ export class NotImportedSymbolInspection implements Inspection {
1819
if (node.type !== "identifier" && node.type !== "type_identifier") return
1920
const resolved = Reference.resolve(new NamedNode(node, file))
2021
if (!resolved) return
21-
if (resolved instanceof Primitive || resolved instanceof Contract) return
22+
if (
23+
resolved instanceof Primitive ||
24+
resolved instanceof Contract ||
25+
resolved instanceof Field
26+
) {
27+
return
28+
}
2229

2330
// don't need to import same file
2431
if (resolved.file.uri === file.uri) return
@@ -28,6 +35,8 @@ export class NotImportedSymbolInspection implements Inspection {
2835
if (file.alreadyImport(importPath)) return
2936
// some files like stubs or stdlib imported implicitly
3037
if (resolved.file.isImportedImplicitly()) return
38+
// guard for multi projects
39+
if (index.hasSeveralDeclarations(resolved.name())) return
3140

3241
diagnostics.push({
3342
severity: lsp.DiagnosticSeverity.Error,

0 commit comments

Comments
 (0)