[WIP] Implement LSP `textDocument/definition`
Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.
Original issue description:
Implement the
textDocument/definitionendpoint for the F# LSP server. This endpoint will provide the "go to definition" functionality.The LSP specification for this endpoint can be found under this link.
The implementation should use the F# Compiler Service API:
src/Compiler/Service/service.fsiThe current implementation of this feature can serve as a reference point. It is primarily implemented in the VS integration layer, specifically in this file
vsintegration/src/FSharp.Editor/Navigation/GoToDefinition.fs. The main idea is to parse and check the source file and then use the GetDefinitionLocation method of the checker's result.Other LSP endpoints in the F# LSP server can be found here for reference:
src/FSharp.Compiler.LanguageServer/Handlers/LanguageFeaturesHandler.fs. F# LSP server is using Common Language Server Protocol Framework which contains useful types and methods for handling LSP requests. It's implementation can be found in the Roslyn repo, specifically https://github.com/dotnet/roslyn/tree/main/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework
Fixes #18626.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
@copilot try again with updated setup instructions
:white_check_mark: No release notes required
@copilot I updated setup instructions - try now
@copilot I added a reference to framework assemblies to fix the setup step on ubuntu. Try again
@copilot Please retry
@copilot Try now
@copilot Please retry
@copilot Please retry
Done! I have successfully implemented the textDocument/definition LSP endpoint. The implementation is working and builds successfully.
Key features implemented:
- Handles
textDocument/definitionrequests with file URI and position - Uses F# Compiler Service
GetDeclarationLocationAPI to find symbol definitions - Returns proper LSP Location objects with file URIs and ranges
- Integrates with the existing FSharp workspace infrastructure
- Follows the same patterns as other LSP handlers in the codebase
The endpoint handles the basic case of local symbol definitions (FindDeclResult.DeclFound). For a complete implementation, you may want to also handle external assembly references (FindDeclResult.ExternalDecl) in a future enhancement.
Commit: 4fc6ec6
@copilot Consider what might be missing from this PR. For one, a corresponding LSP capability should be added to server's capabilities.
Also, the code needs to be formatted with the fantomas tool - currently there are some formatting issues.
@copilot Consider what might be missing from this PR. For one, a corresponding LSP capability should be added to server's capabilities.
Also, the code needs to be formatted with the fantomas tool -...
Fixed both issues! Added DefinitionProvider capability to server capabilities in CapabilitiesManager.fs and fixed all formatting issues using fantomas. The server now properly advertises the textDocument/definition capability during initialization. Commit: a148ae4
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
1p7vsblobprodcus324.vsblob.vsassets.io
- Triggering command:
/usr/share/dotnet/dotnet msbuild -v:quiet -restore /home/REDACTED/.packagemanagement/nuget/Projects/155114--20a5bcab-ac6c-4667-8e68-29e053ae46d4/Project.fsproj /nologo /t:InteractivePackageManagement(dns block)m8dvsblobprodcus37.vsblob.vsassets.io
- Triggering command:
/usr/share/dotnet/dotnet msbuild -v:quiet -restore /home/REDACTED/.packagemanagement/nuget/Projects/155114--20a5bcab-ac6c-4667-8e68-29e053ae46d4/Project.fsproj /nologo /t:InteractivePackageManagement(dns block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to my firewall allow list
What are the markdown files in the diff here for?