lsp

package
v0.14.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2023 License: BSD-3-Clause Imports: 53 Imported by: 0

README

lsp

internal/lsp provides much of the Language Server Protocol (lsp) implementation for gopls.

Documentation for users and contributors can be found in the gopls/doc directory.

Documentation

Overview

Package lsp implements LSP for gopls.

Index

Constants

View Source
const (
	TelemetryPromptWorkTitle    = "Checking telemetry prompt"     // progress notification title, for awaiting in tests
	GoplsConfigDirEnvvar        = "GOPLS_CONFIG_DIR"              // overridden for testing
	FakeTelemetryModefileEnvvar = "GOPLS_FAKE_TELEMETRY_MODEFILE" // overridden for testing
	TelemetryYes                = "Yes, I'd like to help."
	TelemetryNo                 = "No, thanks."
)

The following constants are used for testing telemetry integration.

View Source
const (
	// FromDidOpen is from a didOpen notification.
	FromDidOpen = ModificationSource(iota)

	// FromDidChange is from a didChange notification.
	FromDidChange

	// FromDidChangeWatchedFiles is from didChangeWatchedFiles notification.
	FromDidChangeWatchedFiles

	// FromDidSave is from a didSave notification.
	FromDidSave

	// FromDidClose is from a didClose notification.
	FromDidClose

	// FromDidChangeConfiguration is from a didChangeConfiguration notification.
	FromDidChangeConfiguration

	// FromRegenerateCgo refers to file modifications caused by regenerating
	// the cgo sources for the workspace.
	FromRegenerateCgo

	// FromInitialWorkspaceLoad refers to the loading of all packages in the
	// workspace when the view is first created.
	FromInitialWorkspaceLoad
)
View Source
const WorkspaceLoadFailure = "Error loading workspace"

Variables

View Source
var GoVersionTable = []GoVersionSupport{
	{12, "", "v0.7.5"},
	{15, "", "v0.9.5"},
	{16, "v0.13.0", "v0.11.0"},
	{17, "v0.13.0", "v0.11.0"},
}

GoVersionTable maps Go versions to the gopls version in which support will be deprecated, and the final gopls version supporting them without warnings. Keep this in sync with gopls/README.md.

Must be sorted in ascending order of Go version.

Mutable for testing.

Functions

func DiagnosticWorkTitle

func DiagnosticWorkTitle(cause ModificationSource) string

DiagnosticWorkTitle returns the title of the diagnostic work resulting from a file change originating from the given cause.

func OldestSupportedGoVersion

func OldestSupportedGoVersion() int

OldestSupportedGoVersion is the last X in Go 1.X that this version of gopls supports.

func SemMods

func SemMods(n int) []string

SemMods returns the []string equivalent of the mods, for gopls semtok.

func SemType

func SemType(n int) string

SemType returns a string equivalent of the type, for gopls semtok

func SemanticModifiers

func SemanticModifiers() []string

SemanticModifiers to use in case there is no client.

func SemanticTypes

func SemanticTypes() []string

SemanticTypes to use in case there is no client, as in the command line, or tests

Types

type GoVersionSupport

type GoVersionSupport struct {
	GoVersion           int
	DeprecatedVersion   string // if unset, the version is already deprecated
	InstallGoplsVersion string
}

GoVersionSupport holds information about end-of-life Go version support.

type ModificationSource

type ModificationSource int

ModificationSource identifies the origin of a change.

func (ModificationSource) String

func (m ModificationSource) String() string

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server implements the protocol.Server interface.

func NewServer

func NewServer(session *cache.Session, client protocol.ClientCloser, options *source.Options) *Server

NewServer creates an LSP server and binds it to handle incoming client messages on the supplied stream.

func (*Server) CodeAction

func (s *Server) CodeAction(ctx context.Context, params *protocol.CodeActionParams) ([]protocol.CodeAction, error)

func (*Server) CodeLens

func (s *Server) CodeLens(ctx context.Context, params *protocol.CodeLensParams) ([]protocol.CodeLens, error)

func (*Server) Completion

func (s *Server) Completion(ctx context.Context, params *protocol.CompletionParams) (*protocol.CompletionList, error)

func (*Server) Definition

func (s *Server) Definition(ctx context.Context, params *protocol.DefinitionParams) ([]protocol.Location, error)

func (*Server) Diagnostic

func (s *Server) Diagnostic(context.Context, *string) (*string, error)

func (*Server) Diagnostics

func (s *Server) Diagnostics() map[string][]string

Diagnostics formattedfor the debug server (all the relevant fields of Server are private) (The alternative is to export them)

func (*Server) DidChange

func (s *Server) DidChange(ctx context.Context, params *protocol.DidChangeTextDocumentParams) error

