langserver

package
v0.0.0-...-76bcd77 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2019 License: MIT Imports: 35 Imported by: 0

Documentation

Overview

Package langserver is a language server for Go that adheres to the Language Server Protocol (LSP).

Index

Constants

View Source
const HasAlias = true

Variables

This section is empty.

Functions

func NewCancel

func NewCancel() *cancel

func NewHandler

func NewHandler(defaultCfg Config) jsonrpc2.Handler

NewHandler creates a Go language server handler.

Types

type Config

type Config struct {
	// DisableFuncSnippet enables the returning of argument snippets on `func`
	// completions, eg. func(foo string, arg2 bar). Requires code complete
	// to be enabled.
	//
	// Defaults to true if not specified.
	DisableFuncSnippet bool

	// EnableGlobalCache enable global cache when hover, reference, definition. Can be overridden by InitializationOptions.
	//
	// Defaults to "always" if not specified
	GlobalCacheStyle string

	// DiagnosticsEnabled enables handling of diagnostics
	//
	// Defaults to false if not specified.
	DiagnosticsStyle string

	// FormatStyle format style
	//
	// Defaults to "gofmt" if not secified
	FormatStyle string

	// GoimportsLocalPrefix sets the local prefix (comma-separated string) that goimports will use
	//
	// Defaults to empty string if not specified.
	GoimportsLocalPrefix string

	// EnhanceSignatureHelp enhance the signature help with return result.
	//
	// Defaults to false
	EnhanceSignatureHelp bool

	// BuildTags controls build tag constraints and will be passed to build flags.
	//
	// Defaults to empty
	BuildTags []string
}

Config adjusts the behaviour of go-langserver. Please keep in sync with InitializationOptions in the README.

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig returns the default config. See the field comments for the defaults.

func (Config) Apply

func (c Config) Apply(o *InitializationOptions) Config

Apply sets the corresponding field in c for each non-nil field in o.

type DiagnosticsStyleEnum

type DiagnosticsStyleEnum string

type FilterType

type FilterType string
const (
	FilterExported FilterType = "exported"
	FilterDir      FilterType = "dir"
)

type HandlerCommon

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

HandlerCommon contains functionality that both the build and lang handlers need. They do NOT share the memory of this HandlerCommon struct; it is just common functionality. (Unlike HandlerCommon, HandlerShared is shared in-memory.)

func (*HandlerCommon) CheckReady

func (h *HandlerCommon) CheckReady() error

CheckReady returns an error if the handler has been shut down.

func (*HandlerCommon) ShutDown

func (h *HandlerCommon) ShutDown()

ShutDown marks this server as being shut down and causes all future calls to checkReady to return an error.

type HandlerShared

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

HandlerShared contains data structures that a build server and its wrapped lang server may share in memory.

func (*HandlerShared) FilePath

func (h *HandlerShared) FilePath(uri lsp.DocumentURI) string

func (*HandlerShared) View

func (h *HandlerShared) View() source.View

type InitializationOptions

type InitializationOptions struct {
	// DisableFuncSnippet is an optional version of Config.DisableFuncSnippet
	DisableFuncSnippet *bool `json:"disableFuncSnippet"`

	// DiagnosticsEnabled enables handling of diagnostics
	//
	// Defaults to false if not specified.
	DiagnosticsStyle *string `json:"diagnosticsStyle"`

	// EnableGlobalCache enable global cache when hover, reference, definition. Can be overridden by InitializationOptions.
	//
	// Defaults to false if not specified
	GlobalCacheStyle *string `json:"globalCacheStyle"`

	// FormatStyle format style
	//
	// Defaults to "gofmt" if not specified
	FormatStyle *string `json:"formatStyle"`

	// Enhance sigature help
	//
	// Defaults to false if not specified
	EnhanceSignatureHelp *bool `json:"enhanceSignatureHelp"`

	// GoimportsLocalPrefix is an optional version of
	// Config.GoimportsLocalPrefix
	GoimportsLocalPrefix *string `json:"goimportsLocalPrefix"`

	// BuildTags is an optional version of Config.BuildTags
	BuildTags []string `json:"buildTags"`
}

InitializationOptions are the options supported by go-langserver. It is the Config struct, but each field is optional.

type InitializeParams

type InitializeParams struct {
	lsp.InitializeParams

	InitializationOptions *InitializationOptions `json:"initializationOptions,omitempty"`

	// TODO these should be InitializationOptions
	// RootImportPath is the root Go import path for this
	// workspace. For example,
	// "golang.org/x/tools" is the root import
	// path for "github.com/golang/tools".
	RootImportPath string
}

type LangHandler

type LangHandler struct {
	HandlerCommon
	*HandlerShared

	// DefaultConfig is the default values used for configuration. It is
	// combined with InitializationOptions after initialize. This should be
	// set by LangHandler creators. Please read config instead.
	DefaultConfig Config
	// contains filtered or unexported fields
}

LangHandler is a Go language server LSP/JSON-RPC handler.

func (*LangHandler) Handle

func (h *LangHandler) Handle(ctx context.Context, conn jsonrpc2.JSONRPC2, req *jsonrpc2.Request) (result interface{}, err error)

Handle creates a response for a JSONRPC2 LSP request. Note: LSP has strict ordering requirements, so this should not just be wrapped in an jsonrpc2.AsyncHandler. Ensure you have the same ordering as used in the NewHandler implementation.

type Query

type Query struct {
	Kind      lsp.SymbolKind
	Filter    FilterType
	File, Dir string
	Tokens    []string

	Symbol lspext.SymbolDescriptor
}

Query is a structured representation that is parsed from the user's raw query string.

func ParseQuery

func ParseQuery(q string) (qu Query)

ParseQuery parses a user's raw query string and returns a structured representation of the query.

func (Query) String

func (q Query) String() string

String converts the query back into a logically equivalent, but not strictly byte-wise equal, query string. It is useful for converting a modified query structure back into a query string.

type SymbolCollector

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

SymbolCollector stores symbol information for an AST

func (*SymbolCollector) Visit

func (c *SymbolCollector) Visit(n ast.Node) (w ast.Visitor)

Visit visits AST nodes and collects symbol information

Directories

Path Synopsis
internal
diff
Package diff implements the Myers diff algorithm.
Package diff implements the Myers diff algorithm.
source
Package source provides core features for use by Go editors and tools.
Package source provides core features for use by Go editors and tools.
sys

Jump to

Keyboard shortcuts

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