Skip to content

Add workspace_folders parameter to LSP::Client#190

Merged
shugo merged 2 commits intomainfrom
feature/lsp-workspace-folders
Feb 19, 2026
Merged

Add workspace_folders parameter to LSP::Client#190
shugo merged 2 commits intomainfrom
feature/lsp-workspace-folders

Conversation

@shugo
Copy link
Owner

@shugo shugo commented Feb 18, 2026

Send workspaceFolders in the LSP initialize request so servers can index the correct project root. The server registry passes [root_path], and the parameter defaults to [Dir.pwd] for direct Client usage.

Also advertise workspace.workspaceFolders: true in client capabilities.

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 updates the Textbringer LSP client initialization handshake to send workspaceFolders (so servers can index the correct project root) and advertises workspace.workspaceFolders support in client capabilities.

Changes:

  • Pass workspace_folders from ServerRegistry when constructing an LSP client.
  • Add workspaceFolders to the LSP initialize request params.
  • Flip client_capabilities[:workspace][:workspaceFolders] from false to true.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
lib/textbringer/lsp/server_registry.rb Passes [root_path] as workspace_folders when creating a client per project root.
lib/textbringer/lsp/client.rb Adds workspace_folders support to initialize, sends workspaceFolders in initialize params, and advertises workspace folder support in capabilities.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 13 to 18
def initialize(command:, args: [], root_path:, server_name: nil, workspace_folders: [Dir.pwd])
@command = command
@args = args
@root_path = root_path
@server_name = server_name || command
@workspace_folders = workspace_folders
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

The default workspace_folders: [Dir.pwd] can diverge from the required root_path argument (e.g., callers pass root_path different from the current working directory). That would cause rootUri and workspaceFolders to disagree and can lead servers to index the wrong root. Consider defaulting workspace_folders to [root_path] (or setting @workspace_folders ||= [@root_path] in the body) and normalizing to an array of paths.

Suggested change
def initialize(command:, args: [], root_path:, server_name: nil, workspace_folders: [Dir.pwd])
@command = command
@args = args
@root_path = root_path
@server_name = server_name || command
@workspace_folders = workspace_folders
def initialize(command:, args: [], root_path:, server_name: nil, workspace_folders: nil)
@command = command
@args = args
@root_path = root_path
@server_name = server_name || command
@workspace_folders = Array(workspace_folders || @root_path)

Copilot uses AI. Check for mistakes.
Comment on lines +179 to +181
workspaceFolders: @workspace_folders.map { |path|
{ uri: "file://#{path}", name: File.basename(path) }
},
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

workspaceFolders URIs are constructed via string interpolation ("file://#{path}"), which produces invalid DocumentUri values for paths containing spaces or other characters requiring percent-encoding. Consider generating file URIs via Ruby's URI helpers (and ensuring paths are absolute/expanded) before sending them to the server.

Copilot uses AI. Check for mistakes.
},
workspace: {
workspaceFolders: false
workspaceFolders: true
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

client_capabilities now advertises workspace.workspaceFolders: true, but the client does not handle the server request workspace/workspaceFolders (it will currently respond "Method not found"). Servers that use this capability may fail or degrade. Either implement handling for workspace/workspaceFolders (returning the current workspace folders) or keep this capability disabled.

Suggested change
workspaceFolders: true
workspaceFolders: false

Copilot uses AI. Check for mistakes.
Comment on lines 175 to 182
params: {
processId: Process.pid,
rootUri: "file://#{@root_path}",
rootPath: @root_path,
workspaceFolders: @workspace_folders.map { |path|
{ uri: "file://#{path}", name: File.basename(path) }
},
capabilities: client_capabilities,
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

The new workspaceFolders initialization behavior isn’t covered by tests. Since this file already has LSP client tests, it would be good to add a test that initialize params include the expected workspaceFolders array (and that it matches the configured workspace folder paths).

Copilot uses AI. Check for mistakes.
Send workspaceFolders in the LSP initialize request so servers can
index the correct project root. The server registry passes [root_path],
and the parameter defaults to [Dir.pwd] for direct Client usage.

Also advertise workspace.workspaceFolders: true in client capabilities.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shugo shugo force-pushed the feature/lsp-workspace-folders branch from 1bad27f to 30279df Compare February 19, 2026 00:58
- Implement workspace/workspaceFolders server request handler so that
  advertising workspaceFolders: true actually works correctly
- Default workspace_folders to root_path instead of Dir.pwd to avoid
  rootUri/workspaceFolders disagreement
- Remove redundant workspace_folders: [root_path] from server_registry
  since the default now matches root_path
- Add tests for workspace_folders defaulting and explicit values

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shugo shugo enabled auto-merge February 19, 2026 01:04
@shugo shugo merged commit 871701c into main Feb 19, 2026
7 checks passed
@shugo shugo deleted the feature/lsp-workspace-folders branch February 19, 2026 01:06
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.

2 participants