提交 25ba09f1 编写于 作者: C CyrusNajmabadi

Add per language options to disable GoToDef and GoToImpl.

上级 653bc642
...@@ -109,6 +109,8 @@ ...@@ -109,6 +109,8 @@
<Compile Include="FindUsages\IFindUsagesContext.cs" /> <Compile Include="FindUsages\IFindUsagesContext.cs" />
<Compile Include="FindUsages\IFindUsagesService.cs" /> <Compile Include="FindUsages\IFindUsagesService.cs" />
<Compile Include="FindUsages\SimpleFindUsagesContext.cs" /> <Compile Include="FindUsages\SimpleFindUsagesContext.cs" />
<Compile Include="GoToDefinition\GoToDefinitionOptions.cs" />
<Compile Include="GoToImplementation\GoToImplementationOptions.cs" />
<Compile Include="Tags\ExportImageMonikerServiceAttribute.cs" /> <Compile Include="Tags\ExportImageMonikerServiceAttribute.cs" />
<Compile Include="Implementation\NavigateTo\AbstractNavigateToItemDisplay.cs" /> <Compile Include="Implementation\NavigateTo\AbstractNavigateToItemDisplay.cs" />
<Compile Include="CommandArgs.cs" /> <Compile Include="CommandArgs.cs" />
......
...@@ -27,15 +27,21 @@ internal class GoToDefinitionCommandHandler : ...@@ -27,15 +27,21 @@ internal class GoToDefinitionCommandHandler :
public CommandState GetCommandState(GoToDefinitionCommandArgs args, Func<CommandState> nextHandler) 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) public void ExecuteCommand(GoToDefinitionCommandArgs args, Action nextHandler)
{ {
var caretPos = args.TextView.GetCaretPoint(args.SubjectBuffer); var subjectBuffer = args.SubjectBuffer;
if (caretPos.HasValue && TryExecuteCommand(args.SubjectBuffer.CurrentSnapshot, caretPos.Value)) if (subjectBuffer.GetFeatureOnOffOption(GoToDefinitionOptions.Enabled))
{ {
return; var caretPos = args.TextView.GetCaretPoint(subjectBuffer);
if (caretPos.HasValue && TryExecuteCommand(subjectBuffer.CurrentSnapshot, caretPos.Value))
{
return;
}
} }
nextHandler(); nextHandler();
......
// 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);
}
}
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Navigation; using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Options;
namespace Microsoft.CodeAnalysis.Editor namespace Microsoft.CodeAnalysis.Editor
{ {
......
...@@ -34,21 +34,27 @@ internal partial class GoToImplementationCommandHandler : ICommandHandler<GoToIm ...@@ -34,21 +34,27 @@ internal partial class GoToImplementationCommandHandler : ICommandHandler<GoToIm
public CommandState GetCommandState(GoToImplementationCommandArgs args, Func<CommandState> nextHandler) public CommandState GetCommandState(GoToImplementationCommandArgs args, Func<CommandState> nextHandler)
{ {
// Because this is expensive to compute, we just always say yes // Because this is expensive to compute, we just always say yes as long as the language allows it.
return CommandState.Available; return args.SubjectBuffer.GetFeatureOnOffOption(GoToImplementationOptions.Enabled)
? CommandState.Available
: CommandState.Unavailable;
} }
public void ExecuteCommand(GoToImplementationCommandArgs args, Action nextHandler) 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(); var caret = args.TextView.GetCaretPoint(subjectBuffer);
if (document != null) if (caret.HasValue)
{ {
ExecuteCommand(document, caret.Value); var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
return; if (document != null)
{
ExecuteCommand(document, caret.Value);
return;
}
} }
} }
......
// 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);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册