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

terminal cmd+click soft link file but open in original folder #129023

Closed
laowong opened this issue Jul 20, 2021 · 17 comments
Closed

terminal cmd+click soft link file but open in original folder #129023

laowong opened this issue Jul 20, 2021 · 17 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities linux Issues with VS Code on Linux macos Issues with VS Code on MAC/OS X terminal Integrated terminal issues terminal-links wont-fix
Milestone

Comments

@laowong
Copy link

laowong commented Jul 20, 2021

Issue Type: Bug

1、I'm using extension "Remote - SSH" develop in remote machine
2、My home folder is "/home/xxx/" which is a soft link to /data00/home/xxx
3、Open a folder "/home/xxx/project" in remote machine with vscode
4、 In integrated terminal use "git grep --line-number " to search some content in folder "/home/xxx/project", and "cmd+click" the file path
5、vscode open the file in origin folder "/data00/home/xxx/project/yyy.go", but I think it should be open in "/home/xxx/project/yyy.go", becase my workspace folder in vscode is "/home/xxx/project"

VS Code version: Code 1.58.2 (c3f1263, 2021-07-14T22:09:06.581Z)
OS version: Darwin x64 20.5.0
Restricted Mode: No
Remote OS version: Linux x64 4.19.117.bsk.6-amd64
Remote OS version: Linux x64 4.19.117.bsk.6-amd64
Remote OS version: Linux x64 4.19.117.bsk.6-amd64
Remote OS version: Linux x64 4.19.117.bsk.6-amd64

System Info
Item Value
CPUs Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz (12 x 2600)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 3, 3, 3
Memory (System) 32.00GB (0.26GB free)
Process Argv --crash-reporter-id 882949e7-e8bb-454f-b5bf-a038f7b08a64
Screen Reader no
VM 0%
Item Value
Remote SSH: devbox
OS Linux x64 4.19.117.bsk.6-amd64
CPUs Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz (8 x 2394)
Memory (System) 15.03GB (1.37GB free)
VM 0%
Item Value
Remote SSH: devbox
OS Linux x64 4.19.117.bsk.6-amd64
CPUs Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz (8 x 2394)
Memory (System) 15.03GB (1.37GB free)
VM 0%
Item Value
Remote SSH: devbox
OS Linux x64 4.19.117.bsk.6-amd64
CPUs Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz (8 x 2394)
Memory (System) 15.03GB (1.37GB free)
VM 0%
Item Value
Remote SSH: devbox
OS Linux x64 4.19.117.bsk.6-amd64
CPUs Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz (8 x 2394)
Memory (System) 15.03GB (1.37GB free)
VM 0%
Extensions (10)
Extension Author (truncated) Version
vscode-language-pack-zh-hans MS- 1.58.8
remote-containers ms- 0.187.0
remote-ssh ms- 0.65.7
remote-ssh-edit ms- 0.65.7
remote-wsl ms- 0.58.2
vscode-remote-extensionpack ms- 0.21.0
go gol 0.26.0
python ms- 2021.6.944021595
vscode-pylance ms- 2021.7.4
jupyter ms- 2021.8.1046824664
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
pythonvspyt602:30300191
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt639:30300192
pythontb:30283811
pythonvspyt551:30311712
vspre833:30321513
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
pythondataviewer:30285071
vscus158:30321503
pythonvsuse255:30340121
vscod805:30301674
pythonvspyt200:30331937
vscextlangct:30333562
binariesv615:30325510
bridge0708:30335490

@vscodebot
Copy link

vscodebot bot commented Jul 20, 2021

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@Tyriar
Copy link
Member

Tyriar commented Jul 21, 2021

This works fine when I tried to repro:

mkdir actual
ln -s actual link
touch actual/testfile
cd link
echo $(pwd)/testfile

The printed link /home/daniel/link/testfile correctly does not resolve the symlink:

image

Anything in the repro I'm missing?

@Tyriar Tyriar added the info-needed Issue requires more information from poster label Jul 21, 2021
@laowong
Copy link
Author

laowong commented Jul 21, 2021

It's also OK when I tried in local machine, but was wrong when tried in remote machine using extension "Remote - SSH".

@Tyriar
Copy link
Member

Tyriar commented Jul 21, 2021

This was on Windows via WSL which should work the same as Windows -> SSH. 🤷

@laowong
Copy link
Author

laowong commented Jul 21, 2021

@Tyriar I'm on MAC OS^_^

@Tyriar
Copy link
Member

Tyriar commented Jul 21, 2021

