lsp: Use Path
instead of String
for path handling
#22762
Draft
+192
−144
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
During my work on PR #22616, while trying to fix the
test_reporting_fs_changes_to_language_servers
test case, I noticed that we are currently handling paths usingString
in some places. However, this approach causes issues on Windows.This draft PR modifies
rebuild_watched_paths_inner
andglob_literal_prefix
. For example, take theglob_literal_prefix
function modified in this PR:The current implementation treats path as
String
and relies on\
as the path separator on Windows, but on Windows, both/
and\
can be used as separators. This means thatnode_modules\**/*.js
is also a valid path representation.There are two potential solutions to this issue:
String
, and on Windows, replace all/
with\
.Path
for path handling, which is the solution implemented in this PR.Advantages of Solution 1:
Advantages of Solution 2:
strip_prefix
.Currently, the logic for removing a path prefix looks like this:
However, using
Path
simplifies this process and makes it more robust:Release Notes: