From 25ba09f180db37d3de6830eb7cffa5fe014aa7a5 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Fri, 16 Dec 2016 13:30:51 -0800 Subject: [PATCH] Add per language options to disable GoToDef and GoToImpl. --- src/EditorFeatures/Core/EditorFeatures.csproj | 2 ++ .../GoToDefinitionCommandHandler.cs | 14 ++++++++---- .../GoToDefinition/GoToDefinitionOptions.cs | 12 ++++++++++ .../GoToDefinition/IGoToDefinitionService.cs | 1 + .../GoToImplementationCommandHandler.cs | 22 ++++++++++++------- .../GoToImplementationOptions.cs | 12 ++++++++++ 6 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 src/EditorFeatures/Core/GoToDefinition/GoToDefinitionOptions.cs create mode 100644 src/EditorFeatures/Core/GoToImplementation/GoToImplementationOptions.cs diff --git a/src/EditorFeatures/Core/EditorFeatures.csproj b/src/EditorFeatures/Core/EditorFeatures.csproj index 2aeb8bdb603..42074fd2c07 100644 --- a/src/EditorFeatures/Core/EditorFeatures.csproj +++ b/src/EditorFeatures/Core/EditorFeatures.csproj @@ -109,6 +109,8 @@ + + diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs index 43ca3a34f9b..a908e385adf 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs @@ -27,15 +27,21 @@ internal class GoToDefinitionCommandHandler : public CommandState GetCommandState(GoToDefinitionCommandArgs args, Func nextHandler) { - return CommandState.Available; + return args.SubjectBuffer.GetFeatureOnOffOption(GoToDefinitionOptions.Enabled) + ? CommandState.Available + : CommandState.Unavailable; } public void ExecuteCommand(GoToDefinitionCommandArgs args, Action nextHandler) { - var caretPos = args.TextView.GetCaretPoint(args.SubjectBuffer); - if (caretPos.HasValue && TryExecuteCommand(args.SubjectBuffer.CurrentSnapshot, caretPos.Value)) + var subjectBuffer = args.SubjectBuffer; + if (subjectBuffer.GetFeatureOnOffOption(GoToDefinitionOptions.Enabled)) { - return; + var caretPos = args.TextView.GetCaretPoint(subjectBuffer); + if (caretPos.HasValue && TryExecuteCommand(subjectBuffer.CurrentSnapshot, caretPos.Value)) + { + return; + } } nextHandler(); diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionOptions.cs b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionOptions.cs new file mode 100644 index 00000000000..6c884f8ca08 --- /dev/null +++ b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionOptions.cs @@ -0,0 +1,12 @@ +// 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/GoToDefinition/IGoToDefinitionService.cs b/src/EditorFeatures/Core/GoToDefinition/IGoToDefinitionService.cs index a8fda42a08a..2afa5b41f2f 100644 --- a/src/EditorFeatures/Core/GoToDefinition/IGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/IGoToDefinitionService.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Navigation; +using Microsoft.CodeAnalysis.Options; namespace Microsoft.CodeAnalysis.Editor { diff --git a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs index 061a065bbfd..c08225651bb 100644 --- a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs +++ b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs @@ -34,21 +34,27 @@ internal partial class GoToImplementationCommandHandler : ICommandHandler nextHandler) { - // Because this is expensive to compute, we just always say yes - return CommandState.Available; + // Because this is expensive to compute, we just always say yes as long as the language allows it. + return args.SubjectBuffer.GetFeatureOnOffOption(GoToImplementationOptions.Enabled) + ? CommandState.Available + : CommandState.Unavailable; } public void ExecuteCommand(GoToImplementationCommandArgs args, Action nextHandler) { - var caret = args.TextView.GetCaretPoint(args.SubjectBuffer); + var subjectBuffer = args.SubjectBuffer; - if (caret.HasValue) + if (subjectBuffer.GetFeatureOnOffOption(GoToImplementationOptions.Enabled)) { - var document = args.SubjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); - if (document != null) + var caret = args.TextView.GetCaretPoint(subjectBuffer); + if (caret.HasValue) { - ExecuteCommand(document, caret.Value); - return; + var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); + if (document != null) + { + ExecuteCommand(document, caret.Value); + return; + } } } diff --git a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationOptions.cs b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationOptions.cs new file mode 100644 index 00000000000..1a23fa2fc01 --- /dev/null +++ b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationOptions.cs @@ -0,0 +1,12 @@ +// 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