ipc

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package ipc provides IPC communication between JS and Go using stdio

Index

Constants

View Source
const Version = "1.0.0"

Version is the IPC protocol version

Variables

This section is empty.

Functions

func EncodeAST added in v0.1.13

func EncodeAST(sourceFile *ast.SourceFile, id string) ([]byte, error)

func IsIPCMode

func IsIPCMode() bool

IsIPCMode returns true if the process is in IPC mode

Types

type ApplyFixesRequest added in v0.1.12

type ApplyFixesRequest struct {
	FileContent string       `json:"fileContent"` // Current content of the file
	Diagnostics []Diagnostic `json:"diagnostics"` // Diagnostics with fixes to apply
}

ApplyFixesRequest represents a request to apply fixes from JS to Go

type ApplyFixesResponse added in v0.1.12

type ApplyFixesResponse struct {
	FixedContent   []string `json:"fixedContent"`   // The content after applying fixes (array of intermediate versions)
	WasFixed       bool     `json:"wasFixed"`       // Whether any fixes were actually applied
	AppliedCount   int      `json:"appliedCount"`   // Number of fixes that were applied
	UnappliedCount int      `json:"unappliedCount"` // Number of fixes that couldn't be applied
}

ApplyFixesResponse represents a response after applying fixes

type ByteArray added in v0.1.13

type ByteArray []byte

type Diagnostic

type Diagnostic struct {
	RuleName  string `json:"ruleName"`
	Message   string `json:"message"`
	FilePath  string `json:"filePath"`
	Range     Range  `json:"range"`
	Severity  string `json:"severity,omitempty"`
	MessageId string `json:"messageId"`
	Fixes     []Fix  `json:"fixes,omitempty"`
}

Diagnostic represents a single lint diagnostic

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
}

ErrorResponse represents an error response

type Fix added in v0.1.12

type Fix struct {
	Text     string `json:"text"`
	StartPos int    `json:"startPos"` // Character position in the file content
	EndPos   int    `json:"endPos"`   // Character position in the file content
}

Fix represents a single fix that can be applied

type Handler

type Handler interface {
	HandleLint(req LintRequest) (*LintResponse, error)
	HandleApplyFixes(req ApplyFixesRequest) (*ApplyFixesResponse, error)
}

Handler defines the interface for handling IPC messages

type HandshakeRequest

type HandshakeRequest struct {
	Version string `json:"version"`
}

HandshakeRequest represents a handshake request

type HandshakeResponse

type HandshakeResponse struct {
	Version string `json:"version"`
	OK      bool   `json:"ok"`
}

HandshakeResponse represents a handshake response

type LanguageOptions added in v0.1.13

type LanguageOptions struct {
	ParserOptions *ParserOptions `json:"parserOptions,omitempty"`
}

LanguageOptions contains language-specific configuration options

type LintRequest

type LintRequest struct {
	Files            []string `json:"files,omitempty"`
	Config           string   `json:"config,omitempty"` // Path to rslint.json config file
	Format           string   `json:"format,omitempty"`
	WorkingDirectory string   `json:"workingDirectory,omitempty"`
	// Supports both string level and array [level, options] format
	RuleOptions               map[string]interface{} `json:"ruleOptions,omitempty"`
	FileContents              map[string]string      `json:"fileContents,omitempty"`              // Map of file paths to their contents for VFS
	LanguageOptions           *LanguageOptions       `json:"languageOptions,omitempty"`           // Override languageOptions from config file
	IncludeEncodedSourceFiles bool                   `json:"includeEncodedSourceFiles,omitempty"` // Whether to include encoded source files in response
}

LintRequest represents a lint request from JS to Go

type LintResponse

type LintResponse struct {
	Diagnostics        []Diagnostic         `json:"diagnostics"`
	ErrorCount         int                  `json:"errorCount"`
	FileCount          int                  `json:"fileCount"`
	RuleCount          int                  `json:"ruleCount"`
	EncodedSourceFiles map[string]ByteArray `json:"encodedSourceFiles,omitempty"`
}

LintResponse represents a lint response from Go to JS

type Message

type Message struct {
	Kind MessageKind `json:"kind"`
	ID   int         `json:"id"`
	Data interface{} `json:"data,omitempty"`
}

Message represents an IPC message

type MessageKind

type MessageKind string

MessageKind represents the kind of IPC message

const (
	// KindLint is sent from JS to Go to request linting
	KindLint MessageKind = "lint"
	// KindApplyFixes is sent from JS to Go to request applying fixes
	KindApplyFixes MessageKind = "applyFixes"
	// KindResponse is sent from Go to JS with the lint results
	KindResponse MessageKind = "response"
	// KindError is sent when an error occurs
	KindError MessageKind = "error"
	// KindHandshake is sent for initial connection verification
	KindHandshake MessageKind = "handshake"
	// KindExit is sent to request termination
	KindExit MessageKind = "exit"
)

type ParserOptions added in v0.1.13

type ParserOptions struct {
	ProjectService bool         `json:"projectService"`
	Project        ProjectPaths `json:"project,omitempty"`
}

ParserOptions contains parser-specific configuration

type Position

type Position struct {
	Line   int `json:"line"`
	Column int `json:"column"`
}

Position represents a position in a file

type ProjectPaths added in v0.1.13

type ProjectPaths []string

ProjectPaths represents project paths that can be either a single string or an array of strings

func (*ProjectPaths) UnmarshalJSON added in v0.1.13

func (p *ProjectPaths) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling to support both string and string[] formats

type Range

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

Range represents a position range in a file

type Service

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

Service manages the IPC communication

func NewService

func NewService(reader io.Reader, writer io.Writer, handler Handler) *Service

NewService creates a new IPC service

func (*Service) Start

func (s *Service) Start() error

Start starts the IPC service

Jump to

Keyboard shortcuts

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