Skip to content

Conversation

@jakebailey
Copy link
Member

@jakebailey jakebailey commented Nov 14, 2025

This PR modifies the LSP generator to also generate a version of ClientCapabilities which is fully "resolved", that is, free of pointers and safe to access all the way down to the deepest field, along with a function that does this. On initialized, we resolve the caps, fix up the weird diagnostic cap bug (for now), then save that result for later.

This allows us to stop checking nil 1000 times over, eliminating a load of random helpers, if statements, etc, and preventing us from making the same mistake in the future.

This is however a lossy process; we won't know if something was nil versus "", or something. But I do not believe his matters for anything in the caps, so I think the ergonomics is worth it.

In addition, I've replaced the one-off passing of options with a context value; this is passed to LSP handler methods, replacing our very random use of capabilities (or, derived-from-capability values).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors LSP client capabilities handling by generating a fully "resolved" version of ClientCapabilities with all pointer fields converted to values, eliminating the need for repetitive nil checking throughout the codebase. The capabilities are now passed via context to LSP handlers instead of being passed as individual function parameters.

Key Changes:

  • Generated ResolvedClientCapabilities type and conversion function that dereferences all pointers with zero-value fallbacks
  • Implemented context-based capability access via WithClientCapabilities and GetClientCapabilities
  • Removed numerous helper functions that performed nil-checking on capability fields

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/lsp/lsproto/_generate/generate.mts Added generator logic to create resolved capability types and conversion functions with proper dependency ordering
internal/lsp/lsproto/lsp_generated.go Generated resolved types for all capability structures with derefOr helper for safe pointer dereferencing
internal/lsp/lsproto/lsp.go Added context utilities for storing/retrieving capabilities and PreferredMarkupKind helper function
internal/lsp/server.go Resolved capabilities on initialization, added context passing in request handler, removed obsolete helper functions, includes workaround for diagnostic capability bug
internal/ls/definition.go Updated to retrieve capability from context instead of function parameters
internal/ls/diagnostics.go Simplified diagnostic conversion by accessing resolved capabilities from context
internal/ls/completions.go Removed clientOptions parameters throughout, using context-based capability access instead
internal/ls/hover.go Retrieves content format preference from context capabilities
internal/ls/signaturehelp.go Removed capability parameters, using context-based access for documentation format
internal/ls/symbols.go Accesses hierarchical symbol support directly from context capabilities
internal/ls/string_completions.go Removed capability parameters, passing context instead
internal/ls/findallreferences.go Simplified implementation lookup by accessing link support from context
internal/project/untitled_test.go Updated test call to match new function signature without capability parameter

s.initializeParams.Capabilities.Workspace == nil ||
s.initializeParams.Capabilities.Workspace.Diagnostics == nil ||
!ptrIsTrue(s.initializeParams.Capabilities.Workspace.Diagnostics.RefreshSupport) {
if !s.clientCapabilities.Workspace.Diagnostics.RefreshSupport {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ctx here, since this is not an LSP method, but rather a callback given to Session.

@jakebailey jakebailey added this pull request to the merge queue Nov 14, 2025
@jakebailey
Copy link
Member Author

@sheetalkamat I'm sorry if this causes you to have to solve conflicts on #1991 again ☹️

Merged via the queue into main with commit dd043f4 Nov 14, 2025
22 checks passed
@jakebailey jakebailey deleted the jabaile/finalized-client-caps branch November 14, 2025 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants