summaryrefslogtreecommitdiff
path: root/internal/lsp/handlers_init.go
blob: d86d1047109afa5e03f63e8f9be6033698d562b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Summary: Initialization and lifecycle handlers split from handlers.go.
package lsp

import (
	"os"

	"codeberg.org/snonux/hexai/internal"
	"codeberg.org/snonux/hexai/internal/logging"
	tmx "codeberg.org/snonux/hexai/internal/tmux"
)

func (s *Server) handleInitialize(req Request) {
	client := s.currentLLMClient()
	version := internal.Version
	if client != nil {
		version = version + " [" + client.Name() + ":" + client.DefaultModel() + "]"
	}
	res := InitializeResult{
		Capabilities: ServerCapabilities{
			TextDocumentSync: 1, // 1 = TextDocumentSyncKindFull
			CompletionProvider: &CompletionOptions{
				ResolveProvider:   false,
				TriggerCharacters: s.triggerCharacters(),
			},
			CodeActionProvider: CodeActionOptions{ResolveProvider: true},
		},
		ServerInfo: &ServerInfo{Name: "hexai", Version: version},
	}
	s.reply(req.ID, res, nil)
}

func (s *Server) handleInitialized() {
	logging.Logf("lsp ", "client initialized")
	// Emit an initial tmux heartbeat with provider/model
	if client := s.currentLLMClient(); client != nil {
		_ = tmx.SetStatus(tmx.FormatLLMStartStatus(client.Name(), client.DefaultModel()))
	}
}

func (s *Server) handleShutdown(req Request) {
	s.reply(req.ID, nil, nil)
}

func (s *Server) handleExit() {
	s.exited = true
	os.Exit(0)
}