-
-
Notifications
You must be signed in to change notification settings - Fork 90
library: Remove the need for noop code files #689
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
Changes from all commits
aaa9d54
cb4482d
b156c92
0fc9248
373b7a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -276,74 +276,14 @@ export default function Window({ application, session }) { | |
| previewer.stop(); | ||
| panel_ui.stop(); | ||
|
|
||
| const { language } = panel_code; | ||
| try { | ||
| await panel_ui.update(); | ||
|
|
||
| if (format) { | ||
| await formatCode(); | ||
| } | ||
|
|
||
| if (language === "JavaScript") { | ||
| await previewer.update(true); | ||
|
|
||
| // We have to create a new file each time | ||
| // because gjs doesn't appear to use etag for module caching | ||
| // ?foo=Date.now() also does not work as expected | ||
| // TODO: File a bug | ||
| const [file_javascript] = Gio.File.new_tmp("workbench-XXXXXX.js"); | ||
| await file_javascript.replace_contents_async( | ||
| new GLib.Bytes(document_javascript.code_view.buffer.text || " "), | ||
| null, | ||
| false, | ||
| Gio.FileCreateFlags.NONE, | ||
| null, | ||
| ); | ||
| let exports; | ||
| try { | ||
| exports = await import(`file://${file_javascript.get_path()}`); | ||
| } catch (err) { | ||
| await previewer.update(true); | ||
| throw err; | ||
| } finally { | ||
| file_javascript | ||
| .delete_async(GLib.PRIORITY_DEFAULT, null) | ||
| .catch(console.error); | ||
| } | ||
| previewer.setSymbols(exports); | ||
| } else if (language === "Vala") { | ||
| if (!isValaEnabled()) { | ||
| action_extensions.activate(null); | ||
| return; | ||
| } | ||
|
|
||
| compiler_vala = compiler_vala || ValaCompiler({ session }); | ||
| const success = await compiler_vala.compile(); | ||
| if (success) { | ||
| await previewer.useExternal(); | ||
| if (await compiler_vala.run()) { | ||
| await previewer.open(); | ||
| } else { | ||
| await previewer.useInternal(); | ||
| } | ||
| } | ||
| } else if (language === "Rust") { | ||
| if (!isRustEnabled()) { | ||
| action_extensions.activate(null); | ||
| return; | ||
| } | ||
|
|
||
| compiler_rust = compiler_rust || RustCompiler({ session }); | ||
| const success = await compiler_rust.compile(); | ||
| if (success) { | ||
| await previewer.useExternal(); | ||
| if (await compiler_rust.run()) { | ||
| await previewer.open(); | ||
| } else { | ||
| await previewer.useInternal(); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
-287
to
-346
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was extracted into the |
||
| await compile(); | ||
| } catch (err) { | ||
| // prettier xml errors are not instances of Error | ||
| if (err instanceof Error || err instanceof GLib.Error) { | ||
|
|
@@ -360,6 +300,78 @@ export default function Window({ application, session }) { | |
| term_console.scrollToEnd(); | ||
| } | ||
|
|
||
| async function compile() { | ||
| const { language } = panel_code; | ||
|
|
||
| const lang = langs[language.toLowerCase()]; | ||
| // Do nothing if there is no code to avoid compile errors | ||
| const text = lang.document.code_view.buffer.text.trim(); | ||
| if (text === "") { | ||
| return; | ||
| } | ||
|
|
||
| if (language === "JavaScript") { | ||
| await previewer.update(true); | ||
|
|
||
| // We have to create a new file each time | ||
| // because gjs doesn't appear to use etag for module caching | ||
| // ?foo=Date.now() also does not work as expected | ||
| // TODO: File a bug | ||
| const [file_javascript] = Gio.File.new_tmp("workbench-XXXXXX.js"); | ||
| await file_javascript.replace_contents_async( | ||
| new GLib.Bytes(text), | ||
| null, | ||
| false, | ||
| Gio.FileCreateFlags.NONE, | ||
| null, | ||
| ); | ||
| let exports; | ||
| try { | ||
| exports = await import(`file://${file_javascript.get_path()}`); | ||
| } catch (err) { | ||
| await previewer.update(true); | ||
| throw err; | ||
| } finally { | ||
| file_javascript | ||
| .delete_async(GLib.PRIORITY_DEFAULT, null) | ||
| .catch(console.error); | ||
| } | ||
| previewer.setSymbols(exports); | ||
| } else if (language === "Vala") { | ||
| if (!isValaEnabled()) { | ||
| action_extensions.activate(null); | ||
| return; | ||
| } | ||
|
|
||
| compiler_vala = compiler_vala || ValaCompiler({ session }); | ||
| const success = await compiler_vala.compile(); | ||
| if (success) { | ||
| await previewer.useExternal(); | ||
| if (await compiler_vala.run()) { | ||
| await previewer.open(); | ||
| } else { | ||
| await previewer.useInternal(); | ||
| } | ||
| } | ||
| } else if (language === "Rust") { | ||
| if (!isRustEnabled()) { | ||
| action_extensions.activate(null); | ||
| return; | ||
| } | ||
|
|
||
| compiler_rust = compiler_rust || RustCompiler({ session }); | ||
| const success = await compiler_rust.compile(); | ||
| if (success) { | ||
| await previewer.useExternal(); | ||
| if (await compiler_rust.run()) { | ||
| await previewer.open(); | ||
| } else { | ||
| await previewer.useInternal(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const action_run = new Gio.SimpleAction({ | ||
| name: "run", | ||
| }); | ||
|
|
||
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.
this was necessary because demos without Code didn't have a
.jsfile (but they had Rust and Vala files that did nothing)With this we don't show language for demos without code anymore