Skip to content

Commit bb7cc6a

Browse files
committed
fix: ignore empty fields in the returned results when querying references and definitions
1 parent 2717f4b commit bb7cc6a

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

internal/service/indexer.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,10 +1041,11 @@ func (i *indexer) QueryReferences(ctx context.Context, opts *types.QueryReferenc
10411041
continue
10421042
} // 只处理 类、接口、函数、方法
10431043
// 是定义,查找它的引用。当前采用遍历的方式(通过import过滤)
1044+
position := types.ToPosition(s.Range)
10441045
def := &types.RelationNode{
10451046
FilePath: fileElementTable.Path,
10461047
SymbolName: s.Name,
1047-
Position: types.ToPosition(s.Range),
1048+
Position: &position,
10481049
NodeType: string(proto.ElementTypeFromProto(s.ElementType)),
10491050
Children: make([]*types.RelationNode, 0),
10501051
}
@@ -1087,10 +1088,11 @@ func (i *indexer) findSymbolReferences(ctx context.Context, projectUuid string,
10871088
}
10881089
// 引用
10891090
if v, ok := definitionNames[element.Name]; ok {
1091+
position := types.ToPosition(element.Range)
10901092
v.Children = append(v.Children, &types.RelationNode{
10911093
FilePath: elementTable.Path,
10921094
SymbolName: element.Name,
1093-
Position: types.ToPosition(element.Range),
1095+
Position: &position,
10941096
NodeType: string(proto.ElementTypeFromProto(element.ElementType)),
10951097
})
10961098
}
@@ -1416,11 +1418,12 @@ func (i *indexer) queryCallGraphBySymbol(ctx context.Context, projectUuid string
14161418
i.logger.Error("failed to get parameters from extra data, err: %v", err)
14171419
continue
14181420
}
1421+
position := types.ToPosition(symbol.Range)
14191422
node := &types.RelationNode{
14201423
SymbolName: symbol.Name,
14211424
FilePath: filePath,
14221425
NodeType: string(types.NodeTypeDefinition),
1423-
Position: types.ToPosition(symbol.Range),
1426+
Position: &position,
14241427
Children: make([]*types.RelationNode, 0),
14251428
}
14261429
callee := &CalleeInfo{
@@ -1467,11 +1470,12 @@ func (i *indexer) queryCallGraphByLineRange(ctx context.Context, projectUuid str
14671470
i.logger.Error("failed to get parameters from extra data, err: %v", err)
14681471
continue
14691472
}
1473+
position := types.ToPosition(symbol.Range)
14701474
node := &types.RelationNode{
14711475
SymbolName: symbol.Name,
14721476
FilePath: filePath,
14731477
NodeType: string(types.NodeTypeDefinition),
1474-
Position: types.ToPosition(symbol.Range),
1478+
Position: &position,
14751479
Children: make([]*types.RelationNode, 0),
14761480
}
14771481
callee := &CalleeInfo{
@@ -1578,7 +1582,7 @@ func (i *indexer) buildCallGraphBFS(ctx context.Context, projectUuid string, roo
15781582
callerNode := &types.RelationNode{
15791583
FilePath: caller.FilePath,
15801584
SymbolName: caller.SymbolName,
1581-
Position: caller.Position,
1585+
Position: &caller.Position,
15821586
NodeType: string(types.NodeTypeReference),
15831587
Children: make([]*types.RelationNode, 0),
15841588
}

pkg/codegraph/types/index.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ type QueryCallGraphOptions struct {
6565
MaxLayer int
6666
}
6767
type RelationNode struct {
68-
FilePath string `json:"filePath"`
69-
SymbolName string `json:"symbolName"`
70-
Position Position `json:"position"`
71-
Content string `json:"content"`
72-
NodeType string `json:"nodeType"`
73-
Children []*RelationNode `json:"children"`
68+
FilePath string `json:"filePath,omitempty"`
69+
SymbolName string `json:"symbolName,omitempty"`
70+
Position *Position `json:"position,omitempty"`
71+
Content string `json:"content,omitempty"`
72+
NodeType string `json:"nodeType,omitempty"`
73+
Children []*RelationNode `json:"children,omitempty"`
7474
}
7575
type CallerElement struct {
7676
FilePath string `json:"filePath,omitempty"`

0 commit comments

Comments
 (0)