Skip to content

Percent-decode file URIs in language server path conversion - #1182

Open
Anatomydotexe wants to merge 1 commit into
JohnnyMorganz:mainfrom
Anatomydotexe:fix/lsp-uri-percent-decode
Open

Anatomydotexe wants to merge 1 commit into
JohnnyMorganz:mainfrom
Anatomydotexe:fix/lsp-uri-percent-decode

Conversation

@Anatomydotexe

Copy link
Copy Markdown

Fixes #1122.

Problem

When run as a language server, StyLua resolved the configuration from the file's path taken straight from the document URI, without percent-decoding it (to_file_path in src/cli/lsp.rs used self.path().as_str()). Editors such as VS Code percent-encode paths, so for a file whose path contains a space or a non-ASCII character, the .stylua.toml / .editorconfig lookup ran on a path that doesn't exist and the server fell back to default settings. The CLI formatted the same file differently. The decoding step from the ls-types reference implementation seems to have been dropped when it was ported in #1068.

Change

to_file_path now percent-decodes the path through fluent-uri, which is already used by lsp_types::Uri, before both the Unix and Windows branches. No new dependencies, and no other behavior changes.

Tests

Three new tests in src/cli/lsp.rs:

  • LSP and CLI produce the same output for a file in a directory with a space and an accented character
  • simple paths with no special characters are unchanged
  • .stylua.toml still takes precedence over .editorconfig through the LSP

On Linux, cargo test passes with default features, no default features, all features, and each syntax feature (luau, lua52, lua53, lua54, luajit, cfxlua). cargo fmt --check and cargo clippy -D warnings also pass. When the fix is reverted, exactly the 3 new tests fail.

Limitations: the cfg(windows) tests were only compiled for x86_64-pc-windows-gnu. They weren't run on Windows. Percent sequences that aren't valid UTF-8 decode lossily. I included a CHANGELOG entry and I'm happy to drop it.

This change was prepared with AI coding agents and reviewed by me before submission.

This branch has not been deployed

No deployments
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.

Mismatch behavior between stylua cli and stylua --lsp with .editorconfig

1 participant