I wouldn't expect that to make a difference, but it's possible.

@laowong
Copy link
Author

laowong commented Jul 22, 2021

@Tyriar Supply the screenshot。The step difference with you is I "cmd+click" the relative path on grep result.

image

@laowong laowong closed this as completed Jul 22, 2021
@laowong
Copy link
Author

laowong commented Jul 22, 2021

Sorry I closed this issue carelessly.

@laowong laowong reopened this Jul 22, 2021
@Tyriar
Copy link
Member

Tyriar commented Jul 22, 2021

That's great thanks, can repro. It happens with ./testfile:xxx but not ./testfile the folder also must be open to make it happen since it's a relative link. It also seems to require the link folder open, not its parent.

@Tyriar Tyriar added this to the July 2021 milestone Jul 22, 2021
@Tyriar Tyriar added bug Issue identified by VS Code Team member as probable bug terminal Integrated terminal issues terminal-links and removed info-needed Issue requires more information from poster labels Jul 22, 2021
@Tyriar
Copy link
Member

Tyriar commented Jul 22, 2021

Ok more info on repro which is much more involved than initially thought:

  • Happens in a local workspace on Linux and macOS
  • Do setup in terminal cmd+click soft link file but open in original folder #129023 (comment)
  • Open the link folder, make sure the symlink isn't resolved when opening the window which can happen when opening via the open command, use the CLI instead: code ./link
  • Run echo ./testfile, it's important that enter is pressed at least once before trying to click the link*
  • Wait 2+ seconds
  • Try open the test file via the link

*Note that if you reload the window you need to hit enter and wait before it will happen

@Tyriar
Copy link
Member

Tyriar commented Jul 22, 2021

What I've found so far

@Tyriar
Copy link
Member

Tyriar commented Jul 22, 2021

Can confirm unresolved cwd is passed to node-pty:

Screen Shot 2021-07-22 at 5 01 44 AM

@Tyriar
Copy link
Member

Tyriar commented Jul 22, 2021

For Linux it happens because of the readlink here: https://github.com/Microsoft/vscode/blob/424a1166f37f10e11f8f88dbbb5d6930a8f9d3f9/src/vs/platform/terminal/node/terminalProcess.ts#L507-L507. Not sure it's possible using /proc to get link instead of actual since readlink is just resolving a single symlink (unless -f is provided).

@Tyriar
Copy link
Member

Tyriar commented Jul 22, 2021

Asked on unix stack exchange: https://unix.stackexchange.com/q/659464/115410

@Tyriar Tyriar modified the milestones: July 2021, Backlog Jul 22, 2021
@Tyriar Tyriar added linux Issues with VS Code on Linux macos Issues with VS Code on MAC/OS X help wanted Issues identified as good community contribution opportunities labels Jul 22, 2021
@Tyriar
Copy link
Member

Tyriar commented Jul 22, 2021

If all else fails we could check if the initial cwd was a symlink and that is resolves to the current cwd and use that. It's not ideal, plus it would fall apart if you actually cd into actual

@Fallonma
Copy link

Fallonma commented Sep 9, 2021

I met this issue recently. Besides this, there are two more issues. #108306, #105656. Maybe they have the same reason.

@Tyriar
Copy link
Member

Tyriar commented Oct 19, 2021

Closing as the only way to fix this would be using a hack, plus it's not that big of an issue really.

@Tyriar Tyriar closed this as completed Oct 19, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2021
phil-blain added a commit to phil-blain/vscode that referenced this issue Apr 9, 2022
In some environments, it is common for a user's home directory to be a
symbolic link (symlink) to a different filesystem location. For
example, for user 'john' the value of the HOME environment variable is
'/home/john' but '/home/john' is actually a symbolic link to
'/some/place/else/homes/john'. This setup is very common on high
performance computing (HPC) systems.

When such a user opens a folder in VS Code, the 'Open Folder' dialog
defaults to the user' HOME, i.e. '/home/jane'. If the user opens a
folder located somwhere in their home, this directory is opened by VS
Code unresolved, i.e. '/home/jane/project'.

When the users opens a file by Ctrl-clicking a file link in the
integrated terminal, the resolved file path is opened, i.e.
'/some/place/else/homes/jane/project/file'. This is suboptimal because
if 'file' was already opened in the workspace, opening it from the
integrated terminal opens a second tab instead of focusing on the
already opened tab, as VS Code does not recognize it is the same file.
This is made worse by the fact that some language extensions that
provide 'Outline' functionality do not work at all in this newly opened
tab from the resolved file path.

