Documentation ¶
Overview ¶
The file package defines types used for working with LSP files.
Index ¶
Constants ¶
const ( // UnknownKind is a file type we don't know about. UnknownKind = Kind(iota) // Go is a Go source file. Go // Mod is a go.mod file. Mod // Sum is a go.sum file. Sum // Tmpl is a template file. Tmpl // Work is a go.work file. Work )
const ( UnknownAction = Action(iota) Open Change Close Save Create Delete )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handle ¶
type Handle interface { // URI is the URI for this file handle. URI() protocol.DocumentURI // Identity returns an Identity for the file, even if there was an error // reading it. Identity() Identity // SameContentsOnDisk reports whether the file has the same content on disk: // it is false for files open on an editor with unsaved edits. SameContentsOnDisk() bool // Version returns the file version, as defined by the LSP client. // For on-disk file handles, Version returns 0. Version() int32 // Content returns the contents of a file. // If the file is not available, returns a nil slice and an error. Content() ([]byte, error) }
A FileHandle represents the URI, content, hash, and optional version of a file tracked by the LSP session.
File content may be provided by the file system (for Saved files) or from an overlay, for open files with unsaved edits. A FileHandle may record an attempt to read a non-existent file, in which case Content returns an error.
type Hash ¶
A Hash is a cryptographic digest of the contents of a file. (Although at 32B it is larger than a 16B string header, it is smaller and has better locality than the string header + 64B of hex digits.)
type Identity ¶
type Identity struct { URI protocol.DocumentURI Hash Hash // digest of file contents }
An Identity identifies the name and contents of a file.
TODO(rfindley): Identity may not carry its weight. Consider instead just exposing Handle.Hash, and using an ad-hoc key type where necessary. Or perhaps if mod/work parsing is moved outside of the memoize cache, a notion of Identity simply isn't needed.
type Kind ¶
type Kind int
Kind describes the kind of the file in question. It can be one of Go,mod, Sum, or Tmpl.
func KindForLang ¶
KindForLang returns the file kind associated with the given language ID (from protocol.TextDocumentItem.LanguageID), or UnknownKind if the language ID is not recognized.
type Modification ¶
type Modification struct { URI protocol.DocumentURI Action Action // OnDisk is true if a watched file is changed on disk. // If true, Version will be -1 and Text will be nil. OnDisk bool // Version will be -1 and Text will be nil when they are not supplied, // specifically on textDocument/didClose and for on-disk changes. Version int32 Text []byte // LanguageID is only sent from the language client on textDocument/didOpen. LanguageID string }
Modification represents a modification to a file.
type Source ¶
type Source interface { // ReadFile returns the Handle for a given URI, either by reading the content // of the file or by obtaining it from a cache. // // Invariant: ReadFile must only return an error in the case of context // cancellation. If ctx.Err() is nil, the resulting error must also be nil. ReadFile(ctx context.Context, uri protocol.DocumentURI) (Handle, error) }
A Source maps URIs to Handles.