Commit graph

259 commits

Author SHA1 Message Date
Tobias Hunger
255fe56c94
online_editor: Fix fake baseURI 2023-02-15 11:43:53 +01:00
Tobias Hunger
b33fd32002 online_editor: Fix firefox
Firefox does not handle modules in web workers yet, but that is what we
asked vite to build (to work around a compatibility issue after
upgrading to vite 4). So Chrome worked, but Firefox did not.

This PR adds a pretty ugly work around to that problem.

The good news is: Firefox will apparently be able to handle modules in
web workers starting with 111, so let's hope we do not need this for too
long!
2023-02-14 20:53:36 +01:00
Simon Hausmann
a7eaf5a8bb Fix loading of the LSP worker script in the online editor
The update to vite 4 triggered the vite 3 bug vitejs/vite#9879
for us, where the wasm-pack generated .js is included as iife and
therefore the use of import.meta.url gets transpiled to some shim that
tries to access the document, assuming that the JS is running in the
browser instead of in a worker environment.

Explicitly set the output type for the worker to ES modules, so that no
changes are needed and import.meta.url remains in use. This matches the
worker invocation anyway, as we pass "type": "module" to the Worker
constructor.
2023-02-03 15:08:28 +01:00
ogoffart
e7f48512ee Bump version number to 1.0.0 2023-02-03 11:07:15 +01:00
Simon Hausmann
e430716adb Fix the online editor not loading the wasm-interpreter anymore
The upgrade of vite from 2 to 4 in commit
5951ae6272 also brought an update of
rollup to version three. That one documents that relative externals are
resolved to absolute paths by default, which explains the symptom that
the online editor tried to load /some/absolute/path/wasm_interpreter.js.