func (*Server) DidChangeConfiguration

func (s *Server) DidChangeConfiguration(ctx context.Context, _gen *protocol.DidChangeConfigurationParams) error

func (*Server) DidChangeNotebookDocument

func (s *Server) DidChangeNotebookDocument(context.Context, *protocol.DidChangeNotebookDocumentParams) error

func (*Server) DidChangeWatchedFiles

func (s *Server) DidChangeWatchedFiles(ctx context.Context, params *protocol.DidChangeWatchedFilesParams) error

func (*Server) DidChangeWorkspaceFolders

func (s *Server) DidChangeWorkspaceFolders(ctx context.Context, params *protocol.DidChangeWorkspaceFoldersParams) error

func (*Server) DidClose

func (s *Server) DidClose(ctx context.Context, params *protocol.DidCloseTextDocumentParams) error

func (*Server) DidCloseNotebookDocument

func (s *Server) DidCloseNotebookDocument(context.Context, *protocol.DidCloseNotebookDocumentParams) error

func (*Server) DidCreateFiles

func (s *Server) DidCreateFiles(context.Context, *protocol.CreateFilesParams) error

func (*Server) DidDeleteFiles

func (s *Server) DidDeleteFiles(context.Context, *protocol.DeleteFilesParams) error

func (*Server) DidOpen

func (s *Server) DidOpen(ctx context.Context, params *protocol.DidOpenTextDocumentParams) error

func (*Server) DidOpenNotebookDocument

func (s *Server) DidOpenNotebookDocument(context.Context, *protocol.DidOpenNotebookDocumentParams) error

func (*Server) DidRenameFiles

func (s *Server) DidRenameFiles(context.Context, *protocol.RenameFilesParams) error

func (*Server) DidSave

func (s *Server) DidSave(ctx context.Context, params *protocol.DidSaveTextDocumentParams) error

func (*Server) DidSaveNotebookDocument

func (s *Server) DidSaveNotebookDocument(context.Context, *protocol.DidSaveNotebookDocumentParams) error

func (*Server) DocumentHighlight

func (s *Server) DocumentHighlight(ctx context.Context, params *protocol.DocumentHighlightParams) ([]protocol.DocumentHighlight, error)
func (s *Server) DocumentLink(ctx context.Context, params *protocol.DocumentLinkParams) ([]protocol.DocumentLink, error)

func (*Server) DocumentSymbol

func (s *Server) DocumentSymbol(ctx context.Context, params *protocol.DocumentSymbolParams) ([]interface{}, error)

func (*Server) ExecuteCommand

func (s *Server) ExecuteCommand(ctx context.Context, params *protocol.ExecuteCommandParams) (interface{}, error)

func (*Server) Exit

func (s *Server) Exit(ctx context.Context) error

func (*Server) FoldingRange

func (s *Server) FoldingRange(ctx context.Context, params *protocol.FoldingRangeParams) ([]protocol.FoldingRange, error)

func (*Server) Formatting

func (s *Server) Formatting(ctx context.Context, params *protocol.DocumentFormattingParams) ([]protocol.TextEdit, error)

func (*Server) Hover

func (s *Server) Hover(ctx context.Context, params *protocol.HoverParams) (*protocol.Hover, error)

func (*Server) Implementation

func (s *Server) Implementation(ctx context.Context, params *protocol.ImplementationParams) ([]protocol.Location, error)

func (*Server) Initialize

func (s *Server) Initialize(ctx context.Context, params *protocol.ParamInitialize) (*protocol.InitializeResult, error)

func (*Server) Initialized

func (s *Server) Initialized(ctx context.Context, params *protocol.InitializedParams) error

func (*Server) InlayHint

func (s *Server) InlayHint(ctx context.Context, params *protocol.InlayHintParams) ([]protocol.InlayHint, error)

func (*Server) InlineValue

func (*Server) Moniker

func (*Server) NonstandardRequest

func (s *Server) NonstandardRequest(ctx context.Context, method string, params interface{}) (interface{}, error)

func (*Server) Options added in v0.14.0

func (s *Server) Options() *source.Options

Options returns the current server options.

The caller must not modify the result.

func (*Server) PrepareCallHierarchy

func (s *Server) PrepareCallHierarchy(ctx context.Context, params *protocol.CallHierarchyPrepareParams) ([]protocol.CallHierarchyItem, error)

func (*Server) PrepareRename

func (s *Server) PrepareRename(ctx context.Context, params *protocol.PrepareRenameParams) (*protocol.PrepareRename2Gn, error)

func (*Server) Progress

func (*Server) RangesFormatting added in v0.13.0

func (*Server) References

func (s *Server) References(ctx context.Context, params *protocol.ReferenceParams) ([]protocol.Location, error)

