lsp

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NeedName            = 1 << 0
	NeedFiles           = 1 << 1
	NeedCompiledGoFiles = 1 << 2
	NeedImports         = 1 << 3
	NeedDeps            = 1 << 4
	NeedTypesSizes      = 1 << 9
	NeedModule          = 1 << 13
)

gopackagesdriver LoadMode flags

View Source
const (
	SKFile        = 1
	SKModule      = 2
	SKNamespace   = 3
	SKPackage     = 4
	SKClass       = 5
	SKMethod      = 6
	SKProperty    = 7
	SKField       = 8
	SKConstructor = 9
	SKEnum        = 10
	SKInterface   = 11
	SKFunction    = 12
	SKVariable    = 13
	SKConstant    = 14
	SKString      = 15
	SKNumber      = 16
	SKBoolean     = 17
	SKArray       = 18
	SKStruct      = 23
)

LSP Symbol kinds

View Source
const (
	SyncNone        = 0
	SyncFull        = 1
	SyncIncremental = 2
)

TextDocumentSync kinds

Variables

This section is empty.

Functions

func RunDriver

func RunDriver(rootDir string, patterns []string) error

RunDriver reads a DriverRequest from stdin and writes a DriverResponse to stdout.

Types

type Diagnostic

type Diagnostic struct {
	Range    Range  `json:"range"`
	Severity int    `json:"severity"` // 1=Error, 2=Warning, 3=Info, 4=Hint
	Source   string `json:"source,omitempty"`
	Message  string `json:"message"`
}

type DocumentSymbol

type DocumentSymbol struct {
	Name           string           `json:"name"`
	Kind           int              `json:"kind"`
	Range          Range            `json:"range"`
	SelectionRange Range            `json:"selectionRange"`
	Children       []DocumentSymbol `json:"children,omitempty"`
}

type DriverError

type DriverError struct {
	Pos string `json:"Pos,omitempty"`
	Msg string `json:"Msg"`
}

type DriverPackage

type DriverPackage struct {
	ID              string            `json:"ID"`
	Name            string            `json:"Name"`
	PkgPath         string            `json:"PkgPath"`
	GoFiles         []string          `json:"GoFiles,omitempty"`
	CompiledGoFiles []string          `json:"CompiledGoFiles,omitempty"`
	Imports         map[string]string `json:"Imports,omitempty"`
	Errors          []DriverError     `json:"Errors,omitempty"`
}

type DriverRequest

type DriverRequest struct {
	Mode       int               `json:"mode"`
	Env        []string          `json:"env"`
	BuildFlags []string          `json:"build_flags"`
	Tests      bool              `json:"tests"`
	Overlay    map[string][]byte `json:"overlay"`
}

type DriverResponse

type DriverResponse struct {
	NotHandled bool             `json:"NotHandled,omitempty"`
	Compiler   string           `json:"Compiler,omitempty"`
	Arch       string           `json:"Arch,omitempty"`
	Roots      []string         `json:"Roots,omitempty"`
	Packages   []*DriverPackage `json:"Packages,omitempty"`
}

func HandleDriverRequest

func HandleDriverRequest(rootDir string, req DriverRequest, patterns []string) (*DriverResponse, error)

HandleDriverRequest processes a gopackagesdriver request.

type HandlerFunc

type HandlerFunc func(params json.RawMessage) (any, error)

HandlerFunc processes a JSON-RPC request and returns a result or error.

type Hover

type Hover struct {
	Contents MarkupContent `json:"contents"`
	Range    *Range        `json:"range,omitempty"`
}

Hover response

type InitializeParams

type InitializeParams struct {
	RootURI  string `json:"rootUri"`
	RootPath string `json:"rootPath"`
}

LSP types -- minimal set for initialize

type InitializeResult

type InitializeResult struct {
	Capabilities ServerCapabilities `json:"capabilities"`
	ServerInfo   *ServerInfo        `json:"serverInfo,omitempty"`
}

type LSPLocation

type LSPLocation struct {
	URI   string `json:"uri"`
	Range Range  `json:"range"`
}

type MarkupContent

type MarkupContent struct {
	Kind  string `json:"kind"` // "plaintext" or "markdown"
	Value string `json:"value"`
}

type NotifyFunc

type NotifyFunc func(params json.RawMessage)

NotifyFunc processes a JSON-RPC notification (no response expected).

type Position

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

type PublishDiagnosticsParams

type PublishDiagnosticsParams struct {
	URI         string       `json:"uri"`
	Diagnostics []Diagnostic `json:"diagnostics"`
}

type Range

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

type RenameParams

type RenameParams struct {
	TextDocument TextDocumentIdentifier `json:"textDocument"`
	Position     Position               `json:"position"`
	NewName      string                 `json:"newName"`
}

type Server

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

Server implements the JSON-RPC 2.0 transport for LSP.

func NewServer

func NewServer(in io.Reader, out io.Writer, log io.Writer) *Server

func (*Server) Handle

func (s *Server) Handle(method string, fn HandlerFunc)

func (*Server) Notify

func (s *Server) Notify(method string, params any) error

Notify sends a server-initiated notification (e.g., diagnostics).

func (*Server) OnNotify

func (s *Server) OnNotify(method string, fn NotifyFunc)

func (*Server) Serve

func (s *Server) Serve() error

Serve reads messages in a loop until EOF or shutdown.

func (*Server) ServeOnce

func (s *Server) ServeOnce() error

ServeOnce reads and handles a single message.

type ServerCapabilities

type ServerCapabilities struct {
	TextDocumentSync        int  `json:"textDocumentSync,omitempty"`
	DocumentSymbolProvider  bool `json:"documentSymbolProvider,omitempty"`
	WorkspaceSymbolProvider bool `json:"workspaceSymbolProvider,omitempty"`
	DefinitionProvider      bool `json:"definitionProvider,omitempty"`
	ReferencesProvider      bool `json:"referencesProvider,omitempty"`
	HoverProvider           bool `json:"hoverProvider,omitempty"`
	CompletionProvider      any  `json:"completionProvider,omitempty"`
	RenameProvider          bool `json:"renameProvider,omitempty"`
	DiagnosticProvider      any  `json:"diagnosticProvider,omitempty"`
}

type ServerInfo

type ServerInfo struct {
	Name    string `json:"name"`
	Version string `json:"version,omitempty"`
}

type Service

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

Service holds workspace state and handles LSP requests.

func NewService

func NewService(proxyMgr *proxy.Manager) *Service

func (*Service) Register

func (s *Service) Register(srv *Server)

Register wires all LSP handlers onto a Server.

func (*Service) StartSocket

func (s *Service) StartSocket() *socket.Server

StartSocket starts the Unix socket server for CLI client queries. Call after handleInitialize sets rootPath.

type SymbolInformation

type SymbolInformation struct {
	Name     string      `json:"name"`
	Kind     int         `json:"kind"`
	Location LSPLocation `json:"location"`
}

type TextDocumentIdentifier

type TextDocumentIdentifier struct {
	URI string `json:"uri"`
}

Text document types

type TextDocumentItem

type TextDocumentItem struct {
	URI        string `json:"uri"`
	LanguageID string `json:"languageId"`
	Version    int    `json:"version"`
	Text       string `json:"text"`
}

type TextEdit

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

type WorkspaceEdit

type WorkspaceEdit struct {
	Changes map[string][]TextEdit `json:"changes,omitempty"`
}

Jump to

Keyboard shortcuts

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