Skip to content

assistant_slash_commands: Fix AI text thread path display bugs on Windows and all platforms#41880

Merged
Veykril merged 2 commits intozed-industries:mainfrom
CLoaKY233:main
Dec 15, 2025
Merged

assistant_slash_commands: Fix AI text thread path display bugs on Windows and all platforms#41880
Veykril merged 2 commits intozed-industries:mainfrom
CLoaKY233:main

Conversation

@CLoaKY233
Copy link
Contributor

@CLoaKY233 CLoaKY233 commented Nov 4, 2025

Fix incorrect directory path folding in slash command file collection

Description:
This PR fixes a bug in the collect_files function where the directory folding logic (used to compact chains like .github/workflows) failed to reset its state when traversing out of a folded branch.

The Issue:
The folded_directory_names accumulator was persisting across loop iterations. If the traversal moved from a folded directory (e.g., .github/workflows) to a sibling directory (e.g., .zed), the sibling would incorrectly inherit the prefix of the previously folded path, resulting in incorrect paths like .github/.zed.

The Fix:

  • Introduced folded_directory_path to track the specific path currently being folded.
  • Added a check to reset folded_directory_names whenever the traversal encounters an entry that is not a child of the currently folded path.
  • Ensured state is cleared immediately after a folded directory is rendered.

Release Notes:

  • Fixed an issue where using slash commands to collect files would sometimes display incorrect directory paths (e.g., showing .github/.zed instead of .zed) when adjacent directories were automatically folded.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Nov 4, 2025
@SomeoneToIgnore SomeoneToIgnore added the area:ai Improvement related to Agent Panel, Edit Prediction, Copilot, or other AI features label Nov 4, 2025
@CLoaKY233 CLoaKY233 marked this pull request as ready for review November 4, 2025 08:09
@dinocosta
Copy link
Member

Hey @CLoaKY233 ! Sorry that the review is taking longer than expected, I did not forge this PR but want to make sure that the glob normalization doesn't introduce any problems. Since the current changes are simply replacing \ with /

let sanitized = SanitizedPath::new(glob).to_string();
let normalized = sanitized.replace('\\', "/");

I'm worried that it might break, for example, in macOS, for a directory with a space, which could show up as something like ~/Developer/Awesome\ Project/*.txt . With the current changes this would likely be converted to ~/Developer/Awesome/ Project/*.txt so I'm exploring whether we need different code paths for Windows specifically 🙂

@Veykril
Copy link
Member

Veykril commented Nov 11, 2025

There likely is a RelPath issue here, we've gotten reports about a couple specifically wrt to the glob matcher. I'm looking into those right now.

@dinocosta
Copy link
Member

Thank you, @Veykril , help on the Windows side is much appreciated, as I don’t have access to a Windows development machine 🙂

Let me know if I can assist with anything macOS-related!

@CLoaKY233
Copy link
Contributor Author

CLoaKY233 commented Nov 12, 2025

Thanks for the thoughtful review and for investigating the Windows issues,
If there's anything specific I can help with (testing, logs, etc.), I'll be up for it.

@franciskafyi
Copy link
Collaborator

@CLoaKY233 it looks like we fixed the underlying issue that this PR solves for. Can I go ahead and close this?

@CLoaKY233
Copy link
Contributor Author

CLoaKY233 commented Dec 11, 2025

@CLoaKY233 it looks like we fixed the underlying issue that this PR solves for. Can I go ahead and close this?

Is the fix shipped in the latest version ?
@franciskafyi

Zed: v0.216.0+stable.94.f381f06bcd9fd7fae8c62c2308887edcc00f2d3d (Zed) 
OS: Linux Wayland ubuntu 25.10
Memory: 14.9 GiB
Architecture: x86_64
GPU: Intel(R) UHD Graphics (TGL GT1) || Intel open-source Mesa driver || Mesa 25.2.3-1ubuntu1

I am still facing the issue

image

.github being a foldable directory is changing the path of .zed
where both directories are on the same levels not nested.

@Veykril Veykril self-assigned this Dec 11, 2025
@github-project-automation github-project-automation bot moved this to Community Champion PRs in Quality Week – December 2025 Dec 11, 2025
@franciskafyi franciskafyi moved this from Community Champion PRs to Community PRs in Quality Week – December 2025 Dec 11, 2025
@franciskafyi
Copy link
Collaborator

I saw Lukas assigned himself so he might have more context. It might not have hit Stable just yet.

@Veykril
Copy link
Member

Veykril commented Dec 12, 2025

Indeed this does not seem to be fixed entirely, I mustve missed something in testing.

@CLoaKY233
Copy link
Contributor Author

Indeed this does not seem to be fixed entirely, I mustve missed something in testing.

I would love to work on this issue if possible, finding the issue and adding a test for this particular condition.

@Veykril
Copy link
Member

Veykril commented Dec 12, 2025

Can you check if the diff in #44687 works fully? I am not too familiar with text threads, but from what I just checked this should fix things properly.

@CLoaKY233
Copy link
Contributor Author

Can you check if the diff in #44687 works fully? I am not too familiar with text threads, but from what I just checked this should fix things properly.

