only update in-memory file text from external change if open

This commit is contained in:
Matt Parker
2025-11-19 23:52:56 +10:00
parent fc4eed8d0a
commit 59454e6b31
2 changed files with 9 additions and 1 deletions

View File

@@ -34,6 +34,14 @@ public class IdeOpenTabsFileManager(ILogger<IdeOpenTabsFileManager> logger)
_openFiles[file] = newLazyTask;
}
public async Task UpdateFileTextInMemoryIfOpen(SharpIdeFile file, string newText)
{
if (!_openFiles.ContainsKey(file)) return;
var newLazyTask = new Lazy<Task<string>>(() => Task.FromResult(newText));
_openFiles[file] = newLazyTask;
}
public async Task SaveFileAsync(SharpIdeFile file)
{
if (!_openFiles.ContainsKey(file)) throw new InvalidOperationException("File is not open in memory.");

View File

@@ -68,7 +68,7 @@ public class FileChangedService(RoslynAnalysis roslynAnalysis, IdeOpenTabsFileMa
// Disk is already up to date
// Update any open tabs
// update in memory
await _openTabsFileManager.UpdateFileTextInMemory(file, newContents);
await _openTabsFileManager.UpdateFileTextInMemoryIfOpen(file, newContents);
file.FileContentsChangedExternally.InvokeParallelFireAndForget(linePosition);
}
else if (changeType is FileChangeType.CodeActionChange)