MCPcopy Create free account
hub / github.com/freecodexyz/free-code / changeFile

Function changeFile

src/services/lsp/LSPServerManager.ts:312–343  ·  view source on GitHub ↗
(filePath: string, content: string)

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 7

getServerForFileFunction · 0.85
openFileFunction · 0.85
logForDebuggingFunction · 0.85
resolveMethod · 0.80
errorMessageFunction · 0.50
logErrorFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected