2024-04-17 20:18:07 -07:00
|
|
|
// A little class for updating the code state when we need to and explicitly
|
|
|
|
// NOT updating the code state when we don't need to.
|
|
|
|
// This prevents re-renders of the codemirror editor, when typing.
|
|
|
|
import { bracket } from 'lib/exampleKcl'
|
2024-08-16 07:15:42 -04:00
|
|
|
import { isDesktop } from 'lib/isDesktop'
|
2024-04-17 20:18:07 -07:00
|
|
|
import toast from 'react-hot-toast'
|
2024-04-19 14:24:40 -07:00
|
|
|
import { editorManager } from 'lib/singletons'
|
2024-07-03 21:28:51 -07:00
|
|
|
import { Annotation, Transaction } from '@codemirror/state'
|
2024-11-18 18:08:22 -08:00
|
|
|
import { EditorView, KeyBinding } from '@codemirror/view'
|
2024-11-16 16:49:44 -05:00
|
|
|
import { recast, Program } from 'lang/wasm'
|
|
|
|
import { err } from 'lib/trap'
|
2024-11-18 18:08:22 -08:00
|
|
|
import { Compartment } from '@codemirror/state'
|
|
|
|
import { history } from '@codemirror/commands'
|
2024-04-17 20:18:07 -07:00
|
|
|
|
2024-07-02 17:16:27 +10:00
|
|
|
const PERSIST_CODE_KEY = 'persistCode'
|
2024-04-17 20:18:07 -07:00
|
|
|
|
2024-07-08 21:07:15 -07:00
|
|
|
const codeManagerUpdateAnnotation = Annotation.define<boolean>()
|
|
|
|
export const codeManagerUpdateEvent = codeManagerUpdateAnnotation.of(true)
|
2024-11-18 18:08:22 -08:00
|
|
|
export const codeManagerHistoryCompartment = new Compartment()
|
2024-06-29 18:10:07 -07:00
|
|
|
|
2024-04-17 20:18:07 -07:00
|
|
|
export default class CodeManager {
|
|
|
|
private _code: string = bracket
|
2024-05-06 19:28:30 +10:00
|
|
|
#updateState: (arg: string) => void = () => {}
|
2024-04-19 14:24:40 -07:00
|
|
|
private _currentFilePath: string | null = null
|
2024-05-20 20:52:33 -07:00
|
|
|
private _hotkeys: { [key: string]: () => void } = {}
|
2024-10-21 16:07:20 -04:00
|
|
|
private timeoutWriter: ReturnType<typeof setTimeout> | undefined = undefined
|
2024-04-17 20:18:07 -07:00
|
|
|
|
2024-10-25 18:07:50 -04:00
|
|
|
public writeCausedByAppCheckedInFileTreeFileSystemWatcher = false
|
|
|
|
|
2024-04-17 20:18:07 -07:00
|
|
|
constructor() {
|
2024-08-16 07:15:42 -04:00
|
|
|
if (isDesktop()) {
|
2024-04-17 20:18:07 -07:00
|
|
|
this.code = ''
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:16:27 +10:00
|
|
|
const storedCode = safeLSGetItem(PERSIST_CODE_KEY)
|
2024-04-17 20:18:07 -07:00
|
|
|
// TODO #819 remove zustand persistence logic in a few months
|
2024-08-16 07:15:42 -04:00
|
|
|
// short term migration, shouldn't make a difference for desktop app users
|
2024-04-17 20:18:07 -07:00
|
|
|
// anyway since that's filesystem based.
|
|
|
|
const zustandStore = JSON.parse(safeLSGetItem('store') || '{}')
|
|
|
|
if (storedCode === null && zustandStore?.state?.code) {
|
|
|
|
this.code = zustandStore.state.code
|
|
|
|
zustandStore.state.code = ''
|
|
|
|
safeLSSetItem('store', JSON.stringify(zustandStore))
|
|
|
|
} else if (storedCode === null) {
|
|
|
|
this.code = bracket
|
|
|
|
} else {
|
Move all tests over to electron (#4484)
* Move all tests over to electron
* Pass the correct param to playwright-electron.sh
* Add shebang to script and add macos-14-large as a target
* Get sketch-tests.spec.ts passing in electron
* Try out 4 workers
* Got testing-segment-overlays passing
* Pass testing-selections.spec.ts
* Go back to fix up sketch-tests test
* Pass various.spec.ts, by far the hardest one
* Pass can-sketch-on-all-planes... with ease
* Pass command bar tests
* fmt
* Completely fix code mirror text navigating for tests
* Pass debug pane tests
* Pass desktop export tests
* Pass editor tests
* Pass file tree tests
* Pass onboarding tests
* Corrected a fixme in file-tree.spec!
* Painfully fix hardcoded coordinates in point-click.spec
* Pass machine.spec tests
* Pass projects, fought hard with filechooser
* Pass regresion-tests.spec tests
* Pass network and connection tests
* Pass camera-movement.spec tests
* Extreme time eaten by gizmo test fixes. All passing now.
* Merge main (tests changed x_x) and pass all constraints.spec tests (pain)
* Pass another painful spec suite: testing-settings
* Pass perspective-toggle, interesting note
* Pass samples loading tests
* Pass app header tests
* Pass text-to-cad tests
* Pass segment-overlays (minor ache) and ability to switch to web if needed :)
* Fix a ton of syntax changes and deflake 2 more tests (pain)
* Correct all tsc errors
* Remove to-electron script
* Add an f-ton of shit because playwright doesnt want S P R E A D
* Try CI again
* Stop snapshots of exports (already test in e2e)
* Fix flake in double click editor
* Hopefully help CI flake
* Fixmes, fixmes everywhere
* One more fixme to settings
* Skip another code pane flake
* Port jess's projects.spec tests
* fixup
* Reuse electron window; difficult task
* Rebased and refixed
* Remove duplicate cases
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Reduce the workers to something CI can handle
* Lower it further, we need to think about the others
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Fix the last tests and tsc errors
* Timeout to 120 and windows-2022-16core
* Fix windows runner detection, enable concurrency temporarily
* Hopefully this time fix windows runner detection
* Comment out Vector, add back removed camera test code
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Fix camera tests again
* Massively deflake a whole class of tests
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Try new CI and fix small onboarding test
* Derp
* No github tuning
* Try mac
* Add back all the OS
* Lord, hallow be thy name
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* One last try with window-16-cores
* Trigger CI
* Try AWS Windows runner
* Passing on windows locally with a few skips
* Skip more win tests, add back all three oses
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-16-cores)
* Add two more fixmes
* 2 more fixmes
* skip segment overlays on win32
* Another fixme
* Trigger CI
* Trigger CI
* Quick clean up
* Move all tests over to electron
* Pass the correct param to playwright-electron.sh
* Add shebang to script and add macos-14-large as a target
* Get sketch-tests.spec.ts passing in electron
* Try out 4 workers
* Got testing-segment-overlays passing
* Pass testing-selections.spec.ts
* Go back to fix up sketch-tests test
* Pass various.spec.ts, by far the hardest one
* Pass can-sketch-on-all-planes... with ease
* Pass command bar tests
* fmt
* Completely fix code mirror text navigating for tests
* Pass debug pane tests
* Pass desktop export tests
* Pass editor tests
* Pass file tree tests
* Pass onboarding tests
* Corrected a fixme in file-tree.spec!
* Painfully fix hardcoded coordinates in point-click.spec
* Pass machine.spec tests
* Pass projects, fought hard with filechooser
* Pass regresion-tests.spec tests
* Pass network and connection tests
* Pass camera-movement.spec tests
* Extreme time eaten by gizmo test fixes. All passing now.
* Merge main (tests changed x_x) and pass all constraints.spec tests (pain)
* Pass another painful spec suite: testing-settings
* Pass perspective-toggle, interesting note
* Pass samples loading tests
* Pass app header tests
* Pass text-to-cad tests
* Pass segment-overlays (minor ache) and ability to switch to web if needed :)
* Fix a ton of syntax changes and deflake 2 more tests (pain)
* Correct all tsc errors
* Remove to-electron script
* Add an f-ton of shit because playwright doesnt want S P R E A D
* Try CI again
* Stop snapshots of exports (already test in e2e)
* Fix flake in double click editor
* Hopefully help CI flake
* Fixmes, fixmes everywhere
* One more fixme to settings
* Skip another code pane flake
* Port jess's projects.spec tests
* fixup
* Reuse electron window; difficult task
* Rebased and refixed
* Remove duplicate cases
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Reduce the workers to something CI can handle
* Lower it further, we need to think about the others
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Fix the last tests and tsc errors
* Timeout to 120 and windows-2022-16core
* Fix windows runner detection, enable concurrency temporarily
* Hopefully this time fix windows runner detection
* Comment out Vector, add back removed camera test code
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Fix camera tests again
* Massively deflake a whole class of tests
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Try new CI and fix small onboarding test
* Derp
* No github tuning
* Try mac
* Add back all the OS
* Lord, hallow be thy name
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* Try AWS Windows runner
* Passing on windows locally with a few skips
* Trigger CI
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* fmt, tsc, lint
* Enable two fixmes again
* Fix lint, codespell, fmt
* Fix lint
* Don't run e2e on draft, add back concurrency, clean up
* One last windows skip
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
Co-authored-by: Pierre Jacquier <pierre@zoo.dev>
2024-12-18 17:58:03 -05:00
|
|
|
this.code = storedCode || ''
|
2024-04-17 20:18:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set code(code: string) {
|
|
|
|
this._code = code
|
|
|
|
}
|
|
|
|
|
|
|
|
get code(): string {
|
|
|
|
return this._code
|
|
|
|
}
|
|
|
|
|
Move all tests over to electron (#4484)
* Move all tests over to electron
* Pass the correct param to playwright-electron.sh
* Add shebang to script and add macos-14-large as a target
* Get sketch-tests.spec.ts passing in electron
* Try out 4 workers
* Got testing-segment-overlays passing
* Pass testing-selections.spec.ts
* Go back to fix up sketch-tests test
* Pass various.spec.ts, by far the hardest one
* Pass can-sketch-on-all-planes... with ease
* Pass command bar tests
* fmt
* Completely fix code mirror text navigating for tests
* Pass debug pane tests
* Pass desktop export tests
* Pass editor tests
* Pass file tree tests
* Pass onboarding tests
* Corrected a fixme in file-tree.spec!
* Painfully fix hardcoded coordinates in point-click.spec
* Pass machine.spec tests
* Pass projects, fought hard with filechooser
* Pass regresion-tests.spec tests
* Pass network and connection tests
* Pass camera-movement.spec tests
* Extreme time eaten by gizmo test fixes. All passing now.
* Merge main (tests changed x_x) and pass all constraints.spec tests (pain)
* Pass another painful spec suite: testing-settings
* Pass perspective-toggle, interesting note
* Pass samples loading tests
* Pass app header tests
* Pass text-to-cad tests
* Pass segment-overlays (minor ache) and ability to switch to web if needed :)
* Fix a ton of syntax changes and deflake 2 more tests (pain)
* Correct all tsc errors
* Remove to-electron script
* Add an f-ton of shit because playwright doesnt want S P R E A D
* Try CI again
* Stop snapshots of exports (already test in e2e)
* Fix flake in double click editor
* Hopefully help CI flake
* Fixmes, fixmes everywhere
* One more fixme to settings
* Skip another code pane flake
* Port jess's projects.spec tests
* fixup
* Reuse electron window; difficult task
* Rebased and refixed
* Remove duplicate cases
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Reduce the workers to something CI can handle
* Lower it further, we need to think about the others
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Fix the last tests and tsc errors
* Timeout to 120 and windows-2022-16core
* Fix windows runner detection, enable concurrency temporarily
* Hopefully this time fix windows runner detection
* Comment out Vector, add back removed camera test code
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Fix camera tests again
* Massively deflake a whole class of tests
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Try new CI and fix small onboarding test
* Derp
* No github tuning
* Try mac
* Add back all the OS
* Lord, hallow be thy name
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* One last try with window-16-cores
* Trigger CI
* Try AWS Windows runner
* Passing on windows locally with a few skips
* Skip more win tests, add back all three oses
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-16-cores)
* Add two more fixmes
* 2 more fixmes
* skip segment overlays on win32
* Another fixme
* Trigger CI
* Trigger CI
* Quick clean up
* Move all tests over to electron
* Pass the correct param to playwright-electron.sh
* Add shebang to script and add macos-14-large as a target
* Get sketch-tests.spec.ts passing in electron
* Try out 4 workers
* Got testing-segment-overlays passing
* Pass testing-selections.spec.ts
* Go back to fix up sketch-tests test
* Pass various.spec.ts, by far the hardest one
* Pass can-sketch-on-all-planes... with ease
* Pass command bar tests
* fmt
* Completely fix code mirror text navigating for tests
* Pass debug pane tests
* Pass desktop export tests
* Pass editor tests
* Pass file tree tests
* Pass onboarding tests
* Corrected a fixme in file-tree.spec!
* Painfully fix hardcoded coordinates in point-click.spec
* Pass machine.spec tests
* Pass projects, fought hard with filechooser
* Pass regresion-tests.spec tests
* Pass network and connection tests
* Pass camera-movement.spec tests
* Extreme time eaten by gizmo test fixes. All passing now.
* Merge main (tests changed x_x) and pass all constraints.spec tests (pain)
* Pass another painful spec suite: testing-settings
* Pass perspective-toggle, interesting note
* Pass samples loading tests
* Pass app header tests
* Pass text-to-cad tests
* Pass segment-overlays (minor ache) and ability to switch to web if needed :)
* Fix a ton of syntax changes and deflake 2 more tests (pain)
* Correct all tsc errors
* Remove to-electron script
* Add an f-ton of shit because playwright doesnt want S P R E A D
* Try CI again
* Stop snapshots of exports (already test in e2e)
* Fix flake in double click editor
* Hopefully help CI flake
* Fixmes, fixmes everywhere
* One more fixme to settings
* Skip another code pane flake
* Port jess's projects.spec tests
* fixup
* Reuse electron window; difficult task
* Rebased and refixed
* Remove duplicate cases
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Reduce the workers to something CI can handle
* Lower it further, we need to think about the others
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Fix the last tests and tsc errors
* Timeout to 120 and windows-2022-16core
* Fix windows runner detection, enable concurrency temporarily
* Hopefully this time fix windows runner detection
* Comment out Vector, add back removed camera test code
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Fix camera tests again
* Massively deflake a whole class of tests
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Try new CI and fix small onboarding test
* Derp
* No github tuning
* Try mac
* Add back all the OS
* Lord, hallow be thy name
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* Try AWS Windows runner
* Passing on windows locally with a few skips
* Trigger CI
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* fmt, tsc, lint
* Enable two fixmes again
* Fix lint, codespell, fmt
* Fix lint
* Don't run e2e on draft, add back concurrency, clean up
* One last windows skip
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
Co-authored-by: Pierre Jacquier <pierre@zoo.dev>
2024-12-18 17:58:03 -05:00
|
|
|
localStoragePersistCode(): string {
|
|
|
|
return safeLSGetItem(PERSIST_CODE_KEY) || ''
|
|
|
|
}
|
|
|
|
|
2024-04-19 14:24:40 -07:00
|
|
|
registerCallBacks({ setCode }: { setCode: (arg: string) => void }) {
|
2024-05-06 19:28:30 +10:00
|
|
|
this.#updateState = setCode
|
2024-04-17 20:18:07 -07:00
|
|
|
}
|
|
|
|
|
2024-05-20 20:52:33 -07:00
|
|
|
registerHotkey(hotkey: string, callback: () => void) {
|
|
|
|
this._hotkeys[hotkey] = callback
|
|
|
|
}
|
|
|
|
|
|
|
|
getCodemirrorHotkeys(): KeyBinding[] {
|
|
|
|
return Object.keys(this._hotkeys).map((key) => ({
|
|
|
|
key,
|
|
|
|
run: () => {
|
|
|
|
this._hotkeys[key]()
|
|
|
|
return false
|
|
|
|
},
|
2024-07-25 20:18:11 -04:00
|
|
|
preventDefault: true,
|
2024-05-20 20:52:33 -07:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2025-01-28 15:43:39 -08:00
|
|
|
get currentFilePath(): string | null {
|
|
|
|
return this._currentFilePath
|
|
|
|
}
|
|
|
|
|
2024-04-19 14:24:40 -07:00
|
|
|
updateCurrentFilePath(path: string) {
|
|
|
|
this._currentFilePath = path
|
2024-04-17 20:18:07 -07:00
|
|
|
}
|
|
|
|
|
2024-06-20 21:39:01 -04:00
|
|
|
/**
|
|
|
|
* This updates the code state and calls the updateState function.
|
|
|
|
*/
|
2024-04-17 20:18:07 -07:00
|
|
|
updateCodeState(code: string): void {
|
|
|
|
if (this._code !== code) {
|
|
|
|
this.code = code
|
2024-05-06 19:28:30 +10:00
|
|
|
this.#updateState(code)
|
2024-04-17 20:18:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-20 21:39:01 -04:00
|
|
|
/**
|
|
|
|
* Update the code in the editor.
|
|
|
|
*/
|
2024-11-18 18:08:22 -08:00
|
|
|
updateCodeEditor(code: string, clearHistory?: boolean): void {
|
2024-04-19 14:24:40 -07:00
|
|
|
this.code = code
|
|
|
|
if (editorManager.editorView) {
|
2024-11-18 18:08:22 -08:00
|
|
|
if (clearHistory) {
|
|
|
|
clearCodeMirrorHistory(editorManager.editorView)
|
|
|
|
}
|
2024-04-19 14:24:40 -07:00
|
|
|
editorManager.editorView.dispatch({
|
2024-05-06 19:28:30 +10:00
|
|
|
changes: {
|
|
|
|
from: 0,
|
|
|
|
to: editorManager.editorView.state.doc.length,
|
|
|
|
insert: code,
|
|
|
|
},
|
2024-06-29 18:10:07 -07:00
|
|
|
annotations: [
|
|
|
|
codeManagerUpdateEvent,
|
2024-11-18 18:08:22 -08:00
|
|
|
Transaction.addToHistory.of(!clearHistory),
|
2024-06-29 18:10:07 -07:00
|
|
|
],
|
2024-04-19 14:24:40 -07:00
|
|
|
})
|
|
|
|
}
|
2024-04-17 20:18:07 -07:00
|
|
|
}
|
|
|
|
|
2024-06-20 21:39:01 -04:00
|
|
|
/**
|
|
|
|
* Update the code, state, and the code the code mirror editor sees.
|
|
|
|
*/
|
2024-11-18 18:08:22 -08:00
|
|
|
updateCodeStateEditor(code: string, clearHistory?: boolean): void {
|
2024-04-17 20:18:07 -07:00
|
|
|
if (this._code !== code) {
|
|
|
|
this.code = code
|
2024-05-06 19:28:30 +10:00
|
|
|
this.#updateState(code)
|
2024-11-18 18:08:22 -08:00
|
|
|
this.updateCodeEditor(code, clearHistory)
|
2024-04-17 20:18:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async writeToFile() {
|
2024-08-16 07:15:42 -04:00
|
|
|
if (isDesktop()) {
|
2024-10-21 16:07:20 -04:00
|
|
|
// Only write our buffer contents to file once per second. Any faster
|
|
|
|
// and file-system watchers which read, will receive empty data during
|
|
|
|
// writes.
|
2024-11-16 16:49:44 -05:00
|
|
|
|
2024-10-21 16:07:20 -04:00
|
|
|
clearTimeout(this.timeoutWriter)
|
2024-10-25 18:07:50 -04:00
|
|
|
this.writeCausedByAppCheckedInFileTreeFileSystemWatcher = true
|
2024-11-16 16:49:44 -05:00
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
this.timeoutWriter = setTimeout(() => {
|
|
|
|
if (!this._currentFilePath)
|
|
|
|
return reject(new Error('currentFilePath not set'))
|
|
|
|
|
|
|
|
// Wait one event loop to give a chance for params to be set
|
|
|
|
// Save the file to disk
|
2024-08-16 07:15:42 -04:00
|
|
|
window.electron
|
|
|
|
.writeFile(this._currentFilePath, this.code ?? '')
|
2024-11-16 16:49:44 -05:00
|
|
|
.then(resolve)
|
2024-08-16 07:15:42 -04:00
|
|
|
.catch((err: Error) => {
|
|
|
|
// TODO: add tracing 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')
|
2024-11-16 16:49:44 -05:00
|
|
|
reject(err)
|
2024-08-16 07:15:42 -04:00
|
|
|
})
|
2024-11-16 16:49:44 -05:00
|
|
|
}, 1000)
|
|
|
|
})
|
2024-04-17 20:18:07 -07:00
|
|
|
} else {
|
2024-07-02 17:16:27 +10:00
|
|
|
safeLSSetItem(PERSIST_CODE_KEY, this.code)
|
2024-04-17 20:18:07 -07:00
|
|
|
}
|
|
|
|
}
|
2024-11-16 16:49:44 -05:00
|
|
|
|
|
|
|
async updateEditorWithAstAndWriteToFile(ast: Program) {
|
|
|
|
const newCode = recast(ast)
|
|
|
|
if (err(newCode)) return
|
|
|
|
this.updateCodeStateEditor(newCode)
|
|
|
|
await this.writeToFile()
|
|
|
|
}
|
2024-04-17 20:18:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function safeLSGetItem(key: string) {
|
Move all tests over to electron (#4484)
* Move all tests over to electron
* Pass the correct param to playwright-electron.sh
* Add shebang to script and add macos-14-large as a target
* Get sketch-tests.spec.ts passing in electron
* Try out 4 workers
* Got testing-segment-overlays passing
* Pass testing-selections.spec.ts
* Go back to fix up sketch-tests test
* Pass various.spec.ts, by far the hardest one
* Pass can-sketch-on-all-planes... with ease
* Pass command bar tests
* fmt
* Completely fix code mirror text navigating for tests
* Pass debug pane tests
* Pass desktop export tests
* Pass editor tests
* Pass file tree tests
* Pass onboarding tests
* Corrected a fixme in file-tree.spec!
* Painfully fix hardcoded coordinates in point-click.spec
* Pass machine.spec tests
* Pass projects, fought hard with filechooser
* Pass regresion-tests.spec tests
* Pass network and connection tests
* Pass camera-movement.spec tests
* Extreme time eaten by gizmo test fixes. All passing now.
* Merge main (tests changed x_x) and pass all constraints.spec tests (pain)
* Pass another painful spec suite: testing-settings
* Pass perspective-toggle, interesting note
* Pass samples loading tests
* Pass app header tests
* Pass text-to-cad tests
* Pass segment-overlays (minor ache) and ability to switch to web if needed :)
* Fix a ton of syntax changes and deflake 2 more tests (pain)
* Correct all tsc errors
* Remove to-electron script
* Add an f-ton of shit because playwright doesnt want S P R E A D
* Try CI again
* Stop snapshots of exports (already test in e2e)
* Fix flake in double click editor
* Hopefully help CI flake
* Fixmes, fixmes everywhere
* One more fixme to settings
* Skip another code pane flake
* Port jess's projects.spec tests
* fixup
* Reuse electron window; difficult task
* Rebased and refixed
* Remove duplicate cases
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Reduce the workers to something CI can handle
* Lower it further, we need to think about the others
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Fix the last tests and tsc errors
* Timeout to 120 and windows-2022-16core
* Fix windows runner detection, enable concurrency temporarily
* Hopefully this time fix windows runner detection
* Comment out Vector, add back removed camera test code
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Fix camera tests again
* Massively deflake a whole class of tests
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Try new CI and fix small onboarding test
* Derp
* No github tuning
* Try mac
* Add back all the OS
* Lord, hallow be thy name
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* One last try with window-16-cores
* Trigger CI
* Try AWS Windows runner
* Passing on windows locally with a few skips
* Skip more win tests, add back all three oses
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-16-cores)
* Add two more fixmes
* 2 more fixmes
* skip segment overlays on win32
* Another fixme
* Trigger CI
* Trigger CI
* Quick clean up
* Move all tests over to electron
* Pass the correct param to playwright-electron.sh
* Add shebang to script and add macos-14-large as a target
* Get sketch-tests.spec.ts passing in electron
* Try out 4 workers
* Got testing-segment-overlays passing
* Pass testing-selections.spec.ts
* Go back to fix up sketch-tests test
* Pass various.spec.ts, by far the hardest one
* Pass can-sketch-on-all-planes... with ease
* Pass command bar tests
* fmt
* Completely fix code mirror text navigating for tests
* Pass debug pane tests
* Pass desktop export tests
* Pass editor tests
* Pass file tree tests
* Pass onboarding tests
* Corrected a fixme in file-tree.spec!
* Painfully fix hardcoded coordinates in point-click.spec
* Pass machine.spec tests
* Pass projects, fought hard with filechooser
* Pass regresion-tests.spec tests
* Pass network and connection tests
* Pass camera-movement.spec tests
* Extreme time eaten by gizmo test fixes. All passing now.
* Merge main (tests changed x_x) and pass all constraints.spec tests (pain)
* Pass another painful spec suite: testing-settings
* Pass perspective-toggle, interesting note
* Pass samples loading tests
* Pass app header tests
* Pass text-to-cad tests
* Pass segment-overlays (minor ache) and ability to switch to web if needed :)
* Fix a ton of syntax changes and deflake 2 more tests (pain)
* Correct all tsc errors
* Remove to-electron script
* Add an f-ton of shit because playwright doesnt want S P R E A D
* Try CI again
* Stop snapshots of exports (already test in e2e)
* Fix flake in double click editor
* Hopefully help CI flake
* Fixmes, fixmes everywhere
* One more fixme to settings
* Skip another code pane flake
* Port jess's projects.spec tests
* fixup
* Reuse electron window; difficult task
* Rebased and refixed
* Remove duplicate cases
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* Reduce the workers to something CI can handle
* Lower it further, we need to think about the others
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Update package.json
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
* Fix the last tests and tsc errors
* Timeout to 120 and windows-2022-16core
* Fix windows runner detection, enable concurrency temporarily
* Hopefully this time fix windows runner detection
* Comment out Vector, add back removed camera test code
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Fix camera tests again
* Massively deflake a whole class of tests
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: macos-14-large)
* Try new CI and fix small onboarding test
* Derp
* No github tuning
* Try mac
* Add back all the OS
* Lord, hallow be thy name
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores)
* Try AWS Windows runner
* Passing on windows locally with a few skips
* Trigger CI
* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)
* fmt, tsc, lint
* Enable two fixmes again
* Fix lint, codespell, fmt
* Fix lint
* Don't run e2e on draft, add back concurrency, clean up
* One last windows skip
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
Co-authored-by: Pierre Jacquier <pierre@zoo.dev>
2024-12-18 17:58:03 -05:00
|
|
|
if (typeof window === 'undefined') return
|
2024-04-17 20:18:07 -07:00
|
|
|
return localStorage?.getItem(key)
|
|
|
|
}
|
|
|
|
|
|
|
|
function safeLSSetItem(key: string, value: string) {
|
|
|
|
if (typeof window === 'undefined') return
|
|
|
|
localStorage?.setItem(key, value)
|
|
|
|
}
|
2024-11-18 18:08:22 -08:00
|
|
|
|
|
|
|
function clearCodeMirrorHistory(view: EditorView) {
|
|
|
|
// Clear history
|
|
|
|
view.dispatch({
|
|
|
|
effects: [codeManagerHistoryCompartment.reconfigure([])],
|
|
|
|
annotations: [codeManagerUpdateEvent],
|
|
|
|
})
|
|
|
|
|
|
|
|
// Add history back
|
|
|
|
view.dispatch({
|
|
|
|
effects: [codeManagerHistoryCompartment.reconfigure([history()])],
|
|
|
|
annotations: [codeManagerUpdateEvent],
|
|
|
|
})
|
|
|
|
}
|