Working imports

This commit is contained in:
2026-04-22 09:34:23 +02:00
parent 53b87eb02e
commit ea6aabd896
5 changed files with 42 additions and 27 deletions
+12 -2
View File
@@ -6,6 +6,7 @@ import (
"go/token"
"go/types"
"os"
"unicode"
"golang.org/x/tools/go/packages"
)
@@ -78,7 +79,7 @@ func main() {
switch obj := obj.(type) {
case *types.Func:
scopeData.Functions[name] = buildFunction(obj)
scopeData.Functions[LowerFirst(name)] = buildFunction(obj)
case *types.TypeName:
if strct, ok := buildStruct(obj); ok {
@@ -99,6 +100,15 @@ func main() {
fmt.Println(string(out))
}
func LowerFirst(s string) string {
if s == "" {
return ""
}
r := []rune(s)
r[0] = unicode.ToLower(r[0])
return string(r)
}
func buildFunction(fn *types.Func) FunctionSymbol {
sig := fn.Type().(*types.Signature)
@@ -166,7 +176,7 @@ func buildStruct(tn *types.TypeName) (StructSymbol, bool) {
continue
}
methods[m.Name()] = buildFunction(m)
methods[LowerFirst(m.Name())] = buildFunction(m)
}
return StructSymbol{
+1 -1
View File
@@ -14,7 +14,7 @@ pub mod top_level;
pub fn walk_ast(top_scope: Arc<Scope>, tl: &mut Vec<parser::ast::TopLevel>) {
for tl in tl {
match tl {
parser::ast::TopLevel::Import(package) => {}
parser::ast::TopLevel::Import(_) => {}
parser::ast::TopLevel::Package(_) => {}
parser::ast::TopLevel::FunctionDecl {
+5
View File
@@ -120,6 +120,11 @@ impl LocalScope {
*id = field.name.clone();
current_type = field.var_type.clone();
}
TypeRef::Package(p) => {
let var_ref = p.variables.get(id)?;
*id = var_ref.name.clone();
current_type = var_ref.var_type.clone();
}
_ => unimplemented!(),
},
Postfix::Call(_args) => match &*current_type {
+23 -23
View File
@@ -3,7 +3,7 @@
"package_name": "fmt",
"structs": {},
"functions": {
"Append": {
"append": {
"export": true,
"name": "Append",
"params": {
@@ -22,7 +22,7 @@
"[]byte"
]
},
"Appendf": {
"appendf": {
"export": true,
"name": "Appendf",
"params": {
@@ -46,7 +46,7 @@
"[]byte"
]
},
"Appendln": {
"appendln": {
"export": true,
"name": "Appendln",
"params": {
@@ -65,7 +65,7 @@
"[]byte"
]
},
"Errorf": {
"errorf": {
"export": true,
"name": "Errorf",
"params": {
@@ -84,7 +84,7 @@
"error"
]
},
"FormatString": {
"formatString": {
"export": true,
"name": "FormatString",
"params": {
@@ -103,7 +103,7 @@
"string"
]
},
"Fprint": {
"fprint": {
"export": true,
"name": "Fprint",
"params": {
@@ -123,7 +123,7 @@
"error"
]
},
"Fprintf": {
"fprintf": {
"export": true,
"name": "Fprintf",
"params": {
@@ -148,7 +148,7 @@
"error"
]
},
"Fprintln": {
"fprintln": {
"export": true,
"name": "Fprintln",
"params": {
@@ -168,7 +168,7 @@
"error"
]
},
"Fscan": {
"fscan": {
"export": true,
"name": "Fscan",
"params": {
@@ -188,7 +188,7 @@
"error"
]
},
"Fscanf": {
"fscanf": {
"export": true,
"name": "Fscanf",
"params": {
@@ -213,7 +213,7 @@
"error"
]
},
"Fscanln": {
"fscanln": {
"export": true,
"name": "Fscanln",
"params": {
@@ -233,7 +233,7 @@
"error"
]
},
"Print": {
"print": {
"export": true,
"name": "Print",
"params": {
@@ -248,7 +248,7 @@
"error"
]
},
"Printf": {
"printf": {
"export": true,
"name": "Printf",
"params": {
@@ -268,7 +268,7 @@
"error"
]
},
"Println": {
"println": {
"export": true,
"name": "Println",
"params": {
@@ -283,7 +283,7 @@
"error"
]
},
"Scan": {
"scan": {
"export": true,
"name": "Scan",
"params": {
@@ -298,7 +298,7 @@
"error"
]
},
"Scanf": {
"scanf": {
"export": true,
"name": "Scanf",
"params": {
@@ -318,7 +318,7 @@
"error"
]
},
"Scanln": {
"scanln": {
"export": true,
"name": "Scanln",
"params": {
@@ -333,7 +333,7 @@
"error"
]
},
"Sprint": {
"sprint": {
"export": true,
"name": "Sprint",
"params": {
@@ -347,7 +347,7 @@
"string"
]
},
"Sprintf": {
"sprintf": {
"export": true,
"name": "Sprintf",
"params": {
@@ -366,7 +366,7 @@
"string"
]
},
"Sprintln": {
"sprintln": {
"export": true,
"name": "Sprintln",
"params": {
@@ -380,7 +380,7 @@
"string"
]
},
"Sscan": {
"sscan": {
"export": true,
"name": "Sscan",
"params": {
@@ -400,7 +400,7 @@
"error"
]
},
"Sscanf": {
"sscanf": {
"export": true,
"name": "Sscanf",
"params": {
@@ -425,7 +425,7 @@
"error"
]
},
"Sscanln": {
"sscanln": {
"export": true,
"name": "Sscanln",
"params": {
+1 -1
View File
@@ -3,5 +3,5 @@ package main;
import "fmt";
function main() {
fmt.Println("hello");
fmt.println("hello");
}