diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-12 09:33:49 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-12 09:33:49 +0200 |
| commit | da160fbdfb30a55a4d617553baeb5b0a5a9d5fb8 (patch) | |
| tree | 8c8c184d3947211c82f10b198c7b366a01cd4780 /cmd/hexai-lsp-server/main.go | |
| parent | cfd02d2874992f7e293d5098bd328a495825a8d4 (diff) | |
Rename hexai-lsp command to hexai-lsp-server
Amp-Thread-ID: https://ampcode.com/threads/T-019c50bc-2906-77db-a31e-0d553338d99b
Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'cmd/hexai-lsp-server/main.go')
| -rw-r--r-- | cmd/hexai-lsp-server/main.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/cmd/hexai-lsp-server/main.go b/cmd/hexai-lsp-server/main.go new file mode 100644 index 0000000..c8cdd8f --- /dev/null +++ b/cmd/hexai-lsp-server/main.go @@ -0,0 +1,52 @@ +// Summary: Hexai LSP entrypoint; parses flags and delegates to internal/hexailsp. +package main + +import ( + "flag" + "fmt" + "log" + "os" + "strings" + + "codeberg.org/snonux/hexai/internal" + "codeberg.org/snonux/hexai/internal/appconfig" + "codeberg.org/snonux/hexai/internal/hexailsp" +) + +func main() { + defaultLog := defaultLogPath() + logPath := flag.String("log", defaultLog, "path to log file (optional)") + defaultCfg := defaultConfigPath() + configPath := flag.String("config", "", fmt.Sprintf("path to config file (default: %s)", defaultCfg)) + showVersion := flag.Bool("version", false, "print version and exit") + flag.Parse() + if *showVersion { + log.Println(internal.Version) + return + } + + path := strings.TrimSpace(*configPath) + if err := hexailsp.RunWithConfig(*logPath, path, os.Stdin, os.Stdout, os.Stderr); err != nil { + log.Fatalf("server error: %v", err) + } +} + +func defaultConfigPath() string { + path, err := appconfig.ConfigPath() + if err != nil { + return "$XDG_CONFIG_HOME/hexai/config.toml" + } + return path +} + +// defaultLogPath returns the default LSP log file path in the state directory. +// Falls back to /tmp if state directory cannot be determined. +// defaultLogPath returns the default LSP log file path in the state directory. +// Panics if state directory cannot be created. +func defaultLogPath() string { + stateDir, err := appconfig.StateDir() + if err != nil { + panic(fmt.Sprintf("cannot create state directory: %v", err)) + } + return fmt.Sprintf("%s/hexai-lsp-server.log", stateDir) +} |
