lsp

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lsp is the stdio language server behind `wtctl lsp` (LSP 3.17): production latency and error lenses and hovers on functions. It sends only file paths and function names to the API, never source text.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Literal added in v0.3.1

func Literal(line string) string

Literal is the longest fixed text of the first string literal on a logger line, without format verbs and placeholders (%s, %d, {}, {0}, ${x}); "" when under 6 characters. The template fallback when records carry no code location.

func LogSites added in v0.3.1

func LogSites(name, text string, max int) []int

LogSites returns the 0-based lines of logger calls in text, at most max.

Types

type Client

type Client struct {
	BaseURL string // WT_API_URL
	Key     string // WT_API_KEY
	HTTP    *http.Client
	// contains filtered or unexported fields
}

Client calls the Watchtower API. It sends only the service, file path and function names.

func (*Client) CodeStats

func (c *Client) CodeStats(ctx context.Context, project, service, file string, funcs []string) (map[string]Stat, error)

CodeStats returns stats by function name; functions with no data are absent.

func (*Client) LogsAt added in v0.3.1

func (c *Client) LogsAt(ctx context.Context, project, service, file string, line int, lit string) (LogSite, error)

LogsAt asks POST /logs/search for the last 24h of records logged at file:line (1-based).

When no record carries the location and lit is not empty, it falls back to records whose body contains lit.

type Config

type Config struct {
	Service      string   `yaml:"service"`
	PathPrefixes []string `yaml:"path_prefixes"`
	Project      string   `yaml:"project"`
}

Config is watchtower.yaml in the repository root.

func LoadConfig

func LoadConfig(root string) (*Config, error)

LoadConfig reads root/watchtower.yaml. A missing file is not an error: nothing maps.

func (*Config) ServiceFor

func (c *Config) ServiceFor(rel string) (string, bool)

ServiceFor returns the service for a repo-relative path. No prefixes means the whole repo.

type Func

type Func struct {
	Name string
	Line int
}

Func is a function declaration found in source (0-based line).

func Functions

func Functions(name, text string) []Func

Functions lists function names with their lines for the file extension of name.

type LogSite added in v0.3.1

type LogSite struct {
	Lines []string // newest first, "severity body"
	Count int      // matched lines in the window (capped at logWindow)
	More  bool
}

LogSite is what the logs API holds for one source line.

type Server

type Server struct {
	API    *Client
	WebURL string // base of issue and trace links; defaults to the API URL
	// contains filtered or unexported fields
}

Server is one LSP session.

func NewServer

func NewServer(api *Client, webURL string, out io.Writer) *Server

NewServer builds a server writing responses to out.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, in io.Reader) error

Serve reads framed messages from in until exit or EOF.

type Stat

type Stat struct {
	Function  string  `json:"function"`
	Count     uint64  `json:"count"`
	Errors    uint64  `json:"errors"`
	P50Ms     float64 `json:"p50_ms"`
	P95Ms     float64 `json:"p95_ms"`
	LastIssue *struct {
		ID    string `json:"id"`
		Title string `json:"title"`
	} `json:"last_issue"`
	TraceExample string `json:"trace_example"`
}

Stat mirrors one entry of GET /v1/projects/{p}/code-stats.

Jump to

Keyboard shortcuts

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