lsp

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Go         = LanguageId("Go")
	JavaScript = LanguageId("JavaScript")
	Python     = LanguageId("Python")
	TypeScript = LanguageId("TypeScript")
)

Language IDs based on https://github.com/go-enry/go-enry For reference see https://github.com/go-enry/go-enry/blob/master/data/languageInfo.go

Variables

View Source
var LspServerExecutables = map[LanguageId]Command{
	Go:         NewCommand("gopls", []string{}),
	Python:     NewCommand("pyright-langserver", []string{"--stdio"}),
	JavaScript: NewCommand("typescript-language-server", []string{"--stdio"}),
	TypeScript: NewCommand("typescript-language-server", []string{"--stdio"}),
}

Functions

func NewClient

func NewClient(server Process) (Client, Diagnostics)

func PathToURI

func PathToURI(path string) protocol.DocumentUri

Types

type Client

type Client interface {
	GetWorkspaceSymbols(ctx context.Context, params protocol.WorkspaceSymbolParams) ([]protocol.SymbolInformation, error)
	GetDocumentSymbols(ctx context.Context, params protocol.DocumentSymbolParams) ([]protocol.DocumentSymbol, error)
	Initialize(ctx context.Context, params protocol.InitializeParams) (protocol.InitializeResult, error)
	NotifyInitialized(ctx context.Context) error
	NotifyDidOpen(ctx context.Context, params protocol.DidOpenTextDocumentParams) error
	NotifyDidClose(ctx context.Context, params protocol.DidCloseTextDocumentParams) error
	// TODO: check if any LSP server supports this
	// PullDiagnostics(ctx context.Context, params DocumentDiagnosticParams) (DocumentDiagnosticReport, error)
	Shutdown(ctx context.Context) error
}

type ClientImpl

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

func (*ClientImpl) GetDocumentSymbols added in v0.5.0

func (c *ClientImpl) GetDocumentSymbols(ctx context.Context, params protocol.DocumentSymbolParams) ([]protocol.DocumentSymbol, error)

func (*ClientImpl) GetWorkspaceSymbols

func (c *ClientImpl) GetWorkspaceSymbols(ctx context.Context, params protocol.WorkspaceSymbolParams) ([]protocol.SymbolInformation, error)

func (*ClientImpl) Initialize

func (*ClientImpl) NotifyDidClose

func (c *ClientImpl) NotifyDidClose(ctx context.Context, params protocol.DidCloseTextDocumentParams) error

func (*ClientImpl) NotifyDidOpen

func (c *ClientImpl) NotifyDidOpen(ctx context.Context, params protocol.DidOpenTextDocumentParams) error

func (*ClientImpl) NotifyInitialized

func (c *ClientImpl) NotifyInitialized(ctx context.Context) error

func (*ClientImpl) Shutdown

func (c *ClientImpl) Shutdown(ctx context.Context) error

type ClientPool

type ClientPool interface {
	Get(projectId ProjectId, languageId LanguageId) (Client, bool)
	GetAllForProject(projectId ProjectId) (map[LanguageId]Client, bool)
	Set(projectId ProjectId, languageId LanguageId, client Client)
	Delete(projectId ProjectId, languageId LanguageId)
	DeleteAllForProject(projectId ProjectId)
}

type ClientPoolImpl

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

In memory store for clients. Applies mutex locking for concurrent access.

func NewClientPool

func NewClientPool() *ClientPoolImpl

func (*ClientPoolImpl) Delete

func (c *ClientPoolImpl) Delete(projectId ProjectId, languageId LanguageId)

func (*ClientPoolImpl) DeleteAllForProject

func (c *ClientPoolImpl) DeleteAllForProject(projectId ProjectId)

func (*ClientPoolImpl) Get

func (c *ClientPoolImpl) Get(projectId ProjectId, languageId LanguageId) (Client, bool)

func (*ClientPoolImpl) GetAllForProject

func (c *ClientPoolImpl) GetAllForProject(projectId ProjectId) (map[LanguageId]Client, bool)

