Documentation ¶
Overview ¶
Package langsvr provides a simple interface to implement a language server.
Index ¶
- Constants
- func Connect(ctx context.Context, stream io.ReadWriter, server Server) error
- func PathToURI(path string) string
- func URItoPath(uri string) (string, error)
- type Body
- type CodeActionsProvider
- type CodeLens
- type CodeLensProvider
- type Command
- type CompletionItem
- type CompletionItemKind
- type CompletionList
- type CompletionProvider
- type DefinitionProvider
- type Diagnostic
- type Diagnostics
- type Document
- type FormatOnTypeProvider
- type FormatProvider
- type FormatRangeProvider
- type FormattingOptions
- type Highlight
- type HighlightKind
- type HighlightList
- type HighlightsProvider
- type HoverProvider
- type InitConfig
- type Location
- type Parameter
- type ParameterList
- type Position
- type Range
- type ReferencesProvider
- type RenameProvider
- type Server
- type Severity
- type Signature
- type SignatureList
- type SignatureProvider
- type SourceCode
- type SourceCodeList
- type Symbol
- type SymbolKind
- type SymbolList
- type SymbolsProvider
- type TextEdit
- type TextEditList
- type WorkspaceEdit
- type WorkspaceSymbolsProvider
Constants ¶
const ( Text = CompletionItemKind(protocol.Text) Method = CompletionItemKind(protocol.Method) Function = CompletionItemKind(protocol.Function) Constructor = CompletionItemKind(protocol.Constructor) Field = CompletionItemKind(protocol.Field) Variable = CompletionItemKind(protocol.Variable) Class = CompletionItemKind(protocol.Class) Interface = CompletionItemKind(protocol.Interface) Module = CompletionItemKind(protocol.Module) Property = CompletionItemKind(protocol.Property) Unit = CompletionItemKind(protocol.Unit) Value = CompletionItemKind(protocol.Value) Enum = CompletionItemKind(protocol.Enum) Keyword = CompletionItemKind(protocol.Keyword) Snippet = CompletionItemKind(protocol.Snippet) Color = CompletionItemKind(protocol.Color) File = CompletionItemKind(protocol.File) Reference = CompletionItemKind(protocol.Reference) )
const ( // SeverityError reports an error. SeverityError = Severity(protocol.SeverityError) // SeverityWarning reports a warning. SeverityWarning = Severity(protocol.SeverityWarning) // SeverityInformation reports an information. SeverityInformation = Severity(protocol.SeverityInformation) // SeverityHint reports a hint. SeverityHint = Severity(protocol.SeverityHint) )
const ( // TextHighlight represents a textual occurrance. TextHighlight = HighlightKind(protocol.TextHighlight) // ReadHighlight represents read-access of a symbol, like reading a // variable. ReadHighlight = HighlightKind(protocol.ReadHighlight) // WriteHighlight represents write-access of a symbol, like writing to a // variable. WriteHighlight = HighlightKind(protocol.WriteHighlight) )
const ( KindFile = SymbolKind(protocol.KindFile) KindModule = SymbolKind(protocol.KindModule) KindNamespace = SymbolKind(protocol.KindNamespace) KindPackage = SymbolKind(protocol.KindPackage) KindClass = SymbolKind(protocol.KindClass) KindMethod = SymbolKind(protocol.KindMethod) KindProperty = SymbolKind(protocol.KindProperty) KindField = SymbolKind(protocol.KindField) KindConstructor = SymbolKind(protocol.KindConstructor) KindEnum = SymbolKind(protocol.KindEnum) KindInterface = SymbolKind(protocol.KindInterface) KindFunction = SymbolKind(protocol.KindFunction) KindVariable = SymbolKind(protocol.KindVariable) KindConstant = SymbolKind(protocol.KindConstant) KindString = SymbolKind(protocol.KindString) KindNumber = SymbolKind(protocol.KindNumber) KindBoolean = SymbolKind(protocol.KindBoolean) KindArray = SymbolKind(protocol.KindArray) )
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
Connect creates a connection to between server and the client (code editor) communicating on stream.
Types ¶
type Body ¶
type Body struct {
// contains filtered or unexported fields
}
Body represents the body of a document.
func NewBodyFromRunes ¶
NewBodyFromRunes returns a body containing the specified text in runes.
type CodeActionsProvider ¶
type CodeActionsProvider interface { // CodeActions compute commands for a given document and range. // The request is triggered when the user moves the cursor into an problem // marker in the editor or presses the lightbulb associated with a marker. CodeActions(context.Context, *Document, Range, []Diagnostic) ([]Command, error) }
CodeActionsProvider is the interface implemented by servers that support code actions.
type CodeLens ¶
type CodeLens struct { // Range is the document range this codelens spans. Range Range // Resolve returns the Command for this CodeLens Resolve func(context.Context) Command }
CodeLens represents a command that should be shown along with source text, like the number of references, a way to run tests, etc.
type CodeLensProvider ¶
type CodeLensProvider interface { // CodeLenses returns a list of CodeLens for the specified document. CodeLenses(context.Context, *Document) ([]CodeLens, error) }
CodeLensProvider is the interface implemented by servers that support code lenes.
type Command ¶
type Command struct { // Title of the command, like `save`. Title string // The identifier of the actual command handler. Command string // Arguments that the command handler should be invoked with. Arguments map[string]interface{} }
Command represents a reference to a command. Provides a title which will be used to represent a command in the UI and, optionally, an array of arguments which will be passed to the command handler function when invoked.
type CompletionItem ¶
type CompletionItem struct { // The label of this completion item. By default also the text that is // inserted when selecting this completion. Label string // The kind of this completion item. Based of the kind an icon is chosen by // the editor. Kind CompletionItemKind // An optional human-readable string with additional information about this // item, like type or symbol information. Detail string // An optional human-readable string that represents a doc-comment. Documentation string // An optional string that should be used when comparing this item with // other items. SortText string // An optional string that should be used when filtering a set of completion // items. FilterText string // An optional string that should be inserted into the document when // selecting this completion. Defaults to the label. InsertText string }
CompletionItem represents a completion item to be presented in the editor.
type CompletionItemKind ¶
type CompletionItemKind int
CompletionItemKind is the kind of a completion entry.
type CompletionList ¶
type CompletionList struct { // If true then the list it not complete. // Further typing should result in recomputing this list. Incomplete bool // The completion items. Items []CompletionItem }
CompletionList is a list of completion items.
func (*CompletionList) Add ¶
func (c *CompletionList) Add(label string, kind CompletionItemKind, detail string)
Add appends a completion item to the list.
type CompletionProvider ¶
type CompletionProvider interface { // Completions returns completion items at a given cursor position. // Completion items are presented in the IntelliSense user interface. Completions(context.Context, *Document, Position) (CompletionList, error) }
CompletionProvider is the interface implemented by servers that support completion information.
type DefinitionProvider ¶
type DefinitionProvider interface { // Definitions returns the list of definition locations for the given symbol // in the specified document at position. Definitions(context.Context, *Document, Position) ([]Location, error) }
DefinitionProvider is the interface implemented by servers that support symbol definition information.
type Diagnostic ¶
type Diagnostic struct { // The range at which the message applies Range Range // The diagnostic's severity. Severity Severity // The diagnostic's message. Message string // The diagnostic's code (optional) Code string // The source of the diagnostic Source string }
Diagnostic represents a compiler diagnostic, such as a warning or error.
type Diagnostics ¶
type Diagnostics []Diagnostic
Diagnostics is a list of Diagnostic
func (*Diagnostics) Error ¶
func (l *Diagnostics) Error(rng Range, msg string)
Error appends a error diagnostic at rng.
func (*Diagnostics) Hint ¶
func (l *Diagnostics) Hint(rng Range, msg string)
Hint appends a hint diagnostic at rng.
func (*Diagnostics) Info ¶
func (l *Diagnostics) Info(rng Range, msg string)
Info appends an info diagnostic at rng.
func (*Diagnostics) Warning ¶
func (l *Diagnostics) Warning(rng Range, msg string)
Warning appends a warning diagnostic at rng.
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document represents a text document file.
func (*Document) SetDiagnostics ¶
func (d *Document) SetDiagnostics(diagnostics Diagnostics)
SetDiagnostics sets the diagnostics for the document.
type FormatOnTypeProvider ¶
type FormatOnTypeProvider interface { // FormatOnType returns a list of edits required to format the code // currently being written at pos, after char was typed. FormatOnType(doc *Document, pos Position, char rune, opts FormattingOptions) (TextEditList, error) }
FormatOnTypeProvider is the interface implemented by servers that support reformatting as-you-type.
type FormatProvider ¶
type FormatProvider interface { // Format returns a list of edits required to format the entire document. Format(ctx context.Context, doc *Document, opts FormattingOptions) (TextEditList, error) }
FormatProvider is the interface implemented by servers that support whole-document reformatting.
type FormatRangeProvider ¶
type FormatRangeProvider interface { // FormatRange returns a list of edits required to format the specified // range in the specified document. FormatRange(ctx context.Context, doc *Document, rng Range, opts FormattingOptions) (TextEditList, error) }
FormatRangeProvider is the interface implemented by servers that support document-range reformatting.
type FormattingOptions ¶
type FormattingOptions struct { // Size of a tab in spaces. TabSize int // Prefer spaces over tabs. InsertSpaces bool }
FormattingOptions holds options for formatting requests.
type Highlight ¶
type Highlight struct { // The range this highlight applies to. Range Range // The highlight kind, default is Text. Kind HighlightKind }
Highlight a range inside a text document which deserves special attention. Usually a document highlight is visualized by changing the background color of its range.
type HighlightList ¶
type HighlightList []Highlight
HighlightList is a list of highlights
func (*HighlightList) Add ¶
func (l *HighlightList) Add(rng Range, kind HighlightKind)
Add appends the highlight to the list.
type HighlightsProvider ¶
type HighlightsProvider interface { // Highlights returns a list of highlights for the given symbol in the // specified document at position. Highlights(context.Context, *Document, Position) (HighlightList, error) }
HighlightsProvider is the interface implemented by servers that support symbol highlight information.
type HoverProvider ¶
type HoverProvider interface { // Hover returns a list of source code snippets and range for the given // symbol at the specified position. Hover(context.Context, *Document, Position) (SourceCodeList, Range, error) }
HoverProvider is the interface implemented by servers that support hover information.
type InitConfig ¶
type InitConfig struct { // The language identifier for this language server. LanguageID string // CompletionTriggerCharacters is the list of characters that will trigger a // completion suggestion. CompletionTriggerCharacters []rune // CompletionTriggerCharacters is the list of characters that will trigger a // signature hint. SignatureTriggerCharacters []rune // Documents is a list of all the document paths that should be watched from // initialization. WorkspaceDocuments []string }
InitConfig is returned by Server.Initialize().
type Location ¶
Location represents a location inside a resource, such as a line inside a text file.
var NoLocation Location
NoLocation represents no location
type Parameter ¶
type Parameter struct { // The label of this signature. Will be shown in the UI. Label string // The human-readable doc-comment of this signature. // Will be shown in the UI but can be omitted. Documentation string }
Parameter represents a parameter of a callable-signature.
type ParameterList ¶
type ParameterList []Parameter
ParameterList is a list of parameters.
func (*ParameterList) Add ¶
func (l *ParameterList) Add(label, doc string)
Add appends the signature to the list.
type ReferencesProvider ¶
type ReferencesProvider interface { // References returns a list of references for the given symbol in the // specified document at position. References(context.Context, *Document, Position) ([]Location, error) }
ReferencesProvider is the interface implemented by servers that support symbol reference information.
type RenameProvider ¶
type RenameProvider interface { // Rename is called to rename the symbol at pos with newName. Rename(ctx context.Context, doc *Document, pos Position, newName string) (WorkspaceEdit, error) }
RenameProvider is the interface implemented by servers that support renaming symbols.
type Server ¶
type Server interface { // Initialize is called when the server is first initialized by the client. Initialize(ctx context.Context, rootPath string) (InitConfig, error) // Shutdown is called to shutdown the server. Shutdown(context.Context) error // OnConfigChange is called when the configuration settings change. OnConfigChange(context.Context, map[string]interface{}) error // OnDocumentsAdded is called when new documents of interest are discovered. OnDocumentsAdded(context.Context, []*Document) error // OnDocumentsChanged is called when documents are changed. OnDocumentsChanged(context.Context, []*Document) error // OnDocumentsRemoved is called when documents are no longer monitored. OnDocumentsRemoved(context.Context, []*Document) error // OnDocumentSaved is called when an open document is saved. OnDocumentSaved(context.Context, *Document) error }
Server is the interface implemented by language servers.
type Signature ¶
type Signature struct { // The label of this signature. Will be shown in the UI. Label string // The human-readable doc-comment of this signature. // Will be shown in the UI but can be omitted. Documentation string // The parameters of this signature. Parameters ParameterList }
Signature represents the signature of something callable.
type SignatureList ¶
type SignatureList []Signature
SignatureList is a list of signatures.
func (*SignatureList) Add ¶
func (l *SignatureList) Add(label, doc string, params ParameterList)
Add appends the signature to the list.
type SignatureProvider ¶
type SignatureProvider interface { // Signatures returns the list of function signatures that are candidates // at the given cursor position. The activeSig and activeParam are indices // of the signature and parameter to highlight for the given cursor // position. Signatures(context.Context, *Document, Position) (sigs SignatureList, activeSig, activeParam int, err error) }
SignatureProvider is the interface implemented by servers that support callable signature information.
type SourceCode ¶
type SourceCode struct { // The language the source is in. Language string // The source code. Source string }
SourceCode contains some source code and a language specifier.
type SourceCodeList ¶
type SourceCodeList []SourceCode
SourceCodeList is a list of source code snippits.
func (*SourceCodeList) Add ¶
func (l *SourceCodeList) Add(lang, source string)
Add appends the source code snippet with the specified language and source.
type Symbol ¶
type Symbol struct { // The name of this symbol. Name string // The kind of this symbol. Kind SymbolKind // The location of this symbol. Location Location // The name of the symbol containing this symbol. Container *Symbol }
Symbol represents information about programming constructs like variables, classes, interfaces etc.
type SymbolList ¶
type SymbolList []Symbol
SymbolList is a list of symbols
func (*SymbolList) Add ¶
func (l *SymbolList) Add(name string, kind SymbolKind, loc Location, container *Symbol) Symbol
Add appends a new symbol to the list.
func (SymbolList) Filter ¶
func (l SymbolList) Filter(pred func(Symbol) bool) SymbolList
Filter returns a new symbol list with only the symbols that pass the predicate function.
type SymbolsProvider ¶
type SymbolsProvider interface { // Symbols returns symbolic information about the specified document. Symbols(context.Context, *Document) (SymbolList, error) }
SymbolsProvider is the interface implemented by servers that support document symbol information.
type TextEdit ¶
type TextEdit struct { // The range of the text document to be manipulated. Range Range // The string to be inserted. For delete operations use an empty string. NewText string }
TextEdit is a textual edit applicable to a text document.
type TextEditList ¶
type TextEditList []TextEdit
TextEditList is a list of TextEdits
func (*TextEditList) Add ¶
func (l *TextEditList) Add(rng Range, newText string)
Add appends a TextEdit to the list.
type WorkspaceEdit ¶
type WorkspaceEdit map[string]TextEditList
WorkspaceEdit is a collection of edits across an entire workspace.
func (WorkspaceEdit) Add ¶
func (w WorkspaceEdit) Add(loc Location, newText string)
Add appends an edit at the specified location
type WorkspaceSymbolsProvider ¶
type WorkspaceSymbolsProvider interface { // WorkspaceSymbols returns all project-wide symbols. WorkspaceSymbols(ctx context.Context) (SymbolList, error) }
WorkspaceSymbolsProvider is the interface implemented by servers that support whole-workspace symbol information.