Stdlib indexer appears to point types to wrong module paths
Identified here: https://github.com/pherrymason/c3-lsp/pull/107#discussion_r1931034940
The stdlib indexer is specifying that each type's declared module path is that where it is used, which is wrong.
We should probably keep the type's module path of origin in the generated code, and apply this change to all builders which currently receive only type name strings.
However, this is currently broken for generic types for some reason. The LSP seems to be thinking that type parameters originate from other modules simply because they have the same name. So the fix wouldn't be able to be applied to type parameters just yet - although they are _usually_ used in the same module as they are declared, but I _believe_ you can also use them in child modules (to be confirmed).
Here's a preliminary diff for a fix (rebased on #107):
```diff
diff --git a/server/cmd/stdlib_indexer/blurp.go b/server/cmd/stdlib_indexer/blurp.go
index 1d7b3f8277..103595cf48 100644
--- a/server/cmd/stdlib_indexer/blurp.go
+++ b/server/cmd/stdlib_indexer/blurp.go
@@ -232,13 +232,15 @@
return funDef
}
-// TODO: This appears to indicate that the module at which the type is being used
-// is where it was declared, which is clearly false, so this may lead to wrong LSP
-// results.
func Generate_type(type_ *s.Type, mod string) *jen.Statement {
+ typeModule := type_.GetModule()
+ if type_.IsGenericArgument() {
+ // Temporary fix for generic types' modules being misdetected
+ typeModule = mod
+ }
return jen.Qual(PackageName+"symbols", "NewTypeFromString").
Call(
jen.Lit(type_.String()),
- jen.Lit(mod),
+ jen.Lit(typeModule),
)
}
diff --git a/server/pkg/symbols/type.go b/server/pkg/symbols/type.go
index c1ee2e4625..538038e1db 100644
--- a/server/pkg/symbols/type.go
+++ b/server/pkg/symbols/type.go
@@ -48,6 +48,10 @@
return t.module + "::" + t.name
}
+func (t *Type) GetModule() string {
+ return t.module
+}
+
func (t *Type) SetModule(module string) {
t.module = module
}
```
关闭于 2025-01-28 0 条评论