-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support trimmer compose for trimming multiple IDLs #204
base: main
Are you sure you want to change the base?
Conversation
d32ea72
to
be99ee9
Compare
be99ee9
to
232d28b
Compare
8fbd6a1
to
093c6a9
Compare
093c6a9
to
8b944ee
Compare
|
||
func parseAndCheckAST(path string, includeDirs []string, recursive bool) *parser.Thrift { | ||
ast, err := parser.ParseFile(path, includeDirs, recursive) | ||
check(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check 里面是 os.Exit 吗,统一抛出 error,在 main.go 相关的地方再处理 error 然后 os.Exit 吧,不然 sdk 调用的时候容易把进程搞炸
@@ -77,6 +76,12 @@ func (t *TrimResultInfo) FieldTrimmedPercentage() float64 { | |||
return float64(t.FieldsTrimmed) / float64(t.FieldsTotal) * 100 | |||
} | |||
|
|||
type TrimASTWithComposeArg struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为啥不能直接在 TrimASTArgs 上加?要单独包一层
@@ -19,20 +19,27 @@ import ( | |||
) | |||
|
|||
// traverse and remove the unmarked part of ast | |||
func (t *Trimmer) traversal(ast *parser.Thrift, filename string) { | |||
func (t *Trimmer) traversal(ast *parser.Thrift) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没太懂为啥要封一个doTraversal
另外没看到改动之后 travversal 在哪里被调用了?直接把 t.countStructs 放在 traversal 调用前执行一次就好了吧?
trimmer, err := newTrimmer(nil, "") | ||
if err != nil { | ||
return nil, err | ||
func TrimASTWithCompose(arg *TrimASTWithComposeArg) (trimResultInfo *TrimResultInfo, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个为啥要改名
} | ||
cfg := arg.Cfg | ||
// When ReadCfgFromLocal is set, local cfg has higher priority and the passed cfg would be ignored | ||
if arg.ReadCfgFromLocal { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
读文件这些感觉可以提到上面TrimAST里,doTrimAST里就只做裁切相关的事
trimmer.trimMethodValid = make([]bool, len(trimMethods)) | ||
trimmer.forceTrimming = forceTrimming | ||
trimmer.matchGoName = matchGoName | ||
for i, method := range trimMethods { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段怎么也删了呢
t.marks[ast.Filename] = make(map[interface{}]bool) | ||
t.preProcess(ast, ast.Filename) | ||
func (t *Trimmer) markAST(ast *parser.Thrift, arg *YamlArguments) { | ||
t.refresh(ast, arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arg放到trimmer的 field 里传递可能会好些?
t.markInclude(ast.Includes[theType.Reference.Index], filename) | ||
} | ||
|
||
if theType.IsTypedef != nil { | ||
t.markTypeDef(theType, baseAST, filename) | ||
t.markTypeDef(theType, baseAST) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我看你把所有mark的 filename 都去掉了,改为从ast拿,这里我不能完全确定对不对,需要保证 filename 一定和 ast 一致。但似乎看这一行,和原来的代码行为可能就会有出入了(baseAST可能变成别的,但filename是不变的,到你的实现里,传入的filename就变了)
return | ||
} | ||
t.marks[filename][str] = true | ||
t.marks[ast.Filename][str.Name] = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
原本这之前是用指针,现在改成了用string为key,是有啥必要吗?(虽然直觉看着也是唯一的)
Description
Motivation and Context
Related Issue