server

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: Apache-2.0 Imports: 17 Imported by: 1

README

ls-builder - Server

package main

import (
    lsp "github.com/newstack-cloud/ls-builder/server"
)

This package provides transport and socket implementations for language servers that can be used for packages that implement different versions of the Language Server Protocol.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTimeout = time.Minute

DefaultTimeout is the default timeout used for a JSON-RPC 2.0 connection.

Functions

func CreateConnectionOptions

func CreateConnectionOptions(debug bool, logger *zap.Logger) []jsonrpc2.ConnOpt

func NewLSPContext

func NewLSPContext(ctx context.Context, conn *jsonrpc2.Conn, request *jsonrpc2.Request) *common.LSPContext

NewLSPContext creates a new LSP context from the given connection and request.

func NewStreamConnection

func NewStreamConnection(handler jsonrpc2.Handler, stream io.ReadWriteCloser, opts ...ConnOption) *jsonrpc2.Conn

NewStreamConnection creates a new JSON-RPC 2.0 connection over a stream (io.ReadWriterCloser).

func NewWebSocketConnection

func NewWebSocketConnection(handler jsonrpc2.Handler, wsConn *websocket.Conn, opts ...ConnOption) *jsonrpc2.Conn

NewWebSocketConnection creates a new JSON-RPC 2.0 connection over a WebSocket connection.

func RunTCP

func RunTCP(ctx context.Context, address string, server *Server, logger *zap.Logger) error

RunTCP begins listening for TCP connections on the provided address, creating a LSP over JSON-RPC 2.0 connection on top of each incoming TCP connection with the provided server.

func RunWebSocketServer

func RunWebSocketServer(address string, server *Server, logger *zap.Logger, httpServer *http.Server) error

RunWebSocketServer starts a new web socket server on the provided address.

Types

type ConnOption

type ConnOption func(*connWrapper)

ConnOption is a function that configures a connection.

func WithJSONRPCConnOptions

func WithJSONRPCConnOptions(opts ...jsonrpc2.ConnOpt) ConnOption

WithJSONRPCConnOptions configures the connection with JSON-RPC 2.0 connection options.

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) ConnOption

WithReadTimeout configures the connection with a read timeout.

func WithTimeout

func WithTimeout(timeout time.Duration) ConnOption

WithTimeout configures the connection with a timeout.

func WithWebSocket

func WithWebSocket(wsConn *websocket.Conn) ConnOption

WithWebSocket configures the connection with a WebSocket connection.

func WithWriteTimeout

func WithWriteTimeout(timeout time.Duration) ConnOption

WithWriteTimeout configures the connection with a write timeout.

type JSONRPCLogger

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

func (*JSONRPCLogger) Printf

func (l *JSONRPCLogger) Printf(format string, v ...any)

Printf implements the jsonrpc2.Logger interface.

type Server

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

Server is an LSP over JSON-RPC 2.0 server that works for all versions of LSP that ls-builder provides.

func NewServer

func NewServer(
	handler common.Handler,
	debug bool,
	logger *zap.Logger,
	conn *jsonrpc2.Conn,
	opts ...ServerOption,
) *Server

NewServer creates a new LSP server over JSON-RPC 2.0.

func (*Server) GetReadTimeout

func (s *Server) GetReadTimeout() time.Duration

GetReadTimeout returns the server's read timeout.

func (*Server) GetTimeout

func (s *Server) GetTimeout() time.Duration

GetTimeout returns the server's timeout.

func (*Server) GetWriteTimeout

func (s *Server) GetWriteTimeout() time.Duration

GetWriteTimeout returns the server's write timeout.

func (*Server) NewHandler

func (s *Server) NewHandler() jsonrpc2.Handler

NewHandler creates a handler from the server to handle JSON-RPC requests.

func (*Server) Serve

func (s *Server) Serve(optConn *jsonrpc2.Conn, connLogger *zap.Logger)

Serve serves a JSON-RPC 2.0 connection. If nil is passed in for the connection, the server will use the connection that was configured when the server was created.

func (*Server) ServeWebSocket

func (s *Server) ServeWebSocket(conn *websocket.Conn, logger *zap.Logger)

ServeWebSocket serves a JSON-RPC 2.0 connection over a WebSocket connection. See `RunWebSocketServer` for a complete example of how to serve JSON-RPC 2.0 communication over WebSockets.

type ServerOption

type ServerOption func(*Server)

ServerOption is a function that configures a server.

func WithServerReadTimeout

func WithServerReadTimeout(timeout time.Duration) ServerOption

WithServerReadTimeout configures the server with a read timeout.

func WithServerTimeout

func WithServerTimeout(timeout time.Duration) ServerOption

WithServerTimeout configures the server with a timeout.

func WithServerWriteTimeout

func WithServerWriteTimeout(timeout time.Duration) ServerOption

WithServerWriteTimeout configures the server with a write timeout.

type Stdio

type Stdio struct{}

Stdio provides a ReadWriteCloser interface to os.Stdin and os.Stdout to be used as the transport layer for a language server over JSON-RPC 2.0.

func (Stdio) Close

func (Stdio) Close() error

Close closes os.Stdin and os.Stdout. Fulfils the io.Closer interface.

func (Stdio) Read

func (Stdio) Read(p []byte) (int, error)

Read reads from os.Stdin. Fulfils the io.Reader interface.

func (Stdio) Write

func (Stdio) Write(p []byte) (int, error)

Write writes to os.Stdout. Fulfils the io.Writer interface.

Jump to

Keyboard shortcuts

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