diff --git a/src/EditorFeatures/Core/EditorFeatures.csproj b/src/EditorFeatures/Core/EditorFeatures.csproj
index 2aeb8bdb6039ec846c96f4081fdb4fe110e87eb3..42074fd2c07a6b0b59bb938c91abe8168d6cb37f 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 43ca3a34f9b61f1f384db67425e8d448a407ab69..a908e385adf98425d62365898e44d04ed918b3fd 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 0000000000000000000000000000000000000000..6c884f8ca085b328d48d5458fdd5568d0711cf2b
--- /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 a8fda42a08a4bc91a70090b29748be94d005f949..2afa5b41f2f73e2ac31ca6aa0fba9cea699917a4 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 061a065bbfdd122c938f1dfd242ad6539465a73b..c08225651bb1ad316667241c3312cb43b179c276 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 0000000000000000000000000000000000000000..1a23fa2fc012e447943b9e95662d92ad8b80273e
--- /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