Skip to content

feat(fmt): add --lsp language server mode - #323

Merged
chenjiahan merged 5 commits into
mainfrom
feat-fmt-lsp
Aug 12, 2026
Merged

feat(fmt): add --lsp language server mode#323
chenjiahan merged 5 commits into
mainfrom
feat-fmt-lsp

Conversation

@fi3ework

Copy link
Copy Markdown
Member

Summary

This PR adds rs fmt --lsp, which serves document formatting over the Language Server Protocol on stdio, so editors can format open buffers through a standard LSP client instead of spawning rs fmt --stdin-filepath per request.

  • The server advertises documentFormattingProvider only, loads the project config once per server lifetime from the client-reported workspace root, and returns a minimal TextEdit computed by a prefix/suffix trim that never splits surrogate pairs or \r\n sequences.
  • Client formatting options are ignored: the Rstack config stays the single source of truth. Ignored, unsupported, and unparsable documents resolve to no edits, and the console is redirected to LSP log messages so user config code cannot corrupt the stdio framing.
  • vscode-languageserver and vscode-languageserver-textdocument are devDependencies bundled into a lazily loaded fmtLsp chunk (~211 kB), growing the published package from ~301 kB to ~512 kB; published dependencies are unchanged.
  • The global --config option is now resolved to an absolute path at CLI parse time for all commands, so the server (whose workspace root can differ from its cwd) shares the same relative-path semantics as the rest of the CLI.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 11, 2026

Copy link
Copy Markdown

Deploying rstack-cli with  Cloudflare Pages  Cloudflare Pages

Latest commit: b2b670c
Status: ✅  Deploy successful!
Preview URL: https://e66c5d91.rstack-cli.pages.dev
Branch Preview URL: https://feat-fmt-lsp.rstack-cli.pages.dev

View logs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 69fcea7b13

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/rstack/src/fmt/lsp/server.ts Outdated

@chenjiahan chenjiahan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we use full document sync instead?

Formatting only needs the latest complete text, so each didChange could simply replace the cached document.

This avoids incremental range/position edge cases, simplifies state management, and allows us to remove the vscode-languageserver-textdocument dependency.

@fi3ework

Copy link
Copy Markdown
Member Author

@chenjiahan agreed — formatting doesn't happen on every keystroke, so incremental sync buys us nothing here. switched to full sync and dropped vscode-languageserver-textdocument from the runtime bundle (kept as a devDependency for tests).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e74ba2b58

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/rstack/src/fmt/lsp/minimalEdit.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5adb718c54

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/rstack/src/fmt/lsp/server.ts
@fi3ework
fi3ework requested a review from chenjiahan August 12, 2026 06:05

@chenjiahan chenjiahan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 👍

@chenjiahan
chenjiahan merged commit 3e14999 into main Aug 12, 2026
5 checks passed
@chenjiahan
chenjiahan deleted the feat-fmt-lsp branch August 12, 2026 06:48
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