To fix this, canonicalize the value of a user's home directory early in
the environment initialization, by calling 'realpathSync' on the path
returned by Node's 'homedir()' in the constructor of
NativeEnvironmentService. This results in the resolved value of a user's
home directory being the default location for the 'Open Folder'
dialog. Since now the already opened 'file' and 'file' opened from the
integrated terminal have the same path, VS Code does recognize they are
indeed the same file, and focuses on the already opened tab instead of
opening a second tab.

Test this by temporarily changing the value of HOME (USERPROFILE on
Windows) to point to a symlink and verifying that the userHome property
of a newly created NativeEnvironmentService is returned as resolved.
Note that for some reason, in order for 'fs.rmSync' to correctly clean
up the symlink after the test, it has to be called with 'recursive:
true'.

Fixes: microsoft#118973
Fixes: microsoft#129023
phil-blain added a commit to phil-blain/vscode that referenced this issue Apr 9, 2022
In some environments, it is common for a user's home directory to be a
symbolic link (symlink) to a different filesystem location. For
example, for user 'john' the value of the HOME environment variable is
'/home/john' but '/home/john' is actually a symbolic link to
'/some/place/else/homes/john'. This setup is very common on high
performance computing (HPC) systems.

When such a user opens a folder in VS Code, the 'Open Folder' dialog
defaults to the user' HOME, i.e. '/home/jane'. If the user opens a
folder located somwhere in their home, this directory is opened by VS
Code unresolved, i.e. '/home/jane/project'.

When the users opens a file by Ctrl-clicking a file link in the
integrated terminal, the resolved file path is opened, i.e.
'/some/place/else/homes/jane/project/file'. This is suboptimal because
if 'file' was already opened in the workspace, opening it from the
integrated terminal opens a second tab instead of focusing on the
already opened tab, as VS Code does not recognize it is the same file.
This is made worse by the fact that some language extensions that
provide 'Outline' functionality do not work at all in this newly opened
tab from the resolved file path.

To fix this, canonicalize the value of a user's home directory early in
the environment initialization, by calling 'realpathSync' on the path
returned by Node's 'homedir()' in the constructor of
NativeEnvironmentService. This results in the resolved value of a user's
home directory being the default location for the 'Open Folder'
dialog. Since now the already opened 'file' and 'file' opened from the
integrated terminal have the same path, VS Code does recognize they are
indeed the same file, and focuses on the already opened tab instead of
opening a second tab.

Test this by temporarily changing the value of HOME (USERPROFILE on
Windows) to point to a symlink and verifying that the userHome property
of a newly created NativeEnvironmentService is returned as resolved.
Note that for some reason, in order for 'fs.rmSync' to correctly clean
up the symlink after the test, it has to be called with 'recursive:
true'.

Fixes: microsoft#118973
Fixes: microsoft#129023
phil-blain added a commit to phil-blain/vscode that referenced this issue Apr 9, 2022
In some environments, it is common for a user's home directory to be a
symbolic link (symlink) to a different filesystem location. For
example, for user 'jane' the value of the HOME environment variable is
'/home/jane' but '/home/jane' is actually a symbolic link to
'/some/place/else/homes/jane'. This setup is very common on high
performance computing (HPC) systems.

When such a user opens a folder in VS Code, the 'Open Folder' dialog
defaults to the user' HOME, i.e. '/home/jane'. If the user opens a
folder located somwhere in their home, this directory is opened by VS
Code unresolved, i.e. '/home/jane/project'.

When the users opens a file by Ctrl-clicking a file link in the
integrated terminal, the resolved file path is opened, i.e.
'/some/place/else/homes/jane/project/file'. This is suboptimal because
if 'file' was already opened in the workspace, opening it from the
integrated terminal opens a second tab instead of focusing on the
already opened tab, as VS Code does not recognize it is the same file.
This is made worse by the fact that some language extensions that
provide 'Outline' functionality do not work at all in this newly opened
tab from the resolved file path.

To fix this, canonicalize the value of a user's home directory early in
the environment initialization, by calling 'realpathSync' on the path
returned by Node's 'homedir()' in the constructor of
NativeEnvironmentService. This results in the resolved value of a user's
home directory being the default location for the 'Open Folder'
dialog. Since now the already opened 'file' and 'file' opened from the
integrated terminal have the same path, VS Code does recognize they are
indeed the same file, and focuses on the already opened tab instead of
opening a second tab.

