Skip to content

Commit 0fb56ca

Browse files
committed
feat: store file path
1 parent ea3b731 commit 0fb56ca

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

src/compress/golang/plugin/parse/parser.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ func (p *GoParser) ParseRepo() (Repository, error) {
139139
}
140140

141141
func (p *GoParser) ParseModule(mod *Module, dir string) (err error) {
142+
filepath.Walk(dir, func(path string, info fs.FileInfo, e error) error {
143+
if info != nil && info.IsDir() && filepath.Base(path) == ".git" {
144+
return filepath.SkipDir
145+
}
146+
if e != nil || info.IsDir() {
147+
return nil
148+
}
149+
rel, _ := filepath.Rel(p.homePageDir, path)
150+
mod.Files[rel] = NewFile(path)
151+
return nil
152+
})
142153
return p.loadPackages(mod, dir, "./...")
143154
}
144155

src/compress/golang/plugin/parse/pkg.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,11 @@ func (p *GoParser) loadPackages(mod *Module, dir string, pkgPath PkgPath) (err e
200200
}
201201
ctx.imports = imports
202202
relpath, _ := filepath.Rel(p.homePageDir, filePath)
203-
f := NewFile(relpath)
204-
mod.Files[relpath] = f
203+
f := mod.Files[relpath]
204+
if f == nil {
205+
f = NewFile(relpath)
206+
mod.Files[relpath] = f
207+
}
205208
f.Imports = imports.Origins
206209
if err := p.parseFile(ctx, file); err != nil {
207210
return err

src/lang/collect/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
141141
fileLine := c.fileLine(symbol.Location)
142142
// collect files
143143
if module.Files[relfile] == nil {
144-
module.Files[relfile] = uniast.NewFile(relfile)
144+
module.Files[relfile] = uniast.NewFile(file)
145145
}
146146

147147
content := symbol.Text

src/lang/rust/patch.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
/**
16-
* Copyright 2024 ByteDance Inc.
17-
*
18-
* Licensed under the Apache License, Version 2.0 (the "License");
19-
* you may not use this file except in compliance with the License.
20-
* You may obtain a copy of the License at
21-
*
22-
* https://www.apache.org/licenses/LICENSE-2.0
23-
*
24-
* Unless required by applicable law or agreed to in writing, software
25-
* distributed under the License is distributed on an "AS IS" BASIS,
26-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27-
* See the License for the specific language governing permissions and
28-
* limitations under the License.
29-
*/
30-
3115
package rust
3216

3317
import (
@@ -48,20 +32,22 @@ func (p *RustModulePatcher) Patch(ast *uniast.Module) {
4832
return err
4933
}
5034
if info.IsDir() {
35+
if filepath.Base(path) == "target" || filepath.Base(path) == ".git" {
36+
return filepath.SkipDir
37+
}
5138
return nil
5239
}
53-
if filepath.Ext(path) != ".rs" {
54-
return nil
55-
}
56-
// 找到对应文件package并存放
5740
relpath, err := filepath.Rel(p.Root, path)
5841
if err != nil {
5942
log.Error("get relative path of %s failed: %v", path, err)
6043
return nil
6144
}
6245
file := ast.Files[relpath]
6346
if file == nil {
64-
log.Error("get file %s failed", relpath)
47+
file = uniast.NewFile(path)
48+
ast.Files[relpath] = file
49+
}
50+
if filepath.Ext(path) != ".rs" {
6551
return nil
6652
}
6753
// 解析use语句

src/uniast/ast.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ func NewRepository(name string) Repository {
4949
type File struct {
5050
Name string
5151
Imports []string
52+
Path string
5253
}
5354

5455
func NewFile(path string) *File {
56+
abs, _ := filepath.Abs(path)
5557
ret := File{
5658
Name: filepath.Base(path),
59+
Path: abs,
5760
}
5861
return &ret
5962
}

0 commit comments

Comments
 (0)