Documentation
¶
Overview ¶
Package langfeatures is the features model of area 3 (SPEC §9.12): the language features the editor asks for (completion, hover, signature help, navigation, symbols, code actions, formatting, rename, highlights), the registry of the providers that answer them (a language server and the providers an extension wrote in Go alike), the merging of their answers the way VS Code merges them, the conversion of the answers of a language server (core/lsp) to the types of this package, and the application of a WorkspaceEdit to the documents and files of a window.
It has no user interface and imports no Glutter. Positions and ranges are Emetos's: zero-based lines and columns in bytes of the UTF-8 line (D6). A provider is called off the UI thread with a Document, an immutable snapshot of the text at one version, so that its answer can be dropped when the document has changed meanwhile; applying a WorkspaceEdit belongs to the goroutine that owns the documents (the UI thread).
Ported from VS Code, as behavior and not as code: src/vs/editor/common/languageFeatureRegistry.ts (the score of a selector and the order of the providers: higher score first, the newer registration first among equals), src/vs/editor/contrib/suggest/browser/suggest.ts (the first group of providers that answers), src/vs/editor/contrib/hover/browser/getHover.ts and src/vs/editor/contrib/gotoSymbol/browser/goToSymbol.ts (hovers and locations of all providers) and src/vs/editor/contrib/format/browser/format.ts (the choice of one formatter).
Index ¶
- Constants
- func AfterSpace(line string, col int) bool
- func ApplySemanticEdits(prev []uint32, edits []SemanticEdit) ([]uint32, error)
- func CompareSuggestItems(a, b *SuggestItem) int
- func Kind(kind string) *string
- func KindContains(parent, child string) bool
- func KindIntersects(a, b string) bool
- func LastRuneStart(s string) int
- func LeadingWhitespace(s string) string
- func SelectionRangesFromLSP(enc lsp.Encoding, doc Document, answer []lsp.SelectionRange) [][]Range
- func SortSuggestItems(items []*SuggestItem, order SnippetOrder)
- func SymbolKindLabel(kind int) string
- func SymbolKindSetting(kind int) string
- type ApplyOptions
- type ApplyResult
- type Change
- type ChangeKind
- type CodeAction
- type CodeActionAutoApply
- type CodeActionFilter
- type CodeActionKinds
- type CodeActionProvider
- type CodeActionRequest
- type CodeActionResolver
- type CodeActionSet
- type CodeActionSource
- type CodeActionTrigger
- type CodeActionTriggerType
- type CodeLens
- type CodeLensProvider
- type CodeLensResolver
- type Command
- type CompletionItem
- type CompletionKind
- type CompletionList
- type CompletionProvider
- type CompletionQuery
- type CompletionResolver
- type CompletionTrigger
- type CompletionTriggerKind
- type Diagnostic
- type Document
- type DocumentHighlight
- type DocumentSymbol
- type EditHost
- type EditTracker
- type Feature
- type FileOptions
- type FlatSymbol
- type FoldingProvider
- type FoldingRange
- type FoldingRangeProvider
- type FormattingOptions
- type FormattingProvider
- type HighlightKind
- type HighlightProvider
- type Hover
- type HoverProvider
- type HoverResult
- type InlayHint
- type InlayHintKind
- type InlayHintPart
- type InlayHintProvider
- type InlayHintResolver
- type ItemFilter
- type LineContext
- type Location
- type LocationLink
- type Markup
- type MemoryMode
- type NavKind
- type NavigationProvider
- type OnTypeFormattingProvider
- type Parameter
- type Position
- type PrepareRename
- type ProviderError
- type Range
- type RangeFormattingProvider
- type ReferenceProvider
- type Registered
- type Registry
- func (r *Registry) CanResolveCodeAction(a CodeAction) bool
- func (r *Registry) CanResolveCodeLens(l CodeLens) bool
- func (r *Registry) CanResolveCompletion(item CompletionItem) bool
- func (r *Registry) CanResolveInlayHint(h InlayHint) bool
- func (r *Registry) CanResolveWorkspaceSymbol(sym WorkspaceSymbol) bool
- func (r *Registry) Changed()
- func (r *Registry) CodeActionKinds(doc Document) []string
- func (r *Registry) CodeActions(ctx context.Context, doc Document, req CodeActionRequest) ([]CodeAction, []ProviderError)
- func (r *Registry) CodeLenses(ctx context.Context, doc Document) ([]CodeLens, []ProviderError)
- func (r *Registry) Completion(ctx context.Context, doc Document, pos Position, trigger CompletionTrigger) (CompletionList, []ProviderError)
- func (r *Registry) CompletionFor(ctx context.Context, doc Document, pos Position, trigger CompletionTrigger, ...) (CompletionList, []ProviderError)
- func (r *Registry) CompletionTriggers(doc Document) []string
- func (r *Registry) DocumentHighlights(ctx context.Context, doc Document, pos Position) ([]DocumentHighlight, []ProviderError)
- func (r *Registry) DocumentSymbols(ctx context.Context, doc Document) ([]DocumentSymbol, []ProviderError)
- func (r *Registry) FoldingRanges(ctx context.Context, doc Document) (ranges []folding.SyntaxRange, collapsed map[int]string, ok bool, ...)
- func (r *Registry) FormatDocument(ctx context.Context, doc Document, opts FormattingOptions, ...) ([]TextEdit, error)
- func (r *Registry) FormatOnType(ctx context.Context, doc Document, pos Position, ch string, ...) ([]TextEdit, error)
- func (r *Registry) FormatRange(ctx context.Context, doc Document, rng Range, opts FormattingOptions, ...) ([]TextEdit, error)
- func (r *Registry) Formatters(doc Document) []Registered[FormattingProvider]
- func (r *Registry) GetCodeActions(ctx context.Context, doc Document, req CodeActionRequest, ...) (CodeActionSet, []ProviderError)
- func (r *Registry) Has(doc Document, f Feature) bool
- func (r *Registry) HasCompletion(doc Document) bool
- func (r *Registry) HasHover(doc Document) bool
- func (r *Registry) HasSignatureHelp(doc Document) bool
- func (r *Registry) Hover(ctx context.Context, doc Document, pos Position) ([]Hover, []ProviderError)
- func (r *Registry) HoverEach(ctx context.Context, doc Document, pos Position, each func(HoverResult)) []ProviderError
- func (r *Registry) InlayHints(ctx context.Context, doc Document, rng Range) ([]InlayHint, []ProviderError)
- func (r *Registry) Locations(ctx context.Context, doc Document, pos Position, kind NavKind) ([]LocationLink, []ProviderError)
- func (r *Registry) OnChange(fn func()) (stop func())
- func (r *Registry) OnRefresh(fn func(Feature)) (stop func())
- func (r *Registry) OnTypeFormattingTriggers(doc Document) []string
- func (r *Registry) PickFormatter(doc Document, defaultFormatter string) (reg Registered[FormattingProvider], others int, ok bool)
- func (r *Registry) PrepareRename(ctx context.Context, doc Document, pos Position) (*PrepareRename, error)
- func (r *Registry) References(ctx context.Context, doc Document, pos Position, includeDeclaration bool) ([]Location, []ProviderError)
- func (r *Registry) Refreshed(f Feature)
- func (r *Registry) RegisterCodeActions(owner string, sel Selector, p CodeActionProvider) (remove func())
- func (r *Registry) RegisterCodeLens(owner string, sel Selector, p CodeLensProvider) (remove func())
- func (r *Registry) RegisterCompletion(owner string, sel Selector, p CompletionProvider, triggers ...string) (remove func())
- func (r *Registry) RegisterFoldingRanges(owner string, sel Selector, p FoldingRangeProvider) (remove func())
- func (r *Registry) RegisterFormatting(owner string, sel Selector, p FormattingProvider) (remove func())
- func (r *Registry) RegisterHighlights(owner string, sel Selector, p HighlightProvider) (remove func())
- func (r *Registry) RegisterHover(owner string, sel Selector, p HoverProvider) (remove func())
- func (r *Registry) RegisterInlayHints(owner string, sel Selector, p InlayHintProvider) (remove func())
- func (r *Registry) RegisterNavigation(owner string, sel Selector, p NavigationProvider) (remove func())
- func (r *Registry) RegisterOnTypeFormatting(owner string, sel Selector, p OnTypeFormattingProvider) (remove func())
- func (r *Registry) RegisterReferences(owner string, sel Selector, p ReferenceProvider) (remove func())
- func (r *Registry) RegisterRename(owner string, sel Selector, p RenameProvider) (remove func())
- func (r *Registry) RegisterSelectionRanges(owner string, sel Selector, p SelectionRangeProvider) (remove func())
- func (r *Registry) RegisterSemanticTokens(owner string, sel Selector, p SemanticTokensProvider) (remove func())
- func (r *Registry) RegisterSignatureHelp(owner string, sel Selector, p SignatureHelpProvider, triggers ...string) (remove func())
- func (r *Registry) RegisterSymbols(owner string, sel Selector, p SymbolProvider) (remove func())
- func (r *Registry) RegisterWorkspaceSymbols(owner string, p WorkspaceSymbolProvider) (remove func())
- func (r *Registry) Rename(ctx context.Context, doc Document, pos Position, newName string) (*WorkspaceEdit, error)
- func (r *Registry) ResolveCodeAction(ctx context.Context, a CodeAction) (CodeAction, error)
- func (r *Registry) ResolveCodeLens(ctx context.Context, doc Document, l CodeLens) (CodeLens, error)
- func (r *Registry) ResolveCompletion(ctx context.Context, doc Document, item CompletionItem) (CompletionItem, error)
- func (r *Registry) ResolveInlayHint(ctx context.Context, doc Document, h InlayHint) (InlayHint, error)
- func (r *Registry) ResolveWorkspaceSymbol(ctx context.Context, sym WorkspaceSymbol) (WorkspaceSymbol, error)
- func (r *Registry) SelectionRanges(ctx context.Context, doc Document, positions []Position) (SelectionRangeSet, bool, []ProviderError)
- func (r *Registry) SemanticTokensProviderFor(doc Document) SemanticTokensProvider
- func (r *Registry) SignatureCharacters(doc Document) (triggers, retriggers []string)
- func (r *Registry) SignatureHelp(ctx context.Context, doc Document, pos Position, sc SignatureContext) (*SignatureHelp, []ProviderError)
- func (r *Registry) SignatureTriggers(doc Document) []string
- func (r *Registry) SupportsCodeActionKind(doc Document, kind string) bool
- func (r *Registry) WorkspaceSymbols(ctx context.Context, query string) ([]WorkspaceSymbol, []ProviderError)
- type RenameProvider
- type SelectionRangeProvider
- type SelectionRangeSet
- type Selector
- type SemanticEdit
- type SemanticLegend
- type SemanticRangeProvider
- type SemanticToken
- type SemanticTokens
- type SemanticTokensCache
- type SemanticTokensProvider
- type SemanticUpdate
- type Server
- type ServerProvider
- func (sp *ServerProvider) CanResolve(item CompletionItem) bool
- func (sp *ServerProvider) CanResolveAction(a CodeAction) bool
- func (sp *ServerProvider) CanResolveCodeLens(l CodeLens) bool
- func (sp *ServerProvider) CanResolveInlayHint(h InlayHint) bool
- func (sp *ServerProvider) CanResolveSymbol(sym WorkspaceSymbol) bool
- func (sp *ServerProvider) CodeActionKinds() []string
- func (sp *ServerProvider) CompletionTriggers() []string
- func (sp *ServerProvider) ExecuteCommand(ctx context.Context, cmd Command) error
- func (sp *ServerProvider) Offers(f Feature) bool
- func (sp *ServerProvider) OnTypeTriggers() []string
- func (sp *ServerProvider) PrepareRename(ctx context.Context, doc Document, pos Position) (*PrepareRename, error)
- func (sp *ServerProvider) ProvideCodeActions(ctx context.Context, doc Document, req CodeActionRequest) ([]CodeAction, error)
- func (sp *ServerProvider) ProvideCodeLenses(ctx context.Context, doc Document) ([]CodeLens, error)
- func (sp *ServerProvider) ProvideCompletion(ctx context.Context, doc Document, pos Position, trigger CompletionTrigger) (CompletionList, error)
- func (sp *ServerProvider) ProvideDocumentHighlights(ctx context.Context, doc Document, pos Position) ([]DocumentHighlight, error)
- func (sp *ServerProvider) ProvideDocumentSymbols(ctx context.Context, doc Document) ([]DocumentSymbol, error)
- func (sp *ServerProvider) ProvideFoldingRanges(ctx context.Context, doc Document) ([]FoldingRange, error)
- func (sp *ServerProvider) ProvideFormatting(ctx context.Context, doc Document, opts FormattingOptions) ([]TextEdit, error)
- func (sp *ServerProvider) ProvideHover(ctx context.Context, doc Document, pos Position) (*Hover, error)
- func (sp *ServerProvider) ProvideInlayHints(ctx context.Context, doc Document, r Range) ([]InlayHint, error)
- func (sp *ServerProvider) ProvideLocations(ctx context.Context, doc Document, pos Position, kind NavKind) ([]LocationLink, error)
- func (sp *ServerProvider) ProvideOnTypeFormatting(ctx context.Context, doc Document, pos Position, ch string, ...) ([]TextEdit, error)
- func (sp *ServerProvider) ProvideRangeFormatting(ctx context.Context, doc Document, r Range, opts FormattingOptions) ([]TextEdit, error)
- func (sp *ServerProvider) ProvideReferences(ctx context.Context, doc Document, pos Position, includeDeclaration bool) ([]Location, error)
- func (sp *ServerProvider) ProvideRename(ctx context.Context, doc Document, pos Position, newName string) (*WorkspaceEdit, error)
- func (sp *ServerProvider) ProvideSelectionRanges(ctx context.Context, doc Document, positions []Position) ([][]Range, error)
- func (sp *ServerProvider) ProvideSemanticTokens(ctx context.Context, doc Document, previousResultID string) (*SemanticUpdate, error)
- func (sp *ServerProvider) ProvideSemanticTokensRange(ctx context.Context, doc Document, r Range) (*SemanticUpdate, error)
- func (sp *ServerProvider) ProvideSignatureHelp(ctx context.Context, doc Document, pos Position, sc SignatureContext) (*SignatureHelp, error)
- func (sp *ServerProvider) ProvideWorkspaceSymbols(ctx context.Context, query string) ([]WorkspaceSymbol, error)
- func (sp *ServerProvider) Register(r *Registry, owner string, sel Selector) (remove func())
- func (sp *ServerProvider) ResolveCodeAction(ctx context.Context, a CodeAction) (CodeAction, error)
- func (sp *ServerProvider) ResolveCodeLens(ctx context.Context, doc Document, l CodeLens) (CodeLens, error)
- func (sp *ServerProvider) ResolveCompletion(ctx context.Context, doc Document, item CompletionItem) (CompletionItem, error)
- func (sp *ServerProvider) ResolveInlayHint(ctx context.Context, doc Document, h InlayHint) (InlayHint, error)
- func (sp *ServerProvider) ResolveWorkspaceSymbol(ctx context.Context, sym WorkspaceSymbol) (WorkspaceSymbol, error)
- func (sp *ServerProvider) SemanticLegend() SemanticLegend
- func (sp *ServerProvider) SignatureCharacters() (triggers, retriggers []string)
- func (sp *ServerProvider) SignatureTriggers() []string
- type Severity
- type Signature
- type SignatureContext
- type SignatureHelp
- type SignatureHelpProvider
- type SignatureTrigger
- type SnippetOrder
- type SuggestItem
- type SuggestMemory
- type SuggestModel
- type SuggestModelOptions
- type SuggestRequest
- type SymbolCache
- type SymbolProvider
- type SymbolSortOrder
- type TextEdit
- type TextSource
- type WordFunc
- type WordProvider
- type WorkspaceEdit
- type WorkspaceSymbol
- type WorkspaceSymbolProvider
- type WorkspaceSymbolResolver
Constants ¶
const ( KindQuickFix = "quickfix" KindRefactor = "refactor" KindRefactorExtract = "refactor.extract" KindRefactorInline = "refactor.inline" KindRefactorMove = "refactor.move" KindRefactorRewrite = "refactor.rewrite" KindSurroundWith = "refactor.surround" KindSource = "source" KindSourceOrganize = "source.organizeImports" KindSourceFixAll = "source.fixAll" )
The kinds of code action (LSP's CodeActionKind; a kind is a dotted path and contains the kinds below it).
const ( WordsOff = "off" WordsOffWithInline = "offWithInlineSuggestions" WordsCurrentDocument = "currentDocument" WordsMatchingDocuments = "matchingDocuments" WordsAllDocuments = "allDocuments" )
The values of editor.wordBasedSuggestions.
const DefaultScore = -100
DefaultScore is the score of an item with nothing to match: out of the range the scorer gives.
const SnippetOwner = "emetos.snippets"
SnippetOwner is the owner of the items that are the user's snippets (SPEC §9.9, §9.12 "Completion").
const SymbolKindCount = len(symbolKinds)
SymbolKindCount is the number of symbol kinds.
const WordOwner = "emetos.words"
WordOwner is the owner of the items that are words of the open documents.
Variables ¶
This section is empty.
Functions ¶
func AfterSpace ¶
AfterSpace tells whether the character before the byte column col of the line is white space.
func ApplySemanticEdits ¶
func ApplySemanticEdits(prev []uint32, edits []SemanticEdit) ([]uint32, error)
ApplySemanticEdits makes the data a delta describes from the data of the previous result: the edits refer to the previous data, are applied in the order of their starts, and must not overlap or go beyond it. The previous data is not changed.
func CompareSuggestItems ¶
func CompareSuggestItems(a, b *SuggestItem) int
CompareSuggestItems is the order the items of a request come in: by sort text, then label, then kind.
Ported from VS Code: src/vs/editor/contrib/suggest/browser/suggest.ts (defaultComparator)
func KindContains ¶
KindContains tells whether the kind parent contains the kind child: they are equal, or child is below parent in the dotted path; the empty kind contains every kind (VS Code's HierarchicalKind.contains).
func KindIntersects ¶
KindIntersects tells whether one of the kinds contains the other.
func LastRuneStart ¶
LastRuneStart is the byte offset of the last rune of s (0 for an empty string).
func LeadingWhitespace ¶
LeadingWhitespace is the spaces and tabs a line starts with.
func SelectionRangesFromLSP ¶
SelectionRangesFromLSP converts the answer to a selection range request: the chain of parents of each position becomes its list of ranges, the smallest first.
func SortSuggestItems ¶
func SortSuggestItems(items []*SuggestItem, order SnippetOrder)
SortSuggestItems sorts the items of a request (a stable sort, as JavaScript's), with the snippets where the order says.
Ported from VS Code: src/vs/editor/contrib/suggest/browser/suggest.ts (getSuggestionComparator)
func SymbolKindLabel ¶
SymbolKindLabel is the plural name of a symbol kind that the picker groups by with "@:" ("functions", "type parameters"); "properties" for a kind that is not one.
func SymbolKindSetting ¶
SymbolKindSetting is the name that follows "show" in outline.showXxx and breadcrumbs.showXxx for a symbol kind ("Functions", "EnumMembers"); empty for a kind that is not one.
Types ¶
type ApplyOptions ¶
type ApplyOptions struct {
// JoinUndo makes the text changes part of the undo group that is open in each document, instead of a step of their own: the
// participants of a save make one step together.
JoinUndo bool
}
ApplyOptions are the options of ApplyWith.
type ApplyResult ¶
type ApplyResult struct {
// Applied is true when every change was made.
Applied bool
// FailedChange is the index of the change that failed, or -1.
FailedChange int
// Documents are the documents that were edited, in the order of the changes, each once.
Documents []*document.Document
}
ApplyResult says what Apply did.
func Apply ¶
func Apply(ctx context.Context, host EditHost, we *WorkspaceEdit) (ApplyResult, error)
Apply makes the edit (SPEC §9.12): the text edits of each document are one batch, so one undo step per document; an open document is edited in place, a closed file is opened by the host and left open and unsaved (VS Code's rule); the file operations go through the host's. An edit with only text changes is all or nothing: every document is found and every range checked before the first is changed. With file operations the changes are made in order and the first that fails stops the rest (the protocol's "abort"), after the ones before it were made. A URI the editor has no documents for fails with the tags of lsp.ParseDocumentURI. The error has the tags WorkspaceEditInvalid, WorkspaceEditDocumentUnavailable, WorkspaceEditStale, WorkspaceEditReadOnly, WorkspaceEditOverlap and WorkspaceEditFileFailed; ApplyResult.FailedChange says which change.
func ApplyWith ¶
func ApplyWith(ctx context.Context, host EditHost, we *WorkspaceEdit, opts ApplyOptions) (ApplyResult, error)
ApplyWith is Apply with options.
type Change ¶
type Change struct {
Kind ChangeKind
// URI is the document or file, NewURI the target of a rename.
URI, NewURI document.URI
// Version, when set, is the version of the document the Edits are for; the edit is refused when the document has
// another.
Version *int
// Edits are the edits of a ChangeText, their ranges in the text of the document as it was before the change.
Edits []TextEdit
// The options of the file changes.
Overwrite, IgnoreIfExists, Recursive, IgnoreIfNotExists bool
}
Change is one member of a WorkspaceEdit.
type ChangeKind ¶
type ChangeKind int
ChangeKind says what a Change of a WorkspaceEdit does.
const ( // ChangeText edits the text of a document. ChangeText ChangeKind = iota // ChangeCreate creates the file URI. ChangeCreate // ChangeRename renames the file URI to NewURI. ChangeRename // ChangeDelete deletes the file or folder URI. ChangeDelete )
The kinds of change.
type CodeAction ¶
type CodeAction struct {
Title string
Kind string
Diagnostics []Diagnostic
Preferred bool
Disabled string
Edit *WorkspaceEdit
Command *Command
Owner string
// contains filtered or unexported fields
}
CodeAction is an action the user may choose.
func CodeActionsFromLSP ¶
func CodeActionsFromLSP(enc lsp.Encoding, doc Document, owner string, actions lsp.CodeActions) []CodeAction
CodeActionsFromLSP converts the answer to a code action request about the document; owner is the id of the server, which the commands of the actions are run through.
type CodeActionAutoApply ¶
type CodeActionAutoApply int
CodeActionAutoApply says when a command applies an action without showing the list.
const ( // AutoApplyNever always shows the list. AutoApplyNever CodeActionAutoApply = iota // AutoApplyIfSingle applies the only valid action. AutoApplyIfSingle // AutoApplyFirst applies the first valid action. AutoApplyFirst )
The auto apply modes, VS Code's CodeActionAutoApply.
type CodeActionFilter ¶
type CodeActionFilter struct {
// Include, when set, is the kind wanted: the actions of that kind and the kinds below it. Nil is every kind (the empty
// string includes every kind but wants the action to have one).
Include *string
// Excludes are kinds that are left out, unless Include is below them.
Excludes []string
// IncludeSourceActions lets the source kinds through, which are left out unless asked for.
IncludeSourceActions bool
// OnlyPreferred leaves out the actions that are not preferred.
OnlyPreferred bool
}
CodeActionFilter chooses among the kinds of action.
func (CodeActionFilter) Filters ¶
func (f CodeActionFilter) Filters(a CodeAction) bool
Filters tells whether the action passes the filter (VS Code's filtersAction).
func (CodeActionFilter) MayInclude ¶
func (f CodeActionFilter) MayInclude(provided string) bool
MayInclude tells whether a provider of the kind may answer actions the filter wants: the kind may be a subset or a superset of the kind filtered for (VS Code's mayIncludeActionsOfKind).
type CodeActionKinds ¶
type CodeActionKinds interface {
CodeActionKinds() []string
}
CodeActionKinds is implemented by a provider that knows the kinds of the actions it answers (the codeActionKinds of a language server): the registry asks only the providers that may answer the kind wanted.
type CodeActionProvider ¶
type CodeActionProvider interface {
ProvideCodeActions(ctx context.Context, doc Document, req CodeActionRequest) ([]CodeAction, error)
}
CodeActionProvider answers code action requests.
type CodeActionRequest ¶
type CodeActionRequest struct {
Range Range
Diagnostics []Diagnostic
// Only lists the kinds wanted; empty is all.
Only []string
// Automatic is true when the request is made by the editor itself (the light bulb) and not by the user.
Automatic bool
}
CodeActionRequest is what a code action provider is asked for.
type CodeActionResolver ¶
type CodeActionResolver interface {
// CanResolveAction tells whether ResolveCodeAction would ask the provider for the edit of the action.
CanResolveAction(a CodeAction) bool
// ResolveCodeAction returns the action with its edit.
ResolveCodeAction(ctx context.Context, a CodeAction) (CodeAction, error)
}
CodeActionResolver is a provider that leaves the edit of its actions to be asked for when one is applied (codeAction/resolve).
type CodeActionSet ¶
type CodeActionSet struct {
// All lists every action, the disabled ones too; Valid those that can be applied.
All, Valid []CodeAction
}
CodeActionSet is the answer of the providers, sorted as the list shows it (VS Code's ManagedCodeActionSet).
func NewCodeActionSet ¶
func NewCodeActionSet(actions []CodeAction) CodeActionSet
NewCodeActionSet sorts the actions and separates the valid ones from the disabled ones: the actions that fix a diagnostic come first, and within the two groups the preferred ones come first.
Ported from VS Code: codeAction.ts (ManagedCodeActionSet)
func (CodeActionSet) HasAutoFix ¶
func (s CodeActionSet) HasAutoFix() bool
HasAutoFix tells whether a valid action is a preferred quick fix (the light bulb is then the auto fix one).
type CodeActionSource ¶
type CodeActionSource string
CodeActionSource names what led to the request (VS Code's CodeActionTriggerSource); it is for the log and the tests.
const ( SourceDefault CodeActionSource = "other (default)" SourceLightbulb CodeActionSource = "lightbulb" SourceQuickFix CodeActionSource = "quick fix action" SourceRefactor CodeActionSource = "refactor" SourceRefactorPreview CodeActionSource = "refactor preview" SourceSourceAction CodeActionSource = "source action" SourceFixAll CodeActionSource = "fix all" SourceOrganizeImports CodeActionSource = "organize imports" SourceAutoFix CodeActionSource = "auto fix" SourceQuickFixHover CodeActionSource = "quick fix hover window" SourceOnSave CodeActionSource = "save participants" )
The sources of a request.
type CodeActionTrigger ¶
type CodeActionTrigger struct {
Type CodeActionTriggerType
Source CodeActionSource
Filter CodeActionFilter
// AutoApply is what the command does with the actions that came.
AutoApply CodeActionAutoApply
}
CodeActionTrigger says how the actions are asked for.
type CodeActionTriggerType ¶
type CodeActionTriggerType int
CodeActionTriggerType says who asked for the actions (LSP's CodeActionTriggerKind).
const ( // TriggerInvokedAction is the user asking (Ctrl+., Refactor..., Source Action...). TriggerInvokedAction CodeActionTriggerType = 1 // TriggerAutomatic is the editor asking by itself (the light bulb, the hover, the save participants). TriggerAutomatic CodeActionTriggerType = 2 )
The kinds of trigger.
type CodeLens ¶
type CodeLens struct {
// Range is the line, and the part of it, that the lens belongs to.
Range Range
// Command is what the lens shows and runs; nil while the lens is not resolved.
Command *Command
// Owner is the provider that made the lens: the id of a language server or of an extension.
Owner string
// contains filtered or unexported fields
}
CodeLens is a command shown above a line. Command is nil until the lens is resolved (CanResolveCodeLens, ResolveCodeLens).
type CodeLensProvider ¶
type CodeLensProvider interface {
ProvideCodeLenses(ctx context.Context, doc Document) ([]CodeLens, error)
}
CodeLensProvider answers the code lenses of a document.
type CodeLensResolver ¶
type CodeLensResolver interface {
// CanResolveCodeLens tells whether the provider resolves the lens.
CanResolveCodeLens(l CodeLens) bool
// ResolveCodeLens gives the lens with its command.
ResolveCodeLens(ctx context.Context, doc Document, l CodeLens) (CodeLens, error)
}
CodeLensResolver is a CodeLensProvider that answers lenses without their command and fills it in when the lens comes into view.
type Command ¶
type Command struct {
Title string
ID string
Arguments []json.RawMessage
Owner string
// Disabled says that the command is shown but cannot be run: a code lens shows its title dimmed and a click does nothing.
Disabled bool
}
Command is a command with its arguments. Owner says whose it is: the id of the language server (workspace/executeCommand) or of the extension (a command of the editor); empty for a command of the editor.
type CompletionItem ¶
type CompletionItem struct {
Label string
LabelDetail string
LabelDescription string
Detail string
Documentation *Markup
Kind CompletionKind
Deprecated bool
Preselect bool
SortText string
FilterText string
// InsertText is what is inserted, the label when empty; with Snippet it is a snippet.
InsertText string
Snippet bool
// KeepWhitespace inserts the text as it is, without fitting its indentation to the line (insertTextMode asIs).
KeepWhitespace bool
// Insert and Replace are the ranges the item replaces when it is inserted and when it replaces the word; both nil
// means the word before the cursor; only Insert set is the range of a plain edit.
Insert, Replace *Range
// AdditionalEdits are made with the insertion.
AdditionalEdits []TextEdit
CommitCharacters []string
Command *Command
// Owner is the provider that made the item: the id of a language server or of an extension.
Owner string
// IncompleteList is true when the list the item came in was incomplete: a request made again after more typing may give
// others.
IncompleteList bool
// contains filtered or unexported fields
}
CompletionItem is a row of the suggest widget.
func MergeResolvedCompletion ¶
func MergeResolvedCompletion(item, resolved CompletionItem) CompletionItem
MergeResolvedCompletion is the item with what its resolved copy has more: VS Code assigns the members the provider sent, and the ones a resolve can bring are the documentation, the detail, the additional edits and the command. The label, the text to insert and the ranges stay those of the list, which the sort and the insertion were worked out from.
func SnippetItems ¶
func SnippetItems(snippets []*snippet.Snippet, line string, pos Position, wordAt WordFunc, trigger CompletionTrigger) []CompletionItem
SnippetItems are the snippets that the text before the cursor asks for, as completion items: a snippet is offered when its prefix contains the characters typed since one of the places a prefix may start (a word start, or any character that is not part of a word), in order. A request for a trigger character only keeps the snippets whose prefix starts with it. When the character before the cursor is white space, or the line is empty, the snippets that did not match are offered too, so that a snippet can be found from the empty prefix. The edit of a snippet item starts where the matching text starts.
Ported from VS Code: src/vs/workbench/contrib/snippets/browser/snippetCompletionProvider.ts (provideCompletionItems, _computeSnippetPositions). The step that adds the name of a snippet to equal labels is left out: in VS Code it compares two objects with === and never does anything
func (CompletionItem) EffectiveInsertText ¶
func (it CompletionItem) EffectiveInsertText() string
EffectiveInsertText is the text an item inserts: its InsertText, else its label.
type CompletionKind ¶
type CompletionKind int
CompletionKind is the kind of a completion item; the numbers are the LSP's CompletionItemKind.
const SnippetKind CompletionKind = 15
SnippetKind is the completion kind of a snippet (CompletionItemKind.Snippet).
type CompletionList ¶
type CompletionList struct {
Items []CompletionItem
// Incomplete is true when a provider said its list was incomplete.
Incomplete bool
}
CompletionList is the items of a completion request.
func CompletionFromLSP ¶
func CompletionFromLSP(enc lsp.Encoding, doc Document, l lsp.CompletionList) CompletionList
CompletionFromLSP converts the answer to a completion request about the document. The defaults of the list (LSP 3.17 itemDefaults) are applied to the items.
type CompletionProvider ¶
type CompletionProvider interface {
ProvideCompletion(ctx context.Context, doc Document, pos Position, trigger CompletionTrigger) (CompletionList, error)
}
CompletionProvider answers completion requests.
type CompletionQuery ¶
type CompletionQuery struct {
// Owners, when not nil, are the only providers asked (by owner): the ones whose lists were incomplete, when a request is
// made again for them.
Owners map[string]bool
}
CompletionQuery narrows a completion request.
type CompletionResolver ¶
type CompletionResolver interface {
// CanResolve tells whether ResolveCompletion would ask the provider for more about the item.
CanResolve(item CompletionItem) bool
// ResolveCompletion returns the item with what the provider added; ctx ends when the user moves to another row.
ResolveCompletion(ctx context.Context, doc Document, item CompletionItem) (CompletionItem, error)
}
CompletionResolver is a completion provider that fills in the details of an item when it is focused (completionItem/resolve, SPEC §9.12 "Completion"): the documentation, the detail and the additional edits are left out of the list and asked for the one item the user is looking at.
type CompletionTrigger ¶
type CompletionTrigger struct {
Kind CompletionTriggerKind
Character string
}
CompletionTrigger is the context of a completion request.
type CompletionTriggerKind ¶
type CompletionTriggerKind int
CompletionTriggerKind says why completion was asked for.
const ( // TriggerInvoked is typing or the key for the suggest widget. TriggerInvoked CompletionTriggerKind = iota // TriggerCharacter is a trigger character of a provider that was typed. TriggerCharacter // TriggerIncomplete is the repetition of a request whose answer was incomplete. TriggerIncomplete )
The reasons a completion is asked for.
type Diagnostic ¶
type Diagnostic struct {
Range Range
Severity Severity
Message string
Source string
Code string
// CodeHref is a link that describes the code.
CodeHref string
// Unnecessary and Deprecated are the tags that fade and strike the text.
Unnecessary, Deprecated bool
// Raw is the diagnostic as the server sent it, to send back in the context of a code action request.
Raw json.RawMessage
}
Diagnostic is a problem of a document.
func DiagnosticsFromLSP ¶
func DiagnosticsFromLSP(enc lsp.Encoding, doc Document, ds []lsp.Diagnostic) []Diagnostic
DiagnosticsFromLSP converts the diagnostics a server published for the document (publishDiagnostics, or a pull report).
type Document ¶
Document is what a provider is asked about: an immutable snapshot of a document's text at one version. It is safe to use from any goroutine.
type DocumentHighlight ¶
type DocumentHighlight struct {
Range Range
Kind HighlightKind
}
DocumentHighlight is an occurrence of the symbol under the cursor.
func HighlightsFromLSP ¶
func HighlightsFromLSP(enc lsp.Encoding, doc Document, hs []lsp.DocumentHighlight) []DocumentHighlight
HighlightsFromLSP converts the answer to a document highlight request.
type DocumentSymbol ¶
type DocumentSymbol struct {
Name, Detail string
Kind int
Deprecated bool
Range Range
SelectionRange Range
Children []DocumentSymbol
Owner string
}
DocumentSymbol is a symbol of a document; Kind is the LSP's SymbolKind.
func SortSymbols ¶
func SortSymbols(symbols []DocumentSymbol, order SymbolSortOrder) []DocumentSymbol
SortSymbols returns a copy of the symbols in an order. The copy is shallow: the children of a symbol are not sorted.
func SymbolPathAt ¶
func SymbolPathAt(symbols []DocumentSymbol, pos Position, keep func(DocumentSymbol) bool) []*DocumentSymbol
SymbolPathAt is the chain of symbols that enclose a position, the outermost first: at each level the first symbol whose range holds the position, as VS Code's outline model finds the item at a position. A symbol the keep function refuses (a kind the settings leave out) is not in the chain, and its children are. keep may be nil.
func SymbolsFromLSP ¶
func SymbolsFromLSP(enc lsp.Encoding, doc Document, symbols lsp.DocumentSymbols) []DocumentSymbol
SymbolsFromLSP converts the answer to a document symbol request.
type EditHost ¶
type EditHost interface {
// Document returns the open document with the URI.
Document(uri document.URI) (*document.Document, bool)
// OpenForEdit opens a file that is not open as a document of the window, which stays open and so shows its changes as
// unsaved ones, as VS Code leaves the files a refactoring touched. The read may take a moment.
OpenForEdit(ctx context.Context, path string) (*document.Document, error)
// CreateFile creates an empty file, with the explorer's rules (a missing folder is made).
CreateFile(ctx context.Context, path string, opts FileOptions) error
// RenameFile moves a file or folder, with the explorer's rules; the open documents under it follow.
RenameFile(ctx context.Context, from, to string, opts FileOptions) error
// DeleteFile deletes a file or folder, by moving it to the trash like the explorer does.
DeleteFile(ctx context.Context, path string, opts FileOptions) error
}
EditHost is what a window offers to apply a WorkspaceEdit: its documents and its file operations (SPEC §9.12). All its methods are called on the goroutine that owns the documents.
type EditTracker ¶
type EditTracker interface {
BeginEdit() (end func())
}
EditTracker is an EditHost that wants to know when the changes of an edit start and end: the window keeps the cursors of its editors in their places in the text while the documents change. BeginEdit is called before the first change, on the goroutine that owns the documents, and the function it returns after the last (also after a failure).
type Feature ¶
type Feature int
Feature names a feature the editor asks whether a provider offers, for its context keys and the entries of its menus (VS Code's editorHasDefinitionProvider and its kin).
const ( FeatureDefinition Feature = iota FeatureDeclaration FeatureTypeDefinition FeatureImplementation FeatureReferences FeatureDocumentSymbols FeatureDocumentHighlights FeatureWorkspaceSymbols // FeatureCodeActions is textDocument/codeAction. FeatureCodeActions // FeatureFormatting is formatting the document, FeatureRangeFormatting formatting a range and FeatureOnTypeFormatting // formatting after a character was typed. FeatureFormatting FeatureRangeFormatting FeatureOnTypeFormatting // FeatureRename is rename (prepareRename is part of it). FeatureRename // FeatureCodeLens is textDocument/codeLens, FeatureInlayHints textDocument/inlayHint, FeatureSemanticTokens the semantic // tokens, FeatureFoldingRanges textDocument/foldingRange and FeatureSelectionRanges textDocument/selectionRange (step 12.9). FeatureCodeLens FeatureInlayHints FeatureSemanticTokens FeatureFoldingRanges FeatureSelectionRanges )
The features.
type FileOptions ¶
type FileOptions struct {
Overwrite, IgnoreIfExists, Recursive, IgnoreIfNotExists bool
}
FileOptions are the options of a file operation.
type FlatSymbol ¶
type FlatSymbol struct {
Symbol *DocumentSymbol
// Container is the names of the symbols above it joined with a dot ("Server.Start"), empty at the top.
Container string
// Depth is how many symbols are above it.
Depth int
}
FlatSymbol is a symbol of the flat list of the Go to Symbol picker.
func FlattenSymbols ¶
func FlattenSymbols(symbols []DocumentSymbol) []FlatSymbol
FlattenSymbols lists the symbols and the symbols inside them in the order of the document (a symbol before its children).
type FoldingProvider ¶
type FoldingProvider struct {
Registry *Registry
// Fallback finds the regions without a provider; it is also used for the strategy "indentation".
Fallback folding.Provider
// Limit is editor.foldingMaximumRegions.
Limit folding.Limit
// Strategy gives editor.foldingStrategy ("auto" or "indentation"); nil is "auto".
Strategy func() string
// Log is told of the providers that failed.
Log func(message string, err error)
}
FoldingProvider is the folding.Provider of a document whose language has folding range providers: it asks them, and the folding model gets their ranges; when none answers, or editor.foldingStrategy says "indentation", it is the Fallback (the provider by indentation and markers) that finds the regions. The document comes through the updater's Tag (folding.UpdaterOptions): a langfeatures.Document of the text that is being computed.
Ported from VS Code: src/vs/editor/contrib/folding/browser/syntaxRangeProvider.ts (SyntaxRangeProvider.compute: the fallback provider is used when all the providers return null) and folding.ts (the folding strategy)
type FoldingRange ¶
type FoldingRange struct {
StartLine, EndLine int
// Kind is "comment", "imports", "region" or empty.
Kind string
// CollapsedText is what the folded range shows after its first line instead of the ellipsis; empty for none.
CollapsedText string
}
FoldingRange is a range of lines a provider says can be folded: the first line stays visible, the lines up to EndLine are hidden. Lines are counted from 0.
func FoldingRangesFromLSP ¶
func FoldingRangesFromLSP(ranges []lsp.FoldingRange) []FoldingRange
FoldingRangesFromLSP converts the answer to a folding range request. Lines are lines in every position encoding. A null answer is nil, an empty list is empty: the first leaves the folding to the indentation, the second means there is nothing to fold.
type FoldingRangeProvider ¶
type FoldingRangeProvider interface {
ProvideFoldingRanges(ctx context.Context, doc Document) ([]FoldingRange, error)
}
FoldingRangeProvider answers the folding ranges of a document.
type FormattingOptions ¶
FormattingOptions are the options of a formatting request.
type FormattingProvider ¶
type FormattingProvider interface {
ProvideFormatting(ctx context.Context, doc Document, opts FormattingOptions) ([]TextEdit, error)
}
FormattingProvider formats a document. Range formatting is asked of a provider that also implements RangeFormattingProvider.
type HighlightKind ¶
type HighlightKind int
HighlightKind is the kind of a document highlight.
const ( HighlightText HighlightKind = iota HighlightRead HighlightWrite )
The kinds of highlight.
type HighlightProvider ¶
type HighlightProvider interface {
ProvideDocumentHighlights(ctx context.Context, doc Document, pos Position) ([]DocumentHighlight, error)
}
HighlightProvider answers the occurrences of the symbol under the cursor.
type HoverProvider ¶
type HoverProvider interface {
ProvideHover(ctx context.Context, doc Document, pos Position) (*Hover, error)
}
HoverProvider answers hover requests; a nil Hover is no answer.
type HoverResult ¶
HoverResult is the answer of one hover provider that has contents; Ordinal is the place of the provider in the order of the providers (0 is the first).
type InlayHint ¶
type InlayHint struct {
// Position is where the hint is shown, before the character at the position.
Position Position
// Parts is the label: one part for a plain label, several when the parts have tooltips, places or commands.
Parts []InlayHintPart
Kind InlayHintKind
// Tooltip is the tooltip of the hint as a whole.
Tooltip *Markup
// PaddingLeft and PaddingRight ask for room around the hint.
PaddingLeft, PaddingRight bool
// TextEdits are made when the hint is double clicked, in place of the hint's own commands.
TextEdits []TextEdit
// Owner is the provider that made the hint.
Owner string
// contains filtered or unexported fields
}
InlayHint is a label shown between two characters of the text (a parameter name, a type) that is not part of the text.
func InlayHintsFromLSP ¶
func InlayHintsFromLSP(ctx context.Context, enc lsp.Encoding, doc Document, texts TextSource, owner string, hints []lsp.InlayHint) []InlayHint
InlayHintsFromLSP converts the answer to an inlay hint request; owner is the id of the server, texts says how to read the text of the files that the labels point to.
type InlayHintKind ¶
type InlayHintKind int
InlayHintKind says what a hint is for; the numbers are the LSP's InlayHintKind.
const ( // InlayHintOther is a hint of no kind. InlayHintOther InlayHintKind = 0 // InlayHintType is the type of a variable, a return value or an expression. InlayHintType InlayHintKind = 1 // InlayHintParameter is the name of a parameter at a call. InlayHintParameter InlayHintKind = 2 )
The kinds of inlay hint.
type InlayHintPart ¶
InlayHintPart is a part of the label of an inlay hint, with a tooltip of its own and a place to go to or a command to run.
type InlayHintProvider ¶
type InlayHintProvider interface {
ProvideInlayHints(ctx context.Context, doc Document, r Range) ([]InlayHint, error)
}
InlayHintProvider answers the inlay hints of a range of a document.
type InlayHintResolver ¶
type InlayHintResolver interface {
// CanResolveInlayHint tells whether the provider resolves the hint.
CanResolveInlayHint(h InlayHint) bool
// ResolveInlayHint gives the hint with what the server left out.
ResolveInlayHint(ctx context.Context, doc Document, h InlayHint) (InlayHint, error)
}
InlayHintResolver is an InlayHintProvider that answers hints without their tooltips, places and commands and fills them in when the pointer rests on the hint.
type ItemFilter ¶
type ItemFilter struct {
// HiddenKinds are the kinds that are left out (editor.suggest.show<Kind> off, editor.snippetSuggestions none).
HiddenKinds map[CompletionKind]bool
// HideDeprecated leaves out the items tagged deprecated (editor.suggest.showDeprecated off).
HideDeprecated bool
}
ItemFilter says which items a request keeps (the kind filter and the deprecated ones).
type LineContext ¶
type LineContext struct {
// LeadingLine is the text of the line before the cursor.
LeadingLine string
// Delta is the number of bytes the cursor moved to the right since the request.
Delta int
}
LineContext is the text before the cursor and how far the cursor has moved since the request.
type LocationLink ¶
LocationLink is a location with the span of the symbol that led to it. Origin is nil when the provider did not say.
func LocationsFromLSP ¶
func LocationsFromLSP(ctx context.Context, enc lsp.Encoding, doc Document, texts TextSource, links lsp.LocationLinks) []LocationLink
LocationsFromLSP converts the links of a definition-like answer. Links the editor cannot open (another URI scheme) are left out.
type MemoryMode ¶
type MemoryMode string
MemoryMode is how the suggest widget chooses the item it focuses (editor.suggestSelection).
const ( // MemoryFirst focuses the first item, or the preselected one among the best. MemoryFirst MemoryMode = "first" // MemoryRecentlyUsed focuses the item of the best matches that was accepted last. MemoryRecentlyUsed MemoryMode = "recentlyUsed" // MemoryRecentlyUsedByPrefix focuses the item that was accepted last for the text typed before the cursor. MemoryRecentlyUsedByPrefix MemoryMode = "recentlyUsedByPrefix" )
The modes.
type NavKind ¶
type NavKind int
NavKind is the kind of navigation a location provider answers.
const ( )
The kinds of navigation.
type NavigationProvider ¶
type NavigationProvider interface {
}
NavigationProvider answers go to definition, declaration, type definition and implementation. A provider that does not know the kind answers nothing.
type OnTypeFormattingProvider ¶
type OnTypeFormattingProvider interface {
// OnTypeTriggers are the characters that ask for the formatting.
OnTypeTriggers() []string
ProvideOnTypeFormatting(ctx context.Context, doc Document, pos Position, ch string, opts FormattingOptions) ([]TextEdit, error)
}
OnTypeFormattingProvider formats the text around a position after a character was typed (textDocument/onTypeFormatting).
type Parameter ¶
type Parameter struct {
Label string
Documentation *Markup
// Offsets, when set, are the byte offsets of the parameter in the label of the signature (a server that sent the label as
// a pair of offsets); without them the parameter is found by its text.
Offsets *[2]int
}
Parameter is a parameter of a signature; Label is its text in the label of the signature.
type PrepareRename ¶
type PrepareRename struct {
Range Range
Placeholder string
// DefaultBehavior asks the editor to use the word at the position.
DefaultBehavior bool
}
PrepareRename is what a rename provider says about a position: the range to rename and the text to show.
type ProviderError ¶
ProviderError is the failure of one provider; the others' answers are used all the same (VS Code logs a provider that fails and goes on with the rest).
type Range ¶
Range is the text from Start up to End.
func ModifiedRanges ¶
ModifiedRanges are the ranges of lines of the text that differ from the base: the places that "modifications" mode formats. Deleted lines make no range. The base and the text are given by lines; a diff that runs over its time limit gives the whole text.
Ported from VS Code: src/vs/workbench/contrib/format/browser/formatModified.ts (getModifiedRanges)
type RangeFormattingProvider ¶
type RangeFormattingProvider interface {
ProvideRangeFormatting(ctx context.Context, doc Document, r Range, opts FormattingOptions) ([]TextEdit, error)
}
RangeFormattingProvider formats a range of a document.
type ReferenceProvider ¶
type ReferenceProvider interface {
ProvideReferences(ctx context.Context, doc Document, pos Position, includeDeclaration bool) ([]Location, error)
}
ReferenceProvider answers find all references.
type Registered ¶
type Registered[P any] struct { Owner string Provider P // Score is how well the document matched the selector. Score int // Triggers are the trigger characters the provider was registered with. Triggers []string }
Registered is a provider with the owner that registered it (the id of an extension, or of a language server).
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds the providers of every feature of one window tab (SPEC §9.12). It is safe for concurrent use. Register a provider with the Register methods and ask with the request methods (merge.go), which call the providers that match the document on goroutines of their own and merge their answers.
func (*Registry) CanResolveCodeAction ¶
func (r *Registry) CanResolveCodeAction(a CodeAction) bool
CanResolveCodeAction tells whether the provider that answered with the action can resolve its edit.
func (*Registry) CanResolveCodeLens ¶
CanResolveCodeLens tells whether the provider that answered with the lens can resolve it.
func (*Registry) CanResolveCompletion ¶
func (r *Registry) CanResolveCompletion(item CompletionItem) bool
CanResolveCompletion tells whether the provider that answered with the item can resolve it.
func (*Registry) CanResolveInlayHint ¶
CanResolveInlayHint tells whether the provider that answered with the hint can resolve it.
func (*Registry) CanResolveWorkspaceSymbol ¶
func (r *Registry) CanResolveWorkspaceSymbol(sym WorkspaceSymbol) bool
CanResolveWorkspaceSymbol tells whether the provider that answered with the symbol can resolve its range.
func (*Registry) Changed ¶
func (r *Registry) Changed()
Changed tells the listeners of OnChange that what the providers offer changed.
func (*Registry) CodeActionKinds ¶
CodeActionKinds lists the kinds of action the providers of the document say they answer, without duplicates (the context key supportedCodeAction is these joined by spaces).
func (*Registry) CodeActions ¶
func (r *Registry) CodeActions(ctx context.Context, doc Document, req CodeActionRequest) ([]CodeAction, []ProviderError)
CodeActions asks every code action provider and joins the actions in the order of the providers.
func (*Registry) CodeLenses ¶
CodeLenses asks every code lens provider of the document and joins the lenses, ordered by the place they belong to (a lens of an earlier provider first when two are on one line), without the lenses that are on no line.
func (*Registry) Completion ¶
func (r *Registry) Completion(ctx context.Context, doc Document, pos Position, trigger CompletionTrigger) (CompletionList, []ProviderError)
Completion asks the completion providers of the document. The providers of the best score are asked together; when they have no items and none of their lists is incomplete, the next score is asked (VS Code's groups); the items of the providers that answered are concatenated in the order of the providers, each marked with its provider. A request for a trigger character asks only the providers that have the character as a trigger (VS Code's providerFilter). Sorting is the suggest widget's.
func (*Registry) CompletionFor ¶
func (r *Registry) CompletionFor(ctx context.Context, doc Document, pos Position, trigger CompletionTrigger, q CompletionQuery) (CompletionList, []ProviderError)
CompletionFor is Completion limited by the query.
func (*Registry) CompletionTriggers ¶
CompletionTriggers are the trigger characters of the completion providers that match the document, without duplicates.
func (*Registry) DocumentHighlights ¶
func (r *Registry) DocumentHighlights(ctx context.Context, doc Document, pos Position) ([]DocumentHighlight, []ProviderError)
DocumentHighlights asks the highlight providers and takes the highlights of the first, in the order of the providers, that has any.
func (*Registry) DocumentSymbols ¶
func (r *Registry) DocumentSymbols(ctx context.Context, doc Document) ([]DocumentSymbol, []ProviderError)
DocumentSymbols asks the symbol providers and takes the symbols of the first, in the order of the providers, that has any.
func (*Registry) FoldingRanges ¶
func (r *Registry) FoldingRanges(ctx context.Context, doc Document) (ranges []folding.SyntaxRange, collapsed map[int]string, ok bool, errs []ProviderError)
FoldingRanges asks every folding range provider of the document. The answers of the providers that answered with a list, even an empty one, are joined as syntax ranges ranked by the order of the providers, and ok is true; it is false when no provider answered (none matches, or all failed or offer nothing), which is when the editor folds by indentation. Ranges that are not inside the document, that start after the first line or that are not at least two lines are left out.
func (*Registry) FormatDocument ¶
func (r *Registry) FormatDocument(ctx context.Context, doc Document, opts FormattingOptions, defaultFormatter string) ([]TextEdit, error)
FormatDocument formats the document with the formatter PickFormatter chooses. It fails with NoFormatter when the document has none; the formatter's own error is returned as it is. A formatter that only formats ranges formats the whole document as one range (VS Code's synthetic document formatter).
func (*Registry) FormatOnType ¶
func (r *Registry) FormatOnType(ctx context.Context, doc Document, pos Position, ch string, opts FormattingOptions) ([]TextEdit, error)
FormatOnType asks the first provider that has the character as a trigger for the edits and returns the first non-empty answer (VS Code asks the first provider of the order).
func (*Registry) FormatRange ¶
func (r *Registry) FormatRange(ctx context.Context, doc Document, rng Range, opts FormattingOptions, defaultFormatter string) ([]TextEdit, error)
FormatRange formats a range of the document with the formatter PickFormatter chooses among those that format ranges. It fails with NoFormatter when the document has none.
func (*Registry) Formatters ¶
func (r *Registry) Formatters(doc Document) []Registered[FormattingProvider]
Formatters lists the formatters of the document in the order of the providers: those that format a document, or, as VS Code does, only a range (they format the whole document as a range).
func (*Registry) GetCodeActions ¶
func (r *Registry) GetCodeActions(ctx context.Context, doc Document, req CodeActionRequest, trig CodeActionTrigger) (CodeActionSet, []ProviderError)
GetCodeActions asks the providers of the document for the actions the trigger wants, filters them and sorts them. The request carries the kinds wanted (`only`) when the filter names one. Providers that say which kinds they answer are not asked for others.
Ported from VS Code: codeAction.ts (getCodeActions)
func (*Registry) Has ¶
Has tells whether a provider that matches the document offers the feature (the key editorHasDefinitionProvider and its kin).
func (*Registry) HasCompletion ¶
HasCompletion tells whether a completion provider matches the document.
func (*Registry) HasSignatureHelp ¶
HasSignatureHelp tells whether a signature help provider matches the document (the key editorHasSignatureHelpProvider).
func (*Registry) Hover ¶
func (r *Registry) Hover(ctx context.Context, doc Document, pos Position) ([]Hover, []ProviderError)
Hover asks every hover provider of the document; the answers that have contents are stacked in the order of the providers (VS Code orders them by provider and shows them one under the other).
func (*Registry) HoverEach ¶
func (r *Registry) HoverEach(ctx context.Context, doc Document, pos Position, each func(HoverResult)) []ProviderError
HoverEach asks every hover provider of the document and calls each with the answer of a provider as soon as it comes, in the order the providers answer (VS Code shows the hovers as the providers resolve); an answer without contents is not reported. Calls of each never overlap, and each runs on the goroutine of the provider that answered, so it must hand the result over to where it is used. HoverEach returns when every provider has answered or ctx has ended.
func (*Registry) InlayHints ¶
func (r *Registry) InlayHints(ctx context.Context, doc Document, rng Range) ([]InlayHint, []ProviderError)
InlayHints asks every inlay hint provider of the document for the hints of a range and joins them, ordered by position (the hints of an earlier provider first at one place), without the hints whose label is empty.
func (*Registry) Locations ¶
func (r *Registry) Locations(ctx context.Context, doc Document, pos Position, kind NavKind) ([]LocationLink, []ProviderError)
Locations asks every navigation provider for a kind of location (definition, declaration, type definition, implementation) and joins the answers, in the order of the providers, without the same place twice.
func (*Registry) OnChange ¶
func (r *Registry) OnChange(fn func()) (stop func())
OnChange calls fn when what the providers offer changed without a registration changing: a language server that started or stopped (Changed). The editors ask for the symbols and the highlights again then. fn runs on the goroutine that called Changed. The function that stops the listener is returned.
func (*Registry) OnRefresh ¶
OnRefresh calls fn when a language server asks for one kind of its answers to be asked for again (the refresh requests of semantic tokens, code lenses and inlay hints): the feature says which. fn runs on the goroutine that called Refreshed. The function that stops the listener is returned.
func (*Registry) OnTypeFormattingTriggers ¶
OnTypeFormattingTriggers are the characters that ask for formatting after they are typed, of the providers that match the document, without duplicates.
func (*Registry) PickFormatter ¶
func (r *Registry) PickFormatter(doc Document, defaultFormatter string) (reg Registered[FormattingProvider], others int, ok bool)
PickFormatter chooses the formatter for the document: the one registered by defaultFormatter (editor.defaultFormatter, the id of an extension) when there is one, else the first of the order. ok is false when the document has no formatter; others says how many more there are, which a caller may tell the user (VS Code asks them to choose a default).
func (*Registry) PrepareRename ¶
func (r *Registry) PrepareRename(ctx context.Context, doc Document, pos Position) (*PrepareRename, error)
PrepareRename asks the rename providers in order and answers with the first that has an answer; an error of a provider is a refusal and is returned as it is.
func (*Registry) References ¶
func (r *Registry) References(ctx context.Context, doc Document, pos Position, includeDeclaration bool) ([]Location, []ProviderError)
References asks every references provider and joins the answers without the same place twice.
func (*Registry) Refreshed ¶
Refreshed tells the listeners of OnRefresh that the answers of a feature are stale.
func (*Registry) RegisterCodeActions ¶
func (r *Registry) RegisterCodeActions(owner string, sel Selector, p CodeActionProvider) (remove func())
RegisterCodeActions adds a code action provider.
func (*Registry) RegisterCodeLens ¶
func (r *Registry) RegisterCodeLens(owner string, sel Selector, p CodeLensProvider) (remove func())
RegisterCodeLens adds a code lens provider.
func (*Registry) RegisterCompletion ¶
func (r *Registry) RegisterCompletion(owner string, sel Selector, p CompletionProvider, triggers ...string) (remove func())
RegisterCompletion adds a completion provider; triggers are the characters that start a request when typed.
func (*Registry) RegisterFoldingRanges ¶
func (r *Registry) RegisterFoldingRanges(owner string, sel Selector, p FoldingRangeProvider) (remove func())
RegisterFoldingRanges adds a folding range provider.
func (*Registry) RegisterFormatting ¶
func (r *Registry) RegisterFormatting(owner string, sel Selector, p FormattingProvider) (remove func())
RegisterFormatting adds a formatter.
func (*Registry) RegisterHighlights ¶
func (r *Registry) RegisterHighlights(owner string, sel Selector, p HighlightProvider) (remove func())
RegisterHighlights adds a provider of document highlights.
func (*Registry) RegisterHover ¶
func (r *Registry) RegisterHover(owner string, sel Selector, p HoverProvider) (remove func())
RegisterHover adds a hover provider.
func (*Registry) RegisterInlayHints ¶
func (r *Registry) RegisterInlayHints(owner string, sel Selector, p InlayHintProvider) (remove func())
RegisterInlayHints adds an inlay hint provider.
func (*Registry) RegisterNavigation ¶
func (r *Registry) RegisterNavigation(owner string, sel Selector, p NavigationProvider) (remove func())
RegisterNavigation adds a provider of definitions and its kin.
func (*Registry) RegisterOnTypeFormatting ¶
func (r *Registry) RegisterOnTypeFormatting(owner string, sel Selector, p OnTypeFormattingProvider) (remove func())
RegisterOnTypeFormatting adds a provider of the formatting that follows a typed character.
func (*Registry) RegisterReferences ¶
func (r *Registry) RegisterReferences(owner string, sel Selector, p ReferenceProvider) (remove func())
RegisterReferences adds a references provider.
func (*Registry) RegisterRename ¶
func (r *Registry) RegisterRename(owner string, sel Selector, p RenameProvider) (remove func())
RegisterRename adds a rename provider.
func (*Registry) RegisterSelectionRanges ¶
func (r *Registry) RegisterSelectionRanges(owner string, sel Selector, p SelectionRangeProvider) (remove func())
RegisterSelectionRanges adds a selection range provider.
func (*Registry) RegisterSemanticTokens ¶
func (r *Registry) RegisterSemanticTokens(owner string, sel Selector, p SemanticTokensProvider) (remove func())
RegisterSemanticTokens adds a semantic tokens provider.
func (*Registry) RegisterSignatureHelp ¶
func (r *Registry) RegisterSignatureHelp(owner string, sel Selector, p SignatureHelpProvider, triggers ...string) (remove func())
RegisterSignatureHelp adds a signature help provider; triggers start a request when typed.
func (*Registry) RegisterSymbols ¶
func (r *Registry) RegisterSymbols(owner string, sel Selector, p SymbolProvider) (remove func())
RegisterSymbols adds a provider of the symbols of a document.
func (*Registry) RegisterWorkspaceSymbols ¶
func (r *Registry) RegisterWorkspaceSymbols(owner string, p WorkspaceSymbolProvider) (remove func())
RegisterWorkspaceSymbols adds a provider of the symbols of the workspace. It has no selector: it is asked whatever document is open.
func (*Registry) Rename ¶
func (r *Registry) Rename(ctx context.Context, doc Document, pos Position, newName string) (*WorkspaceEdit, error)
Rename asks the rename providers in order and answers with the edit of the first that has one.
func (*Registry) ResolveCodeAction ¶
func (r *Registry) ResolveCodeAction(ctx context.Context, a CodeAction) (CodeAction, error)
ResolveCodeAction asks the provider that answered with the action for its edit, when it has none and the provider can resolve it (VS Code's CodeActionItem.resolve); the action is returned as it was otherwise.
func (*Registry) ResolveCodeLens ¶
ResolveCodeLens asks the provider that answered with the lens for its command. A lens that has its command, or whose provider cannot resolve it, is returned as it was.
func (*Registry) ResolveCompletion ¶
func (r *Registry) ResolveCompletion(ctx context.Context, doc Document, item CompletionItem) (CompletionItem, error)
ResolveCompletion asks the provider that answered with the item for the rest of it. An item whose provider cannot resolve is returned as it is. The error is the provider's.
func (*Registry) ResolveInlayHint ¶
func (r *Registry) ResolveInlayHint(ctx context.Context, doc Document, h InlayHint) (InlayHint, error)
ResolveInlayHint asks the provider that answered with the hint for what it left out. A hint whose provider cannot resolve it is returned as it was.
func (*Registry) ResolveWorkspaceSymbol ¶
func (r *Registry) ResolveWorkspaceSymbol(ctx context.Context, sym WorkspaceSymbol) (WorkspaceSymbol, error)
ResolveWorkspaceSymbol asks the provider that answered with the symbol for its range. A symbol that has one, or whose provider cannot resolve, is returned as it is.
func (*Registry) SelectionRanges ¶
func (r *Registry) SelectionRanges(ctx context.Context, doc Document, positions []Position) (SelectionRangeSet, bool, []ProviderError)
SelectionRanges asks every selection range provider of the document and joins their ranges for each position (sorted and made into steps by edit.ProvideSelectionRanges). ok is false when no provider matches the document.
func (*Registry) SemanticTokensProviderFor ¶
func (r *Registry) SemanticTokensProviderFor(doc Document) SemanticTokensProvider
SemanticTokensProviderFor is the provider of the semantic tokens of the document: the first, in the order of the providers, that offers them (VS Code asks the best provider only); nil when there is none.
func (*Registry) SignatureCharacters ¶
SignatureCharacters are the characters that start signature help and those that start it again while it shows, of the providers that match the document, without duplicates. Every trigger character is a retrigger character too (VS Code's parameter hints model); a provider that does not tell them apart (SignatureTriggers) has trigger characters only.
func (*Registry) SignatureHelp ¶
func (r *Registry) SignatureHelp(ctx context.Context, doc Document, pos Position, sc SignatureContext) (*SignatureHelp, []ProviderError)
SignatureHelp asks the signature help providers and takes the answer of the first, in the order of the providers, that has signatures.
func (*Registry) SignatureTriggers ¶
SignatureTriggers are the trigger characters of the signature help providers that match the document.
func (*Registry) SupportsCodeActionKind ¶
SupportsCodeActionKind tells whether a provider of the document may answer actions of the kind (the keys of Refactor..., Source Action... and Organize Imports: VS Code's contextKeyForSupportedActions).
func (*Registry) WorkspaceSymbols ¶
func (r *Registry) WorkspaceSymbols(ctx context.Context, query string) ([]WorkspaceSymbol, []ProviderError)
WorkspaceSymbols asks every workspace symbol provider for the symbols that match the query and joins the answers in the order of the providers.
type RenameProvider ¶
type RenameProvider interface {
PrepareRename(ctx context.Context, doc Document, pos Position) (*PrepareRename, error)
ProvideRename(ctx context.Context, doc Document, pos Position, newName string) (*WorkspaceEdit, error)
}
RenameProvider answers rename: PrepareRename may answer nil (use the word at the position) and refuses with an error; ProvideRename answers the edit.
type SelectionRangeProvider ¶
type SelectionRangeProvider interface {
ProvideSelectionRanges(ctx context.Context, doc Document, positions []Position) ([][]Range, error)
}
SelectionRangeProvider answers, for positions of a document, the ranges around each, from the smallest to the largest.
type SelectionRangeSet ¶
type SelectionRangeSet struct {
// contains filtered or unexported fields
}
SelectionRangeSet is the selection ranges the providers gave for some positions. It is an edit.SelectionRangeProvider for those positions, so that Expand Selection steps through the ranges of the providers and the word, bracket and line ranges together.
func (SelectionRangeSet) Positions ¶
func (s SelectionRangeSet) Positions() []Position
Positions are the positions the set was asked for.
func (SelectionRangeSet) SelectionRanges ¶
func (s SelectionRangeSet) SelectionRanges(_ edit.Model, positions []buffer.Position) [][]buffer.Range
SelectionRanges implements edit.SelectionRangeProvider: for a position the set was asked about, its ranges; none for others.
type Selector ¶
type Selector struct {
Languages []string
Pattern string
Schemes []string
// Folder is the folder a relative Pattern is matched from.
Folder string
}
Selector says which documents a provider is for (SPEC §9.12): a document matches when its language is one of Languages or its path matches Pattern (a VS Code glob over the whole path or over the path relative to Folder), and, when Schemes is not empty, its scheme is one of them. A selector with neither a language nor a pattern matches every document.
type SemanticEdit ¶
SemanticEdit replaces DeleteCount numbers of the data of the previous result from Start with Data.
type SemanticLegend ¶
type SemanticLegend struct {
Types, Modifiers []string
}
SemanticLegend names the token types and the token modifiers that the numbers of the tokens index: a token's type is an index of Types and its modifiers are the bits of a number, bit n for Modifiers[n].
type SemanticRangeProvider ¶
type SemanticRangeProvider interface {
SemanticTokensProvider
// ProvideSemanticTokensRange answers the tokens of a range, as data relative to the start of the document.
ProvideSemanticTokensRange(ctx context.Context, doc Document, r Range) (*SemanticUpdate, error)
}
SemanticRangeProvider is a SemanticTokensProvider that also answers the tokens of a range of the document.
type SemanticToken ¶
type SemanticToken struct {
Line, Col, Len int
// Type is the index of the type in the legend, Modifiers the set of modifier bits.
Type int
Modifiers uint32
}
SemanticToken is a token with an absolute place: a run of Len bytes at the column Col of a line, of a type and modifiers named by the legend.
func DecodeSemanticTokens ¶
DecodeSemanticTokens turns the data of the protocol into tokens with absolute lines and byte columns of the text. A token of no length, one that starts before the end of the one before it, and one on a line the text does not have are left out (VS Code warns about them and draws the rest). The columns of the data count in the encoding.
type SemanticTokens ¶
type SemanticTokens struct {
// Version is the version of the document the tokens were made for.
Version int
Legend SemanticLegend
Tokens []SemanticToken
// Range is true for the tokens of a part of the document, asked while the whole was not known.
Range bool
}
SemanticTokens are the tokens of a document at a version, in the order of the text.
func (*SemanticTokens) ModifierNames ¶
func (t *SemanticTokens) ModifierNames(tok SemanticToken) []string
ModifierNames are the names of the modifiers of a token that the legend has.
func (*SemanticTokens) OnLine ¶
func (t *SemanticTokens) OnLine(line int) []SemanticToken
OnLine gives the tokens of a line, which are sorted by column.
func (*SemanticTokens) TypeName ¶
func (t *SemanticTokens) TypeName(tok SemanticToken) string
TypeName is the name of the type of a token in the legend, or "" when the legend does not have it.
type SemanticTokensCache ¶
type SemanticTokensCache struct {
// contains filtered or unexported fields
}
SemanticTokensCache shares the semantic tokens of the documents of the window between the editors that show them. It keeps, for each document, the data and the result ID of the latest answer so that the next request is a delta request when the provider supports it, and the tokens decoded for the latest version asked for. It is safe for concurrent use.
func NewSemanticTokensCache ¶
func NewSemanticTokensCache(reg *Registry) *SemanticTokensCache
NewSemanticTokensCache makes the cache of a registry.
func (*SemanticTokensCache) Forget ¶
func (c *SemanticTokensCache) Forget(uri document.URI)
Forget drops what the cache knows of a document.
func (*SemanticTokensCache) Get ¶
func (c *SemanticTokensCache) Get(ctx context.Context, doc Document) (*SemanticTokens, error)
Get gives the tokens of the document at its version, asking the provider when the cache does not have them: with the previous result ID when it has one (the provider may answer with edits). It gives nil when no provider has semantic tokens for the document. A request waits for the one before it; ctx ends the wait and the request.
func (*SemanticTokensCache) GetRange ¶
func (c *SemanticTokensCache) GetRange(ctx context.Context, doc Document, r Range) (*SemanticTokens, error)
GetRange gives the tokens of a range of the document, from a provider that answers ranges; nil when none does. They are not kept: a range is asked for while the tokens of the whole document are not known yet (VS Code does so for the first view of a document).
func (*SemanticTokensCache) Refresh ¶
func (c *SemanticTokensCache) Refresh()
Refresh tells the cache that the server wants the tokens asked for again (workspace/semanticTokens/refresh): the tokens it holds are stale, but the data stays, to be the base of the next delta.
type SemanticTokensProvider ¶
type SemanticTokensProvider interface {
// SemanticLegend is the legend of the tokens the provider answers.
SemanticLegend() SemanticLegend
// ProvideSemanticTokens answers all the tokens; with a previous result ID the provider may answer the edits since that
// result. It answers nil when it has no tokens.
ProvideSemanticTokens(ctx context.Context, doc Document, previousResultID string) (*SemanticUpdate, error)
}
SemanticTokensProvider answers the semantic tokens of a document.
type SemanticUpdate ¶
type SemanticUpdate struct {
// ResultID is what the next request gives back as the previous result, empty when the provider does not do deltas.
ResultID string
Delta bool
Data []uint32
Edits []SemanticEdit
// Encoding is the position encoding of the columns in the data.
Encoding lsp.Encoding
}
SemanticUpdate is the answer of a provider: the whole data (Delta false), or the edits that turn the data of the previous result into the new one (Delta true).
type Server ¶
type Server interface {
// Call sends a request and decodes its result.
Call(ctx context.Context, method string, params, result any) error
// Capabilities are the capabilities the server returned from initialize.
Capabilities() lsp.ServerCapabilities
// Encoding is the position encoding negotiated with the server.
Encoding() lsp.Encoding
// Registered lists the dynamic registrations of a method.
Registered(method string) []lsp.Registration
}
Server is the part of an lsp.Client that a ServerProvider uses; *lsp.Client is one.
type ServerProvider ¶
type ServerProvider struct {
// Name is the id of the server; the commands of its code actions are run through it.
Name string
// Client gives the client of the server, or nil while there is none. It is called from the goroutines of the requests.
Client func() Server
// Texts gives the text of the other documents that answers refer to; see TextSource.
Texts TextSource
}
ServerProvider answers the feature requests of the documents with a language server (SPEC §9.12). One value implements every provider interface of this package; Register adds it to a registry. The server is asked for the current client at each request, so a server that restarts keeps its registration, and a request while there is no client (starting, crashed) answers nothing. A feature the server does not offer (neither in its capabilities nor by registration) answers nothing without asking.
func (*ServerProvider) CanResolve ¶
func (sp *ServerProvider) CanResolve(item CompletionItem) bool
CanResolve implements CompletionResolver: the server offers completionItem/resolve and sent the item.
func (*ServerProvider) CanResolveAction ¶
func (sp *ServerProvider) CanResolveAction(a CodeAction) bool
CanResolveAction implements CodeActionResolver: the server offers codeAction/resolve and sent the action.
func (*ServerProvider) CanResolveCodeLens ¶
func (sp *ServerProvider) CanResolveCodeLens(l CodeLens) bool
CanResolveCodeLens implements CodeLensResolver: the server offers codeLens/resolve and sent the lens.
func (*ServerProvider) CanResolveInlayHint ¶
func (sp *ServerProvider) CanResolveInlayHint(h InlayHint) bool
CanResolveInlayHint implements InlayHintResolver: the server offers inlayHint/resolve and sent the hint.
func (*ServerProvider) CanResolveSymbol ¶
func (sp *ServerProvider) CanResolveSymbol(sym WorkspaceSymbol) bool
CanResolveSymbol implements WorkspaceSymbolResolver: the server offers workspaceSymbol/resolve and sent the symbol.
func (*ServerProvider) CodeActionKinds ¶
func (sp *ServerProvider) CodeActionKinds() []string
CodeActionKinds implements CodeActionKinds: the kinds the server declared in its capabilities, and those it declared when it registered the feature (client/registerCapability): Eclipse JDT LS announces its kinds, source.organizeImports among them, only that way, and without them Shift+Alt+O and the Source Action menu stay off for its files.
func (*ServerProvider) CompletionTriggers ¶
func (sp *ServerProvider) CompletionTriggers() []string
CompletionTriggers are the trigger characters the server declared; none while there is no server.
func (*ServerProvider) ExecuteCommand ¶
func (sp *ServerProvider) ExecuteCommand(ctx context.Context, cmd Command) error
ExecuteCommand runs a command of the server (workspace/executeCommand), for the command of a completion item or a code action. It does nothing while there is no server.
func (*ServerProvider) Offers ¶
func (sp *ServerProvider) Offers(f Feature) bool
Offers implements featureOffers: whether the server offers a feature, by its capabilities or a registration. The editor asks it for the keys editorHasDefinitionProvider and its kin, so a server that cannot find references does not enable Go to References.
func (*ServerProvider) OnTypeTriggers ¶
func (sp *ServerProvider) OnTypeTriggers() []string
OnTypeTriggers implements OnTypeFormattingProvider: the first trigger character the server declared and the others.
func (*ServerProvider) PrepareRename ¶
func (sp *ServerProvider) PrepareRename(ctx context.Context, doc Document, pos Position) (*PrepareRename, error)
PrepareRename implements RenameProvider. A server that cannot prepare answers nil, which asks the editor to use the word at the position; a server that refuses (null) gives the error NotRenameable.
func (*ServerProvider) ProvideCodeActions ¶
func (sp *ServerProvider) ProvideCodeActions(ctx context.Context, doc Document, req CodeActionRequest) ([]CodeAction, error)
ProvideCodeActions implements CodeActionProvider.
func (*ServerProvider) ProvideCodeLenses ¶
ProvideCodeLenses implements CodeLensProvider.
func (*ServerProvider) ProvideCompletion ¶
func (sp *ServerProvider) ProvideCompletion(ctx context.Context, doc Document, pos Position, trigger CompletionTrigger) (CompletionList, error)
ProvideCompletion implements CompletionProvider.
func (*ServerProvider) ProvideDocumentHighlights ¶
func (sp *ServerProvider) ProvideDocumentHighlights(ctx context.Context, doc Document, pos Position) ([]DocumentHighlight, error)
ProvideDocumentHighlights implements HighlightProvider.
func (*ServerProvider) ProvideDocumentSymbols ¶
func (sp *ServerProvider) ProvideDocumentSymbols(ctx context.Context, doc Document) ([]DocumentSymbol, error)
ProvideDocumentSymbols implements SymbolProvider.
func (*ServerProvider) ProvideFoldingRanges ¶
func (sp *ServerProvider) ProvideFoldingRanges(ctx context.Context, doc Document) ([]FoldingRange, error)
ProvideFoldingRanges implements FoldingRangeProvider.
func (*ServerProvider) ProvideFormatting ¶
func (sp *ServerProvider) ProvideFormatting(ctx context.Context, doc Document, opts FormattingOptions) ([]TextEdit, error)
ProvideFormatting implements FormattingProvider.
func (*ServerProvider) ProvideHover ¶
func (sp *ServerProvider) ProvideHover(ctx context.Context, doc Document, pos Position) (*Hover, error)
ProvideHover implements HoverProvider.
func (*ServerProvider) ProvideInlayHints ¶
func (sp *ServerProvider) ProvideInlayHints(ctx context.Context, doc Document, r Range) ([]InlayHint, error)
ProvideInlayHints implements InlayHintProvider.
func (*ServerProvider) ProvideLocations ¶
func (sp *ServerProvider) ProvideLocations(ctx context.Context, doc Document, pos Position, kind NavKind) ([]LocationLink, error)
ProvideLocations implements NavigationProvider.
func (*ServerProvider) ProvideOnTypeFormatting ¶
func (sp *ServerProvider) ProvideOnTypeFormatting(ctx context.Context, doc Document, pos Position, ch string, opts FormattingOptions) ([]TextEdit, error)
ProvideOnTypeFormatting implements OnTypeFormattingProvider.
func (*ServerProvider) ProvideRangeFormatting ¶
func (sp *ServerProvider) ProvideRangeFormatting(ctx context.Context, doc Document, r Range, opts FormattingOptions) ([]TextEdit, error)
ProvideRangeFormatting implements RangeFormattingProvider.
func (*ServerProvider) ProvideReferences ¶
func (sp *ServerProvider) ProvideReferences(ctx context.Context, doc Document, pos Position, includeDeclaration bool) ([]Location, error)
ProvideReferences implements ReferenceProvider.
func (*ServerProvider) ProvideRename ¶
func (sp *ServerProvider) ProvideRename(ctx context.Context, doc Document, pos Position, newName string) (*WorkspaceEdit, error)
ProvideRename implements RenameProvider.
func (*ServerProvider) ProvideSelectionRanges ¶
func (sp *ServerProvider) ProvideSelectionRanges(ctx context.Context, doc Document, positions []Position) ([][]Range, error)
ProvideSelectionRanges implements SelectionRangeProvider.
func (*ServerProvider) ProvideSemanticTokens ¶
func (sp *ServerProvider) ProvideSemanticTokens(ctx context.Context, doc Document, previousResultID string) (*SemanticUpdate, error)
ProvideSemanticTokens implements SemanticTokensProvider: a delta request when the server does deltas and there is a previous result, else a full one.
func (*ServerProvider) ProvideSemanticTokensRange ¶
func (sp *ServerProvider) ProvideSemanticTokensRange(ctx context.Context, doc Document, r Range) (*SemanticUpdate, error)
ProvideSemanticTokensRange implements SemanticRangeProvider; the server must offer range requests.
func (*ServerProvider) ProvideSignatureHelp ¶
func (sp *ServerProvider) ProvideSignatureHelp(ctx context.Context, doc Document, pos Position, sc SignatureContext) (*SignatureHelp, error)
ProvideSignatureHelp implements SignatureHelpProvider.
func (*ServerProvider) ProvideWorkspaceSymbols ¶
func (sp *ServerProvider) ProvideWorkspaceSymbols(ctx context.Context, query string) ([]WorkspaceSymbol, error)
ProvideWorkspaceSymbols implements WorkspaceSymbolProvider (workspace/symbol). A symbol whose location has no range is left for workspaceSymbol/resolve (ResolveWorkspaceSymbol).
func (*ServerProvider) Register ¶
func (sp *ServerProvider) Register(r *Registry, owner string, sel Selector) (remove func())
Register adds the provider for every feature to the registry, for the documents the selector matches, under the owner (the id of the extension), and returns the function that removes them all. The characters that trigger completion and signature help are those the server declared: the registry asks the provider for them (CompletionTriggers and SignatureTriggers) when it is asked, so they are right once the server is up.
func (*ServerProvider) ResolveCodeAction ¶
func (sp *ServerProvider) ResolveCodeAction(ctx context.Context, a CodeAction) (CodeAction, error)
ResolveCodeAction implements CodeActionResolver: the action goes back to the server, which fills in its edit.
func (*ServerProvider) ResolveCodeLens ¶
func (sp *ServerProvider) ResolveCodeLens(ctx context.Context, doc Document, l CodeLens) (CodeLens, error)
ResolveCodeLens implements CodeLensResolver: the lens goes back to the server, which fills in its command.
func (*ServerProvider) ResolveCompletion ¶
func (sp *ServerProvider) ResolveCompletion(ctx context.Context, doc Document, item CompletionItem) (CompletionItem, error)
ResolveCompletion implements CompletionResolver: the item goes back to the server, which fills in its documentation, its detail and its additional edits. The item is returned as it was when the server cannot resolve it.
func (*ServerProvider) ResolveInlayHint ¶
func (sp *ServerProvider) ResolveInlayHint(ctx context.Context, doc Document, h InlayHint) (InlayHint, error)
ResolveInlayHint implements InlayHintResolver: the hint goes back to the server, which fills in its tooltips, places and commands.
func (*ServerProvider) ResolveWorkspaceSymbol ¶
func (sp *ServerProvider) ResolveWorkspaceSymbol(ctx context.Context, sym WorkspaceSymbol) (WorkspaceSymbol, error)
ResolveWorkspaceSymbol implements WorkspaceSymbolResolver: the symbol goes back to the server, which fills in the range.
func (*ServerProvider) SemanticLegend ¶
func (sp *ServerProvider) SemanticLegend() SemanticLegend
SemanticLegend implements SemanticTokensProvider: the legend the server declared.
func (*ServerProvider) SignatureCharacters ¶
func (sp *ServerProvider) SignatureCharacters() (triggers, retriggers []string)
SignatureCharacters are the trigger characters and the retrigger characters the server declared for signature help; none while there is no server.
func (*ServerProvider) SignatureTriggers ¶
func (sp *ServerProvider) SignatureTriggers() []string
SignatureTriggers are the trigger and retrigger characters the server declared for signature help.
type Signature ¶
type Signature struct {
Label string
Documentation *Markup
Parameters []Parameter
ActiveParameter *int
}
Signature is a signature of a function.
func (Signature) LabelRange ¶
LabelRange is where a parameter is in the label of a signature, as byte offsets: the offsets the provider gave, else the first place the text of the parameter stands as a word of its own (VS Code's rule: after a non-word character or the start, before one or the end). It is empty when the parameter is not found.
Ported from VS Code: src/vs/editor/contrib/parameterHints/browser/parameterHintsWidget.ts (getParameterLabelOffsets)
type SignatureContext ¶
type SignatureContext struct {
// Kind is why the help is asked for; zero is SignatureTriggerCharacter when Character is set, else SignatureInvoke.
Kind SignatureTrigger
// Character is the character that was typed, for a SignatureTriggerCharacter.
Character string
// IsRetrigger says that the help was showing, or being asked for, when this request was made.
IsRetrigger bool
// Active is the help that showed when the request was made (nil when none did).
Active *SignatureHelp
}
SignatureContext is the context of a signature help request.
type SignatureHelp ¶
type SignatureHelp struct {
Signatures []Signature
ActiveSignature int
ActiveParameter int
Owner string
// contains filtered or unexported fields
}
SignatureHelp is the signatures at a position with the active one.
func SignatureHelpFromLSP ¶
func SignatureHelpFromLSP(h *lsp.SignatureHelp) *SignatureHelp
SignatureHelpFromLSP converts the answer to a signature help request.
type SignatureHelpProvider ¶
type SignatureHelpProvider interface {
ProvideSignatureHelp(ctx context.Context, doc Document, pos Position, sc SignatureContext) (*SignatureHelp, error)
}
SignatureHelpProvider answers signature help requests; nil is no answer.
type SignatureTrigger ¶
type SignatureTrigger int
SignatureTrigger says why signature help is asked for (VS Code's SignatureHelpTriggerKind, LSP's numbers).
const ( // SignatureInvoke: the user asked (Ctrl+Shift+Space). SignatureInvoke SignatureTrigger = 1 // SignatureTriggerCharacter: a trigger or retrigger character was typed. SignatureTriggerCharacter SignatureTrigger = 2 // SignatureContentChange: the cursor or the text changed while the help showed. SignatureContentChange SignatureTrigger = 3 )
The reasons signature help is asked for.
type SnippetOrder ¶
type SnippetOrder int
SnippetOrder says where snippets stand among the items (editor.snippetSuggestions).
const ( // SnippetsInline sorts snippets with the other items. SnippetsInline SnippetOrder = iota // SnippetsTop puts the snippets before the other items. SnippetsTop // SnippetsBottom puts them after. SnippetsBottom )
The snippet orders.
type SuggestItem ¶
type SuggestItem struct {
CompletionItem
// Position is where the request was made.
Position Position
// EditStart is the column where the edit of the item starts; InsertEnd and ReplaceEnd are the columns it ends at when the
// item inserts and when it replaces the word. They are bytes in the line of Position.
EditStart, InsertEnd, ReplaceEnd int
// Invalid is set for an item the widget ignores: an empty label, or an edit over several lines or on another line.
Invalid bool
// Score is the result of the last filtering: the score, and the positions of the matching runes of the label (or of the
// filter text when the label did not match). A score of -100 and no positions means there was nothing to match.
Score fuzzy.WordScore
// Word is the text the item was scored against; Idx its place in the order of the request; Distance the locality bonus.
Word string
Idx int
Distance int
// Resolved is set once the details of the item were asked for.
Resolved bool
// contains filtered or unexported fields
}
SuggestItem is an item of the suggest widget: a completion item with the place it was asked at, the columns it edits and the result of the last filtering.
Ported from VS Code: src/vs/editor/contrib/suggest/browser/suggest.ts (CompletionItem)
func NewSuggestItems ¶
func NewSuggestItems(req SuggestRequest, items []CompletionItem, f ItemFilter) []*SuggestItem
NewSuggestItems makes the items of the answer of a request at pos: an item without a range gets the word at the position (it replaces the word, and inserts up to the cursor), an item without a sort text sorts by its label, and an item that is invalid is marked so. Items of a hidden kind are left out.
Ported from VS Code: src/vs/editor/contrib/suggest/browser/suggest.ts (provideSuggestionItems, CompletionItem)
type SuggestMemory ¶
type SuggestMemory struct {
// contains filtered or unexported fields
}
SuggestMemory remembers the suggestions that were accepted, to focus them again. It lives as long as the window tab: it is not saved (VS Code saves it with the state of the workspace).
Ported from VS Code: src/vs/editor/contrib/suggest/browser/suggestMemory.ts
func NewSuggestMemory ¶
func NewSuggestMemory() *SuggestMemory
NewSuggestMemory makes an empty memory.
func (*SuggestMemory) Memorize ¶
func (m *SuggestMemory) Memorize(mode MemoryMode, languageID, wordBefore string, item *SuggestItem)
Memorize remembers that the item was accepted in a document of the language, with the word before the cursor.
func (*SuggestMemory) Select ¶
func (m *SuggestMemory) Select(mode MemoryMode, languageID, wordBefore string, afterSpace bool, items []*SuggestItem) int
Select is the index of the item to focus among items, best first. wordBefore is the word before the cursor and afterSpace tells that the character before the cursor is white space.
type SuggestModel ¶
type SuggestModel struct {
// contains filtered or unexported fields
}
SuggestModel is the sorted, filtered view of the items of a request: what is typed after the request narrows it.
Ported from VS Code: src/vs/editor/contrib/suggest/browser/completionModel.ts
func NewSuggestModel ¶
func NewSuggestModel(items []*SuggestItem, column int, ctx LineContext, opts SuggestModelOptions) *SuggestModel
NewSuggestModel makes the model of items asked for at the byte column column of a line, with the line context now.
func (*SuggestModel) IncompleteOwners ¶
func (m *SuggestModel) IncompleteOwners() map[string]bool
IncompleteOwners are the providers whose list of items was incomplete: asked again when the user types more.
func (*SuggestModel) Items ¶
func (m *SuggestModel) Items() []*SuggestItem
Items are the items that match, best first.
func (*SuggestModel) ItemsByOwner ¶
func (m *SuggestModel) ItemsByOwner() map[string][]*SuggestItem
ItemsByOwner are the valid items that were looked at, by the owner of the provider that made them.
func (*SuggestModel) LineContext ¶
func (m *SuggestModel) LineContext() LineContext
LineContext is the context the items were filtered for.
func (*SuggestModel) SetLineContext ¶
func (m *SuggestModel) SetLineContext(ctx LineContext)
SetLineContext filters the items for a new context: only when it differs from the last. When the cursor only moved to the right the items that did not match before are not looked at again.
type SuggestModelOptions ¶
type SuggestModelOptions struct {
// FilterGraceful accounts for small typos (editor.suggest.filterGraceful).
FilterGraceful bool
// MatchOnWordStartOnly asks the first match to be at a word start (editor.suggest.matchOnWordStartOnly).
MatchOnWordStartOnly bool
// Snippets is where the snippets stand (editor.snippetSuggestions).
Snippets SnippetOrder
}
SuggestModelOptions are the options of a SuggestModel.
type SuggestRequest ¶
type SuggestRequest struct {
Doc Document
Pos Position
// WordAt finds words, as editor.wordSeparators says.
WordAt WordFunc
}
SuggestRequest is what the items of one request are made against.
type SymbolCache ¶
type SymbolCache struct {
// contains filtered or unexported fields
}
SymbolCache shares the document symbols of the window between the features that need them: the Outline view, the breadcrumbs, sticky scroll and the picker of Go to Symbol in Editor. It keeps the symbols of the latest version of each document that was asked for, asks the providers once for a version however many features want it, and cancels the request of a version that a newer one supersedes; a feature whose document has changed since gets context.Canceled (the symbols are for a version that is gone). It is safe for concurrent use.
func NewSymbolCache ¶
func NewSymbolCache(base context.Context, reg *Registry) *SymbolCache
NewSymbolCache makes the cache of a registry; base ends every request of the cache (the window tab).
func (*SymbolCache) Cached ¶
func (c *SymbolCache) Cached(doc Document) ([]DocumentSymbol, bool)
Cached returns the symbols already known for the version of the document, without asking.
func (*SymbolCache) Forget ¶
func (c *SymbolCache) Forget(uri document.URI)
Forget drops what the cache knows of a document, and cancels its request.
func (*SymbolCache) Get ¶
func (c *SymbolCache) Get(ctx context.Context, doc Document) ([]DocumentSymbol, error)
Get returns the symbols of the document at its version, asking the providers when no request for this version exists. The request is the cache's own, so one caller giving up does not stop the others; a request for a version that was superseded returns context.Canceled. The error is that of the first provider that failed when no provider had symbols.
type SymbolProvider ¶
type SymbolProvider interface {
ProvideDocumentSymbols(ctx context.Context, doc Document) ([]DocumentSymbol, error)
}
SymbolProvider answers the symbols of a document.
type SymbolSortOrder ¶
type SymbolSortOrder string
SymbolSortOrder is how a list of symbols is ordered (breadcrumbs.symbolSortOrder).
const ( // SortByPosition keeps the order of the document. SortByPosition SymbolSortOrder = "position" // SortByName orders by name, ignoring case. SortByName SymbolSortOrder = "name" // SortByKind orders by kind and then by position. SortByKind SymbolSortOrder = "type" )
The orders.
type TextEdit ¶
TextEdit replaces a range with text.
func MinimalEdits ¶
MinimalEdits makes the edits as small as the change they make: the text that an edit leaves as it was, at its start and at its end, is taken out, and an edit that replaces several lines becomes an edit for each block of lines that changed. An edit that changes nothing is dropped. The edits are in the text of snap, and apply as the originals would.
Ported from VS Code: editorWorker.ts (computeMoreMinimalEdits)
type TextSource ¶
TextSource gives the text of a document that is not the one a request is about, for the conversion of the positions of a location in it: the snapshot of an open document, or the file read from disk. A nil source, or an error, makes the conversion take the columns of that document for byte columns (right for ASCII and for servers that count bytes).
type WordFunc ¶
WordFunc finds the word of regular characters that touches the byte column col of a line: its start and end columns.
type WordProvider ¶
type WordProvider struct {
// Mode gives the value of editor.wordBasedSuggestions for the document.
Mode func(doc Document) string
// Documents lists snapshots of the open documents, the one of the request included or not. It is called on the goroutine
// of the request and gives up when ctx ends.
Documents func(ctx context.Context) []Document
// WordAt finds the words of a language, as editor.wordSeparators says.
WordAt WordFunc
}
WordProvider answers completion requests with the words of the open documents (editor.wordBasedSuggestions): a document that no other provider serves still gets suggestions. Register it for every document, which gives it the lowest score, so that it is only asked when the providers of the language had nothing to say (VS Code's rule).
Ported from VS Code: src/vs/editor/browser/services/editorWorkerService.ts (WordBasedCompletionItemProvider) and src/vs/editor/common/services/editorSimpleWorker.ts (textualSuggest)
func (*WordProvider) ProvideCompletion ¶
func (p *WordProvider) ProvideCompletion(ctx context.Context, doc Document, pos Position, _ CompletionTrigger) (CompletionList, error)
ProvideCompletion implements CompletionProvider.
type WorkspaceEdit ¶
type WorkspaceEdit struct {
// Label says what the edit is, for the undo label and the preview.
Label string
// Changes are made in order.
Changes []Change
// contains filtered or unexported fields
}
WorkspaceEdit changes documents and files together (SPEC §9.12 "Features model"). Make one from a provider's answer with Changes, or from a language server's with FromLSPEdit.
func ExpandEdit ¶
func ExpandEdit(ctx context.Context, we *WorkspaceEdit, texts TextSource) (*WorkspaceEdit, error)
ExpandEdit makes the edit of a language server into the changes it is made of, with the ranges of every edit counted in bytes of the document they are in (the text of the document comes from texts), so that the edits can be listed, previewed and chosen one by one. The changes are those of the edit in order; a text change names the version the server gave it. An edit whose documents cannot be read fails with WorkspaceEditDocumentUnavailable.
func FilterEdit ¶
func FilterEdit(we *WorkspaceEdit, keep func(change, edit int) bool) *WorkspaceEdit
FilterEdit keeps the changes of an expanded edit that keep says yes to: keep is called with the index of the change and, for the edits of a text change, with the index of the edit; for a file operation (and for the change as a whole) the edit index is -1. A text change with no edit left is left out.
func FromLSPEdit ¶
func FromLSPEdit(enc lsp.Encoding, we lsp.WorkspaceEdit) *WorkspaceEdit
FromLSPEdit makes the WorkspaceEdit of an edit that a language server sent, whose positions count in the encoding.
type WorkspaceSymbol ¶
type WorkspaceSymbol struct {
Name string
ContainerName string
Kind int
Deprecated bool
// Location is where the symbol is. Its range is the start of the file when Unresolved is true.
Location Location
// Unresolved says that the server left the range of the symbol to workspaceSymbol/resolve.
Unresolved bool
// Owner is the provider that made the symbol: the id of a language server or of an extension.
Owner string
// contains filtered or unexported fields
}
WorkspaceSymbol is a symbol of the workspace that Go to Symbol in Workspace lists (workspace/symbol). Kind is the LSP's SymbolKind.
func WorkspaceSymbolsFromLSP ¶
func WorkspaceSymbolsFromLSP(ctx context.Context, enc lsp.Encoding, texts TextSource, syms []lsp.WorkspaceSymbol) []WorkspaceSymbol
WorkspaceSymbolsFromLSP converts the answer to a workspace/symbol request. The positions are converted with the text of the file the symbol is in (texts). A symbol of a URI the editor has no documents for is left out; one whose location has no range is Unresolved, at the start of its file.
type WorkspaceSymbolProvider ¶
type WorkspaceSymbolProvider interface {
ProvideWorkspaceSymbols(ctx context.Context, query string) ([]WorkspaceSymbol, error)
}
WorkspaceSymbolProvider answers the symbols of the whole workspace for a query (VS Code's WorkspaceSymbolProvider); it is asked for every query typed after # in the quick open.
type WorkspaceSymbolResolver ¶
type WorkspaceSymbolResolver interface {
// CanResolveSymbol tells whether the provider can resolve the symbol.
CanResolveSymbol(sym WorkspaceSymbol) bool
// ResolveWorkspaceSymbol returns the symbol with its range.
ResolveWorkspaceSymbol(ctx context.Context, sym WorkspaceSymbol) (WorkspaceSymbol, error)
}
WorkspaceSymbolResolver is a provider that leaves the location of its symbols to be asked for when one is chosen (workspaceSymbol/resolve).