Update updates a document's content. This method is called when the client sends a textDocument/didChange notification. It applies content changes to an existing document and updates its version number. Parameters: - uri: Document URI to update - version: New version number (should be greater than
(uri string, version int, changes []TextDocumentContentChangeEvent)
| 191 | // After applying changes, the Lines cache is automatically rebuilt for |
| 192 | // efficient subsequent operations. |
| 193 | func (dm *DocumentManager) Update(uri string, version int, changes []TextDocumentContentChangeEvent) { |
| 194 | dm.mu.Lock() |
| 195 | defer dm.mu.Unlock() |
| 196 | |
| 197 | doc, ok := dm.documents[uri] |
| 198 | if !ok { |
| 199 | return |
| 200 | } |
| 201 | |
| 202 | doc.Version = version |
| 203 | |
| 204 | for _, change := range changes { |
| 205 | if change.Range == nil { |
| 206 | // Full document sync |
| 207 | doc.Content = change.Text |
| 208 | doc.Lines = splitLines(change.Text) |
| 209 | } else { |
| 210 | // Incremental sync |
| 211 | doc.Content = applyChange(doc.Content, doc.Lines, change) |
| 212 | doc.Lines = splitLines(doc.Content) |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | // Close removes a document from the manager. |
| 218 | // |