summaryrefslogtreecommitdiff
path: root/cmd/hexai-lsp
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-08-17 18:52:51 +0300
committerPaul Buetow <paul@buetow.org>2025-08-17 18:52:51 +0300
commit454451105ad3522d2ac3d22136eedee4a4d034af (patch)
treeaa4b5723809c4d45bfc9094a38c01c6415582f9c /cmd/hexai-lsp
parent498923e77c201ca90dc35c7934f4f7f1c9c3ccd2 (diff)
cli+lsp: refactor main packages into internal runners; add tests
- Move CLI logic to internal/hexaicli with Run/RunWithClient - Move LSP logic to internal/hexailsp with Run/RunWithFactory - Extract helpers; keep behavior identical for both binaries - Add unit tests for hexaicli (input parsing, messages, streaming) and hexailsp (factory wiring, client creation, logging settings) - Add top-of-file summaries and 'Not yet reviewed by a human' comments to all Go files - Update README with internal package docs
Diffstat (limited to 'cmd/hexai-lsp')
-rw-r--r--cmd/hexai-lsp/main.go92
1 files changed, 18 insertions, 74 deletions
diff --git a/cmd/hexai-lsp/main.go b/cmd/hexai-lsp/main.go
index 065b6e2..a473ad7 100644
--- a/cmd/hexai-lsp/main.go
+++ b/cmd/hexai-lsp/main.go
@@ -1,82 +1,26 @@
+// Summary: Hexai LSP entrypoint; parses flags and delegates to internal/hexailsp.
+// Not yet reviewed by a human
package main
import (
- "flag"
- "log"
- "os"
- "strings"
+ "flag"
+ "log"
+ "os"
- "hexai/internal"
- "hexai/internal/appconfig"
- "hexai/internal/llm"
- "hexai/internal/logging"
- "hexai/internal/lsp"
+ "hexai/internal"
+ "hexai/internal/hexailsp"
)
func main() {
- logPath := flag.String("log", "/tmp/hexai-lsp.log", "path to log file (optional)")
- showVersion := flag.Bool("version", false, "print version and exit")
- flag.Parse()
- if *showVersion {
- log.Println(internal.Version)
- return
- }
-
- // Configure logging (path flag only)
- logger := log.New(os.Stderr, "hexai-lsp ", log.LstdFlags|log.Lmsgprefix)
- if *logPath != "" {
- f, err := os.OpenFile(*logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
- if err != nil {
- logger.Fatalf("failed to open log file: %v", err)
- }
- defer f.Close()
- logger.SetOutput(f)
- }
- logging.Bind(logger)
-
- // Load config file
- cfg := appconfig.Load(logger)
-
- // Normalize and apply logging config
- cfg.ContextMode = strings.ToLower(strings.TrimSpace(cfg.ContextMode))
- if cfg.LogPreviewLimit >= 0 {
- logging.SetLogPreviewLimit(cfg.LogPreviewLimit)
- }
-
- // Build LLM client from config
- var client llm.Client
- {
- llmCfg := llm.Config{
- Provider: cfg.Provider,
- OpenAIBaseURL: cfg.OpenAIBaseURL,
- OpenAIModel: cfg.OpenAIModel,
- OllamaBaseURL: cfg.OllamaBaseURL,
- OllamaModel: cfg.OllamaModel,
- CopilotBaseURL: cfg.CopilotBaseURL,
- CopilotModel: cfg.CopilotModel,
- }
- oaKey := os.Getenv("OPENAI_API_KEY")
- cpKey := os.Getenv("COPILOT_API_KEY")
- if c, err := llm.NewFromConfig(llmCfg, oaKey, cpKey); err != nil {
- logging.Logf("lsp ", "llm disabled: %v", err)
- } else {
- client = c
- logging.Logf("lsp ", "llm enabled provider=%s model=%s", c.Name(), c.DefaultModel())
- }
- }
-
- server := lsp.NewServer(os.Stdin, os.Stdout, logger, lsp.ServerOptions{
- LogContext: *logPath != "",
- MaxTokens: cfg.MaxTokens,
- ContextMode: cfg.ContextMode,
- WindowLines: cfg.ContextWindowLines,
- MaxContextTokens: cfg.MaxContextTokens,
- NoDiskIO: cfg.NoDiskIO,
- Client: client,
- TriggerCharacters: cfg.TriggerCharacters,
- })
- if err := server.Run(); err != nil {
- logger.Fatalf("server error: %v", err)
- }
+ logPath := flag.String("log", "/tmp/hexai-lsp.log", "path to log file (optional)")
+ showVersion := flag.Bool("version", false, "print version and exit")
+ flag.Parse()
+ if *showVersion {
+ log.Println(internal.Version)
+ return
+ }
+
+ if err := hexailsp.Run(*logPath, os.Stdin, os.Stdout, os.Stderr); err != nil {
+ log.Fatalf("server error: %v", err)
+ }
}
-