Skip to content

Commit 98af6a4

Browse files
Show relative path for call hierarchy item if available (#11265)
1 parent b740f60 commit 98af6a4

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Extension/src/LanguageServer/Providers/callHierarchyProvider.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,21 @@ export class CallHierarchyProvider implements vscode.CallHierarchyProvider {
230230

231231
private makeVscodeCallHierarchyItem(item: CallHierarchyItem): vscode.CallHierarchyItem {
232232
const containerDetail: string = (item.detail !== "") ? `${item.detail} - ` : "";
233-
const fileDetail: string = `${path.basename(item.file)} (${path.dirname(item.file)})`;
233+
const itemUri: vscode.Uri = vscode.Uri.file(item.file);
234+
235+
// Get file detail
236+
const isInWorkspace: boolean = this.client.RootUri !== undefined &&
237+
itemUri.fsPath.startsWith(this.client.RootUri?.fsPath);
238+
const dirPath: string = isInWorkspace ?
239+
path.relative(this.client.RootPath, path.dirname(item.file)) : path.dirname(item.file);
240+
const fileDetail: string = dirPath.length === 0 ?
241+
`${path.basename(item.file)}` : `${path.basename(item.file)} (${dirPath})`;
242+
234243
return new vscode.CallHierarchyItem(
235-
item.kind, item.name, containerDetail + fileDetail,
236-
vscode.Uri.file(item.file),
244+
item.kind,
245+
item.name,
246+
containerDetail + fileDetail,
247+
itemUri,
237248
makeVscodeRange(item.range),
238249
makeVscodeRange(item.selectionRange));
239250
}

0 commit comments

Comments
 (0)