api

package
v0.0.0-...-f77836c Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnClosed     = errors.New("api: connection closed")
	ErrRequestTimeout = errors.New("api: request timeout")
)
View Source
var (
	ErrInvalidRequest = errors.New("api: invalid request")
	ErrClientError    = errors.New("api: client error")
)

Functions

func GeneratePipePath

func GeneratePipePath(name string) string

GeneratePipePath returns a platform-appropriate pipe path for the given name.

func UnmarshalParams

func UnmarshalParams[T any](params json.Value) (*T, error)

UnmarshalParams is a helper to unmarshal params into a typed struct.

Types

type APIFileChangeSummary

type APIFileChangeSummary struct {
	Changed []DocumentIdentifier `json:"changed,omitempty"`
	Created []DocumentIdentifier `json:"created,omitempty"`
	Deleted []DocumentIdentifier `json:"deleted,omitempty"`
}

APIFileChangeSummary lists documents that have been changed, created, or deleted.

type APIFileChanges

type APIFileChanges struct {
	InvalidateAll bool                 `json:"invalidateAll,omitempty"`
	Changed       []DocumentIdentifier `json:"changed,omitempty"`
	Created       []DocumentIdentifier `json:"created,omitempty"`
	Deleted       []DocumentIdentifier `json:"deleted,omitempty"`
}

APIFileChanges describes file changes to apply when updating a snapshot. Either InvalidateAll is true (discard all caches) or Changed/Created/Deleted list individual documents.

type AsyncConn

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

AsyncConn manages bidirectional JSON-RPC communication with async request handling. Each incoming request is handled in its own goroutine, allowing concurrent processing. This is the standard implementation for LSP-style JSON-RPC protocols.

func NewAsyncConn

func NewAsyncConn(rwc io.ReadWriteCloser, handler Handler) *AsyncConn

NewAsyncConn creates a new async connection with the given transport and handler. It uses JSONRPCProtocol (LSP-style Content-Length framing) by default.

func NewAsyncConnWithProtocol

func NewAsyncConnWithProtocol(rwc io.ReadWriteCloser, protocol Protocol, handler Handler) *AsyncConn

NewAsyncConnWithProtocol creates a new async connection with a custom protocol.

func (*AsyncConn) Call

func (c *AsyncConn) Call(ctx context.Context, method string, params any) (json.Value, error)

Call sends a request to the client and waits for a response.

func (*AsyncConn) Notify

func (c *AsyncConn) Notify(ctx context.Context, method string, params any) error

Notify sends a notification to the client (no response expected).

func (*AsyncConn) Run

func (c *AsyncConn) Run(ctx context.Context) error

Run starts processing messages on the connection. It blocks until the context is cancelled or an error occurs.

type ConfigFileResponse

type ConfigFileResponse struct {
	FileNames []string              `json:"fileNames"`
	Options   *core.CompilerOptions `json:"options"`
}

type Conn

type Conn interface {
	// Run starts processing messages on the connection.
	// It blocks until the context is cancelled or an error occurs.
	Run(ctx context.Context) error

	// Call sends a request to the client and waits for a response.
	Call(ctx context.Context, method string, params any) (json.Value, error)

	// Notify sends a notification to the client (no response expected).
	Notify(ctx context.Context, method string, params any) error
}

Conn represents a bidirectional connection for API communication.

type DocumentIdentifier

type DocumentIdentifier struct {
	FileName string              `json:"fileName,omitempty"`
	URI      lsproto.DocumentUri `json:"uri,omitempty"`
}

DocumentIdentifier identifies a document by either a file name (plain string) or a URI object. On the wire it is string | { uri: string }.

func (DocumentIdentifier) String

func (d DocumentIdentifier) String() string

func (DocumentIdentifier) ToAbsoluteFileName

func (d DocumentIdentifier) ToAbsoluteFileName(cwd string) string

func (DocumentIdentifier) ToFileName

func (d DocumentIdentifier) ToFileName() string

func (DocumentIdentifier) ToURI

func (*DocumentIdentifier) UnmarshalJSONFrom

func (d *DocumentIdentifier) UnmarshalJSONFrom(dec *json.Decoder) error