func (*ClientPoolImpl) Set

func (c *ClientPoolImpl) Set(projectId ProjectId, languageId LanguageId, client Client)

type Command

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

func NewCommand

func NewCommand(name string, args []string) Command

type Connection

type Connection interface {
	Call(ctx context.Context, method string, params interface{}, result interface{}) error
	Notify(ctx context.Context, method string, params interface{}) error
}

func NewConnection

func NewConnection(ctx context.Context, rwc io.ReadWriteCloser, handler jsonrpc2.Handler) Connection

type ConnectionImpl

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

func (*ConnectionImpl) Call

func (c *ConnectionImpl) Call(ctx context.Context, method string, params interface{}, result interface{}) error

Call implements Connection.

func (*ConnectionImpl) Notify

func (c *ConnectionImpl) Notify(ctx context.Context, method string, params interface{}) error

Notify implements Connection.

type Diagnostics added in v0.5.0

type Diagnostics <-chan protocol.PublishDiagnosticsParams

type DiagnosticsStore

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

In memory store for diagnostics. Applies mutex locking for concurrent access.

func NewDiagnosticsStore

func NewDiagnosticsStore() *DiagnosticsStore

func (*DiagnosticsStore) DeleteAllForProject

func (d *DiagnosticsStore) DeleteAllForProject(projectId ProjectId)

func (*DiagnosticsStore) Get

func (*DiagnosticsStore) Set

func (d *DiagnosticsStore) Set(projectId ProjectId, uri protocol.DocumentUri, diagnostics []protocol.Diagnostic)

type DocumentOutline added in v0.5.0

type DocumentOutline struct {
	Path            string           `json:"path"`
	DocumentSymbols []DocumentSymbol `json:"document_symbols"`
}

type DocumentSymbol added in v0.5.0

type DocumentSymbol struct {
	Name     string           `json:"name"`
	Detail   string           `json:"detail"`
	Kind     string           `json:"kind"`
	Range    Range            `json:"range"`
	Children []DocumentSymbol `json:"children,omitempty"`
}

type LanguageDetector

type LanguageDetector interface {
	DetectLanguage(file *model.File) string
	DetectLanguages(files []*model.File) map[string]int
	DetectMainLanguage(files []*model.File) string
}

func NewLanguageDetector

func NewLanguageDetector() LanguageDetector

type LanguageDetectorImpl

type LanguageDetectorImpl struct{}

LanguageDetectorImpl implements LanguageDetector using https://github.com/go-enry/go-enry

func (LanguageDetectorImpl) DetectLanguage

func (ld LanguageDetectorImpl) DetectLanguage(file *model.File) LanguageId

func (LanguageDetectorImpl) DetectLanguages

func (ld LanguageDetectorImpl) DetectLanguages(files []*model.File) map[string]int

func (LanguageDetectorImpl) DetectMainLanguage

func (ld LanguageDetectorImpl) DetectMainLanguage(files []*model.File) string

type LanguageId

type LanguageId = string

type LanguageNotSupportedError

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

func NewLanguageNotSupportedError

func NewLanguageNotSupportedError(languageId LanguageId) *LanguageNotSupportedError

func (LanguageNotSupportedError) Error

type LanguageServerAlreadyExistsError

type LanguageServerAlreadyExistsError struct {
	ProjectId  ProjectId
	LanguageId LanguageId
}

func NewLanguageServerAlreadyExistsError

func NewLanguageServerAlreadyExistsError(projectId ProjectId, languageId LanguageId) *LanguageServerAlreadyExistsError

func (LanguageServerAlreadyExistsError) Error

type LanguageServerNotFoundError

type LanguageServerNotFoundError struct {
	ProjectId  ProjectId
	LanguageId LanguageId
}

func NewLanguageServerNotFoundError

func NewLanguageServerNotFoundError(projectId ProjectId, languageId LanguageId) *LanguageServerNotFoundError

func (LanguageServerNotFoundError) Error

type Location

type Location struct {
	Path  string `json:"path"`
	Range Range  `json:"range"`
}

type LspClientStore

type LspClientStore = map[ProjectId]map[LanguageId]Client

type LspDiagnostics

type LspDiagnostics = map[ProjectId]map[protocol.DocumentUri][]protocol.Diagnostic

type Position

type Position struct {
	Line      int `json:"line"`
	Character int `json:"character"`
}

type Process

type Process interface {
	Start() error
	Stop() error
	ReadWriteCloser() io.ReadWriteCloser
	Wait() error
}

func NewProcess

func NewProcess(command Command) (Process, error)

type ProcessImpl

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

func (*ProcessImpl) ReadWriteCloser

func (p *ProcessImpl) ReadWriteCloser() io.ReadWriteCloser

func (*ProcessImpl) Start

func (p *ProcessImpl) Start() error

func (*ProcessImpl) Stop

func (p *ProcessImpl) Stop() error

func (*ProcessImpl) Wait

func (p *ProcessImpl) Wait() error

type ProjectId

type ProjectId = string

type ProjectRoot

type ProjectRoot = string

type Range

type Range struct {
	Start Position `json:"start"`
	End   Position `json:"end"`
}

type Service

type Service interface {
	StartServer(ctx context.Context, languageId LanguageId) error
	StopServer(ctx context.Context, languageId LanguageId) error
	GetWorkspaceSymbols(ctx context.Context, query string, symbolFilter SymbolFilter) ([]SymbolInfo, error)
	GetDocumentOutline(ctx context.Context, file model.File) (DocumentOutline, error)
	NotifyDidOpen(ctx context.Context, file model.File) error
	NotifyDidClose(ctx context.Context, file model.File) error
	// TODO: check if any LSP server supports this
	// PullDiagnostics(ctx context.Context, params DocumentDiagnosticParams) (DocumentDiagnosticReport, error)
	GetDiagnostics(ctx context.Context, file model.File) ([]protocol.Diagnostic, error)
	CleanupProject(ctx context.Context, projectId ProjectId) error
}

func NewService

func NewService(languageDetector LanguageDetector, lspServerExecutables map[LanguageId]Command, diagnosticsStore *DiagnosticsStore, clientPool ClientPool) Service

type ServiceImpl

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

func (*ServiceImpl) CleanupProject

func (s *ServiceImpl) CleanupProject(ctx context.Context, projectId ProjectId) error

func (*ServiceImpl) GetDiagnostics

func (s *ServiceImpl) GetDiagnostics(ctx context.Context, file model.File) ([]protocol.Diagnostic, error)

func (*ServiceImpl) GetDocumentOutline added in v0.5.0

func (s *ServiceImpl) GetDocumentOutline(ctx context.Context, file model.File) (DocumentOutline, error)

func (*ServiceImpl) GetWorkspaceSymbols

func (s *ServiceImpl) GetWorkspaceSymbols(ctx context.Context, query string, symbolFilter SymbolFilter) ([]SymbolInfo, error)

func (*ServiceImpl) NotifyDidClose

func (s *ServiceImpl) NotifyDidClose(ctx context.Context, file model.File) error

NotifyDidClose implements Service.

func (*ServiceImpl) NotifyDidOpen

func (s *ServiceImpl) NotifyDidOpen(ctx context.Context, file model.File) error

NotifyDidOpen implements Service.

func (*ServiceImpl) StartServer

func (s *ServiceImpl) StartServer(ctx context.Context, languageId LanguageId) error

StartServer implements Service.

func (*ServiceImpl) StopServer

func (s *ServiceImpl) StopServer(ctx context.Context, languageId LanguageId) error

type SymbolFilter

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

func NewExcludeSymbolFilter

func NewExcludeSymbolFilter(exclude ...protocol.SymbolKind) SymbolFilter

func NewIncludeSymbolFilter

func NewIncludeSymbolFilter(include ...protocol.SymbolKind) SymbolFilter

type SymbolInfo

type SymbolInfo struct {
	Name     string   `json:"name"`
	Kind     string   `json:"kind"`
	Location Location `json:"location"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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