func (*Server) Rename

func (s *Server) Rename(ctx context.Context, params *protocol.RenameParams) (*protocol.WorkspaceEdit, error)

func (*Server) Resolve

func (*Server) ResolveCodeAction

func (s *Server) ResolveCodeAction(context.Context, *protocol.CodeAction) (*protocol.CodeAction, error)

func (*Server) ResolveCodeLens

func (s *Server) ResolveCodeLens(context.Context, *protocol.CodeLens) (*protocol.CodeLens, error)

func (*Server) ResolveCompletionItem

func (s *Server) ResolveCompletionItem(context.Context, *protocol.CompletionItem) (*protocol.CompletionItem, error)
func (s *Server) ResolveDocumentLink(context.Context, *protocol.DocumentLink) (*protocol.DocumentLink, error)

func (*Server) ResolveWorkspaceSymbol

func (s *Server) ResolveWorkspaceSymbol(context.Context, *protocol.WorkspaceSymbol) (*protocol.WorkspaceSymbol, error)

func (*Server) SelectionRange

func (s *Server) SelectionRange(ctx context.Context, params *protocol.SelectionRangeParams) ([]protocol.SelectionRange, error)

func (*Server) SemanticTokensFull

func (s *Server) SemanticTokensFull(ctx context.Context, params *protocol.SemanticTokensParams) (*protocol.SemanticTokens, error)

func (*Server) SemanticTokensFullDelta

func (s *Server) SemanticTokensFullDelta(context.Context, *protocol.SemanticTokensDeltaParams) (interface{}, error)

func (*Server) SemanticTokensRange

func (s *Server) SemanticTokensRange(ctx context.Context, params *protocol.SemanticTokensRangeParams) (*protocol.SemanticTokens, error)

func (*Server) SetOptions added in v0.14.0

func (s *Server) SetOptions(opts *source.Options)

SetOptions sets the current server options.

The caller must not subsequently modify the options.

func (*Server) SetTrace

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

func (*Server) SignatureHelp

func (s *Server) SignatureHelp(ctx context.Context, params *protocol.SignatureHelpParams) (*protocol.SignatureHelp, error)

func (*Server) Symbol

func (*Server) TypeDefinition

func (s *Server) TypeDefinition(ctx context.Context, params *protocol.TypeDefinitionParams) ([]protocol.Location, error)

func (*Server) WillCreateFiles

func (*Server) WillDeleteFiles

func (*Server) WillRenameFiles

func (*Server) WillSave

func (*Server) WorkDoneProgressCancel

func (s *Server) WorkDoneProgressCancel(ctx context.Context, params *protocol.WorkDoneProgressCancelParams) error

Directories

