8 "github.com/charmbracelet/crush/internal/csync"
9 "github.com/charmbracelet/crush/internal/lsp"
10 "github.com/charmbracelet/crush/internal/pubsub"
13// LSPEventType represents the type of LSP event
14type LSPEventType string
17 LSPEventStateChanged LSPEventType = "state_changed"
18 LSPEventDiagnosticsChanged LSPEventType = "diagnostics_changed"
21// LSPEvent represents an event in the LSP system
30// LSPClientInfo holds information about an LSP client's state
31type LSPClientInfo struct {
41 lspStates = csync.NewMap[string, LSPClientInfo]()
42 lspBroker = pubsub.NewBroker[LSPEvent]()
45// SubscribeLSPEvents returns a channel for LSP events
46func SubscribeLSPEvents(ctx context.Context) <-chan pubsub.Event[LSPEvent] {
47 return lspBroker.Subscribe(ctx)
50// GetLSPStates returns the current state of all LSP clients
51func GetLSPStates() map[string]LSPClientInfo {
52 return maps.Collect(lspStates.Seq2())
55// GetLSPState returns the state of a specific LSP client
56func GetLSPState(name string) (LSPClientInfo, bool) {
57 return lspStates.Get(name)
60// updateLSPState updates the state of an LSP client and publishes an event
61func updateLSPState(name string, state lsp.ServerState, err error, client *lsp.Client, diagnosticCount int) {
62 info := LSPClientInfo{
67 DiagnosticCount: diagnosticCount,
69 if state == lsp.StateReady {
70 info.ConnectedAt = time.Now()
72 lspStates.Set(name, info)
74 // Publish state change event
75 lspBroker.Publish(pubsub.UpdatedEvent, LSPEvent{
76 Type: LSPEventStateChanged,
80 DiagnosticCount: diagnosticCount,
84// updateLSPDiagnostics updates the diagnostic count for an LSP client and publishes an event
85func updateLSPDiagnostics(name string, diagnosticCount int) {
86 if info, exists := lspStates.Get(name); exists {
87 info.DiagnosticCount = diagnosticCount
88 lspStates.Set(name, info)
90 // Publish diagnostics change event
91 lspBroker.Publish(pubsub.UpdatedEvent, LSPEvent{
92 Type: LSPEventDiagnosticsChanged,
96 DiagnosticCount: diagnosticCount,
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list