langsvr

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2019 License: Apache-2.0 Imports: 13 Imported by: 7

Documentation

Overview

Package langsvr provides a simple interface to implement a language server.

Index

Constants

View Source
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)
)
View Source
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)
)

Variables

This section is empty.

Functions

func Connect

func Connect(ctx context.Context, stream io.ReadWriter, server Server) error

Connect creates a connection to between server and the client (code editor) communicating on stream.

func PathToURI

func PathToURI(path string) string

PathToURI returns the URI for the absolute filepath

func URItoPath

func URItoPath(uri string) (string, error)

URItoPath returns the absolute filepath from the given URI.

Types

type Body

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

Body represents the body of a document.

func NewBody

func NewBody(text string) Body

NewBody returns a body containing the specified text.

func NewBodyFromRunes

func NewBodyFromRunes(runes []rune) Body

NewBodyFromRunes returns a body containing the specified text in runes.

func (Body) FullRange

func (b Body) FullRange() Range

FullRange returns the entire range of the document.

func (Body) GetRange

func (b Body) GetRange(rng Range) string

GetRange returns a chunk of the body.

func (Body) Offset

func (b Body) Offset(p Position) int

Offset returns the byte offset of p.

func (Body) Position

func (b Body) Position(offset int) Position

Position returns the position at the specified offset

func (Body) Range

func (b Body) Range(start, end int) Range

Range returns the range for the given start and end offsets.

func (Body) Runes

func (b Body) Runes() []rune

Runes returns the body's runes.

func (Body) Text

func (b Body) Text() string

Text returns the body's text.

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) Body

func (d *Document) Body() Body

Body returns the document's text body

func (Document) Language

func (d Document) Language() string

Language returns the document's file language.

func (Document) Path

func (d Document) Path() string

Path returns the document's absolute file path.

func (*Document) SetDiagnostics

func (d *Document) SetDiagnostics(diagnostics Diagnostics)

SetDiagnostics sets the diagnostics for the document.

func (Document) URI

func (d Document) URI() string

URI returns the document's URI.

func (Document) Version

func (d Document) Version() int

Version returns the document's version.

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 HighlightKind

type HighlightKind int

HighlightKind is a document highlight kind enumerator.

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

type Location struct {
	URI   string
	Range Range
}

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 Position

type Position struct {
	// Line index (1-based)
	Line int
	// Column index (1-based)
	Column int
}

Position represents a location in a document.

type Range

type Range struct {
	// The start of the span.
	Start Position
	// The end of the span.
	End Position
}

Range represents a span of a document.

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 Severity

type Severity int

Severity represents the severity level of a diagnostic.

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 SymbolKind

type SymbolKind int

SymbolKind is an enumerator of symbol kinds.

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.

Directories

Path Synopsis
Package protocol implements the language server protocol.
Package protocol implements the language server protocol.

Jump to

Keyboard shortcuts

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