type GetBaseTypeOfLiteralTypeParams

type GetBaseTypeOfLiteralTypeParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Project  Handle[project.Project]  `json:"project"`
	Type     Handle[checker.Type]     `json:"type"`
}

GetBaseTypeOfLiteralTypeParams returns the base type of a literal type.

type GetContextualTypeParams

type GetContextualTypeParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Project  Handle[project.Project]  `json:"project"`
	Location Handle[ast.Node]         `json:"location"`
}

GetContextualTypeParams returns the contextual type for a node.

type GetDefaultProjectForFileParams

type GetDefaultProjectForFileParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	File     DocumentIdentifier       `json:"file"`
}

type GetExportsOfSymbolParams

type GetExportsOfSymbolParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Symbol   Handle[ast.Symbol]       `json:"symbol"`
}

type GetIntrinsicTypeParams

type GetIntrinsicTypeParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Project  Handle[project.Project]  `json:"project"`
}

GetIntrinsicTypeParams is used for intrinsic type getters (anyType, stringType, etc.).

type GetMembersOfSymbolParams

type GetMembersOfSymbolParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Symbol   Handle[ast.Symbol]       `json:"symbol"`
}

type GetParentOfSymbolParams

type GetParentOfSymbolParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Symbol   Handle[ast.Symbol]       `json:"symbol"`
}

type GetSignaturesOfTypeParams

type GetSignaturesOfTypeParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Project  Handle[project.Project]  `json:"project"`
	Type     Handle[checker.Type]     `json:"type"`
	Kind     int32                    `json:"kind"`
}

type GetSourceFileParams

type GetSourceFileParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Project  Handle[project.Project]  `json:"project"`
	File     DocumentIdentifier       `json:"file"`
}

type GetSymbolAtLocationParams

type GetSymbolAtLocationParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Project  Handle[project.Project]  `json:"project"`
	Location Handle[ast.Node]         `json:"location"`
}

type GetSymbolAtPositionParams

type GetSymbolAtPositionParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Project  Handle[project.Project]  `json:"project"`
	File     DocumentIdentifier       `json:"file"`
	Position uint32                   `json:"position"`
}

type GetSymbolOfTypeParams

type GetSymbolOfTypeParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Type     Handle[checker.Type]     `json:"type"`
}

type GetSymbolsAtLocationsParams

type GetSymbolsAtLocationsParams struct {
	Snapshot  Handle[project.Snapshot] `json:"snapshot"`
	Project   Handle[project.Project]  `json:"project"`
	Locations []Handle[ast.Node]       `json:"locations"`
}

type GetSymbolsAtPositionsParams

type GetSymbolsAtPositionsParams struct {
	Snapshot  Handle[project.Snapshot] `json:"snapshot"`
	Project   Handle[project.Project]  `json:"project"`
	File      DocumentIdentifier       `json:"file"`
	Positions []uint32                 `json:"positions"`
}

type GetTypeAtLocationParams

type GetTypeAtLocationParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Project  Handle[project.Project]  `json:"project"`
	Location Handle[ast.Node]         `json:"location"`
}

type GetTypeAtLocationsParams

type GetTypeAtLocationsParams struct {
	Snapshot  Handle[project.Snapshot] `json:"snapshot"`
	Project   Handle[project.Project]  `json:"project"`
	Locations []Handle[ast.Node]       `json:"locations"`
}

type GetTypeAtPositionParams

type GetTypeAtPositionParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Project  Handle[project.Project]  `json:"project"`
	File     DocumentIdentifier       `json:"file"`
	Position uint32                   `json:"position"`
}

type GetTypeOfSymbolAtLocationParams

type GetTypeOfSymbolAtLocationParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Project  Handle[project.Project]  `json:"project"`
	Symbol   Handle[ast.Symbol]       `json:"symbol"`
	Location Handle[ast.Node]         `json:"location"`
}

GetTypeOfSymbolAtLocationParams returns the narrowed type of a symbol at a specific location.

type GetTypeOfSymbolParams

type GetTypeOfSymbolParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Project  Handle[project.Project]  `json:"project"`
	Symbol   Handle[ast.Symbol]       `json:"symbol"`
}

