lsp-custom-requests

Serialize URIs correctly across custom LSP requests using UriComponents and revive.

1.0k|454|Updated Jun 21, 2017
One-click install
npx skills add https://github.com/forcedotcom/salesforcedx-vscode --skill lsp-custom-requests
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: lsp-custom-requests
Source: https://github.com/forcedotcom/salesforcedx-vscode/tree/main/.claude/skills/lsp-custom-requests
Command: npx skills add https://github.com/forcedotcom/salesforcedx-vscode --skill lsp-custom-requests

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires vscode-uri.

What problem does it solve?

Custom LSP requests that pass URI parameters break at runtime because JSON.stringify converts vscode-uri objects into plain data, causing handlers to receive objects without toString or fsPath methods and producing EntryNotFound or [object Object] failures.

Core Features & Use Cases

  • Wire Format Guidance: Explains why Connection.sendRequest serializes URI params into plain UriComponents objects that lose prototype methods.
  • Revive Pattern: Shows how to type params as UriComponents via ReturnType<URI['toJSON']> and restore them with URI.revive on the receiving side.
  • Use Case: When defining a custom LSP request that sends a file URI from a VS Code extension client to a language server, apply this pattern so workspace.fs.stat and readFile calls in the handler receive a real URI instance instead of failing with EntryNotFound.

Quick Start

Apply the lsp-custom-requests guidance to fix my custom LSP request handler that receives a URI parameter and fails with EntryNotFound.

Frequently Asked Questions about lsp-custom-requests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I pass a URI over a custom LSP request in VS Code?

Type the parameter as UriComponents derived from ReturnType<URI['toJSON']> and send it via Connection.sendRequest. On the receiving side, call URI.revive on the param to restore a real URI instance before using toString or fsPath.

Why does my LSP handler log uri=[object Object]?

JSON.stringify converts the vscode-uri object into plain UriComponents data during sendRequest, so the receiver gets an object without prototype methods. Calling toString on it yields [object Object], confirming the URI was never revived.

Why does workspace.fs.stat fail with EntryNotFound in my language server?

The URI received over the wire is a plain object, not a real URI instance, so fs operations resolve an invalid path. Revive the parameter with URI.revive before passing it to vscode.workspace.fs APIs.

Does vscode-uri export a UriComponents type directly?

No, the vscode-uri package entry does not re-export UriComponents. Derive it yourself using ReturnType<URI['toJSON']> and use URI.revive as the exact inverse to restore cached fsPath and formatted values.

Can I type LSP request params as URI directly?

Typing params as URI compiles cleanly but fails at runtime because the receiver only gets plain serialized data. Always type wire params as UriComponents and revive them in the handler before use.