summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-16 03:59:57 +0200
committerPaul Buetow <paul@buetow.org>2026-03-16 03:59:57 +0200
commitc40056f2102893c4c04aa2fa2380a4146d370e81 (patch)
treeb09795dcce9e172bfb24d38ac480b27e5eedbe98 /internal
parentc578f367d81ce035c1f7b9c55e38101753e99de5 (diff)
Add doc comments to exported types and functions
Document ~30 exported types in lsp/types.go and exported functions in llm/provider.go, lsp/server.go, and hexailsp/run.go. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal')
-rw-r--r--internal/hexailsp/run.go1
-rw-r--r--internal/llm/provider.go11
-rw-r--r--internal/lsp/server.go2
-rw-r--r--internal/lsp/types.go36
4 files changed, 40 insertions, 10 deletions
diff --git a/internal/hexailsp/run.go b/internal/hexailsp/run.go
index ca24016..3741a5e 100644
--- a/internal/hexailsp/run.go
+++ b/internal/hexailsp/run.go
@@ -51,6 +51,7 @@ func Run(logPath string, stdin io.Reader, stdout io.Writer, stderr io.Writer) er
return RunWithConfig(logPath, "", stdin, stdout, stderr)
}
+// RunWithConfig is like Run but accepts an explicit config file path.
func RunWithConfig(logPath string, configPath string, stdin io.Reader, stdout io.Writer, stderr io.Writer) error {
logger := log.New(stderr, "hexai-lsp-server ", log.LstdFlags|log.Lmsgprefix)
if strings.TrimSpace(logPath) != "" {
diff --git a/internal/llm/provider.go b/internal/llm/provider.go
index 847ea60..f3170ef 100644
--- a/internal/llm/provider.go
+++ b/internal/llm/provider.go
@@ -56,9 +56,16 @@ type Options struct {
// RequestOption mutates Options.
type RequestOption func(*Options)
-func WithModel(model string) RequestOption { return func(o *Options) { o.Model = model } }
+// WithModel sets the model name for a request.
+func WithModel(model string) RequestOption { return func(o *Options) { o.Model = model } }
+
+// WithTemperature sets the sampling temperature for a request.
func WithTemperature(t float64) RequestOption { return func(o *Options) { o.Temperature = t } }
-func WithMaxTokens(n int) RequestOption { return func(o *Options) { o.MaxTokens = n } }
+
+// WithMaxTokens sets the maximum number of tokens to generate.
+func WithMaxTokens(n int) RequestOption { return func(o *Options) { o.MaxTokens = n } }
+
+// WithStop sets custom stop sequences for a request.
func WithStop(stop ...string) RequestOption {
return func(o *Options) { o.Stop = append([]string{}, stop...) }
}
diff --git a/internal/lsp/server.go b/internal/lsp/server.go
index 4e8a339..d8fdc92 100644
--- a/internal/lsp/server.go
+++ b/internal/lsp/server.go
@@ -87,6 +87,7 @@ type ServerOptions struct {
StatusSink StatusSink
}
+// NewServer creates a new LSP server that reads from r and writes to w.
func NewServer(r io.Reader, w io.Writer, logger *log.Logger, opts ServerOptions) *Server {
ctx, cancel := context.WithCancel(context.Background())
s := &Server{
@@ -330,6 +331,7 @@ func (s *Server) emitGlobalStatus(reqs int64, rpm float64, sent int64, recv int6
}
}
+// Run starts the server's main loop, reading and dispatching LSP messages until EOF or exit.
func (s *Server) Run() error {
defer s.cancelRequests()
for {
diff --git a/internal/lsp/types.go b/internal/lsp/types.go
index fa9e71f..24be2fe 100644
--- a/internal/lsp/types.go
+++ b/internal/lsp/types.go
@@ -3,7 +3,7 @@ package lsp
import "encoding/json"
-// JSON-RPC 2.0 structures (minimal)
+// Request represents a JSON-RPC 2.0 request message.
type Request struct {
JSONRPC string `json:"jsonrpc"`
ID json.RawMessage `json:"id,omitempty"`
@@ -11,6 +11,7 @@ type Request struct {
Params json.RawMessage `json:"params,omitempty"`
}
+// Response represents a JSON-RPC 2.0 response message.
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID json.RawMessage `json:"id,omitempty"`
@@ -18,22 +19,25 @@ type Response struct {
Error *RespError `json:"error,omitempty"`
}
+// RespError represents the error object in a JSON-RPC 2.0 response.
type RespError struct {
Code int `json:"code"`
Message string `json:"message"`
}
-// LSP responses (subset)
+// InitializeResult is the response payload for the initialize request.
type InitializeResult struct {
Capabilities ServerCapabilities `json:"capabilities"`
ServerInfo *ServerInfo `json:"serverInfo,omitempty"`
}
+// ServerInfo describes the LSP server's name and version.
type ServerInfo struct {
Name string `json:"name"`
Version string `json:"version,omitempty"`
}
+// ServerCapabilities declares the features the server supports.
type ServerCapabilities struct {
TextDocumentSync any `json:"textDocumentSync,omitempty"`
CompletionProvider *CompletionOptions `json:"completionProvider,omitempty"`
@@ -41,16 +45,19 @@ type ServerCapabilities struct {
CodeActionProvider any `json:"codeActionProvider,omitempty"`
}
+// CompletionOptions configures the server's completion provider capabilities.
type CompletionOptions struct {
ResolveProvider bool `json:"resolveProvider,omitempty"`
TriggerCharacters []string `json:"triggerCharacters,omitempty"`
}
+// CompletionList contains a set of completion items returned by the server.
type CompletionList struct {
IsIncomplete bool `json:"isIncomplete"`
Items []CompletionItem `json:"items"`
}
+// CompletionItem represents a single completion suggestion.
type CompletionItem struct {
Label string `json:"label"`
Kind int `json:"kind,omitempty"`
@@ -64,12 +71,12 @@ type CompletionItem struct {
Documentation string `json:"documentation,omitempty"`
}
-// Code action options
+// CodeActionOptions configures the server's code action provider capabilities.
type CodeActionOptions struct {
ResolveProvider bool `json:"resolveProvider,omitempty"`
}
-// LSP param types (subset)
+// TextDocumentItem represents the content of an opened text document.
type TextDocumentItem struct {
URI string `json:"uri"`
LanguageID string `json:"languageId,omitempty"`
@@ -77,52 +84,61 @@ type TextDocumentItem struct {
Text string `json:"text"`
}
+// VersionedTextDocumentIdentifier identifies a specific version of a text document.
type VersionedTextDocumentIdentifier struct {
URI string `json:"uri"`
Version int `json:"version,omitempty"`
}
+// TextDocumentIdentifier identifies a text document by its URI.
type TextDocumentIdentifier struct {
URI string `json:"uri"`
}
+// DidOpenTextDocumentParams is the parameter for textDocument/didOpen notifications.
type DidOpenTextDocumentParams struct {
TextDocument TextDocumentItem `json:"textDocument"`
}
+// TextDocumentContentChangeEvent describes a change to a text document's content.
type TextDocumentContentChangeEvent struct {
Range any `json:"range,omitempty"`
RangeLength int `json:"rangeLength,omitempty"`
Text string `json:"text"`
}
+// DidChangeTextDocumentParams is the parameter for textDocument/didChange notifications.
type DidChangeTextDocumentParams struct {
TextDocument VersionedTextDocumentIdentifier `json:"textDocument"`
ContentChanges []TextDocumentContentChangeEvent `json:"contentChanges"`
}
+// DidCloseTextDocumentParams is the parameter for textDocument/didClose notifications.
type DidCloseTextDocumentParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
}
+// Position represents a zero-based line and character offset in a document.
type Position struct {
Line int `json:"line"`
Character int `json:"character"`
}
+// CompletionParams is the parameter for textDocument/completion requests.
type CompletionParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Position Position `json:"position"`
Context any `json:"context,omitempty"`
}
-// Code actions
+// CodeActionParams is the parameter for textDocument/codeAction requests.
type CodeActionParams struct {
TextDocument TextDocumentIdentifier `json:"textDocument"`
Range Range `json:"range"`
Context json.RawMessage `json:"context,omitempty"`
}
+// WorkspaceEdit represents changes to many resources managed in the workspace.
type WorkspaceEdit struct {
Changes map[string][]TextEdit `json:"changes,omitempty"`
DocumentChanges []any `json:"documentChanges,omitempty"`
@@ -134,6 +150,7 @@ type ApplyWorkspaceEditParams struct {
Edit WorkspaceEdit `json:"edit"`
}
+// CodeAction represents an action the server can perform on the user's behalf.
type CodeAction struct {
Title string `json:"title"`
Kind string `json:"kind,omitempty"`
@@ -142,30 +159,32 @@ type CodeAction struct {
Command *Command `json:"command,omitempty"`
}
-// Extended workspace edit types (minimal subset)
+// TextDocumentEdit describes edits to a single versioned text document.
type TextDocumentEdit struct {
TextDocument VersionedTextDocumentIdentifier `json:"textDocument"`
Edits []TextEdit `json:"edits"`
}
+// CreateFile is a workspace edit operation that creates a new file.
type CreateFile struct {
Kind string `json:"kind"`
URI string `json:"uri"`
}
-// Commands
+// Command represents an LSP command that can be executed by the client.
type Command struct {
Title string `json:"title"`
Command string `json:"command"`
Arguments []any `json:"arguments,omitempty"`
}
+// ExecuteCommandParams is the parameter for workspace/executeCommand requests.
type ExecuteCommandParams struct {
Command string `json:"command"`
Arguments []any `json:"arguments,omitempty"`
}
-// Diagnostics (subset needed for code action context)
+// Diagnostic represents a compiler diagnostic such as an error or warning.
type Diagnostic struct {
Range Range `json:"range"`
Message string `json:"message"`
@@ -174,6 +193,7 @@ type Diagnostic struct {
Source string `json:"source,omitempty"`
}
+// CodeActionContext carries diagnostics associated with a code action request.
type CodeActionContext struct {
Diagnostics []Diagnostic `json:"diagnostics"`
}