type GetTypePropertyParams

type GetTypePropertyParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Type     Handle[checker.Type]     `json:"type"`
}

GetTypePropertyParams is used for all type sub-property endpoints.

type GetTypesAtPositionsParams

type GetTypesAtPositionsParams struct {
	Snapshot  Handle[project.Snapshot] `json:"snapshot"`
	Project   Handle[project.Project]  `json:"project"`
	File      DocumentIdentifier       `json:"file"`
	Positions []uint32                 `json:"positions"`
}

type GetTypesOfSymbolsParams

type GetTypesOfSymbolsParams struct {
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	Project  Handle[project.Project]  `json:"project"`
	Symbols  []Handle[ast.Symbol]     `json:"symbols"`
}

type Handle

type Handle[T any] string

func NodeHandleFrom

func NodeHandleFrom(node *ast.Node) Handle[ast.Node]

NodeHandleFrom creates a node handle from a node. Format: pos.end.kind.path

func ProjectHandle

func ProjectHandle(p *project.Project) Handle[project.Project]

func SignatureHandle

func SignatureHandle(id uint64) Handle[checker.Signature]

func SymbolHandle

func SymbolHandle(symbol *ast.Symbol) Handle[ast.Symbol]

func TypeHandle

func TypeHandle(t *checker.Type) Handle[checker.Type]

type Handler

type Handler interface {
	// HandleRequest handles an incoming request and returns a result or error.
	HandleRequest(ctx context.Context, method string, params json.Value) (any, error)
	// HandleNotification handles an incoming notification.
	HandleNotification(ctx context.Context, method string, params json.Value) error
}

Handler processes incoming API requests and notifications.

type InitializeResponse

type InitializeResponse struct {
	// UseCaseSensitiveFileNames indicates whether the host file system is case-sensitive.
	UseCaseSensitiveFileNames bool `json:"useCaseSensitiveFileNames"`
	// CurrentDirectory is the server's current working directory.
	CurrentDirectory string `json:"currentDirectory"`
}

InitializeResponse is returned by the initialize method.

type JSONRPCProtocol

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

JSONRPCProtocol implements the Protocol interface using JSON-RPC 2.0 with the LSP base protocol framing (Content-Length headers).

func NewJSONRPCProtocol

func NewJSONRPCProtocol(rw io.ReadWriter) *JSONRPCProtocol

NewJSONRPCProtocol creates a new JSON-RPC protocol handler.

func (*JSONRPCProtocol) ReadMessage

func (p *JSONRPCProtocol) ReadMessage() (*Message, error)

ReadMessage implements Protocol.

func (*JSONRPCProtocol) WriteError

func (p *JSONRPCProtocol) WriteError(id *jsonrpc.ID, respErr *jsonrpc.ResponseError) error

WriteError implements Protocol.

func (*JSONRPCProtocol) WriteNotification

func (p *JSONRPCProtocol) WriteNotification(method string, params any) error

WriteNotification implements Protocol.

func (*JSONRPCProtocol) WriteRequest

func (p *JSONRPCProtocol) WriteRequest(id *jsonrpc.ID, method string, params any) error

WriteRequest implements Protocol.

func (*JSONRPCProtocol) WriteResponse

func (p *JSONRPCProtocol) WriteResponse(id *jsonrpc.ID, result any) error

WriteResponse implements Protocol.

type Message

type Message = jsonrpc.Message

Message is an alias for jsonrpc.Message for convenience.

type MessagePackProtocol

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

MessagePackProtocol implements the Protocol interface using a custom msgpack-based tuple format: [MessageType, method, payload].

func NewMessagePackProtocol

func NewMessagePackProtocol(rw io.ReadWriter) *MessagePackProtocol

NewMessagePackProtocol creates a new msgpack protocol handler.

func (*MessagePackProtocol) ReadMessage

func (p *MessagePackProtocol) ReadMessage() (*Message, error)

ReadMessage implements Protocol.

func (*MessagePackProtocol) WriteError

func (p *MessagePackProtocol) WriteError(id *jsonrpc.ID, respErr *jsonrpc.ResponseError) error

WriteError implements Protocol.

func (*MessagePackProtocol) WriteNotification

