From 25ba09f180db37d3de6830eb7cffa5fe014aa7a5 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Fri, 16 Dec 2016 13:30:51 -0800 Subject: [PATCH 1/2] 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 2aeb8bdb6039e..42074fd2c07a6 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 43ca3a34f9b61..a908e385adf98 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs @@ -27,15 +27,21 @@ public 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 0000000000000..6c884f8ca085b --- /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 a8fda42a08a4b..2afa5b41f2f73 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 061a065bbfdd1..c08225651bb1a 100644 --- a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs +++ b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs @@ -34,21 +34,27 @@ public GoToImplementationCommandHandler( public CommandState GetCommandState(GoToImplementationCommandArgs args, Func 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 0000000000000..1a23fa2fc012e --- /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 From 8f5e4227e03c079fbb9dc4a3c86799c30e9a1963 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Fri, 16 Dec 2016 13:44:13 -0800 Subject: [PATCH 2/2] Export the SuggestedActionsSourceProvider for specific langauges. --- src/EditorFeatures/Core/ContentTypeNames.cs | 2 ++ .../Suggestions/SuggestedActionsSourceProvider.cs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/EditorFeatures/Core/ContentTypeNames.cs b/src/EditorFeatures/Core/ContentTypeNames.cs index 072d9018d2aea..b980877273cb3 100644 --- a/src/EditorFeatures/Core/ContentTypeNames.cs +++ b/src/EditorFeatures/Core/ContentTypeNames.cs @@ -10,5 +10,7 @@ internal static class ContentTypeNames public const string VisualBasicContentType = "Basic"; public const string VisualBasicSignatureHelpContentType = "Basic Signature Help"; public const string XamlContentType = "XAML"; + public const string JavaScriptContentTypeName = "JavaScript"; + public const string TypeScriptContentTypeName = "TypeScript"; } } diff --git a/src/EditorFeatures/Core/Implementation/Suggestions/SuggestedActionsSourceProvider.cs b/src/EditorFeatures/Core/Implementation/Suggestions/SuggestedActionsSourceProvider.cs index 7efe5916a92e4..c95e484ece43d 100644 --- a/src/EditorFeatures/Core/Implementation/Suggestions/SuggestedActionsSourceProvider.cs +++ b/src/EditorFeatures/Core/Implementation/Suggestions/SuggestedActionsSourceProvider.cs @@ -36,7 +36,10 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.Suggestions [Export(typeof(ISuggestedActionsSourceProvider))] [Export(typeof(SuggestedActionsSourceProvider))] - [VisualStudio.Utilities.ContentType(ContentTypeNames.RoslynContentType)] + [VisualStudio.Utilities.ContentType(ContentTypeNames.CSharpContentType)] + [VisualStudio.Utilities.ContentType(ContentTypeNames.VisualBasicContentType)] + [VisualStudio.Utilities.ContentType(ContentTypeNames.JavaScriptContentTypeName)] + [VisualStudio.Utilities.ContentType(ContentTypeNames.TypeScriptContentTypeName)] [VisualStudio.Utilities.ContentType(ContentTypeNames.XamlContentType)] [VisualStudio.Utilities.Name("Roslyn Code Fix")] [VisualStudio.Utilities.Order]