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

start of fixing changing files and cleaning up after execute #897

Merged
merged 5 commits into from
Nov 6, 2023

Conversation

Irev-Dev
Copy link
Collaborator

@Irev-Dev Irev-Dev commented Oct 18, 2023

This one was a bit of a pain, lots of running around but a pretty small diff at the end of it.

Ostensibly I set out to fix a weird error where typing code would persist it, but code-gen code wouldn't persist (unless of course, you typed something quickly at the end to get it to save). But there was a lot of confusing race conditions. What code was responsible for saving code to file was not clear, it was actually in the code-mirror editor, which makes sense as to why it only worked for typed and not generated code, so moving that responsibility to the kclManager since it's responsible for code fixed that. There was still an effect watching for code changes loaded from the router that would get the updated code one cycle too late, so it would save old files to the new file location, so moving that into the kclManager fixed that too.

  • Persist code when it's code-gen-code (start a new sketch, create a few segments, then click "go to home" before exiting the sketch, open some other project, go home again and open the original project and check the generated code has stayed)
  • When the above happens make sure artifacts get clean up (this will be obvious that lines are hanging around when doing the above)
  • swapping between two different projects shouldn't carry code from one to the other (some times you would get the code from the last file and it would override)
  • Some constraints (e.g. horizontal distance) also leave artifacts in the scene (this is because the modals actually execute some code to show the user the effect of their maths, but it wasn't cleaning up artifacts in the process, swaping it too the fake executor and some other shuffling fix this)
  • Double check Creating New File Keeps Old Text #900 is covered by this
  • Creating a new file should be blank and not have the bracket sample code
  • Check the tutorial hasn't been broken

@vercel
Copy link

vercel bot commented Oct 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview Nov 3, 2023 9:38am

@@ -207,6 +207,7 @@ const router = createBrowserRouter(
projectPath + sep + PROJECT_ENTRYPOINT
)
const children = await readDir(projectPath, { recursive: true })
kclManager.setCodeAndExecute(code, false)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment on lines 106 to -127
kclManager.setCodeAndExecute(newCode)
if (isTauri() && pathParams.id) {
// Save the file to disk
// Note that PROJECT_ENTRYPOINT is hardcoded until we support multiple files
writeTextFile(pathParams.id, newCode).catch((err) => {
// TODO: add Sentry per GH issue #254 (https://github.com/KittyCAD/modeling-app/issues/254)
console.error('error saving file', err)
toast.error('Error saving file, please check file permissions')
})
}
if (editorView) {
editorView?.dispatch({ effects: addLineHighlight.of([0, 0]) })
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

kclManager.setCodeAndExecute(newCode) handles saving the file too now, hence why all this could be deleted.

}
setCodeAndExecute(code: string) {
this.setCode(code)
setCodeAndExecute(code: string, shouldWriteFile = true) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Generally, when the code is updated we want to save the file as well. Except when the file is first loaded because the user opened a project.

@Irev-Dev Irev-Dev self-assigned this Nov 3, 2023
@Irev-Dev
Copy link
Collaborator Author

Irev-Dev commented Nov 6, 2023

I think I'm going to go ahead and merge this one.

@Irev-Dev Irev-Dev merged commit 34163da into main Nov 6, 2023
10 checks passed
@Irev-Dev Irev-Dev deleted the kurt-file-and-execute-stuff branch November 6, 2023 00:49
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

1 participant