From 3149ba26d3ea5949532028c71b9533658a8cab8b Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Tue, 14 May 2019 15:35:53 -0700 Subject: [PATCH] Add some more AnalyzerConfigDocument functionality to the VisualStudio layer. This includes the changes to enable Preview workspace and Preview changes functionality for analyzer config documents --- .../Def/Implementation/Preview/FileChange.cs | 3 +- .../Implementation/Preview/PreviewEngine.cs | 9 +++ .../PreviewUpdater.PreviewDialogWorkspace.cs | 41 +++++++--- .../Implementation/Preview/TopLevelChange.cs | 16 +++- .../ProjectSystem/VisualStudioProject.cs | 5 ++ .../ProjectSystem/VisualStudioWorkspace.cs | 7 +- ...eImpl.AddAnalyzerConfigDocumentUndoUnit.cs | 24 ++++++ ...sualStudioWorkspaceImpl.OpenFileTracker.cs | 8 +- ...pl.RemoveAnalyzerConfigDocumentUndoUnit.cs | 26 +++++++ .../VisualStudioWorkspaceImpl.cs | 76 +++++++++++++++---- ...osoft.VisualStudio.LanguageServices.csproj | 5 +- .../Core/Impl/RoslynVisualStudioWorkspace.cs | 2 +- 12 files changed, 174 insertions(+), 48 deletions(-) create mode 100644 src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.AddAnalyzerConfigDocumentUndoUnit.cs create mode 100644 src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.RemoveAnalyzerConfigDocumentUndoUnit.cs diff --git a/src/VisualStudio/Core/Def/Implementation/Preview/FileChange.cs b/src/VisualStudio/Core/Def/Implementation/Preview/FileChange.cs index ab204bb5541..2031a6cf8c3 100644 --- a/src/VisualStudio/Core/Def/Implementation/Preview/FileChange.cs +++ b/src/VisualStudio/Core/Def/Implementation/Preview/FileChange.cs @@ -210,7 +210,8 @@ public TextDocument GetUpdatedDocument() return _right.WithText(UpdateBufferText()); } - public bool IsAdditionalDocumentChange => !((_left ?? _right) is Document); + public bool IsAdditionalDocumentChange => !((_left ?? _right) is Document) && !IsAnalyzerConfigDocumentChange; + public bool IsAnalyzerConfigDocumentChange => (_left ?? _right) is AnalyzerConfigDocument; internal override void GetDisplayData(VSTREEDISPLAYDATA[] pData) { diff --git a/src/VisualStudio/Core/Def/Implementation/Preview/PreviewEngine.cs b/src/VisualStudio/Core/Def/Implementation/Preview/PreviewEngine.cs index f0218ab22a6..1f251e7f8dd 100644 --- a/src/VisualStudio/Core/Def/Implementation/Preview/PreviewEngine.cs +++ b/src/VisualStudio/Core/Def/Implementation/Preview/PreviewEngine.cs @@ -133,6 +133,15 @@ public int GetRootChangesList(out object ppIUnknownPreviewChangesList) allDocumentsWithChanges.AddRange(addedAdditionalDocuments); allDocumentsWithChanges.AddRange(removedAdditionalDocuments); + // AnalyzerConfig Documents + var changedAnalyzerConfigDocuments = projectChanges.SelectMany(p => p.GetChangedAnalyzerConfigDocuments()); + var addedAnalyzerConfigDocuments = projectChanges.SelectMany(p => p.GetAddedAnalyzerConfigDocuments()); + var removedAnalyzerConfigDocuments = projectChanges.SelectMany(p => p.GetRemovedAnalyzerConfigDocuments()); + + allDocumentsWithChanges.AddRange(changedAnalyzerConfigDocuments); + allDocumentsWithChanges.AddRange(addedAnalyzerConfigDocuments); + allDocumentsWithChanges.AddRange(removedAnalyzerConfigDocuments); + AppendFileChanges(allDocumentsWithChanges, builder); // References (metadata/project/analyzer) diff --git a/src/VisualStudio/Core/Def/Implementation/Preview/PreviewUpdater.PreviewDialogWorkspace.cs b/src/VisualStudio/Core/Def/Implementation/Preview/PreviewUpdater.PreviewDialogWorkspace.cs index c5083aeeb47..283acb031ab 100644 --- a/src/VisualStudio/Core/Def/Implementation/Preview/PreviewUpdater.PreviewDialogWorkspace.cs +++ b/src/VisualStudio/Core/Def/Implementation/Preview/PreviewUpdater.PreviewDialogWorkspace.cs @@ -25,25 +25,37 @@ public void UnregisterTextContainer(SourceTextContainer container) public void CloseDocument(TextDocument document, SourceText text) { - if (document is Document) + switch (document) { - OnDocumentClosed(document.Id, new PreviewTextLoader(text)); - } - else - { - OnAdditionalDocumentClosed(document.Id, new PreviewTextLoader(text)); + case Document _: + OnDocumentClosed(document.Id, new PreviewTextLoader(text)); + break; + + case AnalyzerConfigDocument _: + OnAnalyzerConfigDocumentClosed(document.Id, new PreviewTextLoader(text)); + break; + + default: + OnAdditionalDocumentClosed(document.Id, new PreviewTextLoader(text)); + break; } } public void OpenDocument(TextDocument document) { - if (document is Document) - { - OpenDocument(document.Id); - } - else + switch (document) { - OpenAdditionalDocument(document.Id); + case Document _: + OpenDocument(document.Id); + break; + + case AnalyzerConfigDocument _: + OpenAnalyzerConfigDocument(document.Id); + break; + + default: + OpenAdditionalDocument(document.Id); + break; } } @@ -57,6 +69,11 @@ protected override void ApplyAdditionalDocumentTextChanged(DocumentId id, Source OnAdditionalDocumentTextChanged(id, text, PreservationMode.PreserveIdentity); } + protected override void ApplyAnalyzerConfigDocumentTextChanged(DocumentId id, SourceText text) + { + OnAnalyzerConfigDocumentTextChanged(id, text, PreservationMode.PreserveIdentity); + } + private class PreviewTextLoader : TextLoader { private readonly SourceText _text; diff --git a/src/VisualStudio/Core/Def/Implementation/Preview/TopLevelChange.cs b/src/VisualStudio/Core/Def/Implementation/Preview/TopLevelChange.cs index 3c9846c6636..826170a21be 100644 --- a/src/VisualStudio/Core/Def/Implementation/Preview/TopLevelChange.cs +++ b/src/VisualStudio/Core/Def/Implementation/Preview/TopLevelChange.cs @@ -82,7 +82,7 @@ private Solution ApplyFileChanges(Solution solution, IEnumerable fil // Apply file change to document. ApplyFileChangesCore(oldTextDocument, updatedTextDocument?.Id, updatedDocumentTextOpt, - fileChange.CheckState, fileChange.IsAdditionalDocumentChange); + fileChange.CheckState, fileChange.IsAdditionalDocumentChange, fileChange.IsAnalyzerConfigDocumentChange); // Now apply file change to linked documents. if (oldTextDocument is Document oldDocument) @@ -95,7 +95,7 @@ private Solution ApplyFileChanges(Solution solution, IEnumerable fil var newLinkedDocumentIdOpt = updatedDocumentTextOpt != null ? oldLinkedDocument.Id : null; ApplyFileChangesCore(oldLinkedDocument, newLinkedDocumentIdOpt, updatedDocumentTextOpt, - fileChange.CheckState, fileChange.IsAdditionalDocumentChange); + fileChange.CheckState, fileChange.IsAdditionalDocumentChange, fileChange.IsAnalyzerConfigDocumentChange); } } else if (updatedTextDocument is Document updatedDocument) @@ -103,7 +103,7 @@ private Solution ApplyFileChanges(Solution solution, IEnumerable fil foreach (var newLinkedDocumentId in updatedDocument.GetLinkedDocumentIds()) { ApplyFileChangesCore(oldTextDocument, newLinkedDocumentId, updatedDocumentTextOpt, - fileChange.CheckState, fileChange.IsAdditionalDocumentChange); + fileChange.CheckState, fileChange.IsAdditionalDocumentChange, fileChange.IsAnalyzerConfigDocumentChange); } } } @@ -116,10 +116,12 @@ private Solution ApplyFileChanges(Solution solution, IEnumerable fil DocumentId updatedDocumentIdOpt, SourceText updateDocumentTextOpt, __PREVIEWCHANGESITEMCHECKSTATE checkState, - bool isAdditionalDoc) + bool isAdditionalDoc, + bool isAnalyzerConfigDoc) { Debug.Assert(oldDocument != null || updatedDocumentIdOpt != null); Debug.Assert((updatedDocumentIdOpt != null) == (updateDocumentTextOpt != null)); + Debug.Assert(!(isAdditionalDoc && isAnalyzerConfigDoc)); if (oldDocument == null) { @@ -129,6 +131,8 @@ private Solution ApplyFileChanges(Solution solution, IEnumerable fil { solution = isAdditionalDoc ? solution.RemoveAdditionalDocument(updatedDocumentIdOpt) : + isAnalyzerConfigDoc ? + solution.RemoveAnalyzerConfigDocument(updatedDocumentIdOpt) : solution.RemoveDocument(updatedDocumentIdOpt); } } @@ -141,6 +145,8 @@ private Solution ApplyFileChanges(Solution solution, IEnumerable fil var oldText = oldDocument.GetTextAsync().Result.ToString(); solution = isAdditionalDoc ? solution.AddAdditionalDocument(oldDocument.Id, oldDocument.Name, oldText, oldDocument.Folders, oldDocument.FilePath) : + isAnalyzerConfigDoc ? + solution.AddAnalyzerConfigDocument(oldDocument.Id, oldDocument.Name, SourceText.From(oldText), oldDocument.Folders, oldDocument.FilePath) : solution.AddDocument(oldDocument.Id, oldDocument.Name, oldText, oldDocument.Folders, oldDocument.FilePath); } } @@ -151,6 +157,8 @@ private Solution ApplyFileChanges(Solution solution, IEnumerable fil // Changed document. solution = isAdditionalDoc ? solution.WithAdditionalDocumentText(updatedDocumentIdOpt, updateDocumentTextOpt) : + isAnalyzerConfigDoc ? + solution.WithAnalyzerConfigDocumentText(updatedDocumentIdOpt, updateDocumentTextOpt) : solution.WithDocumentText(updatedDocumentIdOpt, updateDocumentTextOpt); } } diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioProject.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioProject.cs index 35d35ca6a08..2d81ec48cd0 100644 --- a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioProject.cs +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioProject.cs @@ -526,6 +526,11 @@ private void OnBatchScopeDisposed() _workspace.ApplyChangeToWorkspace(w => w.OnAdditionalDocumentOpened(documentId, textContainer)); } + foreach (var (documentId, textContainer) in analyzerConfigDocumentsToOpen) + { + _workspace.ApplyChangeToWorkspace(w => w.OnAnalyzerConfigDocumentOpened(documentId, textContainer)); + } + // Check for those files being opened to start wire-up if necessary _workspace.QueueCheckForFilesBeingOpen(documentFileNamesAdded.ToImmutable()); } diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspace.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspace.cs index 29aabf71277..44d447b5781 100644 --- a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspace.cs +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspace.cs @@ -6,6 +6,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.FindSymbols; using Microsoft.CodeAnalysis.Host; +using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.VisualStudio.LanguageServices.Implementation.Library.ObjectBrowser.Lists; using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem; using Microsoft.VisualStudio.Shell.Interop; @@ -84,11 +85,7 @@ protected override void OnDocumentClosing(DocumentId documentId) internal abstract Guid GetProjectGuid(ProjectId projectId); public virtual string GetFilePath(DocumentId documentId) - { - var solution = CurrentSolution; - - return (solution.GetDocument(documentId) ?? solution.GetAdditionalDocument(documentId))?.FilePath; - } + => CurrentSolution.GetTextDocument(documentId)?.FilePath; /// /// Given a document id, opens an invisible editor for the document. diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.AddAnalyzerConfigDocumentUndoUnit.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.AddAnalyzerConfigDocumentUndoUnit.cs new file mode 100644 index 00000000000..b9f66ac38dc --- /dev/null +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.AddAnalyzerConfigDocumentUndoUnit.cs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Text; + +namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem +{ + internal partial class VisualStudioWorkspaceImpl + { + private class AddAnalyzerConfigDocumentUndoUnit : AbstractAddDocumentUndoUnit + { + public AddAnalyzerConfigDocumentUndoUnit( + VisualStudioWorkspaceImpl workspace, + DocumentInfo docInfo, + SourceText text) + : base(workspace, docInfo, text) + { + } + + protected override Project AddDocument(Project fromProject) + => fromProject.AddAnalyzerConfigDocument(DocumentInfo.Name, Text, DocumentInfo.Folders, DocumentInfo.FilePath).Project; + } + } +} diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.OpenFileTracker.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.OpenFileTracker.cs index 59e82785a6b..a9996d7f12e 100644 --- a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.OpenFileTracker.cs +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.OpenFileTracker.cs @@ -191,10 +191,8 @@ private void TryOpeningDocumentsForNewCookie(uint cookie) } else { - // TODO: implement the ability for analyze config documents to be opened against - // a live text editor. This is tracked by - // https://devdiv.visualstudio.com/DevDiv/_workitems/edit/750120 Debug.Assert(w.CurrentSolution.ContainsAnalyzerConfigDocument(documentId)); + w.OnAnalyzerConfigDocumentOpened(documentId, textContainer, isCurrentContext); } } } @@ -366,10 +364,8 @@ private void TryClosingDocumentsForCookie(uint cookie) } else { - // TODO: implement the ability for analyze config documents to be opened against - // a live text editor. This is tracked by - // https://devdiv.visualstudio.com/DevDiv/_workitems/edit/750120 Debug.Assert(w.CurrentSolution.ContainsAnalyzerConfigDocument(documentId)); + w.OnAnalyzerConfigDocumentClosed(documentId, new FileTextLoader(moniker, defaultEncoding: null)); } } } diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.RemoveAnalyzerConfigDocumentUndoUnit.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.RemoveAnalyzerConfigDocumentUndoUnit.cs new file mode 100644 index 00000000000..ebf4678d285 --- /dev/null +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.RemoveAnalyzerConfigDocumentUndoUnit.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using Microsoft.CodeAnalysis; + +namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem +{ + internal partial class VisualStudioWorkspaceImpl + { + private class RemoveAnalyzerConfigDocumentUndoUnit : AbstractRemoveDocumentUndoUnit + { + public RemoveAnalyzerConfigDocumentUndoUnit( + VisualStudioWorkspaceImpl workspace, + DocumentId documentId) + : base(workspace, documentId) + { + } + + protected override IReadOnlyList GetDocumentIds(Project fromProject) + => fromProject.State.AnalyzerConfigDocumentIds.AsImmutable(); + + protected override TextDocument GetDocument(Solution currentSolution) + => currentSolution.GetAnalyzerConfigDocument(this.DocumentId); + } + } +} diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.cs index b5f76e2b8f8..1343a12f241 100644 --- a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.cs +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioWorkspaceImpl.cs @@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.PooledObjects; +using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Utilities; using Microsoft.CodeAnalysis.SolutionCrawler; using Microsoft.CodeAnalysis.Text; @@ -313,11 +314,13 @@ public override EnvDTE.FileCodeModel GetFileCodeModel(DocumentId documentId) foreach (var pc in projectChanges) { if (pc.GetAddedAdditionalDocuments().Any() || + pc.GetAddedAnalyzerConfigDocuments().Any() || pc.GetAddedAnalyzerReferences().Any() || pc.GetAddedDocuments().Any() || pc.GetAddedMetadataReferences().Any() || pc.GetAddedProjectReferences().Any() || pc.GetRemovedAdditionalDocuments().Any() || + pc.GetRemovedAnalyzerConfigDocuments().Any() || pc.GetRemovedAnalyzerReferences().Any() || pc.GetRemovedDocuments().Any() || pc.GetRemovedMetadataReferences().Any() || @@ -433,6 +436,9 @@ public override bool CanApplyChange(ApplyChangesKind feature) case ApplyChangesKind.ChangeCompilationOptions: case ApplyChangesKind.ChangeParseOptions: case ApplyChangesKind.ChangeDocumentInfo: + case ApplyChangesKind.AddAnalyzerConfigDocument: + case ApplyChangesKind.RemoveAnalyzerConfigDocument: + case ApplyChangesKind.ChangeAnalyzerConfigDocument: return true; default: @@ -712,16 +718,24 @@ private OleInterop.IOleUndoManager TryGetUndoManager() protected override void ApplyDocumentAdded(DocumentInfo info, SourceText text) { - AddDocumentCore(info, text, isAdditionalDocument: false); + AddDocumentCore(info, text, isAdditionalDocument: false, isAnalyzerConfigDocument: false); } protected override void ApplyAdditionalDocumentAdded(DocumentInfo info, SourceText text) { - AddDocumentCore(info, text, isAdditionalDocument: true); + AddDocumentCore(info, text, isAdditionalDocument: true, isAnalyzerConfigDocument: false); } - private void AddDocumentCore(DocumentInfo info, SourceText initialText, bool isAdditionalDocument) + protected override void ApplyAnalyzerConfigDocumentAdded(DocumentInfo info, SourceText text) { + AddDocumentCore(info, text, isAdditionalDocument: false, isAnalyzerConfigDocument: true); + } + + private void AddDocumentCore(DocumentInfo info, SourceText initialText, bool isAdditionalDocument, bool isAnalyzerConfigDocument) + { + Debug.Assert(!(isAdditionalDocument && isAnalyzerConfigDocument)); + + var isAdditionalOrAnalyzerConfigDocument = isAdditionalDocument || isAnalyzerConfigDocument; GetProjectData(info.Id.ProjectId, out var hierarchy, out var project); // If the first namespace name matches the name of the project, then we don't want to @@ -736,15 +750,15 @@ private void AddDocumentCore(DocumentInfo info, SourceText initialText, bool isA if (IsWebsite(project)) { - AddDocumentToFolder(project, info.Id, SpecializedCollections.SingletonEnumerable(AppCodeFolderName), info.Name, info.SourceCodeKind, initialText, isAdditionalDocument: isAdditionalDocument, filePath: info.FilePath); + AddDocumentToFolder(project, info.Id, SpecializedCollections.SingletonEnumerable(AppCodeFolderName), info.Name, info.SourceCodeKind, initialText, info.FilePath, isAdditionalOrAnalyzerConfigDocument); } else if (folders.Any()) { - AddDocumentToFolder(project, info.Id, folders, info.Name, info.SourceCodeKind, initialText, isAdditionalDocument: isAdditionalDocument, filePath: info.FilePath); + AddDocumentToFolder(project, info.Id, folders, info.Name, info.SourceCodeKind, initialText, info.FilePath, isAdditionalOrAnalyzerConfigDocument); } else { - AddDocumentToProject(project, info.Id, info.Name, info.SourceCodeKind, initialText, isAdditionalDocument: isAdditionalDocument, filePath: info.FilePath); + AddDocumentToProject(project, info.Id, info.Name, info.SourceCodeKind, initialText, info.FilePath, isAdditionalOrAnalyzerConfigDocument); } var undoManager = TryGetUndoManager(); @@ -753,6 +767,10 @@ private void AddDocumentCore(DocumentInfo info, SourceText initialText, bool isA { undoManager?.Add(new RemoveAdditionalDocumentUndoUnit(this, info.Id)); } + else if (isAnalyzerConfigDocument) + { + undoManager?.Add(new RemoveAnalyzerConfigDocumentUndoUnit(this, info.Id)); + } else { undoManager?.Add(new RemoveDocumentUndoUnit(this, info.Id)); @@ -823,7 +841,7 @@ protected override void AddExistingDocument(DocumentId documentId, string filePa SourceCodeKind sourceCodeKind, SourceText initialText = null, string filePath = null, - bool isAdditionalDocument = false) + bool isAdditionalOrAnalyzerConfigDocument = false) { string folderPath = null; if (filePath == null && !project.TryGetFullPath(out folderPath)) @@ -832,7 +850,7 @@ protected override void AddExistingDocument(DocumentId documentId, string filePa throw new Exception(ServicesVSResources.Could_not_find_location_of_folder_on_disk); } - return AddDocumentToProjectItems(project.ProjectItems, documentId, folderPath, documentName, sourceCodeKind, initialText, filePath, isAdditionalDocument); + return AddDocumentToProjectItems(project.ProjectItems, documentId, folderPath, documentName, sourceCodeKind, initialText, filePath, isAdditionalOrAnalyzerConfigDocument); } private ProjectItem AddDocumentToFolder( @@ -843,7 +861,7 @@ protected override void AddExistingDocument(DocumentId documentId, string filePa SourceCodeKind sourceCodeKind, SourceText initialText = null, string filePath = null, - bool isAdditionalDocument = false) + bool isAdditionalOrAnalyzerConfigDocument = false) { var folder = project.FindOrCreateFolder(folders); @@ -854,7 +872,7 @@ protected override void AddExistingDocument(DocumentId documentId, string filePa throw new Exception(ServicesVSResources.Could_not_find_location_of_folder_on_disk); } - return AddDocumentToProjectItems(folder.ProjectItems, documentId, folderPath, documentName, sourceCodeKind, initialText, filePath, isAdditionalDocument); + return AddDocumentToProjectItems(folder.ProjectItems, documentId, folderPath, documentName, sourceCodeKind, initialText, filePath, isAdditionalOrAnalyzerConfigDocument); } private ProjectItem AddDocumentToProjectItems( @@ -865,12 +883,12 @@ protected override void AddExistingDocument(DocumentId documentId, string filePa SourceCodeKind sourceCodeKind, SourceText initialText, string filePath, - bool isAdditionalDocument) + bool isAdditionalOrAnalyzerConfigDocument) { if (filePath == null) { var baseName = Path.GetFileNameWithoutExtension(documentName); - var extension = isAdditionalDocument ? Path.GetExtension(documentName) : GetPreferredExtension(documentId, sourceCodeKind); + var extension = isAdditionalOrAnalyzerConfigDocument ? Path.GetExtension(documentName) : GetPreferredExtension(documentId, sourceCodeKind); var uniqueName = projectItems.GetUniqueName(baseName, extension); filePath = Path.Combine(folderPath, uniqueName); } @@ -889,8 +907,10 @@ protected override void AddExistingDocument(DocumentId documentId, string filePa } private void RemoveDocumentCore( - DocumentId documentId, bool isAdditionalDocument) + DocumentId documentId, bool isAdditionalDocument, bool isAnalyzerConfigDocument) { + Debug.Assert(!(isAdditionalDocument && isAnalyzerConfigDocument)); + if (documentId == null) { throw new ArgumentNullException(nameof(documentId)); @@ -919,6 +939,10 @@ protected override void AddExistingDocument(DocumentId documentId, string filePa { undoManager?.Add(new AddAdditionalDocumentUndoUnit(this, docInfo, text)); } + else if (isAnalyzerConfigDocument) + { + undoManager?.Add(new AddAnalyzerConfigDocumentUndoUnit(this, docInfo, text)); + } else { undoManager?.Add(new AddDocumentUndoUnit(this, docInfo, text)); @@ -928,12 +952,17 @@ protected override void AddExistingDocument(DocumentId documentId, string filePa protected override void ApplyDocumentRemoved(DocumentId documentId) { - RemoveDocumentCore(documentId, isAdditionalDocument: false); + RemoveDocumentCore(documentId, isAdditionalDocument: false, isAnalyzerConfigDocument: false); } protected override void ApplyAdditionalDocumentRemoved(DocumentId documentId) { - RemoveDocumentCore(documentId, isAdditionalDocument: true); + RemoveDocumentCore(documentId, isAdditionalDocument: true, isAnalyzerConfigDocument: false); + } + + protected override void ApplyAnalyzerConfigDocumentRemoved(DocumentId documentId) + { + RemoveDocumentCore(documentId, isAdditionalDocument: false, isAnalyzerConfigDocument: true); } public override void OpenDocument(DocumentId documentId, bool activate = true) @@ -946,6 +975,11 @@ public override void OpenAdditionalDocument(DocumentId documentId, bool activate OpenDocumentCore(documentId, activate); } + public override void OpenAnalyzerConfigDocument(DocumentId documentId, bool activate = true) + { + OpenDocumentCore(documentId, activate); + } + public override void CloseDocument(DocumentId documentId) { CloseDocumentCore(documentId); @@ -956,6 +990,11 @@ public override void CloseAdditionalDocument(DocumentId documentId) CloseDocumentCore(documentId); } + public override void CloseAnalyzerConfigDocument(DocumentId documentId) + { + CloseDocumentCore(documentId); + } + public void OpenDocumentCore(DocumentId documentId, bool activate = true) { if (documentId == null) @@ -1057,6 +1096,11 @@ protected override void ApplyAdditionalDocumentTextChanged(DocumentId documentId ApplyTextDocumentChange(documentId, newText); } + protected override void ApplyAnalyzerConfigDocumentTextChanged(DocumentId documentId, SourceText newText) + { + ApplyTextDocumentChange(documentId, newText); + } + private void ApplyTextDocumentChange(DocumentId documentId, SourceText newText) { EnsureEditableDocuments(documentId); @@ -1070,7 +1114,7 @@ private void ApplyTextDocumentChange(DocumentId documentId, SourceText newText) { if (IsDocumentOpen(documentId)) { - var textBuffer = this.CurrentSolution.GetDocument(documentId).GetTextAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None).Container.TryGetTextBuffer(); + var textBuffer = this.CurrentSolution.GetTextDocument(documentId).GetTextAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None).Container.TryGetTextBuffer(); if (textBuffer != null) { diff --git a/src/VisualStudio/Core/Def/Microsoft.VisualStudio.LanguageServices.csproj b/src/VisualStudio/Core/Def/Microsoft.VisualStudio.LanguageServices.csproj index d3012f6a1d6..7cc5d685cf3 100644 --- a/src/VisualStudio/Core/Def/Microsoft.VisualStudio.LanguageServices.csproj +++ b/src/VisualStudio/Core/Def/Microsoft.VisualStudio.LanguageServices.csproj @@ -52,7 +52,6 @@ MoveToNamespaceDialog.xaml - Code PickMembersDialog.xaml @@ -78,7 +77,7 @@ - + @@ -191,7 +190,7 @@ - + diff --git a/src/VisualStudio/Core/Impl/RoslynVisualStudioWorkspace.cs b/src/VisualStudio/Core/Impl/RoslynVisualStudioWorkspace.cs index ce49e37f427..9197e65a2c9 100644 --- a/src/VisualStudio/Core/Impl/RoslynVisualStudioWorkspace.cs +++ b/src/VisualStudio/Core/Impl/RoslynVisualStudioWorkspace.cs @@ -72,7 +72,7 @@ internal override IInvisibleEditor OpenInvisibleEditor(DocumentId documentId) } } - var document = this.CurrentSolution.GetDocument(documentId) ?? this.CurrentSolution.GetAdditionalDocument(documentId); + var document = this.CurrentSolution.GetTextDocument(documentId); return new InvisibleEditor(ServiceProvider.GlobalProvider, document.FilePath, GetHierarchy(documentId.ProjectId), needsSave, needsUndoDisabled); } -- GitLab