MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / getDisplayPath

Function getDisplayPath

src/platform/common/platform/fs-paths.ts:45–86  ·  view source on GitHub ↗
(
    filename: Uri | string | undefined,
    workspaceFolders: readonly WorkspaceFolder[] | WorkspaceFolder[] = [],
    homePathUri?: Uri
)

Source from the content-addressed store, hash-verified

43}
44
45export function getDisplayPath(
46 filename: Uri | string | undefined,
47 workspaceFolders: readonly WorkspaceFolder[] | WorkspaceFolder[] = [],
48 homePathUri?: Uri
49) {
50 homePathUri = homePathUri || getHomeDir();
51 let fileUri: Uri | undefined = undefined;
52 if (typeof filename && typeof filename === 'string') {
53 fileUri = Uri.file(filename);
54 }
55 if (typeof filename && typeof filename !== 'string') {
56 fileUri = filename;
57 }
58 const relativeToHome = getDisplayPathImpl(fileUri, undefined, homePathUri);
59 const workspaceFolderThatOwnsTheFile = workspaceFolders.find(
60 (w) => fileUri && uriPath.isEqualOrParent(fileUri, w.uri, true)
61 );
62 // If there is more than one workspace folder, then we need to display the workspace folder name.
63 // This is because we can have two files with the same name in different workspace folders.
64 // E.g. .venv/bin/python can exist in multiple workspace folders.
65 if (workspaceFolders.length > 1 && workspaceFolderThatOwnsTheFile) {
66 return `${workspaceFolderThatOwnsTheFile.name}${path.sep}${getDisplayPathImpl(
67 fileUri,
68 workspaceFolderThatOwnsTheFile.uri,
69 homePathUri
70 )}`;
71 }
72
73 const relativeToWorkspaceFolders = workspaceFolderThatOwnsTheFile
74 ? [getDisplayPathImpl(fileUri, workspaceFolderThatOwnsTheFile.uri, homePathUri)]
75 : [];
76 // Pick the shortest path for display purposes.
77 // As those are most likely relative to some workspace folder.
78 let bestDisplayPath = relativeToHome;
79 [relativeToHome, ...relativeToWorkspaceFolders].forEach((relativePath) => {
80 if (relativePath.length < bestDisplayPath.length) {
81 bestDisplayPath = relativePath;
82 }
83 });
84
85 return bestDisplayPath;
86}
87
88function getDisplayPathImpl(file: Uri | undefined, cwd: Uri | undefined, homePath: Uri | undefined): string {
89 const isWindows = getOSType() === OSType.Windows;

Callers 15

initializeLoggersFunction · 0.90
interruptKernelMethod · 0.90
restartKernelImplMethod · 0.90
wrapKernelMethodMethod · 0.90
updateConnectionMethod · 0.90
handleExecutionMethod · 0.90
handleInterruptMethod · 0.90
executeQueuedCellsMethod · 0.90
switchKernelMethod · 0.90
computePreferredMethod · 0.90

Calls 5

getHomeDirFunction · 0.85
getDisplayPathImplFunction · 0.85
isEqualOrParentMethod · 0.65
fileMethod · 0.45
forEachMethod · 0.45