Test this by temporarily changing the value of HOME (USERPROFILE on
Windows) to point to a symlink and verifying that the userHome property
of a newly created NativeEnvironmentService is returned as resolved.
Note that for some reason, in order for 'fs.rmSync' to correctly clean
up the symlink after the test, it has to be called with 'recursive:
true'.

Fixes: microsoft#118973
Fixes: microsoft#129023
phil-blain added a commit to phil-blain/vscode that referenced this issue Apr 13, 2022
In some environments, it is common for a user's home directory to be a
symbolic link (symlink) to a different filesystem location. For
example, for user 'jane' the value of the HOME environment variable is
'/home/jane' but '/home/jane' is actually a symbolic link to
'/some/place/else/homes/jane'. This setup is very common on high
performance computing (HPC) systems.

When such a user opens a folder in VS Code, the 'Open Folder' dialog
defaults to the user' HOME, i.e. '/home/jane'. If the user opens a
folder located somwhere in their home, this directory is opened by VS
Code unresolved, i.e. '/home/jane/project'.

When the users opens a file by Ctrl-clicking a file link in the
integrated terminal, the resolved file path is opened, i.e.
'/some/place/else/homes/jane/project/file'. This is suboptimal because
if 'file' was already opened in the workspace, opening it from the
integrated terminal opens a second tab instead of focusing on the
already opened tab, as VS Code does not recognize it is the same file.
This is made worse by the fact that some language extensions that
provide 'Outline' functionality do not work at all in this newly opened
tab from the resolved file path.

To fix this, canonicalize the value of a user's home directory early in
the environment initialization, by calling 'realpathSync' on the path
returned by Node's 'homedir()' in the constructor of
NativeEnvironmentService. This results in the resolved value of a user's
home directory being the default location for the 'Open Folder'
dialog. Since now the already opened 'file' and 'file' opened from the
integrated terminal have the same path, VS Code does recognize they are
indeed the same file, and focuses on the already opened tab instead of
opening a second tab.

Test this by temporarily changing the value of HOME (USERPROFILE on
Windows) to point to a symlink and verifying that the userHome property
of a newly created NativeEnvironmentService is returned as resolved.
Note that for some reason, in order for 'fs.rmSync' to correctly clean
up the symlink after the test, it has to be called with 'recursive:
true'.

Fixes: microsoft#118973
Fixes: microsoft#129023
phil-blain added a commit to phil-blain/vscode that referenced this issue May 26, 2022
In some environments, it is common for a user's home directory to be a
symbolic link (symlink) to a different filesystem location. For
example, for user 'jane' the value of the HOME environment variable is
'/home/jane' but '/home/jane' is actually a symbolic link to
'/some/place/else/homes/jane'. This setup is very common on high
performance computing (HPC) systems.

When such a user opens a folder in VS Code, the 'Open Folder' dialog
defaults to the user' HOME, i.e. '/home/jane'. If the user opens a
folder located somwhere in their home, this directory is opened by VS
Code unresolved, i.e. '/home/jane/project'.

When the users opens a file by Ctrl-clicking a file link in the
integrated terminal, the resolved file path is opened, i.e.
'/some/place/else/homes/jane/project/file'. This is suboptimal because
if 'file' was already opened in the workspace, opening it from the
integrated terminal opens a second tab instead of focusing on the
already opened tab, as VS Code does not recognize it is the same file.
This is made worse by the fact that some language extensions that
provide 'Outline' functionality do not work at all in this newly opened
tab from the resolved file path.

To fix this, canonicalize the value of a user's home directory early in
the environment initialization, by calling 'realpathSync' on the path
returned by Node's 'homedir()' in the constructor of
NativeEnvironmentService. This results in the resolved value of a user's
home directory being the default location for the 'Open Folder'
dialog. Since now the already opened 'file' and 'file' opened from the
integrated terminal have the same path, VS Code does recognize they are
indeed the same file, and focuses on the already opened tab instead of
opening a second tab.

Test this by temporarily changing the value of HOME (USERPROFILE on
Windows) to point to a symlink and verifying that the userHome property
of a newly created NativeEnvironmentService is returned as resolved.
Note that for some reason, in order for 'fs.rmSync' to correctly clean
up the symlink after the test, it has to be called with 'recursive:
true'.

Fixes: microsoft#118973
Fixes: microsoft#129023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities linux Issues with VS Code on Linux macos Issues with VS Code on MAC/OS X terminal Integrated terminal issues terminal-links wont-fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants