MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / handleDidChange

Method handleDidChange

pkg/lsp/handler.go:295–343  ·  view source on GitHub ↗

handleDidChange handles document change notifications

(params json.RawMessage)

Source from the content-addressed store, hash-verified

293
294// handleDidChange handles document change notifications
295func (h *Handler) handleDidChange(params json.RawMessage) {
296 var p DidChangeTextDocumentParams
297 if err := json.Unmarshal(params, &p); err != nil {
298 h.server.Logger().Printf("textDocument/didChange: failed to parse params: %v (raw: %s)", err, truncateForLog(params))
299 h.sendParseError("didChange", err)
300 return
301 }
302
303 h.server.Logger().Printf("Document changed: %s (version %d)", p.TextDocument.URI, p.TextDocument.Version)
304
305 h.server.Documents().Update(
306 p.TextDocument.URI,
307 p.TextDocument.Version,
308 p.ContentChanges,
309 )
310
311 // Get updated content for size check and debounced validation
312 content, ok := h.server.Documents().GetContent(p.TextDocument.URI)
313 if !ok {
314 return
315 }
316
317 // Check document size limit after update
318 if len(content) > h.server.MaxDocumentSizeBytes() {
319 h.server.Logger().Printf("Document too large after change: %d bytes (max: %d)", len(content), h.server.MaxDocumentSizeBytes())
320 // Clear diagnostics but don't validate
321 h.server.SendNotification("textDocument/publishDiagnostics", PublishDiagnosticsParams{
322 URI: p.TextDocument.URI,
323 Version: p.TextDocument.Version,
324 Diagnostics: []Diagnostic{},
325 })
326 return
327 }
328
329 // Debounce diagnostics — cancel existing timer and schedule new one
330 uri := p.TextDocument.URI
331 version := p.TextDocument.Version
332 h.debounceMu.Lock()
333 if t, ok := h.debounceTimers[uri]; ok {
334 t.Stop()
335 }
336 h.debounceTimers[uri] = time.AfterFunc(300*time.Millisecond, func() {
337 h.debounceMu.Lock()
338 delete(h.debounceTimers, uri)
339 h.debounceMu.Unlock()
340 h.validateDocument(uri, content, version)
341 })
342 h.debounceMu.Unlock()
343}
344
345// handleDidClose handles document close notifications
346func (h *Handler) handleDidClose(params json.RawMessage) {

Callers 1

HandleNotificationMethod · 0.95

Calls 9

sendParseErrorMethod · 0.95
validateDocumentMethod · 0.95
truncateForLogFunction · 0.85
LoggerMethod · 0.80
UpdateMethod · 0.80
DocumentsMethod · 0.80
GetContentMethod · 0.80
MaxDocumentSizeBytesMethod · 0.80
SendNotificationMethod · 0.80

Tested by

no test coverage detected