From f34177470c84193928912732580fd054b9409534 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Sat, 17 Dec 2016 01:06:05 -0800 Subject: [PATCH] Use the presence/absence of services to decide if we'll show GoToDef and GoToImpl --- src/EditorFeatures/Core/EditorFeatures.csproj | 2 -- .../GoToDefinitionCommandHandler.cs | 36 +++++++++---------- .../GoToDefinition/GoToDefinitionOptions.cs | 12 ------- .../GoToImplementationCommandHandler.cs | 35 ++++++++++-------- .../GoToImplementationOptions.cs | 12 ------- 5 files changed, 38 insertions(+), 59 deletions(-) delete mode 100644 src/EditorFeatures/Core/GoToDefinition/GoToDefinitionOptions.cs delete mode 100644 src/EditorFeatures/Core/GoToImplementation/GoToImplementationOptions.cs diff --git a/src/EditorFeatures/Core/EditorFeatures.csproj b/src/EditorFeatures/Core/EditorFeatures.csproj index f0b3db7194b..04b86651a4c 100644 --- a/src/EditorFeatures/Core/EditorFeatures.csproj +++ b/src/EditorFeatures/Core/EditorFeatures.csproj @@ -109,8 +109,6 @@ - - diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs index a908e385adf..987b0587c71 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs @@ -6,6 +6,7 @@ using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Notification; +using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Text; @@ -25,9 +26,16 @@ internal class GoToDefinitionCommandHandler : _waitIndicator = waitIndicator; } + private (Document, IGoToDefinitionService) GetDocumentAndService(ITextSnapshot snapshot) + { + var document = snapshot.GetOpenDocumentInCurrentContextWithChanges(); + return (document, document?.GetLanguageService()); + } + public CommandState GetCommandState(GoToDefinitionCommandArgs args, Func nextHandler) { - return args.SubjectBuffer.GetFeatureOnOffOption(GoToDefinitionOptions.Enabled) + var (document, service) = GetDocumentAndService(args.SubjectBuffer.CurrentSnapshot); + return service != null ? CommandState.Available : CommandState.Unavailable; } @@ -35,10 +43,11 @@ public CommandState GetCommandState(GoToDefinitionCommandArgs args, Func(); - return TryExecuteCommand(document, caretPosition, goToDefinitionService); - } - else - { - // We didn't even have a workspace, so we can let somebody else try to handle this if they can - return false; - } - } + => TryExecuteCommand(snapshot.GetOpenDocumentInCurrentContextWithChanges(), caretPosition); + + internal bool TryExecuteCommand(Document document, int caretPosition) + => TryExecuteCommand(document, caretPosition, document.GetLanguageService()); - // Internal for testing purposes only. internal bool TryExecuteCommand(Document document, int caretPosition, IGoToDefinitionService goToDefinitionService) { string errorMessage = null; @@ -92,4 +92,4 @@ internal bool TryExecuteCommand(Document document, int caretPosition, IGoToDefin return true; } } -} +} \ No newline at end of file diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionOptions.cs b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionOptions.cs deleted file mode 100644 index 6c884f8ca08..00000000000 --- a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionOptions.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 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.Options; - -namespace Microsoft.CodeAnalysis.Editor -{ - internal static class GoToDefinitionOptions - { - public static readonly PerLanguageOption Enabled = new PerLanguageOption( - nameof(GoToDefinitionOptions), nameof(Enabled), defaultValue: true); - } -} diff --git a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs index 06be7cb45a2..37e22d4d186 100644 --- a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs +++ b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs @@ -13,6 +13,7 @@ using Microsoft.CodeAnalysis.Notification; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; +using Microsoft.VisualStudio.Text; namespace Microsoft.CodeAnalysis.Editor.GoToImplementation { @@ -32,40 +33,44 @@ internal partial class GoToImplementationCommandHandler : ICommandHandler(), + document?.GetLanguageService()); + } + public CommandState GetCommandState(GoToImplementationCommandArgs args, Func nextHandler) { // Because this is expensive to compute, we just always say yes as long as the language allows it. - return args.SubjectBuffer.GetFeatureOnOffOption(GoToImplementationOptions.Enabled) + var (document, implService, findUsagesService) = GetDocumentAndServices(args.SubjectBuffer.CurrentSnapshot); + return implService != null || findUsagesService != null ? CommandState.Available : CommandState.Unavailable; } public void ExecuteCommand(GoToImplementationCommandArgs args, Action nextHandler) { - var subjectBuffer = args.SubjectBuffer; - - if (subjectBuffer.GetFeatureOnOffOption(GoToImplementationOptions.Enabled)) + var (document, implService, findUsagesService) = GetDocumentAndServices(args.SubjectBuffer.CurrentSnapshot); + if (implService != null || findUsagesService != null) { - var caret = args.TextView.GetCaretPoint(subjectBuffer); + var caret = args.TextView.GetCaretPoint(args.SubjectBuffer); if (caret.HasValue) { - var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); - if (document != null) - { - ExecuteCommand(document, caret.Value); - return; - } + ExecuteCommand(document, caret.Value, implService, findUsagesService); + return; } } nextHandler(); } - private void ExecuteCommand(Document document, int caretPosition) + private void ExecuteCommand( + Document document, int caretPosition, + IGoToImplementationService synchronousService, + IFindUsagesService streamingService) { - var streamingService = document.GetLanguageService(); - var synchronousService = document.GetLanguageService(); - var streamingPresenter = GetStreamingPresenter(); var streamingEnabled = document.Project.Solution.Workspace.Options.GetOption(FeatureOnOffOptions.StreamingGoToImplementation, document.Project.Language); diff --git a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationOptions.cs b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationOptions.cs deleted file mode 100644 index 1a23fa2fc01..00000000000 --- a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationOptions.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 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.Options; - -namespace Microsoft.CodeAnalysis.Editor.GoToImplementation -{ - internal static class GoToImplementationOptions - { - public static readonly PerLanguageOption Enabled = new PerLanguageOption( - nameof(GoToImplementationOptions), nameof(Enabled), defaultValue: true); - } -} \ No newline at end of file -- GitLab