Skip to content

Commit 53a57d4

Browse files
authored
opt: start File Line from 1 (#37)
1 parent 307427a commit 53a57d4

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

docs/uniast-zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ Universal Abstract-Syntax-Tree 是 ABCoder 建立的一种LLM亲和、语言无
309309
- File:所在的文件名
310310

311311

312-
- Line:**起始位置文件的行号**
312+
- Line:**起始位置文件的行号(从1开始)**
313313

314314

315315
- StartOffset:代码起始位置**相对文件头的字节偏移量**

lang/collect/export.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (c *Collector) fileLine(loc Location) uniast.FileLine {
4343
file_uri := string(loc.URI)
4444
return uniast.FileLine{
4545
File: rel,
46-
Line: loc.Range.Start.Line,
46+
Line: loc.Range.Start.Line + 1,
4747
StartOffset: lsp.PositionOffset(file_uri, text, loc.Range.Start),
4848
EndOffset: lsp.PositionOffset(file_uri, text, loc.Range.End),
4949
}
@@ -319,7 +319,7 @@ func (c *Collector) exportSymbol(repo *uniast.Repository, symbol *DocumentSymbol
319319
}
320320
switch dep.Symbol.Kind {
321321
case lsp.SKStruct, lsp.SKTypeParameter, lsp.SKInterface, lsp.SKEnum, lsp.SKClass:
322-
obj.SubStruct = append(obj.SubStruct, uniast.NewDependency(*depid, c.fileLine(dep.Location)))
322+
obj.SubStruct = uniast.InsertDependency(obj.SubStruct, uniast.NewDependency(*depid, c.fileLine(dep.Location)))
323323
default:
324324
log.Error("dep symbol %s not collected for \n", dep.Symbol, id)
325325
}

lang/golang/parser/ctx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (ctx *fileContext) FileLine(node ast.Node) FileLine {
169169
pos := ctx.fset.Position((node).Pos())
170170
rel, _ := filepath.Rel(ctx.repoDir, pos.Filename)
171171
end := ctx.fset.Position((node).End())
172-
ret := FileLine{File: rel, Line: pos.Line - 1, StartOffset: pos.Offset, EndOffset: end.Offset}
172+
ret := FileLine{File: rel, Line: pos.Line, StartOffset: pos.Offset, EndOffset: end.Offset}
173173
if _, ok := node.(*ast.TypeSpec); ok {
174174
// NOTICE: type spec is not the start of the type definition
175175
// so we need to adjust the offset = len("type ")

0 commit comments

Comments
 (0)