Skip to content

workspace-state.json will be really saved until changes happened #5700

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

Conversation

aelam
Copy link

@aelam aelam commented Jul 31, 2022

cache dependencies and artifacts, workspace-state.json will be really saved until changes happened

Motivation:

here is the original issue #5693

It would be a pain for extension development because there is no file that can be watched for updating the dependency list

  • workspace-state.json is changed all the time even if there is no change

  • show-dependencies will trigger the change

  • the worst case which may be quite general case

    • watching Package.swift and Package.resolved to trigger package resolve
    • watching workspace-state.json to trigger show-dependencies
    1. Package.resolved is modified
    2. workspace-state.json will be updated soon
    3. workspace-state.json change will trigger show-dependencies
    4. [go to step 2], show-dependencies will update workspace-state.json again

Modifications:

cache dependencies and artifacts, when call save(), file will be saved if there is a real change

Result:

workspace-state.json is not updated until there is a change

@tomerd
Copy link
Contributor

tomerd commented Sep 1, 2022

sorry for the slow response on this. workspace-state.json is an internal implementation detail of SwiftPM and should not be relied on by clients / users.

could you help me understand what problem are we trying to solve, perhaps there is a more supported way to achieve this, or we can design one if there isn't

@aelam
Copy link
Author

aelam commented Sep 1, 2022

The motivation is to show the full dependency graph for this extension https://github.com/swift-server/vscode-swift/

The problem is swift package show-dependencies is a bit expensive, In addition, the extension needs to watch interesting file changes (Package.swift Package.resovled) . show-dependencies could be triggered/run again and again

  1. Package.swift file change --> trigger package show-dependencies --> Update UI
  2. ❌ [Infinite loop]Package.resovled file change --> trigger package show-dependencies --> Package.resovled file change

workspace-state.json should be the best watch point to update dependency UI, but calling package show-dependencies could trigger workspace-state.json file change again, this is also an Infinite loop
caching the data in memory could be a workaround. but if SwiftPM has fixed the issue. it would be easier to develop this feature

[PS]
the design of Package.swift Package.resovled workspace-state.json is quite different from other dependency managers
one point is Package.resovled doesn't have the dependency information so that show-dependencies has to traverse all Package.swift.
the other point is that removed dependencies are still treated as managed dependencies so they are not really removed from workspace-state.json. this means the dependencies in workspace-state.json are not equal to the real dependencies, we have to call show-dependencies to get the latest one

Please point out if there is any problem

Thank you

@neonichu
Copy link
Contributor

Closing this for inactivity.

@neonichu neonichu closed this Apr 17, 2023
@MaxDesiatov
Copy link
Contributor

@aelam do you have a corresponding issue on the swift-server/vscode-swift repository that clarifies the original motivation for this change and specifies how this manifests to the user? IMO it would it be better track it there and find a more suitable solution to the problem that doesn't rely on an internal SwiftPM implementation detail that may change between Swift versions without warning.

@aelam
Copy link
Author

aelam commented Apr 18, 2023

@MaxDesiatov
the corresponding issue is vscode-swift cant show a perfect dependency graph
currently, vscode-swift doesn't show the exact latest dependencies because it doesn't call show-dependency because of the high cost. instead, it watches Package.swift and Package.resolved file change to generate dependency graph, but actually the two files are not enough.

@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented Apr 18, 2023

Right, then relying on workspace-state.json is not a good solution as was mentioned previously. Please open an issue with these details on the VS Code extension repository if there isn't one already. Then we can work from there to find a proper API in SourceKit-LSP and possibly SwiftPM if needed.

@aelam aelam deleted the fix/wl-check-before-save-state-json branch June 25, 2024 02:04
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.

4 participants