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

Open
jadekler opened this issue Jan 20, 2020 · 3 comments
Open

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

jadekler opened this issue Jan 20, 2020 · 3 comments
Assignees
Labels
Milestone

Comments

@jadekler
Copy link
Contributor

@jadekler jadekler 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.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jan 21, 2020

Assigning to @griesemer for a doc update.

@griesemer

This comment has been minimized.

Copy link
Contributor

@griesemer griesemer commented Jan 21, 2020

@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
@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
@jadekler

This comment has been minimized.

Copy link
Contributor Author

@jadekler jadekler commented Jan 29, 2020

Thank you! This helps a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.