Skip to content

Commit 85dda97

Browse files
Copilotdibarbet
andauthored
Enable LSP go-to-definition, find-all-references, and go-to-implementation with command handler precedence (#80951)
## Changes: Enable LSP Go-to-Definition, Find-All-References, and Go-to-Implementation Capabilities Allows other extensions to call into our LSP handlers, but ensures that the MEF APIs are still used for normal user invoked commands by ensuring our MEF handlers are ordered before LSP MEF handlers. ### Completed: - [x] Enable `DefinitionProvider`, `ReferencesProvider`, and `ImplementationProvider` capabilities in `AlwaysActivateInProcLanguageClient.GetCapabilities()` regardless of the LSP feature flag - [x] Add `Order(Before = ...)` attribute to `GoToDefinitionCommandHandler` to ensure it runs before any LSP command handlers - [x] Add `Order(Before = ...)` attribute to `FindReferencesCommandHandler` to ensure it runs before any LSP command handlers - [x] Add `Order(Before = ...)` attribute to `GoToImplementationCommandHandler` to ensure it runs before any LSP command handlers - [x] Add new constants `LspGoToDefinition`, `LspFindReferences`, and `LspGoToImplementation` to `PredefinedCommandHandlerNames` - [x] Update command handler name values to exact requested strings - [x] Document that LSP command handler names are externally agreed upon and cannot be changed - [x] Build verified successfully ### Files Modified: 1. `src/EditorFeatures/Core/LanguageServer/AlwaysActivateInProcLanguageClient.cs` - Enabled DefinitionProvider, ReferencesProvider, and ImplementationProvider capabilities unconditionally 2. `src/EditorFeatures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs` - Added Order(Before) attribute for LSP handler 3. `src/EditorFeatures/Core/GoOrFind/FindReferences/FindReferencesCommandHandler.cs` - Added Order(Before) attribute for LSP handler 4. `src/EditorFeatures/Core/GoOrFind/GoToImplementation/GoToImplementationCommandHandler.cs` - Added Order(Before) attribute for LSP handler 5. `src/EditorFeatures/Core/Extensibility/Commands/PredefinedCommandHandlerNames.cs` - Added LSP command handler name constants with exact values and documented they are externally agreed upon ### Summary: These changes enable clients to call the LSP go-to-definition, find-all-references, and go-to-implementation handlers by advertising the capabilities in the AlwaysActiveInProcLanguageServer. The traditional command handlers are ordered to run before any LSP-based command handlers, ensuring they remain active for normal scenarios while allowing experimentation with LSP handlers. <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: dibarbet <[email protected]>
1 parent 7fe7dd9 commit 85dda97

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

src/EditorFeatures/Core/Extensibility/Commands/PredefinedCommandHandlerNames.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,22 @@ internal static class PredefinedCommandHandlerNames
191191
/// Command handler name for showing the Callstack Explorer tool window.
192192
/// </summary>
193193
public const string ShowCallstackExplorer = "Show Callstack Explorer";
194+
195+
/// <summary>
196+
/// Command handler name for LSP Go To Definition.
197+
/// This name is agreed upon externally and cannot be changed.
198+
/// </summary>
199+
public const string LspGoToDefinition = "LSP GoToDefinitionCommandHandler";
200+
201+
/// <summary>
202+
/// Command handler name for LSP Find References.
203+
/// This name is agreed upon externally and cannot be changed.
204+
/// </summary>
205+
public const string LspFindReferences = "LSP FindReferenceCommandHandler";
206+
207+
/// <summary>
208+
/// Command handler name for LSP Go To Implementation.
209+
/// This name is agreed upon externally and cannot be changed.
210+
/// </summary>
211+
public const string LspGoToImplementation = "LSP GoToImplementationCommandHandler";
194212
}

src/EditorFeatures/Core/GoOrFind/FindReferences/FindReferencesCommandHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Microsoft.CodeAnalysis.FindReferences;
1515
[Export(typeof(ICommandHandler))]
1616
[ContentType(ContentTypeNames.RoslynContentType)]
1717
[Name(PredefinedCommandHandlerNames.FindReferences)]
18+
[Order(Before = PredefinedCommandHandlerNames.LspFindReferences)]
1819
[method: ImportingConstructor]
1920
[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")]
2021
internal sealed class FindReferencesCommandHandler(FindReferencesNavigationService navigationService)

src/EditorFeatures/Core/GoOrFind/GoToImplementation/GoToImplementationCommandHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Microsoft.CodeAnalysis.GoToImplementation;
1616
[Export(typeof(ICommandHandler))]
1717
[ContentType(ContentTypeNames.RoslynContentType)]
1818
[Name(PredefinedCommandHandlerNames.GoToImplementation)]
19+
[Order(Before = PredefinedCommandHandlerNames.LspGoToImplementation)]
1920
[method: ImportingConstructor]
2021
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
2122
internal sealed class GoToImplementationCommandHandler(GoToImplementationNavigationService navigationService)

src/EditorFeatures/Core/GoToDefinition/GoToDefinitionCommandHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace Microsoft.CodeAnalysis.GoToDefinition;
2828
[Export(typeof(ICommandHandler))]
2929
[ContentType(ContentTypeNames.RoslynContentType)]
3030
[Name(PredefinedCommandHandlerNames.GoToDefinition)]
31+
[Order(Before = PredefinedCommandHandlerNames.LspGoToDefinition)]
3132
[method: ImportingConstructor]
3233
[method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")]
3334
internal sealed class GoToDefinitionCommandHandler(

src/EditorFeatures/Core/LanguageServer/AlwaysActivateInProcLanguageClient.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ public override ServerCapabilities GetCapabilities(ClientCapabilities clientCapa
118118

119119
serverCapabilities.SpellCheckingProvider = true;
120120

121+
// Enable go to definition, find all references, and go to implementation capabilities for experimentation.
122+
// These are enabled regardless of the LSP feature flag to allow clients to call these handlers.
123+
serverCapabilities.DefinitionProvider = true;
124+
serverCapabilities.ReferencesProvider = new ReferenceOptions
125+
{
126+
WorkDoneProgress = true,
127+
};
128+
serverCapabilities.ImplementationProvider = true;
129+
121130
return serverCapabilities;
122131
}
123132

0 commit comments

Comments
 (0)