Documentation
¶
Overview ¶
Package vcs integrates version-control systems with the editor: diff bases for gutter hunks, changed-file listings, and head names. Git is the only provider today; the Provider interface keeps the API explicit and pluggable
Index ¶
- Constants
- Variables
- func Diff(sides DiffSides) []view.DiffHunk
- type DiffSides
- type Differ
- type Git
- type Provider
- type Session
- func (s *Session) ChangedFiles() ([]view.FileChange, error)
- func (s *Session) Close()
- func (s *Session) DiffBase(doc *view.Document) (string, bool)
- func (s *Session) DiffBaseForPath(path string) string
- func (s *Session) DiffHunks(doc *view.Document) []view.DiffHunk
- func (s *Session) DiffHunksForPath(path string) []view.DiffHunk
- func (s *Session) DocumentChanged(doc *view.Document, _ view.DocumentChange)
- func (s *Session) DocumentClosed(doc *view.Document)
- func (s *Session) DocumentOpened(doc *view.Document)
- func (s *Session) DocumentSaved(doc *view.Document)
- func (s *Session) HeadName(doc *view.Document) (string, bool)
- func (s *Session) Refresh()
- func (s *Session) Updates() <-chan struct{}
Constants ¶
const ( MaxDiffLines = 65536 MaxDiffBytes = 16 << 20 )
MaxDiffLines and MaxDiffBytes bound the inputs Diff will process, so a pathological file cannot stall the diff worker. Larger documents simply render without diff gutter marks
Variables ¶
var ( ErrGitCommand = errors.New("git command failed") ErrGitBadStatus = errors.New("unparsable git status output") )
Functions ¶
Types ¶
type DiffSides ¶ added in v0.2.0
DiffSides is the version-control base text and the working document text being compared against it
type Differ ¶
type Differ struct {
// contains filtered or unexported fields
}
Differ tracks the hunks between a version-control base text and a live document text, recomputing on a background goroutine. Updates are debounced so rapid keystrokes coalesce into one diff
func NewDiffer ¶
NewDiffer starts a differ for the given base and document text. notify is invoked from the worker goroutine after every recompute
func (*Differ) Close ¶
func (d *Differ) Close()
Close stops the worker goroutine. The differ must not be used after
type Git ¶
type Git struct{}
Git reads HEAD state through go-git in-process and reports working-tree status by shelling out to the git binary found on PATH
func (Git) ChangedFiles ¶
func (Git) ChangedFiles(cwd string) ([]view.FileChange, error)
ChangedFiles reports the working-tree changes for the repository containing cwd, with absolute paths. It prefers the git binary (fast) and falls back to go-git's in-process status walk when git is not on PATH
func (Git) DiffBase ¶
DiffBase returns the HEAD contents of path. No eol/ident smudge filtering is applied; .gitattributes eol conversion may cause phantom diffs
type Provider ¶
type Provider interface {
// DiffBase returns the checked-in contents of path, the "base" text a
// diff of the working copy is computed against
DiffBase(path string) ([]byte, error)
// HeadName returns a short display name for the current head, such as
// a branch name
HeadName(path string) (string, error)
// HeadID returns the exact current head revision
HeadID(path string) (string, error)
// ChangedFiles lists workspace files that differ from the head
ChangedFiles(cwd string) ([]view.FileChange, error)
}
Provider supplies diff bases and change information from one version-control system
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session owns a differ per open document and implements the editor's VersionControl seam over the version-control provider
func Attach ¶
Attach starts a version-control session for the editor, observing document lifecycle events and serving diff state
func (*Session) ChangedFiles ¶
func (s *Session) ChangedFiles() ([]view.FileChange, error)
ChangedFiles lists workspace files that differ from the head
func (*Session) DiffBaseForPath ¶
DiffBaseForPath returns the checked-in base text of an arbitrary workspace file. It shells out to the provider, so it is intended for on-demand use such as picker diff previews
func (*Session) DiffHunks ¶
DiffHunks returns the current hunks for the document, loading its diff base on first request for a buffer that was not open at startup
func (*Session) DiffHunksForPath ¶
DiffHunksForPath computes hunks between the checked-in base and the on-disk contents of an arbitrary workspace file. It shells out to the provider and is intended for on-demand use such as picker previews
func (*Session) DocumentChanged ¶
func (s *Session) DocumentChanged(doc *view.Document, _ view.DocumentChange)
DocumentChanged feeds the new document text to the differ
func (*Session) DocumentClosed ¶
DocumentClosed stops and forgets the document's differ
func (*Session) DocumentOpened ¶
DocumentOpened fetches the diff base in the background and starts a differ once it arrives
func (*Session) DocumentSaved ¶
DocumentSaved refreshes the diff base; the head may have moved since the document was opened