Skip to content

Support LSP includeDeclaration field in find all references#80965

Merged
dibarbet merged 3 commits intomainfrom
copilot/update-lsp-find-all-references
Oct 31, 2025
Merged

Support LSP includeDeclaration field in find all references#80965
dibarbet merged 3 commits intomainfrom
copilot/update-lsp-find-all-references

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

The LSP textDocument/references handler was ignoring the includeDeclaration field in the request context, always returning declarations regardless of client preference.

Related to dotnet/vscode-csharp#6217 (comment)

Changes

Protocol Definition

  • Changed ReferenceContext.IncludeDeclaration from bool to bool? to distinguish between "not specified" (null, defaults to true) and "explicitly false"

Handler Implementation

  • FindAllReferencesHandler now extracts includeDeclaration from request context and passes it through to FindUsagesLSPContext
  • Defaults to true when null or not specified per LSP spec

Context Logic

  • FindUsagesLSPContext filters out definitions from results when includeDeclaration is false
  • Applied in both OnDefinitionFoundAsync and OnReferencesFoundAsync to handle definitions that would otherwise be reported lazily

Tests

  • Added tests for includeDeclaration=true, includeDeclaration=false, and includeDeclaration=null scenarios

Example

// Client requests references without declarations
var referenceParams = new ReferenceParams
{
    Context = new ReferenceContext { IncludeDeclaration = false }
};

// Returns only references, definition is filtered out
var results = await handler.HandleRequestAsync(referenceParams, ...);
Original prompt

LSP find references now includes an includeDeclaration field in the request context. Please update the LSP find all references implementation to respect this parameter and add tests for it.


💡 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 AI self-assigned this Oct 30, 2025
- Changed ReferenceContext.IncludeDeclaration to nullable bool to match LSP spec
- Updated FindUsagesLSPContext to accept and respect includeDeclaration parameter
- Updated FindAllReferencesHandler to pass includeDeclaration from request context
- When includeDeclaration is false, definitions are not reported in results
- When includeDeclaration is null or not specified, defaults to true per LSP spec
- Added comprehensive tests for includeDeclaration true/false/null scenarios
- Updated Razor external access to maintain compatibility

Co-authored-by: dibarbet <5749229+dibarbet@users.noreply.github.com>
Copilot AI changed the title [WIP] Update LSP find all references to include declaration parameter Support LSP includeDeclaration field in find all references Oct 30, 2025
Copilot AI requested a review from dibarbet October 30, 2025 20:43
@dibarbet dibarbet marked this pull request as ready for review October 30, 2025 21:46
@dibarbet dibarbet requested a review from a team as a code owner October 30, 2025 21:46
@dibarbet dibarbet force-pushed the copilot/update-lsp-find-all-references branch from 42bffec to 678843d Compare October 30, 2025 21:48
@dibarbet dibarbet merged commit f06fd2e into main Oct 31, 2025
25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 31, 2025
@jcouv jcouv deleted the copilot/update-lsp-find-all-references branch November 13, 2025 17:34
@davidwengier davidwengier modified the milestones: Next, 18.3 Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants