8 "github.com/charmbracelet/crush/internal/config"
9 "github.com/charmbracelet/crush/internal/lsp/util"
10 "github.com/charmbracelet/x/powernap/pkg/lsp/protocol"
13// HandleWorkspaceConfiguration handles workspace configuration requests
14func HandleWorkspaceConfiguration(_ context.Context, _ string, params json.RawMessage) (any, error) {
15 return []map[string]any{{}}, nil
18// HandleRegisterCapability handles capability registration requests
19func HandleRegisterCapability(_ context.Context, _ string, params json.RawMessage) (any, error) {
20 var registerParams protocol.RegistrationParams
21 if err := json.Unmarshal(params, ®isterParams); err != nil {
22 slog.Error("Error unmarshaling registration params", "error", err)
26 for _, reg := range registerParams.Registrations {
28 case "workspace/didChangeWatchedFiles":
29 // Parse the registration options
30 optionsJSON, err := json.Marshal(reg.RegisterOptions)
32 slog.Error("Error marshaling registration options", "error", err)
35 var options protocol.DidChangeWatchedFilesRegistrationOptions
36 if err := json.Unmarshal(optionsJSON, &options); err != nil {
37 slog.Error("Error unmarshaling registration options", "error", err)
40 // Store the file watchers registrations
41 notifyFileWatchRegistration(reg.ID, options.Watchers)
47// HandleApplyEdit handles workspace edit requests
48func HandleApplyEdit(_ context.Context, _ string, params json.RawMessage) (any, error) {
49 var edit protocol.ApplyWorkspaceEditParams
50 if err := json.Unmarshal(params, &edit); err != nil {
54 err := util.ApplyWorkspaceEdit(edit.Edit)
56 slog.Error("Error applying workspace edit", "error", err)
57 return protocol.ApplyWorkspaceEditResult{Applied: false, FailureReason: err.Error()}, nil
60 return protocol.ApplyWorkspaceEditResult{Applied: true}, nil
63// FileWatchRegistrationHandler is a function that will be called when file watch registrations are received
64type FileWatchRegistrationHandler func(id string, watchers []protocol.FileSystemWatcher)
66// fileWatchHandler holds the current handler for file watch registrations
67var fileWatchHandler FileWatchRegistrationHandler
69// RegisterFileWatchHandler sets the handler for file watch registrations
70func RegisterFileWatchHandler(handler FileWatchRegistrationHandler) {
71 fileWatchHandler = handler
74// notifyFileWatchRegistration notifies the handler about new file watch registrations
75func notifyFileWatchRegistration(id string, watchers []protocol.FileSystemWatcher) {
76 if fileWatchHandler != nil {
77 fileWatchHandler(id, watchers)
81// HandleServerMessage handles server messages
82func HandleServerMessage(_ context.Context, method string, params json.RawMessage) {
84 if !cfg.Options.DebugLSP {
88 var msg protocol.ShowMessageParams
89 if err := json.Unmarshal(params, &msg); err != nil {
90 slog.Debug("Server message", "type", msg.Type, "message", msg.Message)
96 slog.Error("LSP Server", "message", msg.Message)
97 case protocol.Warning:
98 slog.Warn("LSP Server", "message", msg.Message)
100 slog.Info("LSP Server", "message", msg.Message)
102 slog.Debug("LSP Server", "message", msg.Message)
106// HandleDiagnostics handles diagnostic notifications from the LSP server
107func HandleDiagnostics(client *Client, params json.RawMessage) {
108 var diagParams protocol.PublishDiagnosticsParams
109 if err := json.Unmarshal(params, &diagParams); err != nil {
110 slog.Error("Error unmarshaling diagnostics params", "error", err)
114 client.diagnostics.Set(diagParams.URI, diagParams.Diagnostics)
116 // Calculate total diagnostic count
118 for _, diagnostics := range client.diagnostics.Seq2() {
119 totalCount += len(diagnostics)
122 // Trigger callback if set
123 if client.onDiagnosticsChanged != nil {
124 client.onDiagnosticsChanged(client.name, totalCount)
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