Resolving back to resolve paths fixes it.
2023-02-02 17:52:06 +01:00
Tobias Hunger
fb09dc5c1d
online editor: Improve waiting for setup to complete (#2133)
The code used to sometimes throw a strange exception indicating that the
previewer WASM module was not fully up yet when used.

Fix the LspWaiter to really wait for both LSP WASM web worker and WASM
previewer to report back that they are fully up. Previously it only
waited for the Lsp, which surprisingly often works on my machine.
2023-01-27 11:04:50 +01:00
Tobias Hunger
5951ae6272 online editor: Update tooling and dependencies
We bundle everything with vite, so treat all dependencies as
dev-dependencies.
2023-01-26 15:04:59 +01:00
Olivier Goffart
4f3d0954fe Online code editor: add a "load_demo" url argument
that loads the demo based on the current version of the editor
2023-01-25 11:11:57 +01:00
Tobias Hunger
c56c484f2a online editor: Fix race on querying the properties from the LSP
When removing a property binding, the editor notified the Properties
Widget before the LSP was updated. So the LSP continued to provide the
old data on the Property Widgets request. So the removed property
binding was still shown as set.

Work around this by polling the LSP till it returns a source version we
expect (or something newer). This should be save enough I hope.
2023-01-24 21:03:32 +01:00
Tobias Hunger
cc4539dfcd online editor: Fix incomplete information from LSP after opening a demo
This sets up the file reader, which has gone missing in action at some
point.

We used to open the main file of the printer demo. That trriggered
loading of all the helper files, but they all came back empty. So any
LSP request that came in got errors as the code was incomplete.

Afterwards the editor loads the files anyway, telling the LSP about the
loaded file each time, filling in the missing information. So after all
files are open in the editor, the information in the LSP is complete and
all LSP commands return proper information going forward.
2023-01-24 19:35:56 +01:00
Tobias Hunger
b718c9c043 tools: Remove progress reporting for file loading
Stop the LSP from reporting progress information on file loading. This
caused problems with VSCode: First it triggered popups in the UI and
secondly it caused problems for the LSP that was asked to process
requests while calling back into the client.

Adapt the online editor and the two VSCode plugins to work with the
updated code.

Note: I did leave in the progress reporting code that can be used to
handle progress initiated by the _client_ side. That is just
notifications which will not block the LSP in any way and we might need
to support that at some point.

I did remove the Middleware code from the client side though that acted
on the progress information.
2023-01-23 19:51:55 +01:00
Simon Hausmann
24dcef5fed
First stage of cleaning up the export handling of the slint root component (#2095)
We implicitly export the last component of a .slint file to the generator.
Issue a warning when that happens and suggest to export it explicitly.
2023-01-23 15:19:49 +01:00
Tobias Hunger
3290e58228 online editor: Make sure the editor tab bar is up to date
... even when monaco changes the models behind our backs.

Fixes: #1851
2023-01-23 13:00:32 +01:00
Tobias Hunger
9ccf6c3bdf ci: Turn of cypress tests of the online editor
The two tests provide somewhat limited value at this time: The Firefox
tests were green before, but we think that should not have been the case
as firefox does not accept the imports in the webworker when serving
with vite in dev mode -- which we did.

Trying to change the test to use the actual generated site fails for
unknown reason: Cypress claims the page reported by `vite prefix` as up
is returning 404 in CI. It works fine locally:-/
2023-01-20 18:27:11 +01:00
Tobias Hunger
15bd48d2fa tools: Add highlight feature to wasm-interpreter
... and use it.
2023-01-20 18:27:11 +01:00
Tobias Hunger
d45d14af8b janitor: online editor: Reorder imports
This might make firefox a bit happier as the (now) last import defines
some constants. That used to happen between imports and is after all
other imports now.

Ugly work-around, but maybe it helps?
2023-01-20 18:27:11 +01:00
Tobias Hunger
d6e5a3ea54 online editor: Treat failure to load files gracefully
Pretend the file was empty when it failed to load. This stops the LSP
from blocking in some error cases, e.g. in the Printerdemo when reading
fonts.
2023-01-20 18:27:11 +01:00
Tobias Hunger
c79cd21baf LSP: Support highlighting via call-out into javascript
This adds a new "preview-api" feature so that this can be turned on in
WASM without dragging in lots of extra dependencies:-/
2023-01-20 18:27:11 +01:00
Tobias Hunger
fb7a5b80ca online editor: Allow LSP to trigger highlight function in Previewer 2023-01-20 18:27:11 +01:00
Tobias Hunger
c7e10446c1 online editor: Split Preview class into a frontend and backend
... that communicate with each other over a channel. This means we can
pass one side into a web worker and still have this work.

Short-term this is mean to enable the LSP running in a web worker take
control of the Preview. Mid-term we might be able to also move the
preview into a web worker, but that needs OffScreenCanvas, which is not
available in Safari-based browsers at this time.
2023-01-20 18:27:11 +01:00
Tobias Hunger
ae77ad3e39 online editor: Move previewer code into the Previewer class
... in lsp.
2023-01-20 18:27:11 +01:00
Tobias Hunger
4c250331a2 online editor: Move previewer out of preview widget into lsp setup 2023-01-20 18:27:11 +01:00
Tobias Hunger
105d751a67 online editor: Factor out code to set up LSP 2023-01-20 18:27:11 +01:00
Tobias Hunger
248212711e online editor: Fix preview rendering sub components instead of main one
I had the mental model of "updating the preview with the new code" since
that is how the LSP works. That is of course wrong here: The Previewer always
compiles again from scratch.

So always feed the main source file to the preview, not the currently
edited one.

Fixes: #2057
2023-01-12 18:45:17 +01:00
Tobias Hunger
7d702c947b online editor: Shrink border around the preview 2023-01-12 13:04:58 +01:00
Olivier Goffart
1f92ffa846 Online editor: use the new syntax in the code sample 2023-01-10 11:50:26 +01:00
Olivier Goffart
fac32410db Online editor: update syntax highlighting keywords 2023-01-10 11:50:26 +01:00
ogoffart
ce07d078ce Bump version number to 0.3.4 2022-12-16 09:36:15 +00:00
Tobias Hunger
19c6600269 online editor: Add an icon for structs in outline widget
We report structs, so add an icon for those.
2022-12-13 20:49:55 +01:00
Olivier Goffart
94bba83446 LSP: reply to the textDocument/prepareRename request 2022-12-13 16:23:26 +01:00
Tobias Hunger
96bf59aa37 tools: Focus input field when activating it 2022-12-13 11:44:41 +01:00
Tobias Hunger
4e3c8f52e7 tools: Prefix our custom LSP commands with "slint/"
Keep the global namespace clean!
2022-12-12 13:01:04 +01:00
Tobias Hunger
2f5b5f3444 tools: Make "Add" button work in vscode/online_editor 2022-12-12 11:34:16 +01:00
Tobias Hunger
423a3b2619 vscode: Add removal of properties 2022-12-09 17:38:04 +01:00
Tobias Hunger
6b143644d8 online editor: Add remove button to properties editor 2022-12-09 17:38:04 +01:00
Tobias Hunger
524e6ed2cf tools: Extract some small helper funtion into shared/utils 2022-12-09 11:19:48 +01:00
Tobias Hunger
71199fbb16 online editor: Have LSP trigger updates in the Properties View
We still get some updates from the editor that we do not really need
anymore, but we also get updtaes from the LSP now.

This fixes e.g. the property value being out of sync right after you
changed it in the property editor.
2022-12-05 15:13:14 +01:00
Tobias Hunger
9cd6c60000 lsp: simplify registration on LSP with properties_widget 2022-12-05 15:13:14 +01:00
Tobias Hunger
6d3506d2d4 online editor: Make the language client handle progress reports 2022-12-05 15:13:14 +01:00
Simon Hausmann
78d070c713 online editor: Fix preview not being visible with Safari
A value of "1" for the style property turns into "none" in the computed style, for the canvas element.

Fixes #1945
2022-12-05 14:49:20 +01:00
Tobias Hunger
24500fbf6b online editor: Explain how preview scaling works 2022-12-02 17:14:05 +01:00
Tobias Hunger
f069d066bd online editor: Add zoom level to preview widget
Add a set of widgets to control the zoom level to the preview widget.
2022-12-02 17:14:05 +01:00
Tobias Hunger
a30c921983 online editor: Add zoom level to preview 2022-12-02 17:14:05 +01:00
Tobias Hunger
765b59ec48 online editor: Fix icons 2022-12-02 17:14:05 +01:00
Tobias Hunger
4d88e59675 online editor: Improve positioning of preview area
Work around the scrollbar not reaching the entire preview canvas when it
is overflowing.

References #1762
2022-12-01 16:56:40 +01:00
Simon Hausmann
ace4f92aad online editor: fix hello world re-appearing unexpectedly
After checking if the instance field is null, we await the promise that
would guarantee DOM attachment.  While we await, the browser processes
other microtasks, and we might end up in render() again. This time the
instance field is also null, but the ensure_attached_to_dom promise is
already resolved, so we would create the first slint component and the
associated window. Later we would return from the first await. At this
point the instance field is already set, so we should re-use the
existing window, but since we're not checking anymore, we'll go ahead
and create a second window on the same canvas element.

Fixes #1926
2022-11-29 17:18:16 +01:00
ogoffart
fb02b4118b Bump version number to 0.3.3 2022-11-28 13:11:11 +00:00
Tobias Hunger
e9d28f00e3 tools: Unshare some code
Do not interact with the language server directly in vscode, but use
vscode.commands.executeCommand(...) instead. The online_editor will of
course need to continue to interact with the language server directy, so
this unshares a bit of code. It is not too much and straight forward
code, so that is not too bad.
2022-11-26 18:26:37 +01:00
Tobias Hunger
b949689e35 Revert "tools: Put code shared between online editor and vscode in NPM package"
This caused trouble with both the online editor as well as the VSCode
extension when built in CI.

This reverts commit c8b434021e.
2022-11-25 17:34:32 +01:00
Tobias Hunger
0672e02115
Tools: Retry getting properties on error (#1907)
* Tools: trigger updates for properties view more often

So far you had to move the cursor to refresh the properties view after
start-up. This is no longer necessary.
2022-11-24 19:40:19 +01:00