MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / getPackageOrFolderDisplayName

Function getPackageOrFolderDisplayName

src/shared/vscode/display_names.ts:14–38  ·  view source on GitHub ↗
(packageFolder: string, { packageName }: { packageName?: string } = {})

Source from the content-addressed store, hash-verified

12 * - In the case where the parent folder name is not displayed and the project folder name matches the package, we only show `package:foo`
13 */
14export function getPackageOrFolderDisplayName(packageFolder: string, { packageName }: { packageName?: string } = {}): string {
15 // If we weren't passed one, try to get the packages name from the pubspec.
16 packageName ??= tryGetPackageName(packageFolder);
17
18 // Get the relative path from the workspace root to the folder we're running up to two segments.
19 const containingWorkspace = vs.workspace.getWorkspaceFolder(vs.Uri.file(packageFolder));
20 const containingWorkspacePath = containingWorkspace ? fsPath(containingWorkspace.uri) : undefined;
21 let folderDisplayName = path.basename(packageFolder);
22 if (containingWorkspacePath) {
23 const relativePath = path.relative(containingWorkspacePath, packageFolder);
24 if (relativePath) {
25 folderDisplayName = relativePath.includes(path.sep)
26 ? relativePath.split(path.sep).slice(-2).join(path.sep)
27 : relativePath;
28 }
29 }
30
31 if (packageName && packageName !== folderDisplayName) {
32 return `package:${packageName} (${folderDisplayName})`;
33 } else if (packageName) {
34 return `package:${packageName}`;
35 } else {
36 return folderDisplayName;
37 }
38}

Callers 5

runBatchFolderOperationFunction · 0.90
flutterCreateMethod · 0.90
dartCreateMethod · 0.90

Calls 2

tryGetPackageNameFunction · 0.90
fsPathFunction · 0.90

Tested by

no test coverage detected