提交 e2f2cd27 编写于 作者: C CyrusNajmabadi

Enable Glyph's on code actions.

上级 613b9912
......@@ -10,6 +10,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Text;
......@@ -261,7 +262,7 @@ private void GetProjectItems(out IList<NavigationBarProjectItem> projectItems, o
projectItems = documents.Select(d =>
new NavigationBarProjectItem(
d.Project.Name,
GetProjectGlyph(d.Project),
d.Project.GetGlyph(),
workspace: d.Project.Solution.Workspace,
documentId: d.Id,
language: d.Project.Language)).OrderBy(projectItem => projectItem.Text).ToList();
......@@ -274,12 +275,6 @@ private void GetProjectItems(out IList<NavigationBarProjectItem> projectItems, o
: projectItems.First();
}
private Glyph GetProjectGlyph(Project project)
{
// TODO: Get the glyph from the hierarchy
return project.Language == LanguageNames.CSharp ? Glyph.CSharpProject : Glyph.BasicProject;
}
/// <summary>
/// Check if the presenter has already been pushed the full model that corresponds to the
/// current buffer's project version stamp.
......@@ -400,4 +395,4 @@ private void NavigateToItem(NavigationBarItem item, Document document, ITextSnap
languageService.NavigateToItem(document, item, _presenter.TryGetCurrentView(), cancellationToken);
}
}
}
}
\ No newline at end of file
......@@ -133,9 +133,11 @@ private async Task<IEnumerable<CodeActionOperation>> GetFixAllOperationsAsync(Co
using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesPreviewChanges, cancellationToken))
{
var previewService = workspace.Services.GetService<IPreviewDialogService>();
var glyph = languageOpt == null ?
Glyph.Assembly :
languageOpt == LanguageNames.CSharp ? Glyph.CSharpProject : Glyph.BasicProject;
var glyph = languageOpt == null
? Glyph.Assembly
: languageOpt == LanguageNames.CSharp
? Glyph.CSharpProject
: Glyph.BasicProject;
var changedSolution = previewService.PreviewChanges(
string.Format(EditorFeaturesResources.PreviewChangesOf, fixAllPreviewChangesTitle),
......
......@@ -43,7 +43,7 @@ protected override async Task<IEnumerable<CodeActionOperation>> ComputeOperation
"vs.codefix.previewchanges",
_originalCodeAction.Title,
EditorFeaturesResources.PreviewChangesRootNodeText,
Glyph.OpenFolder,
CodeAnalysis.Glyph.OpenFolder,
_changeSummary.NewSolution,
_changeSummary.OldSolution,
showCheckBoxes: false);
......
......@@ -259,14 +259,7 @@ void IDisposable.Dispose()
// same as display text
string ISuggestedAction.IconAutomationText => DisplayText;
ImageMoniker ISuggestedAction.IconMoniker
{
get
{
// no icon support
return default(ImageMoniker);
}
}
ImageMoniker ISuggestedAction.IconMoniker => CodeAction.Glyph?.GetImageMoniker() ?? default(ImageMoniker);
string ISuggestedAction.InputGestureText
{
......
......@@ -84,7 +84,7 @@ public ProjectSearchScope(Project project, bool ignoreCase, CancellationToken ca
public override SymbolReference CreateReference<T>(SearchResult<T> searchResult)
{
return new ProjectSymbolReference(
searchResult.WithSymbol<INamespaceOrTypeSymbol>(searchResult.Symbol), _project.Id);
searchResult.WithSymbol<INamespaceOrTypeSymbol>(searchResult.Symbol), _project);
}
}
......
......@@ -49,22 +49,30 @@ public override int GetHashCode()
return this.SearchResult.Symbol.GetHashCode();
}
public abstract Glyph? GetGlyph(Document document);
public abstract Solution UpdateSolution(Document newDocument);
}
private class ProjectSymbolReference : SymbolReference
{
private readonly ProjectId _projectId;
private readonly Project _project;
public ProjectSymbolReference(SearchResult<INamespaceOrTypeSymbol> searchResult, ProjectId projectId)
public ProjectSymbolReference(SearchResult<INamespaceOrTypeSymbol> searchResult, Project project)
: base(searchResult)
{
_projectId = projectId;
_project = project;
}
public override Glyph? GetGlyph(Document document)
{
return document.Project.Id == _project.Id
? default(Glyph?)
: _project.GetGlyph();
}
public override Solution UpdateSolution(Document newDocument)
{
if (_projectId == newDocument.Project.Id)
if (_project.Id == newDocument.Project.Id)
{
// This reference was found while searching in the project for our document. No
// need to make any solution changes.
......@@ -74,7 +82,7 @@ public override Solution UpdateSolution(Document newDocument)
// If this reference came from searching another project, then add a project reference
// as well.
var newProject = newDocument.Project;
newProject = newProject.AddProjectReference(new ProjectReference(_projectId));
newProject = newProject.AddProjectReference(new ProjectReference(_project.Id));
return newProject.Solution;
}
......@@ -90,10 +98,12 @@ public MetadataSymbolReference(SearchResult<INamespaceOrTypeSymbol> searchResult
_reference = reference;
}
public override Glyph? GetGlyph(Document document) => Glyph.Reference;
public override Solution UpdateSolution(Document newDocument)
{
return newDocument.Project.AddMetadataReference(_reference).Solution;
}
}
}
}
}
\ No newline at end of file
......@@ -100,8 +100,8 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
var description = this.GetDescription(reference.SearchResult.Symbol, semanticModel, node);
if (description != null)
{
var action = new MyCodeAction(description, c =>
this.AddImportAndReferenceAsync(node, reference, document, placeSystemNamespaceFirst, c));
var action = new MyCodeAction(description, reference.GetGlyph(document),
c => this.AddImportAndReferenceAsync(node, reference, document, placeSystemNamespaceFirst, c));
context.RegisterCodeFix(action, diagnostic);
}
}
......@@ -383,10 +383,15 @@ private static bool NotNull(SymbolReference reference)
private class MyCodeAction : CodeAction.SolutionChangeAction
{
public MyCodeAction(string title, Func<CancellationToken, Task<Solution>> createChangedSolution) :
private readonly Glyph? _glyph;
public MyCodeAction(string title, Glyph? glyph, Func<CancellationToken, Task<Solution>> createChangedSolution) :
base(title, createChangedSolution, equivalenceKey: title)
{
_glyph = glyph;
}
internal override Glyph? Glyph => _glyph;
}
private struct SearchResult<T> where T : ISymbol
......
......@@ -146,7 +146,6 @@
<Compile Include="CodeRefactorings\PredefinedCodeRefactoringProviderNames.cs" />
<Compile Include="CodeRefactorings\ServicesLayerCodeActionHelpersService.cs" />
<Compile Include="CodeRefactorings\WorkspaceServices\IAddMetadataReferenceCodeActionOperationFactoryWorkspaceService.cs" />
<Compile Include="Common\Glyph.cs" />
<Compile Include="Completion\AbstractCompletionService.cs" />
<Compile Include="Completion\CommonCompletionUtilities.cs" />
<Compile Include="Completion\CompletionFilterReason.cs" />
......
......@@ -47,6 +47,8 @@ public abstract class CodeAction
internal virtual bool IsInvokable => true;
internal virtual Glyph? Glyph => null;
internal virtual ImmutableArray<CodeAction> GetCodeActions()
{
return ImmutableArray<CodeAction>.Empty;
......
......@@ -38,5 +38,13 @@ public static async Task<VersionStamp> GetVersionAsync(this Project project, Can
return version.GetNewerVersion(latestVersion);
}
public static Glyph GetGlyph(this Project project)
{
// TODO: Get the glyph from the hierarchy
return project.Language == LanguageNames.CSharp ? Glyph.CSharpProject :
project.Language == LanguageNames.VisualBasic ? Glyph.BasicProject :
Glyph.Assembly;
}
}
}
}
\ No newline at end of file
......@@ -385,6 +385,7 @@
<Compile Include="FindSymbols\FindReferences\Finders\ILanguageServiceReferenceFinder.cs" />
<Compile Include="FindSymbols\SymbolTree\ISymbolTreeInfoCacheService.cs" />
<Compile Include="FindSymbols\FindReferences\MetadataUnifyingEquivalenceComparer.cs" />
<Compile Include="Shared\Glyph.cs" />
<Compile Include="Utilities\ArraySlice.cs" />
<Compile Include="Utilities\BKTree.cs" />
<Compile Include="FindSymbols\SyntaxTree\AbstractSyntaxTreeInfo.cs" />
......@@ -963,4 +964,4 @@
<ImportGroup Label="Targets">
<Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册