-
Notifications
You must be signed in to change notification settings - Fork 45
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -207,6 +207,7 @@ const router = createBrowserRouter( | |||
projectPath + sep + PROJECT_ENTRYPOINT | |||
) | |||
const children = await readDir(projectPath, { recursive: true }) | |||
kclManager.setCodeAndExecute(code, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]) }) | ||
} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
I think I'm going to go ahead and merge this one. |
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.