Documentation ¶
Overview ¶
Package langserver is a language server for Go that adheres to the Language Server Protocol (LSP).
Index ¶
- func ContainingPackage(bctx *build.Context, filename string) (*build.Package, error)
- func IsFileSystemRequest(method string) bool
- func IsVendorDir(dir string) bool
- func NewHandler() jsonrpc2.Handler
- func PathHasPrefix(s, prefix string) bool
- func PathTrimPrefix(s, prefix string) string
- type FilterType
- type HandlerCommon
- func (h *HandlerCommon) CheckReady() error
- func (h *HandlerCommon) InitTracer(conn *jsonrpc2.Conn)
- func (h *HandlerCommon) Reset(rootURI string) error
- func (h *HandlerCommon) ShutDown()
- func (h *HandlerCommon) SpanForRequest(ctx context.Context, buildOrLang string, req *jsonrpc2.Request, ...) (opentracing.Span, context.Context, error)
- type HandlerShared
- func (h *HandlerShared) FilePath(uri string) string
- func (h *HandlerShared) HandleFileSystemRequest(ctx context.Context, req *jsonrpc2.Request) error
- func (h *HandlerShared) OverlayBuildContext(ctx context.Context, orig *build.Context, useOSFileSystem bool) *build.Context
- func (h *HandlerShared) Reset(overlayRootURI string, useOSFS bool) error
- type InitializeBuildContextParams
- type InitializeParams
- type JSONRPC2Conn
- type LangHandler
- type Query
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainingPackage ¶
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 ¶
IsFileSystemRequest returns if this is an LSP method whose sole purpose is modifying the contents of the overlay file system.
func IsVendorDir ¶
IsVendorDir tells if the specified directory is a vendor directory.
func NewHandler ¶
NewHandler creates a Go language server handler.
func PathHasPrefix ¶
func PathTrimPrefix ¶
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 { // 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 (*HandlerShared) OverlayBuildContext ¶
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 // 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 ¶
ParseQuery parses a user's raw query string and returns a structured representation of the query.