languageserver

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2018 License: Apache-2.0, NCSA Imports: 20 Imported by: 0

Documentation

Overview

Package languageserver provides an implementation of the Language Server Protocol v3.0 (https://github.com/Microsoft/language-server-protocol) This server implements the following capabilities:

textDocumentSync (full)
referenceProvider

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindEnclosing

func FindEnclosing(dir string, match func(string) bool) (string, error)

FindEnclosing returns the nearest enclosing directory d of dir for which match(d) returns true. If no such directory is found, FindEnclosing returns os.ErrNotExist. Any other error is returned immediately.

func ServerHandler

func ServerHandler(ls *Server) jsonrpc2.Handler

ServerHandler produces a JSONRPC 2.0 handler from a Server

Types

type LocalFile

type LocalFile struct {
	Workspace    Workspace // the workspace in which the file is found
	RelativePath string    // the path of the file within the workspace
}

LocalFile represents a file within a given workspace

func (LocalFile) KytheURI

func (l LocalFile) KytheURI() (*kytheuri.URI, error)

KytheURI produces a kytheuri.URI object that represents the file remotely

func (LocalFile) String

func (l LocalFile) String() string

func (LocalFile) URI

func (l LocalFile) URI() lsp.DocumentURI

URI produces a DocumentURI for the given LocalFile

type MappingConfig

type MappingConfig struct {
	Local string      `json:"local"`
	VName VNameConfig `json:"vname"`
}

MappingConfig contains pathmap patterns for local paths and VNames

type Options

type Options struct {
	// The number of cross-references the server will request by default.
	// If ≤ 0, a reasonable default will be chosen.
	PageSize int

	// If set, this function will be called to produce a workspace for the
	// given LSP document. If unset, uses NewSettingsWorkspaceFromURI.
	NewWorkspace func(lsp.DocumentURI) (Workspace, error)
}

Options control optional behaviours of the language server implementation.

type RefResolution

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

RefResolution represents the mapping from a location in a document to a Kythe ticket

type Server

type Server struct {
	XRefs xrefs.Service
	// contains filtered or unexported fields
}

Server provides a Language Server for interacting with data in a Kythe index

func NewServer

func NewServer(xrefs xrefs.Service, opts *Options) Server

NewServer constructs a server that delegates cross-reference requests to the specified xrefs implementation. If opts == nil, sensible defaults are used.

func (*Server) Initialize

func (ls *Server) Initialize(params lsp.InitializeParams) (*lsp.InitializeResult, error)

Initialize is invoked before any other methods, and allows the Server to receive configuration info (such as the project root) and announce its capabilities.

func (*Server) TextDocumentDefinition

func (ls *Server) TextDocumentDefinition(params lsp.TextDocumentPositionParams) ([]lsp.Location, error)

TextDocumentDefinition uses a position in code to produce a list of locations throughout the project that define the semantic node at the original position. This can trigger a diff if the source file is dirty

NOTE: As per the lsp spec, definition must return an error or a non-null result. Therefore, if no error is returned, a non-nil location slice must be returned

func (*Server) TextDocumentDidChange

func (ls *Server) TextDocumentDidChange(params lsp.DidChangeTextDocumentParams) error

TextDocumentDidChange is called when the client edits a file. The Kythe Language Server simply stores the new content and marks the file as dirty

func (*Server) TextDocumentDidClose

func (ls *Server) TextDocumentDidClose(params lsp.DidCloseTextDocumentParams) error

TextDocumentDidClose removes all cached information about the open document. Because all information extracted from documents are stored internally to the document object, this removal shouldn't leak memory

func (*Server) TextDocumentDidOpen

func (ls *Server) TextDocumentDidOpen(params lsp.DidOpenTextDocumentParams) error

TextDocumentDidOpen allows the client to inform the Server that a file has been opened. The Kythe Language Server uses this time to fetch file decorations.

func (*Server) TextDocumentHover

func (ls *Server) TextDocumentHover(params lsp.TextDocumentPositionParams) (lsp.Hover, error)

TextDocumentHover produces a documentation string for the entity referenced at a given location

func (*Server) TextDocumentReferences

func (ls *Server) TextDocumentReferences(params lsp.ReferenceParams) ([]lsp.Location, error)

TextDocumentReferences uses a position in code to produce a list of locations throughout the project that reference the same semantic node. This can trigger a diff if the source file is dirty.

NOTE: As per the lsp spec, references must return an error or a valid array. Therefore, if no error is returned, a non-nil location slice must be returned

type Settings

type Settings struct {
	Root     string          `json:"root"`
	Mappings []MappingConfig `json:"mappings"`
}

Settings contains the user configuration required for the server to communicate properly with its XRefClient

type SettingsWorkspace

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

SettingsWorkspace uses Settings values to map between paths locally and in Kythe

func NewSettingsWorkspace

func NewSettingsWorkspace(s Settings) (*SettingsWorkspace, error)

NewSettingsWorkspace constructs a SettingsWorkspace from a settings object.

func (*SettingsWorkspace) KytheURIFromRelative

func (sw *SettingsWorkspace) KytheURIFromRelative(rel string) (*kytheuri.URI, error)

KytheURIFromRelative implements part of the Workspace interface by iteratively attempting to apply mappings to the relative version of it

func (*SettingsWorkspace) LocalFromKytheURI

func (sw *SettingsWorkspace) LocalFromKytheURI(ticket kytheuri.URI) (LocalFile, error)

LocalFromKytheURI implements part of the Workspace interface by iteratively attempting to apply mappings to the given Kythe URI

func (*SettingsWorkspace) LocalFromURI

func (sw *SettingsWorkspace) LocalFromURI(lspURI lsp.DocumentURI) (LocalFile, error)

LocalFromURI implements part of the Workspace interface

func (*SettingsWorkspace) Root

func (sw *SettingsWorkspace) Root() string

Root returns the SettingsWorkspace's root

func (*SettingsWorkspace) URIFromRelative

func (sw *SettingsWorkspace) URIFromRelative(path string) string

URIFromRelative implements part of the Workspace interface

type VNameConfig

type VNameConfig struct {
	Corpus string `json:"corpus"`
	Path   string `json:"path"`
	Root   string `json:"root"`
}

VNameConfig contains pathmap patterns for VName components

type Workspace

type Workspace interface {
	// LocalFromURI generates a local file path from a DocumentURI usually
	// provided by the language client
	LocalFromURI(lspURI lsp.DocumentURI) (LocalFile, error)

	// KytheURIFromRelative generates a Kythe URI for the local file
	KytheURIFromRelative(rel string) (*kytheuri.URI, error)

	// LocalFromKytheURI generates an absolute local file path from a Kythe URI
	LocalFromKytheURI(ticket kytheuri.URI) (LocalFile, error)

	// URIFromRelative generates a URI that can be passed to a language server
	URIFromRelative(rel string) string

	// Root returns the workspace root as determined by the Workspace
	Root() string
}

Workspace provides the ability to map between paths locally and in Kythe. Because Workspaces get copied into LocalFile objects, it is highly recommended that Workspace be implemented on pointer types

func NewSettingsWorkspaceFromURI

func NewSettingsWorkspaceFromURI(lspURI lsp.DocumentURI) (Workspace, error)

NewSettingsWorkspaceFromURI finds the setttings file and produces a SettingsWorkspace

Directories

Path Synopsis
Binary kythe_languageserver provides a Language Server Protocol v3 implementation for Kythe indexes that communicates via JSONRPC2.0 over stdio
Binary kythe_languageserver provides a Language Server Protocol v3 implementation for Kythe indexes that communicates via JSONRPC2.0 over stdio
Package pathmap provides utilities for matching and generating paths based on a pattern string.
Package pathmap provides utilities for matching and generating paths based on a pattern string.

Jump to

Keyboard shortcuts

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