func (p *MessagePackProtocol) WriteNotification(method string, params any) error

WriteNotification implements Protocol.

func (*MessagePackProtocol) WriteRequest

func (p *MessagePackProtocol) WriteRequest(id *jsonrpc.ID, method string, params any) error

WriteRequest implements Protocol.

func (*MessagePackProtocol) WriteResponse

func (p *MessagePackProtocol) WriteResponse(id *jsonrpc.ID, result any) error

WriteResponse implements Protocol.

type MessageType

type MessageType uint8

MessageType represents the type of message in the msgpack protocol.

const (
	MessageTypeUnknown MessageType = iota
	MessageTypeRequest
	MessageTypeCallResponse
	MessageTypeCallError
	MessageTypeResponse
	MessageTypeError
	MessageTypeCall
)

func (MessageType) IsValid

func (m MessageType) IsValid() bool

func (MessageType) String

func (i MessageType) String() string

type Method

type Method string
const (
	MethodRelease Method = "release"

	MethodInitialize               Method = "initialize"
	MethodUpdateSnapshot           Method = "updateSnapshot"
	MethodParseConfigFile          Method = "parseConfigFile"
	MethodGetDefaultProjectForFile Method = "getDefaultProjectForFile"
	MethodGetSymbolAtPosition      Method = "getSymbolAtPosition"
	MethodGetSymbolsAtPositions    Method = "getSymbolsAtPositions"
	MethodGetSymbolAtLocation      Method = "getSymbolAtLocation"
	MethodGetSymbolsAtLocations    Method = "getSymbolsAtLocations"
	MethodGetTypeOfSymbol          Method = "getTypeOfSymbol"
	MethodGetTypesOfSymbols        Method = "getTypesOfSymbols"
	MethodGetDeclaredTypeOfSymbol  Method = "getDeclaredTypeOfSymbol"
	MethodGetSourceFile            Method = "getSourceFile"
	MethodResolveName              Method = "resolveName"
	MethodGetParentOfSymbol        Method = "getParentOfSymbol"
	MethodGetMembersOfSymbol       Method = "getMembersOfSymbol"
	MethodGetExportsOfSymbol       Method = "getExportsOfSymbol"
	MethodGetSymbolOfType          Method = "getSymbolOfType"
	MethodGetSignaturesOfType      Method = "getSignaturesOfType"
	MethodGetTypeAtLocation        Method = "getTypeAtLocation"
	MethodGetTypeAtLocations       Method = "getTypeAtLocations"
	MethodGetTypeAtPosition        Method = "getTypeAtPosition"
	MethodGetTypesAtPositions      Method = "getTypesAtPositions"

	// Type sub-property methods
	MethodGetTargetOfType              Method = "getTargetOfType"
	MethodGetTypesOfType               Method = "getTypesOfType"
	MethodGetTypeParametersOfType      Method = "getTypeParametersOfType"
	MethodGetOuterTypeParametersOfType Method = "getOuterTypeParametersOfType"
	MethodGetLocalTypeParametersOfType Method = "getLocalTypeParametersOfType"
	MethodGetObjectTypeOfType          Method = "getObjectTypeOfType"
	MethodGetIndexTypeOfType           Method = "getIndexTypeOfType"
	MethodGetCheckTypeOfType           Method = "getCheckTypeOfType"
	MethodGetExtendsTypeOfType         Method = "getExtendsTypeOfType"
	MethodGetBaseTypeOfType            Method = "getBaseTypeOfType"
	MethodGetConstraintOfType          Method = "getConstraintOfType"

	// Checker methods
	MethodGetContextualType                 Method = "getContextualType"
	MethodGetBaseTypeOfLiteralType          Method = "getBaseTypeOfLiteralType"
	MethodGetShorthandAssignmentValueSymbol Method = "getShorthandAssignmentValueSymbol"
	MethodGetTypeOfSymbolAtLocation         Method = "getTypeOfSymbolAtLocation"

	// Intrinsic type getters
	MethodGetAnyType       Method = "getAnyType"
	MethodGetStringType    Method = "getStringType"
	MethodGetNumberType    Method = "getNumberType"
	MethodGetBooleanType   Method = "getBooleanType"
	MethodGetVoidType      Method = "getVoidType"
	MethodGetUndefinedType Method = "getUndefinedType"
	MethodGetNullType      Method = "getNullType"
	MethodGetNeverType     Method = "getNeverType"
	MethodGetUnknownType   Method = "getUnknownType"
	MethodGetBigIntType    Method = "getBigIntType"
	MethodGetESSymbolType  Method = "getESSymbolType"
)

