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 ¶
- Variables
- type Differ
- type Git
- func (g *Git) ChangedFiles(cwd string) ([]view.FileChange, error)
- func (g *Git) Close()
- func (g *Git) DiffBase(path string) ([]byte, error)
- func (g *Git) Discard(cwd, path string) error
- func (g *Git) HeadID(path string) (string, error)
- func (g *Git) HeadName(path string) (string, error)
- func (g *Git) Ignore(cwd, path string) error
- func (g *Git) IndexText(cwd, path string) ([]byte, error)
- func (g *Git) Stage(cwd, path string) error
- func (g *Git) Tracked(cwd, path string) bool
- func (g *Git) Unstage(cwd, path string) error
- 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) DiffHunks(doc *view.Document) []view.DiffHunk
- func (s *Session) Discard(path string) error
- 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) HeadText(path string) string
- func (s *Session) Ignore(path string) error
- func (s *Session) IndexText(path string) string
- func (s *Session) Refresh()
- func (s *Session) Stage(path string) error
- func (s *Session) StagedDiffHunks(path string) []view.DiffHunk
- func (s *Session) Unstage(path string) error
- func (s *Session) UnstagedDiffHunks(path string) []view.DiffHunk
- func (s *Session) Updates() <-chan struct{}
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
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. 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 a background goroutine after every recompute
func (*Differ) Close ¶
func (d *Differ) Close()
Close drops pending recomputes and stops publishing hunks
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git reads HEAD and index contents through one long-running cat-file process per repository, and shells out to git for everything else
func (*Git) ChangedFiles ¶
func (g *Git) ChangedFiles(cwd string) ([]view.FileChange, error)
ChangedFiles reports working-tree changes in cwd's repository, as absolute paths
func (*Git) DiffBase ¶
DiffBase returns the HEAD contents of path. No eol/ident smudge filtering is applied. A .gitattributes eol conversion may cause phantom diffs
func (*Git) Discard ¶ added in v0.4.1
Discard restores the working-tree state of path from the index. An untracked file has no index state to restore, so it is deleted instead
func (*Git) HeadName ¶
HeadName returns the current branch name, or a short commit hash when the head is detached
func (*Git) Ignore ¶ added in v0.4.1
Ignore appends path to the repository's root .gitignore, anchored so it names that one file rather than every file sharing its name
func (*Git) IndexText ¶ added in v0.4.1
IndexText returns the staged blob for path, erroring when the file has no entry in the index
func (*Git) Stage ¶ added in v0.4.1
Stage adds the working-tree state of path to the staging area, recording an added, modified, or deleted file alike
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)
// IndexText returns the staged contents of path
IndexText(cwd, path string) ([]byte, error)
// Stage adds the working-tree state of path to the staging area of the repository
// containing cwd
Stage(cwd, path string) error
// Unstage drops path from that staging area, leaving the working tree
Unstage(cwd, path string) error
// Discard restores the working-tree state of path from the staging area, deleting the file
// when it is untracked
Discard(cwd, path string) error
// Ignore adds path to the ignore list of its repository
Ignore(cwd, path string) error
// Tracked reports whether the repository containing cwd tracks path
Tracked(cwd, path string) bool
// Close releases any processes the provider keeps running
Close()
}
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, including an open document with unsaved changes
func (*Session) Close ¶
func (s *Session) Close()
Close stops all differs and the provider's processes
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) Discard ¶ added in v0.4.1
Discard restores the working-tree state of path from the staging area, deleting the file when version control does not track it
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
func (*Session) HeadText ¶ added in v0.4.1
HeadText returns the head text of an arbitrary workspace file. It reads from the provider on every call, so it is intended for on-demand use such as picker previews
func (*Session) Ignore ¶ added in v0.4.1
Ignore adds path to the ignore list of the repository holding it
func (*Session) IndexText ¶ added in v0.4.1
IndexText returns the staged text of an arbitrary workspace file, falling back to its head text when the file has no entry in the index
func (*Session) Refresh ¶
func (s *Session) Refresh()
Refresh reloads open document diff bases when their repository head moves
func (*Session) Stage ¶ added in v0.4.1
Stage adds the working-tree state of path to the staging area
func (*Session) StagedDiffHunks ¶ added in v0.4.1
StagedDiffHunks computes hunks between the head and the staged contents of an arbitrary workspace file. It reads both sides from the provider each call, so it is intended for on-demand use such as picker previews
func (*Session) Unstage ¶ added in v0.4.1
Unstage drops path from the staging area, leaving the working tree
func (*Session) UnstagedDiffHunks ¶ added in v0.4.1
UnstagedDiffHunks computes hunks between the staged and current contents of a workspace file, preferring its open document over the copy on disk