the issue is actually in the directory folding logic (used to compact chains like .github/workflows), fails to reset its state when traversing out of a folded branch. The folded_directory_names accumulator persists across iterations, causing subsequent sibling directories to incorrectly inherit the prefix of the previously folded path (e.g., .zed rendering as .github/.zed because .github was just processed).

Add folded_directory_path to remember the currently folded directory and
clear it when leaving that path, skipping empty directories, or after
rendering a directory to prevent fold state leaking to unrelated
entries.
Copilot AI review requested due to automatic review settings December 12, 2025 09:01
@zed-industries-bot
Copy link
Contributor

Warnings
⚠️

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by 🚫 dangerJS against 252d97c

@Veykril
Copy link
Member

Veykril commented Dec 12, 2025

Ah right, there are multiple issues at hand here are there. That folding one isn't windows specific I presume then right? (where as the listing one was?)

@CLoaKY233
Copy link
Contributor Author

CLoaKY233 commented Dec 12, 2025

Ah right, there are multiple issues at hand here are there. That folding one isn't windows specific I presume then right? (where as the listing one was?)

I believe so, I could reproduce the folding directory issue on windows as well as linux, and the code is not platform specific.
I've included the changes from #44687 in this pr and fixed the folding issue aswell, but when we see it,

but also is this supposed to be like this ?
image
files directly in the root directory do not have the Project DIR name in their path, but every other directory does

ie. it's EMBRACE/.clang-format, but just src for the directory.

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 fixes two bugs in the /file slash command: Windows path separator handling and folded directory path display issues. The core fix replaces a custom PathMatcher implementation with the standard util::paths::PathMatcher, which properly handles platform-specific path separators. Additionally, a new folded_directory_path tracking variable prevents folded directory names from leaking into sibling directories.

Key changes:

  • Replaced custom PathMatcher with util::paths::PathMatcher that respects platform path styles
  • Added folded_directory_path tracking to properly reset folded states when exiting directory trees
  • Removed direct globset dependency as it's now only needed transitively through util

Reviewed changes

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

File Description
crates/assistant_slash_commands/src/file_command.rs Replaced custom PathMatcher with util::paths::PathMatcher; added folded_directory_path tracking variable and reset logic to prevent path leaking between sibling directories; removed custom_path_matcher module
crates/assistant_slash_commands/Cargo.toml Removed direct globset dependency (now transitive through util)
Cargo.lock Updated assistant_slash_commands dependencies to reflect globset removal

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

@Veykril
Copy link
Member

Veykril commented Dec 12, 2025

I don't think its supposed to be like that, but thats a bug in the current release already, lets not mix that in here.

@CLoaKY233
Copy link
Contributor Author

The folding bug is now fixed—.zed no longer inherits the .github prefix when both are at the same level.

Should I add a test for this specific folding case? I can create one that verifies correct path display when folded directories (like .github/workflows) are adjacent to non-folded siblings (like .zed).

Regarding the root directory naming inconsistency you mentioned, I'll keep that out of this PR as it's a separate existing issue.

@Veykril
Copy link
Member

Veykril commented Dec 12, 2025

If you can come up with a test for that would be appreciated! I asked someone else internally to double check this change as I am not too familiar with text threads (my concern was the windows bug here)

@Veykril Veykril changed the title Fix AI text thread path display bugs on Windows and all platforms assistant_slash_commands: Fix AI text thread path display bugs on Windows and all platforms Dec 15, 2025
@Veykril
Copy link
Member

Veykril commented Dec 15, 2025

Thanks!

@Veykril Veykril merged commit 54c4302 into zed-industries:main Dec 15, 2025
31 checks passed
@github-project-automation github-project-automation bot moved this from Community PRs to Done in Quality Week – December 2025 Dec 15, 2025
CherryWorm pushed a commit to CherryWorm/zed that referenced this pull request Dec 16, 2025
…dows and all platforms (zed-industries#41880)

## Fix incorrect directory path folding in slash command file collection

**Description:**
This PR fixes a bug in the `collect_files` function where the directory
folding logic (used to compact chains like `.github/workflows`) failed
to reset its state when traversing out of a folded branch.

**The Issue:**
The `folded_directory_names` accumulator was persisting across loop
iterations. If the traversal moved from a folded directory (e.g.,
`.github/workflows`) to a sibling directory (e.g., `.zed`), the sibling
would incorrectly inherit the prefix of the previously folded path,
resulting in incorrect paths like `.github/.zed`.

**The Fix:**
* Introduced `folded_directory_path` to track the specific path
currently being folded.
* Added a check to reset `folded_directory_names` whenever the traversal
encounters an entry that is not a child of the currently folded path.
* Ensured state is cleared immediately after a folded directory is
rendered.

**Release Notes:**
- Fixed an issue where using slash commands to collect files would
sometimes display incorrect directory paths (e.g., showing
`.github/.zed` instead of `.zed`) when adjacent directories were
automatically folded.

---------

Co-authored-by: Lukas Wirth <lukas@zed.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai Improvement related to Agent Panel, Edit Prediction, Copilot, or other AI features cla-signed The user has signed the Contributor License Agreement

Projects

Development

Successfully merging this pull request may close these issues.

7 participants