type ParseConfigFileParams

type ParseConfigFileParams struct {
	File DocumentIdentifier `json:"file"`
}

type PipeTransport

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

PipeTransport accepts connections on a Unix domain socket or Windows named pipe.

func NewPipeTransport

func NewPipeTransport(path string) (*PipeTransport, error)

NewPipeTransport creates a new transport listening on the given path. On Unix, this creates a Unix domain socket. On Windows, this creates a named pipe.

func (*PipeTransport) Accept

func (t *PipeTransport) Accept() (io.ReadWriteCloser, error)

Accept implements Transport.

func (*PipeTransport) Close

func (t *PipeTransport) Close() error

Close implements Transport.

func (*PipeTransport) Path

func (t *PipeTransport) Path() string

Path returns the path of the pipe/socket.

type ProjectFileChanges

type ProjectFileChanges struct {
	// ChangedFiles lists source file paths whose content differs.
	ChangedFiles []tspath.Path `json:"changedFiles,omitempty"`
	// DeletedFiles lists source file paths removed from the project's program.
	DeletedFiles []tspath.Path `json:"deletedFiles,omitempty"`
}

ProjectFileChanges describes what source files changed within a single project.

type ProjectResponse

type ProjectResponse struct {
	Id              Handle[project.Project] `json:"id"`
	ConfigFileName  string                  `json:"configFileName"`
	RootFiles       []string                `json:"rootFiles"`
	CompilerOptions *core.CompilerOptions   `json:"compilerOptions"`
}

func NewProjectResponse

func NewProjectResponse(p *project.Project) *ProjectResponse

type Protocol

type Protocol interface {
	// ReadMessage reads the next message from the connection.
	ReadMessage() (*Message, error)
	// WriteRequest writes a request message.
	WriteRequest(id *jsonrpc.ID, method string, params any) error
	// WriteNotification writes a notification message (no ID).
	WriteNotification(method string, params any) error
	// WriteResponse writes a successful response.
	WriteResponse(id *jsonrpc.ID, result any) error
	// WriteError writes an error response.
	WriteError(id *jsonrpc.ID, err *jsonrpc.ResponseError) error
}

Protocol defines the interface for reading and writing API messages.

type RawBinary

type RawBinary []byte

RawBinary is a marker type for binary data that should be written directly by MessagePackProtocol instead of being JSON-encoded.

type ReleaseParams

type ReleaseParams struct {
	Handle string `json:"handle"`
}

ReleaseParams are the parameters for the release method.

type ResolveNameParams

type ResolveNameParams struct {
	Snapshot       Handle[project.Snapshot] `json:"snapshot"`
	Project        Handle[project.Project]  `json:"project"`
	Name           string                   `json:"name"`
	Location       Handle[ast.Node]         `json:"location,omitempty"`       // Optional: node handle for location context
	File           *DocumentIdentifier      `json:"file,omitempty"`           // Optional: file for location context (alternative to Location)
	Position       *uint32                  `json:"position,omitempty"`       // Optional: position in file for location context (with File)
	Meaning        uint32                   `json:"meaning"`                  // SymbolFlags for what kind of symbol to find
	ExcludeGlobals bool                     `json:"excludeGlobals,omitempty"` // Whether to exclude global symbols
}

type Session

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

Session represents an API session that provides programmatic access to TypeScript language services through the LSP server. It implements the Handler interface to process incoming API requests. The session supports multiple active snapshots, each with their own symbol and type registries for maintaining object identity.

func NewSession

func NewSession(projectSession *project.Session, options *SessionOptions) *Session

NewSession creates a new API session with the given project session.

func (*Session) Close

func (s *Session) Close()

Close closes the session and releases all active snapshots, regardless of their ref counts.

func (*Session) HandleNotification

func (s *Session) HandleNotification(ctx context.Context, method string, params json.Value) error

HandleNotification implements Handler.

func (*Session) HandleRequest

func (s *Session) HandleRequest(ctx context.Context, method string, params json.Value) (any, error)

HandleRequest implements Handler.

func (*Session) ID

func (s *Session) ID() string

ID returns the unique identifier for this session.

func (*Session) ProjectSession

func (s *Session) ProjectSession() *project.Session

ProjectSession returns the underlying project session.

type SessionOptions

type SessionOptions struct {
	// UseBinaryResponses enables binary responses for msgpack protocol.
	UseBinaryResponses bool
}

SessionOptions configures an API session.

type SignatureResponse

type SignatureResponse struct {
	Id             Handle[checker.Signature] `json:"id"`
	Flags          uint32                    `json:"flags"`
	Declaration    Handle[ast.Node]          `json:"declaration,omitempty"`
	TypeParameters []Handle[checker.Type]    `json:"typeParameters,omitempty"`
	Parameters     []Handle[ast.Symbol]      `json:"parameters,omitempty"`
	ThisParameter  Handle[ast.Symbol]        `json:"thisParameter,omitempty"`
	Target         Handle[checker.Signature] `json:"target,omitempty"`
}

type SnapshotChanges

type SnapshotChanges struct {
	// ChangedProjects maps project handles to the file changes within that project.
	// Projects not listed here (and not in RemovedProjects) are unchanged.
	ChangedProjects map[Handle[project.Project]]*ProjectFileChanges `json:"changedProjects,omitempty"`
	// RemovedProjects lists project handles that were present in the previous
	// snapshot but absent from the new one.
	RemovedProjects []Handle[project.Project] `json:"removedProjects,omitempty"`
}

SnapshotChanges describes what changed between the previous latest snapshot and the newly created snapshot. Changes are reported per-project so clients can track cache refs at the (snapshot, project) level.

type SourceFileResponse

type SourceFileResponse struct {
	Data string `json:"data"`
}

SourceFileResponse contains the binary-encoded AST data for a source file. The Data field is base64-encoded binary data in the encoder's format.

type StdioServer

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

StdioServer runs an API session over STDIO using MessagePack protocol. This is the entry point for the synchronous STDIO-based API used by native TypeScript tooling integration.

func NewStdioServer

func NewStdioServer(options *StdioServerOptions) *StdioServer

NewStdioServer creates a new STDIO-based API server.

func (*StdioServer) Run

func (s *StdioServer) Run(ctx context.Context) error

Run starts the server and blocks until the connection closes.

type StdioServerOptions

type StdioServerOptions struct {
	In                 io.ReadCloser
	Out                io.WriteCloser
	Err                io.Writer
	Cwd                string
	DefaultLibraryPath string
	// PipePath, if set, listens on a named pipe (Windows) or Unix domain
	// socket instead of using In/Out for communication.
	PipePath string
	// Callbacks specifies which filesystem operations should be delegated
	// to the client (e.g., "readFile", "fileExists"). Empty means no callbacks.
	Callbacks []string
	// Async enables JSON-RPC protocol with async connection handling.
	// When false (default), uses MessagePack protocol with sync connection.
	Async bool
}

StdioServerOptions configures the STDIO-based API server.

type StdioTransport

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

StdioTransport wraps stdin/stdout as a single connection transport. It only accepts one connection.

func NewStdioTransport

func NewStdioTransport(stdin io.ReadCloser, stdout io.WriteCloser) *StdioTransport

NewStdioTransport creates a transport using the given stdin/stdout.

func (*StdioTransport) Accept

func (t *StdioTransport) Accept() (io.ReadWriteCloser, error)

Accept implements Transport.

func (*StdioTransport) Close

func (t *StdioTransport) Close() error

Close implements Transport.

type SymbolResponse

type SymbolResponse struct {
	Id               Handle[ast.Symbol] `json:"id"`
	Name             string             `json:"name"`
	Flags            uint32             `json:"flags"`
	CheckFlags       uint32             `json:"checkFlags"`
	Declarations     []Handle[ast.Node] `json:"declarations,omitempty"`
	ValueDeclaration Handle[ast.Node]   `json:"valueDeclaration,omitempty"`
}

