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

Adding option to follow symlinks when resolving symbols #707

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cgrinker
Copy link

When using clangd in vscode with Bazel — trying to do symbol resolution (Go To Definition, Go To Declaration) will result in a file being opened in the Bazel build intermediate folder. This PR adds a settings flag and middlewares on the symbol resolution functions to follow symlinks back to their actual source file.

This issue has been discussed on the clangd project itself a few years ago. 1 2. From my reading whether or not to follow the symlinks was too deep in the compiler infrastructure itself to change on the LSP server, and that whether or not to follow the symlinks might be situationally dependent.

I attempted to solve the issue using the --path-mappings flag but it doesn't seem suitable for this situation.

[Hedron's](https://github.com/hedronvision/bazel-compile-commands-extractor generator compile_commands.json also seemed like an opportunity to generate different compile commands but 3 it doesn't seem like one could get working compile commands that aren't pointing into bazel's sandbox directory

Having it here behind a feature flag seems like a reasonable middle ground. Folks that need symlink resolution would be able to check the box, and uncheck it if they were getting funky behavior.

I've created a project here to demonstrate the behavior

Symbol Resolution

image

Without Symlink Following

image

With Symlink Following

image

* Adding remapDefinitionSymlink to follow symlinks on Definitions and Declarations.
* Wrapping calls for provideDeclaration, provideDefinition, provideTypeDefinition, provideImplementation with call to remap
* Adding config variable to toggle symlink resolution

return res;
} else {
if (definition.uri.scheme != 'file')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have been preferable to use the vscode filesystem api here, but while it has functionality for checking if a file is a symlink, it doesn't actually have a function to follow it. Gating behind a file uri scheme should avoid situations where you've got some remote filesystem open and we can't actually follow the symlinks

@wudisheng
Copy link

It seems that the modification introduced in PR is not working as expected in my environment (listed below), when the follow symlink option is enabled, it resolves the symlink correctly (examined by infomation message) but vscode window still lands inside _virtual_includes directory.

Version: 1.95.1 (Universal)
Commit: 65edc4939843c90c34d61f4ce11704f09d3e5cb6
Date: 2024-10-31T05:14:54.222Z
Electron: 32.2.1
ElectronBuildId: 10427718
Chromium: 128.0.6613.186
Node.js: 20.18.0
V8: 12.8.374.38-electron.0
OS: Darwin arm64 24.1.0

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.

2 participants