Skip to content

load packages from workspace-state.json, missing packages can show #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from

Conversation

aelam
Copy link
Contributor

@aelam aelam commented Jul 23, 2022

main package --> local A --> local B
if local A depends on local B
local B will not be shown in dependency list unless writting the dependency local B in main package expicitly

I've found workspaceState?.object.dependencies is exactly the same results as in the Xcode

And the other thing is Xcode shows the name of packages but this is showing identify of package

Here is helping locate the issue fast, Free free to close

  • all dependencies can be shown
  • editing dependencies can be shown
  • exposed edit locally for remote package
  • edit locally and use local package both work OK
  • show product name rather than package name as Xcode doing

https://swift-server.slack.com/archives/C02PV8T5HQD/p1658595325605139

@swift-server-bot
Copy link

Can one of the admins verify this patch?

3 similar comments
@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

Copy link
Contributor

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this PR just to the fix for local package dependencies.

private async getAllDependencies(folderContext: FolderContext): Promise<PackageNode[]> {
return (await folderContext.getWorkspaceDependencies()).map(dependency => {
const version =
dependency.packageRef.kind === "fileSystem"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this with swift 5.5 and earlier. Given there was a change to the Package description in 5.6 there is a good chance the workspace state also changed format

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for showing version or branch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested with 5.5, let me check earlier version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5.6, 5.5, 5.4
✅ dependency list OK
✅ edit OK
✅ unedit OK

just kept watching workspace-state.json changes, it's most relevant to the UI of dependency

  • When reset package, it will be deleted, package.resolved has no change
  • when edit/unedit package, it will be changed, the path can be read for get the repo, the editing package info will be added into pins

probably watching the workspace-state.json is the best choice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment above about watching workspace-state.json. The FileSystemWatcher update triggers on every action we run regardless of whether the workspace-state.json changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revolve will trigger workspace-state.json change once even there is no actual change

@adam-fowler
Copy link
Contributor

@swift-server-bot test this please

@aelam
Copy link
Contributor Author

aelam commented Jul 25, 2022

@adam-fowler
Now I confirmed that
[Package.swift + Package.resolved] --> resovle --> update workspace-state.json --> dependency UI
Package.swift + Package.resolved determine what versions should be fetched

the UI should fully map with workspace-state.json

aelam added 2 commits July 25, 2022 22:02
# Conflicts:
#	src/ui/PackageDependencyProvider.ts
@aelam
Copy link
Contributor Author

aelam commented Jul 25, 2022

@swift-server-bot test this please

@aelam
Copy link
Contributor Author

aelam commented Jul 25, 2022

I created a quite general project that could cover more test cases, Please check the readme
https://github.com/aelam/vscode-swift-test-packages

@aelam aelam requested a review from adam-fowler July 25, 2022 13:29
@aelam aelam changed the title fixed local recursive packages don't show load packages from workspace-state.json, missing packages can show Jul 25, 2022
@aelam
Copy link
Contributor Author

aelam commented Jul 26, 2022

@swift-server-bot test this please

@aelam
Copy link
Contributor Author

aelam commented Jul 27, 2022

FYI. I noticed that, the dependencies of workspace-state.json is not exactly the showing-list, for example
I add package A in package.swift and then delete it.
A will be still in workspace-state.json but it's not actually used in the current package

I will fix it

@aelam aelam marked this pull request as draft July 27, 2022 06:05
@aelam aelam force-pushed the fix_dependency_list branch from d693b49 to 65cc690 Compare July 29, 2022 02:56
@aelam aelam force-pushed the fix_dependency_list branch from 65cc690 to 8b72eef Compare July 29, 2022 03:00
@aelam aelam marked this pull request as ready for review July 29, 2022 03:01
{
"command": "swift.uneditDependency",
"when": "view == packageDependencies && viewItem == editing"
"when": "view == packageDependencies && viewItem == edited"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind this change

// view
if (triggerResolvedUpdatedEvent && !folderContext.hasResolveErrors) {
folderContext.fireEvent(FolderEvent.resolvedUpdated);
folderContext.fireEvent(FolderEvent.workspaceStateUpdated);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only trigger UI updates

@@ -194,15 +187,27 @@ export class PackageDependenciesProvider implements vscode.TreeDataProvider<Tree
.filter(dependency => !dependency.requirement && dependency.url)
.map(
dependency =>
new PackageNode(dependency.identity, dependency.url!, "local", "local")
new PackageNode(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added identity to PackageNote, so have to change it here

@adam-fowler
Copy link
Contributor

Why are you traversing the packages to run swift package describe on all of them? Has the workspace-state.json not got enough information. Also it looks you are assuming swift package resolve will have been run on all your local dependencies because you are assuming the workspace-state.json file has been created for each of these packages, when you call dependencyVersion.

@aelam
Copy link
Contributor Author

aelam commented Jul 29, 2022

Has the workspace-state.json not got enough information.
Right, it's not enough

The case is when you add a package in package.swift --> resolve --> comment out the package in package.swift --> resolve, there is basically no change in workspace-state.json

workspace-state.json changing can be the only moment to change dependency tree
and resolve show show-dependency both trigger it change

because you are assuming the workspace-state.json file has been created for each of these packages,

I think so? if we watch the workspace-state.json, there should be no problem, because we can get the final dependencies in the end
dependencyVersion should be no problem because workspace-state.json is ready, evn if it's still updating, then that dependency is absent but finally it will be shown normally

if you run swift package show-dependency, this is the really correct dependency tree which calls recursively just as I am doing

Here are some interesting code in spm
https://github.com/apple/swift-package-manager/blob/2f7ecad9d551ba66525b39c5a9b43807bee67fbb/Sources/Commands/SwiftPackageTool.swift#L459

https://github.com/apple/swift-package-manager/blob/57af70f2f9f5645514a9ce8e6279995c701333b0/Sources/Commands/SwiftPackageTool.swift#L759

https://github.com/apple/swift-package-manager/blob/62454085787f58b56f94cdf248567639caf42a10/Sources/Commands/Utilities/DependenciesSerializer.swift#L71

@adam-fowler
Copy link
Contributor

The case is when you add a package in package.swift --> resolve --> comment out the package in package.swift --> resolve, there is basically no change in workspace-state.json

Ok, there should be easier ways to sort this out. This is quite a niche issue and rebuilding the whole code base to fix this seems a bit of an over reaction.

if we watch the workspace-state.json

Currently workspace-state.json is hit all the time. Not sure I want to be updating the UI every time it is updated.

if you run swift package show-dependency, this is the really correct dependency tree which calls recursively just as I am doing

swift package show-dependency can be an expensive operation. It can kick off unwanted resolves.

I would like to break down this PR into smaller sections. I have a very basic branch which gives you the basics of displaying local dependencies of local dependencies #377. It currently loads workspace-state.json twice but that can be fixed easily. Maybe once that is merged we can consider a PR using workspace-state.json for all dependencies.

@aelam
Copy link
Contributor Author

aelam commented Jul 29, 2022

Currently workspace-state.json is hit all the time. Not sure I want to be updating the UI every time it is updated.

As my observation, it's updated when resolve or show-dependency is done

swift package show-dependency can be an expensive operation. It can kick off unwanted resolves.

I agree, it will trigger package.resolved if it's originally triggered by package.resolved change

I would like to break down this PR into smaller sections. I have a very basic branch which gives you the basics of displaying local dependencies of local dependencies #377. It currently loads workspace-state.json twice but that can be fixed easily. Maybe once that is merged we can consider a PR using workspace-state.json for all dependencies.

Thank you! But firstly let me confirm something

  • It currently loads workspace-state.json twice

I just debugged but I didn't see it's loaded twice. Do you mean the case that we watch workspace-state.json

  • how do I create PR, do I create PR based on your branch?

@adam-fowler
Copy link
Contributor

As my observation, it's updated when resolve or show-dependency is done

I've seen updates on every build, maybe I should verify. If this isn't the case then maybe as another PR we could look at adding a workspace-state file watcher and add a new event workspaceStateUpdated which the UI updates triggers off. If you haven't worked out already. I like small PRs. They give me a better chance of working out what all the implications are of changes. You have to remember we are supporting back to swift 5.4 across macOS, Linux and Windows.

I just debugged but I didn't see it's loaded twice

I fixed that after writing the comment.

That PR is just waiting to be approved and then you can build off of that one.

@aelam
Copy link
Contributor Author

aelam commented Jul 29, 2022

I've seen updates on every build

Oh, I didn't observe on swift build, just checked it does change workspace-state.json every time,

probably there is no content change but it's still updated, if we want to use workspace-state.json maybe we need to cache it then update the UI until it's necessary?

The case is when you add a package in package.swift --> resolve --> comment out the package in package.swift --> resolve, there is basically no change in workspace-state.json

Ok, there should be easier ways to sort this out. This is quite a niche issue and rebuilding the whole code base to fix this seems a bit of an over reaction.

Do you mean just showing the dependencies from workspace-state.json is OK? (I'm thinking maybe it's apple's bug?)

@adam-fowler
Copy link
Contributor

I have a very basic branch which gives you the basics of displaying local dependencies of local dependencies #377

this is now merged. You can create a PR off that one. Lets first merge the three functions getLocalDependencies, getRemoteDependencies and getEditedDependencies into one function which uses workspace-state.json to get its data. I guess you'll need the checkoutStatus as well in WorkspaceStateDependency

@adam-fowler
Copy link
Contributor

Shall we close this now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants