langserver

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2016 License: MIT Imports: 38 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainingPackage

func ContainingPackage(bctx *build.Context, filename string) (*build.Package, error)

ContainingPackage returns the package that contains the given filename. It is like buildutil.ContainingPackage, except that:

  • it returns the whole package (i.e., it doesn't use build.FindOnly)
  • it does not perform FS calls that are unnecessary for us (such as searching the GOROOT; this is only called on the main workspace's code, not its deps).
  • if the file is in the xtest package (package p_test not package p), it returns build.Package only representing that xtest package

func IsFileSystemRequest

func IsFileSystemRequest(method string) bool

IsFileSystemRequest returns if this is an LSP method whose sole purpose is modifying the contents of the overlay file system.

func IsVendorDir

func IsVendorDir(dir string) bool

IsVendorDir tells if the specified directory is a vendor directory.

func NewHandler

func NewHandler() jsonrpc2.Handler

NewHandler creates a Go language server handler.

func PathHasPrefix

func PathHasPrefix(s, prefix string) bool

func PathTrimPrefix

func PathTrimPrefix(s, prefix string) string

Types

type FilterType

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

type HandlerCommon

type HandlerCommon struct {
	RootFSPath string // root path of the project's files in the (possibly virtual) file system, without the "file://" prefix (typically /src/github.com/foo/bar)
	// 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) InitTracer

func (h *HandlerCommon) InitTracer(conn *jsonrpc2.Conn)

InitTracer initializes the tracer for the connection if it has not already been initialized.

It assumes that h is only ever called for this conn.

func (*HandlerCommon) Reset

func (h *HandlerCommon) Reset(rootURI string) error

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.

func (*HandlerCommon) SpanForRequest

func (h *HandlerCommon) SpanForRequest(ctx context.Context, buildOrLang string, req *jsonrpc2.Request, tags opentracing.Tags) (opentracing.Span, context.Context, error)

type HandlerShared

type HandlerShared struct {
	Mu     sync.Mutex       // guards all fields
	Shared bool             // true if this struct is shared with a build server
	FS     ctxvfs.NameSpace // full filesystem (mounts both deps and overlay)

	OverlayMountPath string // mount point of overlay on fs (usually /src/github.com/foo/bar)
	// 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 string) string

func (*HandlerShared) HandleFileSystemRequest

func (h *HandlerShared) HandleFileSystemRequest(ctx context.Context, req *jsonrpc2.Request) error

func (*HandlerShared) OverlayBuildContext

func (h *HandlerShared) OverlayBuildContext(ctx context.Context, orig *build.Context, useOSFileSystem bool) *build.Context

func (*HandlerShared) Reset

func (h *HandlerShared) Reset(overlayRootURI string, useOSFS bool) error

type InitializeBuildContextParams

type InitializeBuildContextParams struct {
	GOOS        string
	GOARCH      string
	GOPATH      string
	GOROOT      string
	CgoEnabled  bool
	UseAllFiles bool
	Compiler    string
	BuildTags   []string
}

type InitializeParams

type InitializeParams struct {
	lsp.InitializeParams

	// NoOSFileSystemAccess makes the server never access the OS file
	// system. It exclusively uses the file overlay (from
	// textDocument/didOpen) and the LSP proxy's VFS.
	NoOSFileSystemAccess bool

	// BuildContext, if set, configures the language server's default
	// go/build.Context.
	BuildContext *InitializeBuildContextParams

	// 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 JSONRPC2Conn

type JSONRPC2Conn interface {
	Notify(ctx context.Context, method string, params interface{}, opt ...jsonrpc2.CallOption) error
}

JSONRPC2Conn is a limited interface to jsonrpc2.Conn. When the build server wraps the lang server, it provides this limited subset of methods. This interface exists to make it possible for the build server to provide the lang server with this limited connection handle.

type LangHandler

type LangHandler struct {
	HandlerCommon
	*HandlerShared
	// 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 JSONRPC2Conn, req *jsonrpc2.Request) (result interface{}, err error)

Handle implements jsonrpc2.Handler, except conn is an interface type for testability. The handle method implements jsonrpc2.Handler exactly.

type Query

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

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.

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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