 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Overview ¶
Package langserver is a language server for Go that adheres to the Language Server Protocol (LSP).
Index ¶
- Constants
- Variables
- func ComputeTextEdits(unformatted string, formatted string) []lsp.TextEdit
- func ContainingPackage(bctx *build.Context, filename string) (*build.Package, error)
- func NewHandler(defaultCfg Config) jsonrpc2.Handler
- type AtomicFS
- func (a *AtomicFS) Bind(old string, newfs ctxvfs.FileSystem, new string, mode ctxvfs.BindMode)
- func (a *AtomicFS) Lstat(ctx context.Context, path string) (os.FileInfo, error)
- func (a *AtomicFS) Open(ctx context.Context, path string) (ctxvfs.ReadSeekCloser, error)
- func (a *AtomicFS) ReadDir(ctx context.Context, path string) ([]os.FileInfo, error)
- func (a *AtomicFS) Stat(ctx context.Context, path string) (os.FileInfo, error)
- func (*AtomicFS) String() string
 
- type Config
- type FilterType
- type FindPackageFunc
- type HandlerCommon
- func (h *HandlerCommon) CheckReady() error
- func (h *HandlerCommon) InitTracer(conn *jsonrpc2.Conn)
- func (h *HandlerCommon) Reset(rootURI lsp.DocumentURI) error
- func (h *HandlerCommon) ShutDown()
- func (h *HandlerCommon) SpanForRequest(ctx context.Context, buildOrLang string, req *jsonrpc2.Request, ...) (opentracing.Span, context.Context, error)
 
- type HandlerShared
- type InitializationOptions
- type InitializeBuildContextParams
- type InitializeParams
- type LangHandler
- type Query
- type RewriteURIer
- type SymbolCollector
Constants ¶
const HasAlias = true
    Variables ¶
var (
	CIKConstantSupported = lsp.CIKVariable // or lsp.CIKConstant if client supported
)
    Functions ¶
func ComputeTextEdits ¶
ComputeTextEdits computes text edits that are required to change the `unformatted` to the `formatted` text.
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 NewHandler ¶
NewHandler creates a Go language server handler.
Types ¶
type AtomicFS ¶
type AtomicFS struct {
	// contains filtered or unexported fields
}
    AtomicFS wraps a ctxvfs.NameSpace but is safe for concurrent calls to Bind while doing FS operations. It is optimized for "ReadMostly" use-case. IE Bind is a relatively rare call compared to actual FS operations.
func NewAtomicFS ¶
func NewAtomicFS() *AtomicFS
NewAtomicFS returns an AtomicFS with an empty wrapped ctxvfs.NameSpace
type Config ¶
type Config struct {
	// FuncSnippetEnabled enables the returning of argument snippets on `func`
	// completions, eg. func(foo string, arg2 bar). Requires code completion
	// to be enabled.
	//
	// Defaults to true if not specified.
	FuncSnippetEnabled bool
	// GocodeCompletionEnabled enables code completion feature (using gocode)
	//
	// Defaults to false if not specified.
	GocodeCompletionEnabled bool
	// FormatTool decides which tool is used to format documents. Supported: goimports and gofmt
	//
	// Defaults to goimports if not specified.
	FormatTool string
	// GoimportsLocalPrefix sets the local prefix (comma-separated string) that goimports will use
	//
	// Defaults to empty string if not specified.
	GoimportsLocalPrefix string
	// DiagnosticsEnabled enables handling of diagnostics
	//
	// Defaults to false if not specified.
	DiagnosticsEnabled bool
	// MaxParallelism controls the maximum number of goroutines that should be used
	// to fulfill requests. This is useful in editor environments where users do
	// not want results ASAP, but rather just semi quickly without eating all of
	// their CPU.
	//
	// Defaults to half of your CPU cores if not specified.
	MaxParallelism int
	// UseBinaryPkgCache controls whether or not $GOPATH/pkg binary .a files should
	// be used.
	//
	// Defaults to true if not specified.
	UseBinaryPkgCache bool
}
    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 FilterType ¶
type FilterType string
const ( FilterExported FilterType = "exported" FilterDir FilterType = "dir" )
type FindPackageFunc ¶
type FindPackageFunc func(ctx context.Context, bctx *build.Context, importPath, fromDir string, mode build.ImportMode) (*build.Package, error)
FindPackageFunc matches the signature of loader.Config.FindPackage, except also takes a context.Context.
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 lsp.DocumentURI) 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 {
	// loader.Config.FindPackage. We use this in production to lazily
	// fetch dependencies + cache lookups.
	FindPackage FindPackageFunc
	// 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) Reset ¶
func (h *HandlerShared) Reset(useOSFS bool) error
type InitializationOptions ¶
type InitializationOptions struct {
	// FuncSnippetEnabled is an optional version of Config.FuncSnippetEnabled
	FuncSnippetEnabled *bool `json:"funcSnippetEnabled"`
	// GocodeCompletionEnabled is an optional version of
	// Config.GocodeCompletionEnabled
	GocodeCompletionEnabled *bool `json:"gocodeCompletionEnabled"`
	// FormatTool is an optional version of
	// Config.FormatTool
	FormatTool *string `json:"formatTool"`
	// GoimportsLocalPrefix is an optional version of
	// Config.GoimportsLocalPrefix
	GoimportsLocalPrefix *string `json:"goimportsLocalPrefix"`
	// MaxParallelism is an optional version of Config.MaxParallelism
	MaxParallelism *int `json:"maxParallelism"`
	// UseBinaryPkgCache is an optional version of Config.UseBinaryPkgCache
	UseBinaryPkgCache *bool `json:"useBinaryPkgCache"`
}
    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"`
	// 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 LangHandler ¶
type LangHandler struct {
	HandlerCommon
	// 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) BuildContext ¶
func (h *LangHandler) BuildContext(ctx context.Context) *build.Context
BuildContext creates a build.Context which uses the overlay FS and the InitializeParams.BuildContext overrides.
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 ¶
ParseQuery parses a user's raw query string and returns a structured representation of the query.
type RewriteURIer ¶
type RewriteURIer interface {
	// RewriteURI will update all URIs in the type using the rewrite
	// function.
	RewriteURI(rewrite func(lsp.DocumentURI) lsp.DocumentURI)
}
    RewriteURIer is a type that implements RewriteURI. The typical use of RewriteURI is a build server which translates workspace URIs into URIs for other systems to consume.
type SymbolCollector ¶
type SymbolCollector struct {
	// contains filtered or unexported fields
}
    SymbolCollector stores symbol information for an AST
       Source Files
      ¶
      Source Files
      ¶
    
  
       Directories
      ¶
      Directories
      ¶
    
    | Path | Synopsis | 
|---|---|
| internal
       | |
| 
          
            godef/go/parser
            
            
          
           A parser for Go source files. | A parser for Go source files. | 
| 
          
            godef/go/types
            
            
          
           Types infers source locations and types from Go expressions. | Types infers source locations and types from Go expressions. |