Skip to content

Commit

Permalink
Merge pull request #15961 from CyrusNajmabadi/lightBulbsFSharp
Browse files Browse the repository at this point in the history
Export the SuggestedActionsSourceProvider for specific langauges.
  • Loading branch information
CyrusNajmabadi authored Dec 19, 2016
2 parents e59176f + 3d0fa30 commit f2d8fcd
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/EditorFeatures/Core/ContentTypeNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
2 changes: 2 additions & 0 deletions src/EditorFeatures/Core/EditorFeatures.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
<Compile Include="FindUsages\IFindUsagesContext.cs" />
<Compile Include="FindUsages\IFindUsagesService.cs" />
<Compile Include="FindUsages\SimpleFindUsagesContext.cs" />
<Compile Include="GoToDefinition\GoToDefinitionOptions.cs" />
<Compile Include="GoToImplementation\GoToImplementationOptions.cs" />
<Compile Include="Implementation\Structure\BlockTagState.cs" />
<Compile Include="Tags\ExportImageMonikerServiceAttribute.cs" />
<Compile Include="Implementation\NavigateTo\AbstractNavigateToItemDisplay.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ public GoToDefinitionCommandHandler(

public CommandState GetCommandState(GoToDefinitionCommandArgs args, Func<CommandState> 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();
Expand Down
12 changes: 12 additions & 0 deletions src/EditorFeatures/Core/GoToDefinition/GoToDefinitionOptions.cs
Original file line number Diff line number Diff line change
@@ -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<bool> Enabled = new PerLanguageOption<bool>(
nameof(GoToDefinitionOptions), nameof(Enabled), defaultValue: true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.Editor
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,27 @@ public GoToImplementationCommandHandler(

public CommandState GetCommandState(GoToImplementationCommandArgs args, Func<CommandState> 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;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<bool> Enabled = new PerLanguageOption<bool>(
nameof(GoToImplementationOptions), nameof(Enabled), defaultValue: true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit f2d8fcd

Please sign in to comment.