From f48ad817b62224b1e218acda154ad644235f3109 Mon Sep 17 00:00:00 2001 From: Wang Lun Date: Sat, 30 Jul 2022 13:54:51 +0900 Subject: [PATCH 1/3] fixed read dependencies from workspace-state.json --- src/SwiftPackage.ts | 12 ++- src/ui/PackageDependencyProvider.ts | 115 ++++++++++++++++++++-------- 2 files changed, 95 insertions(+), 32 deletions(-) diff --git a/src/SwiftPackage.ts b/src/SwiftPackage.ts index 8ad820312..4c9c1c900 100644 --- a/src/SwiftPackage.ts +++ b/src/SwiftPackage.ts @@ -117,9 +117,19 @@ export interface WorkspaceState { version: number; } +/** revision + (branch || version) + * ref: https://github.com/apple/swift-package-manager/blob/e25a590dc455baa430f2ec97eacc30257c172be2/Sources/Workspace/CheckoutState.swift#L19:L23 + */ +export interface CheckoutState { + revision: string; + branch: string | null; + version: string | null; +} + export interface WorkspaceStateDependency { packageRef: { identity: string; kind: string; location: string; name: string }; - state: { name: string; path?: string }; + state: { name: string; path?: string; checkoutState?: CheckoutState }; + subpath: string; } export interface PackagePlugin { diff --git a/src/ui/PackageDependencyProvider.ts b/src/ui/PackageDependencyProvider.ts index ab7877197..3bd497de7 100644 --- a/src/ui/PackageDependencyProvider.ts +++ b/src/ui/PackageDependencyProvider.ts @@ -21,7 +21,7 @@ import { WorkspaceContext } from "../WorkspaceContext"; import { FolderEvent } from "../WorkspaceContext"; import { FolderContext } from "../FolderContext"; import contextKeys from "../contextKeys"; -import { WorkspaceState } from "../SwiftPackage"; +import { WorkspaceState, WorkspaceStateDependency } from "../SwiftPackage"; /** * References: @@ -148,39 +148,24 @@ export class PackageDependenciesProvider implements vscode.TreeDataProvider item.name === child.name); - if (!editedVersion) { - uneditedChildren.push(child); - } - } - return [...uneditedChildren, ...editedChildren].sort((first, second) => - first.name.localeCompare(second.name) - ); + return this.getDependencyGraph(workspaceState, folderContext.folder.fsPath); } - const buildDirectory = buildDirectoryFromWorkspacePath(folderContext.folder.fsPath, true); + return this.getNodesInDirectory(element.path); + } - if (element instanceof PackageNode) { - // Read the contents of a package. - const packagePath = - element.type === "remote" - ? path.join(buildDirectory, "checkouts", getRepositoryName(element.path)) - : element.path; - return this.getNodesInDirectory(packagePath); - } else { - // Read the contents of a directory within a package. - return this.getNodesInDirectory(element.path); - } + private getDependencyGraph( + workspaceState: WorkspaceState | undefined, + folderContext: string + ): PackageNode[] { + return ( + workspaceState?.object.dependencies.map(dependency => { + const type = this.dependencyType(dependency); + const version = this.dependencyDisplayVersion(dependency); + const packagePath = this.dependencyPackagePath(dependency, folderContext); + return new PackageNode(dependency.packageRef.identity, packagePath, version, type); + }) ?? [] + ); } /** @@ -277,4 +262,72 @@ export class PackageDependenciesProvider implements vscode.TreeDataProvider Date: Sat, 30 Jul 2022 14:15:17 +0900 Subject: [PATCH 2/3] clean unused import --- src/ui/PackageDependencyProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/PackageDependencyProvider.ts b/src/ui/PackageDependencyProvider.ts index 3bd497de7..78d20574f 100644 --- a/src/ui/PackageDependencyProvider.ts +++ b/src/ui/PackageDependencyProvider.ts @@ -16,7 +16,7 @@ import * as vscode from "vscode"; import * as fs from "fs/promises"; import * as path from "path"; import configuration from "../configuration"; -import { getRepositoryName, buildDirectoryFromWorkspacePath } from "../utilities/utilities"; +import { buildDirectoryFromWorkspacePath } from "../utilities/utilities"; import { WorkspaceContext } from "../WorkspaceContext"; import { FolderEvent } from "../WorkspaceContext"; import { FolderContext } from "../FolderContext"; From 5b05cce709f66d2b634de8307cbb8f22ceeacaa7 Mon Sep 17 00:00:00 2001 From: Wang Lun Date: Sat, 30 Jul 2022 14:24:21 +0900 Subject: [PATCH 3/3] editing package will show pattern like `editing 1.2.3` --- src/SwiftPackage.ts | 1 + src/ui/PackageDependencyProvider.ts | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/SwiftPackage.ts b/src/SwiftPackage.ts index 4c9c1c900..537563354 100644 --- a/src/SwiftPackage.ts +++ b/src/SwiftPackage.ts @@ -127,6 +127,7 @@ export interface CheckoutState { } export interface WorkspaceStateDependency { + basedOn: WorkspaceStateDependency | null; packageRef: { identity: string; kind: string; location: string; name: string }; state: { name: string; path?: string; checkoutState?: CheckoutState }; subpath: string; diff --git a/src/ui/PackageDependencyProvider.ts b/src/ui/PackageDependencyProvider.ts index 78d20574f..bafb6952f 100644 --- a/src/ui/PackageDependencyProvider.ts +++ b/src/ui/PackageDependencyProvider.ts @@ -292,7 +292,13 @@ export class PackageDependenciesProvider implements vscode.TreeDataProvider 0) { + return "editing " + basedOnVersion; + } + } + return "editing"; } else if (type === "local") { return "local"; } else {