Path Synopsis
analysis
deprecated
Package deprecated defines an Analyzer that marks deprecated symbols and package imports.
Package deprecated defines an Analyzer that marks deprecated symbols and package imports.
embeddirective
Package embeddirective defines an Analyzer that validates //go:embed directives.
Package embeddirective defines an Analyzer that validates //go:embed directives.
fillreturns
Package fillreturns defines an Analyzer that will attempt to automatically fill in a return statement that has missing values with zero value elements.
Package fillreturns defines an Analyzer that will attempt to automatically fill in a return statement that has missing values with zero value elements.
fillstruct
Package fillstruct defines an Analyzer that automatically fills in a struct declaration with zero value elements for each field.
Package fillstruct defines an Analyzer that automatically fills in a struct declaration with zero value elements for each field.
infertypeargs
Package infertypeargs defines an analyzer that checks for explicit function arguments that could be inferred.
Package infertypeargs defines an analyzer that checks for explicit function arguments that could be inferred.
nonewvars
Package nonewvars defines an Analyzer that applies suggested fixes to errors of the type "no new variables on left side of :=".
Package nonewvars defines an Analyzer that applies suggested fixes to errors of the type "no new variables on left side of :=".
noresultvalues
Package noresultvalues defines an Analyzer that applies suggested fixes to errors of the type "no result values expected".
Package noresultvalues defines an Analyzer that applies suggested fixes to errors of the type "no result values expected".
simplifycompositelit
Package simplifycompositelit defines an Analyzer that simplifies composite literals.
Package simplifycompositelit defines an Analyzer that simplifies composite literals.
simplifyrange
Package simplifyrange defines an Analyzer that simplifies range statements.
Package simplifyrange defines an Analyzer that simplifies range statements.
simplifyslice
Package simplifyslice defines an Analyzer that simplifies slice statements.
Package simplifyslice defines an Analyzer that simplifies slice statements.
undeclaredname
Package undeclaredname defines an Analyzer that applies suggested fixes to errors of the type "undeclared name: %s".
Package undeclaredname defines an Analyzer that applies suggested fixes to errors of the type "undeclared name: %s".
unusedparams
Package unusedparams defines an analyzer that checks for unused parameters of functions.
Package unusedparams defines an analyzer that checks for unused parameters of functions.
unusedparams/cmd
The stringintconv command runs the stringintconv analyzer.
The stringintconv command runs the stringintconv analyzer.
unusedvariable
Package unusedvariable defines an analyzer that checks for unused variables.
Package unusedvariable defines an analyzer that checks for unused variables.
useany
Package useany defines an Analyzer that checks for usage of interface{} in constraints, rather than the predeclared any.
Package useany defines an Analyzer that checks for usage of interface{} in constraints, rather than the predeclared any.
Package browser provides utilities for interacting with users' browsers.
Package browser provides utilities for interacting with users' browsers.
Package cache implements the caching layer for gopls.
Package cache implements the caching layer for gopls.
Package cmd handles the gopls command line.
Package cmd handles the gopls command line.
Package command defines the interface provided by gopls for the workspace/executeCommand LSP request.
Package command defines the interface provided by gopls for the workspace/executeCommand LSP request.
commandmeta
Package commandmeta provides metadata about LSP commands, by analyzing the command.Interface type.
Package commandmeta provides metadata about LSP commands, by analyzing the command.Interface type.
gen
Package gen is used to generate command bindings from the gopls command interface.
Package gen is used to generate command bindings from the gopls command interface.
Package debug exports debug information for gopls.
Package debug exports debug information for gopls.
log
Package log provides helper methods for exporting log events to the internal/event package.
Package log provides helper methods for exporting log events to the internal/event package.
Package fake provides fake implementations of a text editor, LSP client plugin, and Sandbox environment for use in tests.
Package fake provides fake implementations of a text editor, LSP client plugin, and Sandbox environment for use in tests.
The filecache package provides a file-based shared durable blob cache.
The filecache package provides a file-based shared durable blob cache.
Package frob is a fast restricted object encoder/decoder in the spirit of encoding/gob.
Package frob is a fast restricted object encoder/decoder in the spirit of encoding/gob.
Package glob implements an LSP-compliant glob pattern matcher for testing.
Package glob implements an LSP-compliant glob pattern matcher for testing.
The helper command generates the declaration of the concrete 'server' type that implements the abstract Server interface defined in protocol/tsserver.go (which is itself generated from the LSP protocol).
The helper command generates the declaration of the concrete 'server' type that implements the abstract Server interface defined in protocol/tsserver.go (which is itself generated from the LSP protocol).
The lru package implements a fixed-size in-memory LRU cache.
The lru package implements a fixed-size in-memory LRU cache.
Package lsprpc implements a jsonrpc2.StreamServer that may be used to serve the LSP on a jsonrpc2 channel.
Package lsprpc implements a jsonrpc2.StreamServer that may be used to serve the LSP on a jsonrpc2 channel.
Package mod provides core features related to go.mod file handling for use by Go editors and tools.
Package mod provides core features related to go.mod file handling for use by Go editors and tools.
Package protocol contains the structs that map directly to the request and response messages of the Language Server Protocol.
Package protocol contains the structs that map directly to the request and response messages of the Language Server Protocol.
generate
The generate command generates Go declarations from VSCode's description of the Language Server Protocol.
The generate command generates Go declarations from VSCode's description of the Language Server Protocol.
Package regtest provides a framework for writing gopls regression tests.
Package regtest provides a framework for writing gopls regression tests.
Package safetoken provides wrappers around methods in go/token, that return errors rather than panicking.
Package safetoken provides wrappers around methods in go/token, that return errors rather than panicking.
Package snippet implements the specification for the LSP snippet format.
Package snippet implements the specification for the LSP snippet format.
Package source provides core features for use by Go editors and tools.
Package source provides core features for use by Go editors and tools.
completion
Package completion provides core functionality for code completion in Go editors and tools.
Package completion provides core functionality for code completion in Go editors and tools.
methodsets
Package methodsets defines an incremental, serializable index of method-set information that allows efficient 'implements' queries across packages of the workspace without using the type checker.
Package methodsets defines an incremental, serializable index of method-set information that allows efficient 'implements' queries across packages of the workspace without using the type checker.
typerefs
Package typerefs extracts symbol-level reachability information from the syntax of a Go package.
Package typerefs extracts symbol-level reachability information from the syntax of a Go package.
xrefs
Package xrefs defines the serializable index of cross-package references that is computed during type checking.
Package xrefs defines the serializable index of cross-package references that is computed during type checking.
Package template contains code for dealing with templates
Package template contains code for dealing with templates
Package tests exports functionality to be used across a variety of gopls tests.
Package tests exports functionality to be used across a variety of gopls tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL