lsproto

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsFilenameToUrl added in v1.3.4

func AbsFilenameToUrl(filename string) (string, error)

func CompletionListToString added in v1.3.4

func CompletionListToString(clist *CompletionList) []string

func GoplsRegistration added in v1.3.3

func GoplsRegistration(stderr bool, tcp bool, trace bool) string

func JsonGetPath

func JsonGetPath(v any, path string) (any, error)

func LocationsToString added in v1.3.4

func LocationsToString(locations []*Location, baseDir string) (string, error)

func ManagerCallHierarchyCallsToString added in v1.3.3

func ManagerCallHierarchyCallsToString(mcalls []*ManagerCallHierarchyCalls, typ CallHierarchyCallType, baseDir string) (string, error)

func PatchTextEdits added in v1.1.0

func PatchTextEdits(src []byte, edits []*TextEdit) ([]byte, error)

func RangeToOffsetLen

func RangeToOffsetLen(rd iorw.ReaderAt, rang *Range) (int, int, error)

func RegistrationExamples

func RegistrationExamples() []string

func UrlToAbsFilename added in v1.3.4

func UrlToAbsFilename(url string) (string, error)

func Utf16Column

func Utf16Column(rd iorw.ReaderAt, lineStartOffset, utf8Col int) (int, error)

func Utf8Column

func Utf8Column(rd iorw.ReaderAt, lineStartOffset, utf16Col int) (int, error)

Input and result is zero based.

Types

type CallHierarchyCall added in v1.3.3

type CallHierarchyCall struct {
	From       *CallHierarchyItem `json:"from,omitempty"` // incoming
	To         *CallHierarchyItem `json:"to,omitempty"`   // outgoing
	FromRanges []*Range           `json:"fromRanges"`
}

func (*CallHierarchyCall) Item added in v1.3.3

func (chc *CallHierarchyCall) Item() *CallHierarchyItem

type CallHierarchyCallType added in v1.3.3

type CallHierarchyCallType int

Not part of the protocol, used to unify/simplify

const (
	IncomingChct CallHierarchyCallType = iota
	OutgoingChct
)

type CallHierarchyCallsParams added in v1.3.3

type CallHierarchyCallsParams struct {
	Item *CallHierarchyItem `json:"item"`
}

type CallHierarchyItem added in v1.3.3

type CallHierarchyItem struct {
	Name           string       `json:"name"`
	Kind           SymbolKind   `json:"kind"`
	Tags           []*SymbolTag `json:"tags,omitempty"` // optional
	Detail         string       `json:"detail"`         // optional
	Uri            DocumentUri  `json:"uri"`
	Range          *Range       `json:"range"`
	SelectionRange *Range       `json:"selectionRange"`
	Data           any          `json:"data,omitempty"` // optional (related to prepare calls)
}

type CallHierarchyPrepareParams added in v1.3.3

type CallHierarchyPrepareParams struct {
	TextDocumentPositionParams
}

type Client

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

func NewClientIO

func NewClientIO(ctx context.Context, rwc io.ReadWriteCloser, li *LangInstance) *Client

func NewClientTCP

func NewClientTCP(ctx context.Context, addr string, li *LangInstance) (*Client, error)

func (*Client) Call

func (cli *Client) Call(ctx context.Context, method string, args, reply any) error

func (*Client) CallHierarchyCalls added in v1.3.3

func (cli *Client) CallHierarchyCalls(ctx context.Context, typ CallHierarchyCallType, item *CallHierarchyItem) ([]*CallHierarchyCall, error)

func (*Client) ExitNotification

func (cli *Client) ExitNotification() error

func (*Client) Initialize

func (cli *Client) Initialize(ctx context.Context) error

func (*Client) ShutdownRequest

func (cli *Client) ShutdownRequest() error

func (*Client) TextDocumentCompletion

func (cli *Client) TextDocumentCompletion(ctx context.Context, filename string, pos Position) (*CompletionList, error)

func (*Client) TextDocumentDefinition

func (cli *Client) TextDocumentDefinition(ctx context.Context, filename string, pos Position) (*Location, error)

func (*Client) TextDocumentDidChange

func (cli *Client) TextDocumentDidChange(ctx context.Context, filename, text string, version int) error

func (*Client) TextDocumentDidClose

func (cli *Client) TextDocumentDidClose(ctx context.Context, filename string) error

func (*Client) TextDocumentDidOpen

func (cli *Client) TextDocumentDidOpen(ctx context.Context, filename, text string, version int) error

func (*Client) TextDocumentDidOpenVersion

func (cli *Client) TextDocumentDidOpenVersion(ctx context.Context, filename string, b []byte) error

func (*Client) TextDocumentDidSave

func (cli *Client) TextDocumentDidSave(ctx context.Context, filename string, text []byte) error

func (*Client) TextDocumentImplementation added in v1.3.3

func (cli *Client) TextDocumentImplementation(ctx context.Context, filename string, pos Position) (*Location, error)

func (*Client) TextDocumentPrepareCallHierarchy added in v1.3.3

func (cli *Client) TextDocumentPrepareCallHierarchy(ctx context.Context, filename string, pos Position) ([]*CallHierarchyItem, error)

func (*Client) TextDocumentReferences added in v1.3.4

func (cli *Client) TextDocumentReferences(ctx context.Context, filename string, pos Position) ([]*Location, error)

func (*Client) TextDocumentRename added in v1.1.0

func (cli *Client) TextDocumentRename(ctx context.Context, filename string, pos Position, newName string) (*WorkspaceEdit, error)

func (*Client) Wait added in v1.1.0

func (cli *Client) Wait() error

type CompletionContext

type CompletionContext struct {
	TriggerKind      int    `json:"triggerKind"` // 1=invoked, 2=char, 3=re-trigger
	TriggerCharacter string `json:"triggerCharacter,omitempty"`
}

type CompletionItem

type CompletionItem struct {
	Label         string                       `json:"label"`
	Kind          CompletionItemKind           `json:"kind,omitempty"`
	Detail        string                       `json:"detail,omitempty"`
	Documentation _completionItemDocumentation `json:"documentation,omitempty"`
	Deprecated    bool                         `json:"deprecated,omitempty"` // deprecated in favor of "tags"
	Tags          []CompletionItemTag          `json:"tags,omitempty"`
}

type CompletionItemKind added in v1.3.7

type CompletionItemKind int

type CompletionItemTag added in v1.3.7

type CompletionItemTag int

type CompletionList

type CompletionList struct {
	IsIncomplete bool              `json:"isIncomplete"`
	Items        []*CompletionItem `json:"items"`
}

type CompletionParams

type CompletionParams struct {
	TextDocumentPositionParams
	Context CompletionContext `json:"context"`
}

type DidChangeTextDocumentParams

type DidChangeTextDocumentParams struct {
	TextDocument   VersionedTextDocumentIdentifier   `json:"textDocument,omitempty"`
	ContentChanges []*TextDocumentContentChangeEvent `json:"contentChanges,omitempty"`
}

type DidChangeWorkspaceFoldersParams

type DidChangeWorkspaceFoldersParams struct {
	Event *WorkspaceFoldersChangeEvent `json:"event,omitempty"`
}

type DidCloseTextDocumentParams

type DidCloseTextDocumentParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
}

type DidOpenTextDocumentParams

type DidOpenTextDocumentParams struct {
	TextDocument TextDocumentItem `json:"textDocument"`
}

type DidSaveTextDocumentParams

type DidSaveTextDocumentParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Text         string                 `json:"text,omitempty"`
}

type DocumentUri added in v1.1.0

type DocumentUri string

type JsonCodec

type JsonCodec struct {
	OnNotificationMessage   func(*NotificationMessage)
	OnUnexpectedServerReply func(*Response)
	// contains filtered or unexported fields
}

Implements rpc.ClientCodec

func NewJsonCodec

func NewJsonCodec(rwc io.ReadWriteCloser) *JsonCodec

Needs a call to ReadLoop() to start reading.

func (*JsonCodec) Close

func (c *JsonCodec) Close() error

func (*JsonCodec) ReadLoop

func (c *JsonCodec) ReadLoop() error

func (*JsonCodec) ReadResponseBody

func (c *JsonCodec) ReadResponseBody(reply any) error

func (*JsonCodec) ReadResponseHeader

func (c *JsonCodec) ReadResponseHeader(resp *rpc.Response) error

Sets response.Seq to have ReadResponseBody be called with the correct reply variable.

func (*JsonCodec) WriteRequest

func (c *JsonCodec) WriteRequest(req *rpc.Request, data any) error

type LangInstance

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

func NewLangInstance

func NewLangInstance(ctx context.Context, lang *LangManager) (*LangInstance, error)

func (*LangInstance) Wait added in v1.1.0

func (li *LangInstance) Wait() error

type LangManager

type LangManager struct {
	Reg *Registration // accessed from editor
	// contains filtered or unexported fields
}

func NewLangManager

func NewLangManager(man *Manager, reg *Registration) *LangManager

func (*LangManager) Close

func (lang *LangManager) Close() (error, bool)

returns true if the instance was running

func (*LangManager) PrintWrapError added in v1.1.0

func (lang *LangManager) PrintWrapError(err error)

func (*LangManager) WrapError

func (lang *LangManager) WrapError(err error) error

func (*LangManager) WrapMsg added in v1.1.0

func (lang *LangManager) WrapMsg(s string) string

type Location

type Location struct {
	Uri   DocumentUri `json:"uri,omitempty"`
	Range *Range      `json:"range,omitempty"`
}

type LogMessageParams added in v1.3.7

type LogMessageParams struct {
	Type    MessageType `json:"type,omitempty"`
	Message string      `json:"message,omitempty"`
}

type Manager

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

Notes: - Manager manages LangManagers - LangManager has a Registration and handles a LangInstance - Client handles client connection to the lsp server - ServerWrap, if used, runs the lsp server process

func NewManager

func NewManager(msgFn func(string)) *Manager

func (*Manager) CallHierarchyCalls added in v1.3.3

func (man *Manager) CallHierarchyCalls(ctx context.Context, filename string, rd iorw.ReaderAt, offset int, typ CallHierarchyCallType) ([]*ManagerCallHierarchyCalls, error)

func (*Manager) Close

func (man *Manager) Close() error

func (*Manager) Error added in v1.1.0

func (man *Manager) Error(err error)

func (*Manager) LangManager

func (man *Manager) LangManager(filename string) (*LangManager, error)

func (*Manager) Message added in v1.1.0

func (man *Manager) Message(s string)

func (*Manager) Register

func (man *Manager) Register(reg *Registration) error

func (*Manager) SyncText added in v1.3.4

func (man *Manager) SyncText(ctx context.Context, filename string, rd iorw.ReaderAt) error

func (*Manager) TextDocumentCompletion

func (man *Manager) TextDocumentCompletion(ctx context.Context, filename string, rd iorw.ReaderAt, offset int) (*CompletionList, error)

func (*Manager) TextDocumentCompletionDetailStrings

func (man *Manager) TextDocumentCompletionDetailStrings(ctx context.Context, filename string, rd iorw.ReaderAt, offset int) ([]string, error)

func (*Manager) TextDocumentDefinition

func (man *Manager) TextDocumentDefinition(ctx context.Context, filename string, rd iorw.ReaderAt, offset int) (string, *Range, error)

func (*Manager) TextDocumentImplementation added in v1.3.3

func (man *Manager) TextDocumentImplementation(ctx context.Context, filename string, rd iorw.ReaderAt, offset int) (string, *Range, error)

func (*Manager) TextDocumentReferences added in v1.3.4

func (man *Manager) TextDocumentReferences(ctx context.Context, filename string, rd iorw.ReaderAt, offset int) ([]*Location, error)

func (*Manager) TextDocumentRename added in v1.1.0

func (man *Manager) TextDocumentRename(ctx context.Context, filename string, rd iorw.ReaderAt, offset int, newName string) (*WorkspaceEdit, error)

func (*Manager) TextDocumentRenameAndPatch added in v1.3.4

func (man *Manager) TextDocumentRenameAndPatch(ctx context.Context, filename string, rd iorw.ReaderAt, offset int, newName string, prePatchFn func([]*WorkspaceEditChange) error) ([]*WorkspaceEditChange, error)

type ManagerCallHierarchyCalls added in v1.3.3

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

type MarkupContent added in v1.3.7

type MarkupContent struct {
	Kind  MarkupKind `json:"kind"`
	Value string     `json:"value"`
}

type MarkupKind added in v1.3.7

type MarkupKind string // ex: plaintext, markup

type Message added in v1.3.3

type Message struct {
	JsonRpc string `json:"jsonrpc"`
}

func MakeMessage added in v1.3.3

func MakeMessage() Message

type MessageType added in v1.3.7

type MessageType int

type NotificationMessage

type NotificationMessage struct {
	Message
	Method string `json:"method,omitempty"`

	//Params any                        `json:"params,omitempty"`
	Params _notificationMessageParams `json:"params,omitempty"`
}

Used as request and response (sent/received).

type Position

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

func OffsetToPosition

func OffsetToPosition(rd iorw.ReaderAt, offset int) (Position, error)

func (*Position) OneBased added in v1.3.4

func (pos *Position) OneBased() (int, int)

type Range

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

type ReferenceContext added in v1.3.4

type ReferenceContext struct {
	IncludeDeclaration bool `json:"includeDeclaration"`
}

