@@ -27,6 +27,7 @@ import (
2727
2828 sitter "github.com/smacker/go-tree-sitter"
2929
30+ "github.com/cloudwego/abcoder/lang/cpp"
3031 "github.com/cloudwego/abcoder/lang/cxx"
3132 "github.com/cloudwego/abcoder/lang/java"
3233 javaipc "github.com/cloudwego/abcoder/lang/java/ipc"
@@ -124,6 +125,8 @@ func switchSpec(l uniast.Language, repo string) LanguageSpec {
124125 return python .NewPythonSpec ()
125126 case uniast .Java :
126127 return java .NewJavaSpec (repo )
128+ case uniast .Cpp :
129+ return cpp .NewCppSpec ()
127130 default :
128131 panic (fmt .Sprintf ("unsupported language %s" , l ))
129132 }
@@ -1836,11 +1839,13 @@ func (c *Collector) getSymbolByLocation(ctx context.Context, loc Location, depth
18361839 // return sym, nil
18371840 // }
18381841
1839- // 1. already loaded
1840- // Optimization: only search in symbols of the same file
1841- if fileSyms , ok := c .symsByFile [loc .URI ]; ok {
1842- if sym := c .findMatchingSymbolIn (loc , fileSyms ); sym != nil {
1843- return sym , nil
1842+ if ! (from .Type == "typeParameter" && c .Language == uniast .Cpp ) {
1843+ // 1. already loaded
1844+ // Optimization: only search in symbols of the same file
1845+ if fileSyms , ok := c .symsByFile [loc .URI ]; ok {
1846+ if sym := c .findMatchingSymbolIn (loc , fileSyms ); sym != nil {
1847+ return sym , nil
1848+ }
18441849 }
18451850 }
18461851
@@ -2070,11 +2075,11 @@ func (c *Collector) processSymbol(ctx context.Context, sym *DocumentSymbol, dept
20702075
20712076 // function info: type params, inputs, outputs, receiver (if !needImpl)
20722077 if sym .Kind == SKFunction || sym .Kind == SKMethod {
2073- var rsym * dependency
2078+ var rd * dependency
20742079 rec , tps , ips , ops := c .spec .FunctionSymbol (* sym )
2075-
2076- if ! hasImpl && rec >= 0 {
2080+ if (! hasImpl || c .Language == uniast .Cpp ) && rec >= 0 {
20772081 rsym , err := c .getSymbolByTokenWithLimit (ctx , sym .Tokens [rec ], depth )
2082+ rd = & dependency {sym .Tokens [rec ].Location , rsym }
20782083 if err != nil || rsym == nil {
20792084 log .Error ("get receiver symbol for token %v failed: %v\n " , rec , err )
20802085 }
@@ -2083,6 +2088,18 @@ func (c *Collector) processSymbol(ctx context.Context, sym *DocumentSymbol, dept
20832088 ipsyms , is := c .getDepsWithLimit (ctx , sym , ips , depth - 1 )
20842089 opsyms , os := c .getDepsWithLimit (ctx , sym , ops , depth - 1 )
20852090
2091+ // filter tsym is type parameter
2092+ if c .Language == uniast .Cpp {
2093+ tsFiltered := make ([]dependency , 0 , len (ts ))
2094+ for _ , d := range ts {
2095+ if d .Symbol == nil || d .Symbol .Kind == SKTypeParameter {
2096+ continue
2097+ }
2098+ tsFiltered = append (tsFiltered , d )
2099+ }
2100+ ts = tsFiltered
2101+ }
2102+
20862103 //get last token of params for get signature
20872104 lastToken := rec
20882105 for _ , t := range tps {
@@ -2101,18 +2118,28 @@ func (c *Collector) processSymbol(ctx context.Context, sym *DocumentSymbol, dept
21012118 }
21022119 }
21032120
2104- c .updateFunctionInfo (sym , tsyms , ipsyms , opsyms , ts , is , os , rsym , lastToken )
2121+ c .updateFunctionInfo (sym , tsyms , ipsyms , opsyms , ts , is , os , rd , lastToken )
21052122 }
21062123
21072124 // variable info: type
21082125 if sym .Kind == SKVariable || sym .Kind == SKConstant {
21092126 i := c .spec .DeclareTokenOfSymbol (* sym )
2127+ // in cpp, it should search form behind to front to find the first entity token
21102128 // find first entity token
2111- for i = i + 1 ; i < len (sym .Tokens ); i ++ {
2112- if c .spec .IsEntityToken (sym .Tokens [i ]) {
2113- break
2129+ if c .Language == uniast .Cpp {
2130+ for i = i - 1 ; i >= 0 ; i -- {
2131+ if c .spec .IsEntityToken (sym .Tokens [i ]) {
2132+ break
2133+ }
2134+ }
2135+ } else {
2136+ for i = i + 1 ; i < len (sym .Tokens ); i ++ {
2137+ if c .spec .IsEntityToken (sym .Tokens [i ]) {
2138+ break
2139+ }
21142140 }
21152141 }
2142+
21162143 if i < 0 || i >= len (sym .Tokens ) {
21172144 log .Error ("get type token of variable symbol %s failed\n " , sym )
21182145 return
0 commit comments