(filePath: string, content: string)
| 310 | } |
| 311 | |
| 312 | async function changeFile(filePath: string, content: string): Promise<void> { |
| 313 | const server = getServerForFile(filePath) |
| 314 | if (!server || server.state !== 'running') { |
| 315 | return openFile(filePath, content) |
| 316 | } |
| 317 | |
| 318 | const fileUri = pathToFileURL(path.resolve(filePath)).href |
| 319 | |
| 320 | // If file hasn't been opened on this server yet, open it first |
| 321 | // LSP servers require didOpen before didChange |
| 322 | if (openedFiles.get(fileUri) !== server.name) { |
| 323 | return openFile(filePath, content) |
| 324 | } |
| 325 | |
| 326 | try { |
| 327 | await server.sendNotification('textDocument/didChange', { |
| 328 | textDocument: { |
| 329 | uri: fileUri, |
| 330 | version: 1, |
| 331 | }, |
| 332 | contentChanges: [{ text: content }], |
| 333 | }) |
| 334 | logForDebugging(`LSP: Sent didChange for ${filePath}`) |
| 335 | } catch (error) { |
| 336 | const err = new Error( |
| 337 | `Failed to sync file change ${filePath}: ${errorMessage(error)}`, |
| 338 | ) |
| 339 | logError(err) |
| 340 | // Re-throw to propagate error to caller |
| 341 | throw err |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Save a file in LSP servers (sends didSave notification) |
nothing calls this directly
no test coverage detected