Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect js file reference from import in jsx file #21974

Open
franciscop opened this issue Dec 13, 2024 · 5 comments
Open

Incorrect js file reference from import in jsx file #21974

franciscop opened this issue Dec 13, 2024 · 5 comments
Labels
navigation Feedback for workspace navigation, breadcrumbs, definitions, files, panels, etc reproducible Verified steps to reproduce included

Comments

@franciscop
Copy link

franciscop commented Dec 13, 2024

Description

When attempting to cmd+click on an import of a file with a name, if another project has a file with the same name Zed might open than instead of the file being referenced. I do want to note I have multiple projects open in the same Zed window.

Environment

Zed: v0.165.4 (Zed)
OS: macOS 15.1.1
Memory: 16 GiB
Architecture: aarch64

If applicable, add screenshots or screencasts of the incorrect state / behavior

  1. I am in the file foreclosures/src/index.jsx
  2. I hover my mouse on the import of import cache from "./cache.js";
  3. I can see the correct file being referenced, which is foreclosures/src/cache.js.
  4. However when I cmd+click on it, it opens documentation-page/src/cache.js.
Kapture.2024-12-13.at.23.51.01.mp4
@franciscop franciscop added admin read bug [core label] labels Dec 13, 2024
@osiewicz
Copy link
Contributor

Are you using yarn?

@franciscop
Copy link
Author

No, I use npm for installing libraries

@notpeter

This comment has been minimized.

@notpeter notpeter reopened this Jan 20, 2025
@notpeter notpeter added the awaiting info Issue that needs more information from the user label Jan 20, 2025
@notpeter notpeter changed the title Wrong file reference Incorrect js file reference from import in jsx file Jan 20, 2025
@notpeter notpeter added javascript JavaScript programming language support jsx and removed triage labels Jan 20, 2025
@devzeth
Copy link
Member

devzeth commented Feb 21, 2025

@notpeter reproducible this way:
Copy & paste and execute this command in your terminal to make the directories files and put the necessary text in to them.

# Create parent directory
mkdir test-zed-navigation
cd test-zed-navigation

# Create project directories
mkdir -p foreclosures/src
mkdir -p documentation-page/src

# Create foreclosures/src/index.jsx
echo 'import cache from "./cache.js";

function App() {
  return <div>Using cache: {cache.version}</div>;
}

export default App;' > foreclosures/src/index.jsx

# Create foreclosures/src/cache.js
echo 'const cache = {
  version: "1.0.0",
  data: {}
};

export default cache;' > foreclosures/src/cache.js

# Create documentation-page/src/cache.js
echo 'const cache = {
  version: "2.0.0", // Different version to verify we opened the right file
  data: {}
};

export default cache;' > documentation-page/src/cache.js

# Print directory structure to verify
tree

Steps to reproduce:

  1. Open documentation folder in zed.
  2. Right click add folder to project named foreclosure.

When viewing foreclosures/src/index.jsx, cmd-clicking ./cache.js works correctly only if the documentation project is still closed the moment we click on it and click on src, it seem to add it to the context buffer and we can reproduce the isuse.

Looking in to hover_links.rs > find_file implementation, we probably need to add multiple steps to choose when there are similar files:

  • only try to resolve within the current worktree first
  • fall back to global worktree?

@devzeth devzeth added reproducible Verified steps to reproduce included navigation Feedback for workspace navigation, breadcrumbs, definitions, files, panels, etc and removed awaiting info Issue that needs more information from the user javascript JavaScript programming language support jsx bug [core label] labels Feb 21, 2025
@notpeter
Copy link
Member

Perfect. I can reproduce with those steps @beniaminzagan.

zed documentation-page foreclosures foreclosures/src/index.jsx

Hovering "./cache.js" shows the correct target in the tooltip, but cmd-clicking will bring you to documentation-page/src/cache.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
navigation Feedback for workspace navigation, breadcrumbs, definitions, files, panels, etc reproducible Verified steps to reproduce included
Projects
None yet
Development

No branches or pull requests

4 participants