Skip to content
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

go/token: articulate what "base offset" is in FileSet.AddFile docs #36648

Closed
jeanbza opened this issue Jan 20, 2020 · 5 comments
Closed

go/token: articulate what "base offset" is in FileSet.AddFile docs #36648

jeanbza opened this issue Jan 20, 2020 · 5 comments

Comments

@jeanbza
Copy link
Member

jeanbza commented Jan 20, 2020

https://golang.org/pkg/go/token/#FileSet.AddFile

AddFile adds a new file with a given filename, base offset, [...]

What is "base offset"? How does one calculate it? There are only self-references in this godoc, and Google search doesn't return anything obviously useful.

@josharian josharian added Documentation NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 20, 2020
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Jan 21, 2020
@ianlancetaylor
Copy link
Contributor

Assigning to @griesemer for a doc update.

@griesemer
Copy link
Contributor

@jadekler A token.Pos is simply a byte offset from a file's base offset, which is the offset corresponding to the file's first byte. The next file's base offset is usually the current file's base offset plus the file size + 1 (for padding). This maps a set (list) of files' positions to contiguous integer values. Usually you don't need to worry about this, just provide a negative value (-1) and AddFile will take care of it.

I'll add a bit more documentation.

@griesemer griesemer modified the milestones: Backlog, Go1.15 Jan 21, 2020
@griesemer griesemer removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 21, 2020
@odeke-em odeke-em changed the title go/token: what is base offset? go/token: articulate what "base offset" is in FileSet.AddFile docs Jan 22, 2020
@jeanbza
Copy link
Member Author

jeanbza commented Jan 29, 2020

Thank you! This helps a lot.

@ianlancetaylor
Copy link
Contributor

@griesemer Still want to do this doc fix for 1.15?

@gopherbot
Copy link

Change https://golang.org/cl/238117 mentions this issue: go/token: explain file base offset better in documentation

@golang golang locked and limited conversation to collaborators Jun 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants