Skip to content

[WIP] Implement LSP textDocument/definition #18679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 10, 2025

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/definition endpoint 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.fsi

The 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.

@abonie
Copy link
Member

abonie commented Jun 10, 2025

@copilot try again with updated setup instructions

Copy link
Contributor

✅ No release notes required

Go back to ubuntu but run build.sh
@abonie
Copy link
Member

abonie commented Jun 10, 2025

@copilot I updated setup instructions - try now

Reference Framework assemblies to build on ubuntu
@abonie
Copy link
Member

abonie commented Jun 10, 2025

@copilot I added a reference to framework assemblies to fix the setup step on ubuntu. Try again

@abonie
Copy link
Member

abonie commented Jun 12, 2025

@copilot Please retry

@abonie
Copy link
Member

abonie commented Jun 12, 2025

@copilot Try now

@abonie
Copy link
Member

abonie commented Jun 16, 2025

@copilot Please retry

Copy link
Contributor Author

Copilot AI commented Jun 16, 2025

@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/definition requests with file URI and position
  • Uses F# Compiler Service GetDeclarationLocation API 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 finished work on behalf of abonie June 16, 2025 18:02
@abonie
Copy link
Member

abonie commented Jun 16, 2025

@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.

Copy link
Contributor Author

Copilot AI commented Jun 16, 2025

@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:

Copilot finished work on behalf of abonie June 16, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

Implement LSP textDocument/definition
2 participants