public void RazorDocumentOutputChanged(RazorFileChangeEventArgs args) { if (args == null) { throw new ArgumentNullException(nameof(args)); } _foregroundDispatcher.AssertBackgroundThread(); // This is required due to a bug in OmniSharp roslyn https://github.com/OmniSharp/omnisharp-roslyn/issues/1418 // OmniSharp doesn't directly listen for .cs file changes in the obj folder like VS windows does. Therefore // we need to play that part and force buffer updates to indirectly update their workspace to include our Razor // declaration files. lock (_refreshLock) { var projectFilePath = args.UnevaluatedProjectInstance.ProjectFileLocation.File; if (!_pendingOutputRefreshes.TryGetValue(projectFilePath, out var outputRefresh)) { outputRefresh = new OutputRefresh(); _pendingOutputRefreshes[projectFilePath] = outputRefresh; } outputRefresh.UpdateWithChange(args); if (!_deferredRefreshTasks.TryGetValue(projectFilePath, out var update) || update.IsCompleted) { _deferredRefreshTasks[projectFilePath] = RefreshAfterDelay(projectFilePath); } } }
private async Task RefreshAsync(OutputRefresh refresh) { // Re-evaluate project instance so we can determine compile items properly. var projectInstance = _projectInstanceEvaluator.Evaluate(refresh.ProjectInstance); foreach (var documentChangeInfo in refresh.DocumentChangeInfos.Values) { try { // Force update the OmniSharp Workspace for component declaration changes. var componentDeclarationLocation = documentChangeInfo.FilePath; var isCompileItem = IsCompileItem(documentChangeInfo.RelativeFilePath, projectInstance); var wasACompileItem = false; lock (_lastSeenCompileItems) { _lastSeenCompileItems.TryGetValue(documentChangeInfo.FilePath, out wasACompileItem); _lastSeenCompileItems[documentChangeInfo.FilePath] = isCompileItem; } if (!isCompileItem && wasACompileItem) { // Output document should no longer be considered as a compile item, clear the workspace content for it. var request = new Request() { FileName = componentDeclarationLocation, Buffer = string.Empty, }; await _updateBufferDispatcher.UpdateBufferAsync(request); } else if (isCompileItem) { // Force update the OmniSharp Workspace for component declaration changes. var request = new UpdateBufferRequest() { FileName = componentDeclarationLocation, FromDisk = true, }; await _updateBufferDispatcher.UpdateBufferAsync(request); } } catch (Exception ex) { _logger.LogError("Unexpected error when updating workspace representation of '" + documentChangeInfo.FilePath + "': " + ex); } } OnRefreshWorkCompleting(); }