lsp

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package lsp provides a pluggable language server protocol implementation, as well as utilities to make building language servers easier.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UTF16Len

func UTF16Len(s []byte) int

UTF16Len returns the number of UTF-16 code units required to encode the given UTF-8 byte slice.

Types

type File

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

File is a representation of a text file that can be modified by LSP text document change events. It keeps track of line breaks to allow for efficient conversion between byte offsets and LSP positions.

func (*File) ApplyChange

func (f *File) ApplyChange(change types.TextDocumentContentChangeEvent) error

ApplyChange applies the given change to the file content.

func (File) Bytes

func (f File) Bytes() []byte

Bytes returns the raw bytes of the file.

func (*File) GetOffset

func (f *File) GetOffset(p types.Position) (int, error)

GetOffset returns the byte offset for the given LSP protocol position.

func (*File) GetPosition

func (f *File) GetPosition(offset int) (types.Position, error)

GetPosition returns the LSP protocol position for the given byte offset.

func (*File) Reset

func (f *File) Reset(s []byte)

Reset initializes the file with the given content.

type Handler

type Handler interface {
	Capabilities() types.ServerCapabilities
	HandleOpen(params types.DidOpenTextDocumentParams) error
	HandleClose(params types.DidCloseTextDocumentParams) error
	HandleChange(params types.DidChangeTextDocumentParams) error
	HandleDefinition(params types.DefinitionParams) ([]types.Location, error)
	HandleReferences(params types.ReferenceParams) ([]types.Location, error)
}

Handler is an interface for handling LSP requests.

type NopHandler

type NopHandler struct{}

NopHandler can be embedded in a struct to provide no-op implementations of ununsed Handler methods.

func (NopHandler) Capabilities

func (NopHandler) Capabilities() types.ServerCapabilities

Capabilities implements Handler.

func (NopHandler) HandleChange

HandleChange implements Handler.

func (NopHandler) HandleClose

HandleClose implements Handler.

func (NopHandler) HandleDefinition

func (NopHandler) HandleDefinition(types.DefinitionParams) ([]types.Location, error)

HandleDefinition implements Handler.

func (NopHandler) HandleOpen

HandleOpen implements Handler.

func (NopHandler) HandleReferences

func (NopHandler) HandleReferences(types.ReferenceParams) ([]types.Location, error)

HandleReferences implements Handler.

type Server

type Server struct {
	Reader     io.Reader
	Writer     io.Writer
	Handler    Handler
	ServerInfo types.ServerInfo
}

Server is an LSP server. It handles the I/O and delegates handling of requests to a Handler.

func (*Server) Run

func (s *Server) Run() error

Run is a blocking function that reads from the server's Reader, processes requests, and writes responses to the server's Writer. It returns an error if the server stops unexpectedly.

Directories

Path Synopsis
Package jsonrpc provides utilities for working with the JSON-RPC protocol.
Package jsonrpc provides utilities for working with the JSON-RPC protocol.
Package testutil provides common utilities for testing the LSP server.
Package testutil provides common utilities for testing the LSP server.
Package types contains the Language Server Protocol specification types.
Package types contains the Language Server Protocol specification types.

Jump to

Keyboard shortcuts

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