type ReferenceParams added in v1.3.4

type ReferenceParams struct {
	TextDocumentPositionParams
	Context ReferenceContext `json:"context"`
}

type Registration

type Registration struct {
	Language string
	Exts     []string
	Network  string // {stdio,tcpclient,tcp{templatevals:.Addr}}
	Cmd      string
	Optional []string // {stderr,nogotoimpl}
}

func NewRegistration

func NewRegistration(s string) (*Registration, error)

func (*Registration) HasOptional

func (reg *Registration) HasOptional(s string) bool

func (*Registration) String added in v1.3.1

func (reg *Registration) String() string

type RenameParams added in v1.1.0

type RenameParams struct {
	TextDocumentPositionParams
	NewName string `json:"newName"`
}

type RequestMessage

type RequestMessage struct {
	Message
	Id     int    `json:"id"`
	Method string `json:"method,omitempty"`
	Params any    `json:"params,omitempty"`
}

type Response

type Response struct {
	*ResponseMessage
	*NotificationMessage
}

func (*Response) IsNotification added in v1.3.3

func (res *Response) IsNotification() bool

type ResponseError

type ResponseError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data"`
}

func (*ResponseError) Error

func (e *ResponseError) Error() string

type ResponseMessage

type ResponseMessage struct {
	Message
	Id     int             `json:"id,omitempty"` // id can be zero on first msg
	Error  *ResponseError  `json:"error,omitempty"`
	Result json.RawMessage `json:"result,omitempty"`
}

type ServerWrap

type ServerWrap struct {
	Cmd osutil.CmdI
	// contains filtered or unexported fields
}

func StartServerWrapIO added in v1.1.0

func StartServerWrapIO(ctx context.Context, cmd string, stderr io.Writer, li *LangInstance) (*ServerWrap, io.ReadWriteCloser, error)

func StartServerWrapTCP added in v1.1.0

func StartServerWrapTCP(ctx context.Context, cmdTmpl string, w io.Writer) (*ServerWrap, string, error)

func (*ServerWrap) Wait added in v1.1.0

func (sw *ServerWrap) Wait() error

type SymbolKind added in v1.3.3

type SymbolKind int

type SymbolTag added in v1.3.3

type SymbolTag int

type TextDocumentContentChangeEvent

type TextDocumentContentChangeEvent struct {
	Range       Range  `json:"range,omitempty"`
	RangeLength int    `json:"rangeLength,omitempty"`
	Text        string `json:"text,omitempty"`
}

type TextDocumentEdit added in v1.1.0

type TextDocumentEdit struct {
	TextDocument VersionedTextDocumentIdentifier `json:"textDocument"`
	Edits        []*TextEdit                     `json:"edits"`
}

type TextDocumentIdentifier

type TextDocumentIdentifier struct {
	Uri DocumentUri `json:"uri"`
}

type TextDocumentItem

type TextDocumentItem struct {
	Uri        DocumentUri `json:"uri"`
	LanguageId string      `json:"languageId,omitempty"`
	Version    int         `json:"version"`
	Text       string      `json:"text"`
}

type TextDocumentPositionParams

type TextDocumentPositionParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Position     Position               `json:"position"`
}

type TextEdit added in v1.1.0

type TextEdit struct {
	Range   *Range `json:"range"`
	NewText string `json:"newText"`
}

type VersionedTextDocumentIdentifier

type VersionedTextDocumentIdentifier struct {
	TextDocumentIdentifier
	Version *int `json:"version"`
}

type WorkspaceEdit added in v1.1.0

type WorkspaceEdit struct {
	Changes         map[DocumentUri][]*TextEdit `json:"changes,omitempty"`
	DocumentChanges []*TextDocumentEdit         `json:"documentChanges,omitempty"`
}

func (*WorkspaceEdit) GetChanges added in v1.3.4

func (we *WorkspaceEdit) GetChanges() ([]*WorkspaceEditChange, error)

type WorkspaceEditChange added in v1.1.0

type WorkspaceEditChange struct {
	Filename string
	Edits    []*TextEdit
}

Not part of the protocol, used to unify/simplify

type WorkspaceFolder

type WorkspaceFolder struct {
	Uri  DocumentUri `json:"uri"`
	Name string      `json:"name"`
}

type WorkspaceFoldersChangeEvent

type WorkspaceFoldersChangeEvent struct {
	Added   []*WorkspaceFolder `json:"added"`
	Removed []*WorkspaceFolder `json:"removed"`
}

Jump to

Keyboard shortcuts

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