Skip to content
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

feat(appcomposer): load and save from VS Code buffer #4482

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JLargent42
Copy link
Contributor

Problem

  • Application Composer works directly off of the workspace files. Changes in VS Code will only be detected by App Composer when the user saves, and changes in Composer will immediately be saved to disk. This does not follow the standard VS Code pattern.

Solution

  • This updates Application Composer to read from and write to VS Code text documents when possible, ensuring that Composer is synced with the latest user changes and giving the user more control over what changes are saved.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@JLargent42 JLargent42 marked this pull request as ready for review February 29, 2024 17:34
@JLargent42 JLargent42 requested a review from a team as a code owner February 29, 2024 17:34
@JLargent42 JLargent42 requested a review from a team February 29, 2024 17:35
@JLargent42 JLargent42 marked this pull request as draft February 29, 2024 23:30
@@ -4352,6 +4352,7 @@
"bytes": "^3.1.2",
"cross-fetch": "^4.0.0",
"cross-spawn": "^7.0.3",
"fast-deep-equal": "^3.1.3",
Copy link
Contributor

@justinmk3 justinmk3 Feb 29, 2024

Choose a reason for hiding this comment

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

Why is this needed? If it's for performance, what were the profiling / benchmark results?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't strictly required, and I don't think the performance is a major concern given that it operates with a 1 second buffer. Using JSON.stringify() on the objects would also work here if we want to avoid adding another dependency. fast-deep-equal is generally faster and is only 13kB unpacked, which is why I added it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

and is only 13kB unpacked

All dependencies must be maintained, and that becomes a big problem over time. :) 13kB is a lot of code which may have bugs and CVEs...

* when at least one of the templates cannot be parsed. Comments and whitespace should not result
* in a template update.
*/
export async function templateShouldBeUpdated(oldTemplate: string, newTemplate: string) {
Copy link
Contributor

@justinmk3 justinmk3 Feb 29, 2024

Choose a reason for hiding this comment

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

Do not create one-function-per file. Use modules to group related functionality. This module could be util.ts , for now.

}
bufferFileChange(event, context)
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid jargon-forking. vscode calls it a textDocument so let's be consistent, since we already have many functions with that name.

Suggested change
bufferFileChange(event, context)
textDocumentChange(event, context)

## Problem
- Application Composer works directly off of the workspace files.
Changes in VS Code will only be detected by App Composer when the user
saves, and changes in Composer will immediately be saved to disk.
This does not follow the standard VS Code pattern.

## Solution
- This updates Application Composer to read from and write to VS Code
text documents when possible, ensuring that Composer is synced with
the latest user changes and giving the user more control over what
changes are saved.
Problem:
When deleting a resource while the template.yaml
file is closed, the template would be broken.

Solution:
The saveFileMessageHandler should replace the entire
file, so using a range from 0 to MAX_INT works
with no performance penalty.
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.

None yet

2 participants