Documentation
¶
Index ¶
- Constants
- type Analyzer
- type Diagnostic
- type FileAction
- type FileHandle
- type FileIdentity
- type FileKind
- type FileModification
- type FileSource
- type Overlay
- type Package
- type ParsedWaFile
- type RelatedInformation
- type Session
- type Snapshot
- type SuggestedFix
- type VersionedFileHandle
- type VersionedFileIdentity
- type View
Constants ¶
const ( // UnknownKind is a file type we don't know about. UnknownKind = FileKind(iota) // Wa is a normal wa source file. Wa // Mod is a wa.mod file. Mod )
const ( UnknownFileAction = FileAction(iota) Open Change Close Save Create Delete InvalidateMetadata )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Analyzer ¶
type Analyzer struct { // Enabled reports whether the analyzer is enabled. This value can be // configured per-analysis in user settings. For staticcheck analyzers, // the value of the Staticcheck setting overrides this field. Enabled bool // Fix is the name of the suggested fix name used to invoke the suggested // fixes for the analyzer. It is non-empty if we expect this analyzer to // provide its fix separately from its diagnostics. That is, we should apply // the analyzer's suggested fixes through a Command, not a TextEdit. Fix string // ActionKind is the kind of code action this analyzer produces. If // unspecified the type defaults to quickfix. ActionKind []protocol.CodeActionKind // Severity is the severity set for diagnostics reported by this // analyzer. If left unset it defaults to Warning. Severity protocol.DiagnosticSeverity }
Analyzer represents a go/analysis analyzer with some boolean properties that let the user know how to use the analyzer.
type Diagnostic ¶
type Diagnostic struct { URI span.URI Range protocol.Range Severity protocol.DiagnosticSeverity Code string CodeHref string // Source is a human-readable description of the source of the error. // Diagnostics generated by an analysis.Analyzer set it to Analyzer.Name. Source string Message string Tags []protocol.DiagnosticTag Related []RelatedInformation // Fields below are used internally to generate quick fixes. They aren't // part of the LSP spec and don't leave the server. SuggestedFixes []SuggestedFix Analyzer *Analyzer }
An Diagnostic corresponds to an LSP Diagnostic. https://microsoft.github.io/language-server-protocol/specification#diagnostic
type FileAction ¶
type FileAction int
func (FileAction) String ¶
func (a FileAction) String() string
type FileHandle ¶
type FileHandle interface { URI() span.URI Kind() FileKind // FileIdentity returns a FileIdentity for the file, even if there was an // error reading it. FileIdentity() FileIdentity // Read reads the contents of a file. // If the file is not available, returns a nil slice and an error. Read() ([]byte, error) // Saved reports whether the file has the same content on disk. Saved() bool }
FileHandle represents a handle to a specific version of a single file.
type FileIdentity ¶
type FileIdentity struct { URI span.URI // Identifier represents a unique identifier for the file's content. Hash string // Kind is the file's kind. Kind FileKind }
FileIdentity uniquely identifies a file at a version from a FileSystem.
func (FileIdentity) String ¶
func (id FileIdentity) String() string
type FileKind ¶
type FileKind int
FileKind describes the kind of the file in question. It can be one of Go, mod, or sum.
type FileModification ¶
type FileModification struct { URI span.URI Action FileAction // 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 }
FileModification represents a modification to a file.
type FileSource ¶
type FileSource interface { // GetFile returns the FileHandle for a given URI. GetFile(ctx context.Context, uri span.URI) (FileHandle, error) }
A FileSource maps uris to FileHandles. This abstraction exists both for testability, and so that algorithms can be run equally on session and snapshot files.
type Overlay ¶
type Overlay interface { VersionedFileHandle }
Overlay is the type for a file held in memory on a session.
type Package ¶
type Package interface { ID() string Name() string PkgPath() string CompiledWaFiles() []*ParsedWaFile File(uri span.URI) (*ParsedWaFile, error) GetSyntax() []*ast.File GetTypes() *types.Package GetTypesInfo() *types.Info GetTypesSizes() types.Sizes IsIllTyped() bool ForTest() string GetImport(pkgPath string) (Package, error) MissingDependencies() []string Imports() []Package HasListOrParseErrors() bool HasTypeErrors() bool }
Package represents a Go package that has been type-checked. It maintains only the relevant fields of a *go/packages.Package.
type ParsedWaFile ¶
type ParsedWaFile struct { URI span.URI File *ast.File Tok *token.File // Source code used to build the AST. It may be different from the // actual content of the file if we have fixed the AST. Src []byte Mapper *protocol.ColumnMapper ParseErr scanner.ErrorList }
A ParsedWaFile contains the results of parsing a Wa file.
type RelatedInformation ¶
type Session ¶
type Session interface { // ID returns the unique identifier for this session on this server. ID() string // NewView creates a new View, returning it and its first snapshot. If a // non-empty tempWorkspace directory is provided, the View will record a copy // of its gopls workspace module in that directory, so that client tooling // can execute in the same main module. NewView(ctx context.Context, name string, folder, tempWorkspace span.URI) (View, Snapshot, func(), error) // Cache returns the cache that created this session, for debugging only. Cache() interface{} // View returns a view with a matching name, if the session has one. View(name string) View // ViewOf returns a view corresponding to the given URI. ViewOf(uri span.URI) (View, error) // Views returns the set of active views built by this session. Views() []View // Shutdown the session and all views it has created. Shutdown(ctx context.Context) // GetFile returns a handle for the specified file. GetFile(ctx context.Context, uri span.URI) (FileHandle, error) // DidModifyFile reports a file modification to the session. It returns // the new snapshots after the modifications have been applied, paired with // the affected file URIs for those snapshots. DidModifyFiles(ctx context.Context, changes []FileModification) (map[Snapshot][]span.URI, []func(), error) // ExpandModificationsToDirectories returns the set of changes with the // directory changes removed and expanded to include all of the files in // the directory. ExpandModificationsToDirectories(ctx context.Context, changes []FileModification) []FileModification // Overlays returns a slice of file overlays for the session. Overlays() []Overlay }
Session represents a single connection from a client. This is the level at which things like open files are maintained on behalf of the client. A session may have many active views at any given time.
type Snapshot ¶
type Snapshot interface { ID() uint64 // View returns the View associated with this snapshot. View() View // BackgroundContext returns a context used for all background processing // on behalf of this snapshot. BackgroundContext() context.Context // Fileset returns the Fileset used to parse all the Go files in this snapshot. FileSet() *token.FileSet // ValidBuildConfiguration returns true if there is some error in the // user's workspace. In particular, if they are both outside of a module // and their GOPATH. ValidBuildConfiguration() bool // FindFile returns the FileHandle for the given URI, if it is already // in the given snapshot. FindFile(uri span.URI) VersionedFileHandle // GetVersionedFile returns the VersionedFileHandle for a given URI, // initializing it if it is not already part of the snapshot. GetVersionedFile(ctx context.Context, uri span.URI) (VersionedFileHandle, error) // GetFile returns the FileHandle for a given URI, initializing it if it is // not already part of the snapshot. GetFile(ctx context.Context, uri span.URI) (FileHandle, error) // AwaitInitialized waits until the snapshot's view is initialized. AwaitInitialized(ctx context.Context) // IsOpen returns whether the editor currently has a file open. IsOpen(uri span.URI) bool // ParseWa returns the parsed AST for the file. // If the file is not available, returns nil and an error. ParseWa(ctx context.Context, fh FileHandle) (*ParsedWaFile, error) // PosToField is a cache of *ast.Fields by token.Pos. This allows us // to quickly find corresponding *ast.Field node given a *types.Var. // We must refer to the AST to render type aliases properly when // formatting signatures and other types. PosToField(ctx context.Context, pkg Package, pos token.Pos) (*ast.Field, error) // PosToDecl maps certain objects' positions to their surrounding // ast.Decl. This mapping is used when building the documentation // string for the objects. PosToDecl(ctx context.Context, pkg Package, pos token.Pos) (ast.Decl, error) }
Snapshot represents the current state for the given view.
type SuggestedFix ¶
type VersionedFileHandle ¶
type VersionedFileHandle interface { FileHandle Version() int32 Session() string // LSPIdentity returns the version identity of a file. VersionedFileIdentity() VersionedFileIdentity }
type VersionedFileIdentity ¶
type View ¶
type View interface { // Name returns the name this view was constructed with. Name() string // Folder returns the folder with which this view was created. Folder() span.URI // TempWorkspace returns the folder this view uses for its temporary // workspace module. TempWorkspace() span.URI // Shutdown closes this view, and detaches it from its session. Shutdown(ctx context.Context) // Snapshot returns the current snapshot for the view. Snapshot(ctx context.Context) (Snapshot, func()) // Rebuild rebuilds the current view, replacing the original view in its session. Rebuild(ctx context.Context) (Snapshot, func(), error) }
View represents a single workspace. This is the level at which we maintain configuration like working directory and build tags.