func NewSymbolResponse

func NewSymbolResponse(symbol *ast.Symbol) *SymbolResponse

type SyncConn

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

SyncConn manages bidirectional communication with synchronous request handling. Requests are handled one at a time inline, and outgoing calls are serialized.

func NewSyncConn

func NewSyncConn(rwc io.ReadWriteCloser, protocol Protocol, handler Handler) *SyncConn

NewSyncConn creates a new sync connection with the given transport and handler.

func (*SyncConn) Call

func (c *SyncConn) Call(ctx context.Context, method string, params any) (json.Value, error)

Call sends a request to the client and waits for a response. This method is safe to call from multiple goroutines - calls are serialized.

func (*SyncConn) Notify

func (c *SyncConn) Notify(ctx context.Context, method string, params any) error

Notify sends a notification to the client (no response expected).

func (*SyncConn) Run

func (c *SyncConn) Run(ctx context.Context) error

Run starts processing messages on the connection. It blocks until the context is cancelled or an error occurs.

type Transport

type Transport interface {
	// Accept waits for and returns the next connection.
	Accept() (io.ReadWriteCloser, error)
	// Close stops the transport from accepting new connections.
	Close() error
}

Transport is an interface for accepting connections from API clients.

type TypeResponse

type TypeResponse struct {
	Id          Handle[checker.Type] `json:"id"`
	Flags       uint32               `json:"flags"`
	ObjectFlags uint32               `json:"objectFlags,omitempty"`

	// LiteralType data
	Value any `json:"value,omitempty"`

	// ObjectType / TypeReference / StringMappingType / IndexType target
	Target Handle[checker.Type] `json:"target,omitempty"`

	// InterfaceType type parameters
	TypeParameters      []Handle[checker.Type] `json:"typeParameters,omitempty"`
	OuterTypeParameters []Handle[checker.Type] `json:"outerTypeParameters,omitempty"`
	LocalTypeParameters []Handle[checker.Type] `json:"localTypeParameters,omitempty"`

	// TupleType data
	ElementFlags  []checker.ElementFlags `json:"elementFlags,omitempty"`
	FixedLength   *int                   `json:"fixedLength,omitempty"`
	TupleReadonly *bool                  `json:"readonly,omitempty"`

	// IndexedAccessType data
	ObjectType Handle[checker.Type] `json:"objectType,omitempty"`
	IndexType  Handle[checker.Type] `json:"indexType,omitempty"`

	// ConditionalType data
	CheckType   Handle[checker.Type] `json:"checkType,omitempty"`
	ExtendsType Handle[checker.Type] `json:"extendsType,omitempty"`

	// SubstitutionType data
	BaseType        Handle[checker.Type] `json:"baseType,omitempty"`
	SubstConstraint Handle[checker.Type] `json:"substConstraint,omitempty"`

	// TemplateLiteralType text segments
	Texts []string `json:"texts,omitempty"`

	// Symbol associated with structured types
	Symbol Handle[ast.Symbol] `json:"symbol,omitempty"`
}

type UpdateSnapshotParams

type UpdateSnapshotParams struct {
	// OpenProject is the path to a tsconfig.json file to open/load in the new snapshot.
	OpenProject string `json:"openProject,omitempty"`
	// FileChanges describes file system changes since the last snapshot.
	FileChanges *APIFileChanges `json:"fileChanges,omitempty"`
}

UpdateSnapshotParams are the parameters for creating a new snapshot. All fields are optional. With no fields set, the server adopts the latest LSP state.

type UpdateSnapshotResponse

type UpdateSnapshotResponse struct {
	// Snapshot is the handle for the newly created snapshot.
	Snapshot Handle[project.Snapshot] `json:"snapshot"`
	// Projects is the list of projects in the snapshot.
	Projects []*ProjectResponse `json:"projects"`
	// Changes describes source file differences from the previous snapshot.
	// Nil for the first snapshot in a session.
	Changes *SnapshotChanges `json:"changes,omitempty"`
}

UpdateSnapshotResponse is returned by updateSnapshot.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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