Using find references in the scm diff view doesn't currently work (possibly by design or bug)
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
Does this issue occur when all extensions are disabled?: I would assume no since it's part of the typescript language features extension, but that extension lives in the main vscode repo
- VS Code Version: 1.126.0 (Universal)
- OS Version: macOS (version not relevant to issue)
Steps to Reproduce:
1. open any version of vscode on any platform
2. open a project workspace with typescript files and where git is already initialized
3. open a typescript file that has imports and reference symbols in other files (notice that if you right click a symbol and click "Find All References" in the context menu (a sidebar is displayed showing the references organized by file path)
5. modify that file by adding just newlines or something that doesn't modify the code
6. navigate to the source control tab and stage that file by click the '+' icon next to it
7. once the file is staged double click the file to open the diff viewer (the diff will open with a lock icon in the file tab name)
8. now try to right click on the same symbol from step 3 and click "Find All References" in the context menu (notice that now instead of the sidebar displaying with found references organized by file path, you get "No results. Try running a previous search again:")
did a little digging and discovered that git:// resources are disabled explicitly in the typescript language features schemas here [fileSchemas.ts](https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/configuration/fileSchemes.ts#L46)
I also verified that when the following changeset is applied that it "fixes" the issue in the sense that "Find All References" in the diff view actually works as expected, but it is unclear to me whether git *should* be in the disabled schemas for other reasons.
```diff
diff --git a/extensions/typescript-language-features/src/configuration/fileSchemes.ts b/extensions/typescript-language-features/src/configuration/fileSchemes.ts
index 02e1d2f143f..fc7df5038a0 100644
--- a/extensions/typescript-language-features/src/configuration/fileSchemes.ts
+++ b/extensions/typescript-language-features/src/configuration/fileSchemes.ts
@@ -45,9 +45,12 @@ export function getSemanticSupportedSchemes() {
/**
* File scheme for which JS/TS language feature should be disabled
+ *
+ * Note: `git` is NOT included here. Git URIs are unwrapped to their
+ * underlying file paths in TypeScriptServiceClient.toTsFilePath so
+ * that language features work on staged files opened from SCM.
*/
export const disabledSchemes = new Set([
- git,
vsls,
github,
azurerepos,
diff --git a/extensions/typescript-language-features/src/typescriptServiceClient.ts b/extensions/typescript-language-features/src/typescriptServiceClient.ts
index ae18dff741c..9e710fb1753 100644
--- a/extensions/typescript-language-features/src/typescriptServiceClient.ts
+++ b/extensions/typescript-language-features/src/typescriptServiceClient.ts
@@ -757,6 +757,22 @@ export default class TypeScriptServiceClient extends Disposable implements IType
}
public toTsFilePath(resource: vscode.Uri): string | undefined {
+
+ // Git URIs wrap a real file path in their query params. Unwrap them
+ // so the TS server can resolve the file it already knows about.
+ // This enables language features (references, definitions, etc.)
+ // on staged files opened from the Source Control view.
+ if (resource.scheme === fileSchemes.git) {
+ try {
+ const params = JSON.parse(resource.query) as { path?: string };
+ if (params.path) {
+ return params.path;
+ }
+ } catch {
+ // Malformed query — fall through to disabled scheme handling
+ }
+ }
+
if (fileSchemes.disabledSchemes.has(resource.scheme)) {
return undefined;
}
```
The UX impact that not being able to use "Find All References" from within the diff viewer is pretty severe. To navigate code it requires unstaging the file (possibly merging the changes with changes that are not yet staged just to use a feature that should imo work in any code oriented view), then finding the file and opening it as the normal file:// resource then using "Find All References".
Contributor guide
Assessment
This issue has not been assessed yet.