Commit graph

819 commits

Author SHA1 Message Date
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
afdd450d86 vscode: Fix some lints 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
f0b4bce3d6 janitor: Make LSP clippy clean 2023-01-16 14:42:36 +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
e456008c8e lsp: Fix document symbols not working
This changes how the selection range is picked: Instead of using the
`QualifiedName` of the root element, look at the Component's
`DeclaredIdentifier`.

This fixes component declarations without `inherits` clause and is also
nicer than the old approach: We would use the Component id as a name of
the DocumentSymbol and set the inherited type name as selection range.
2023-01-12 17:01:11 +01:00
Tobias Hunger
303b8f7c9d lsp: Update unit tests to new slint syntax 2023-01-12 17:01:11 +01:00
Tobias Hunger
7d702c947b online editor: Shrink border around the preview 2023-01-12 13:04:58 +01:00
Olivier Goffart
7cacb78bd9 Rename syntax_updater -> slint-updater 2023-01-11 18:27:47 +01:00
Tobias Hunger
06657eb79a lsp: Improve text range selection on binding removal
Try to delete entire lines if possible. This way we do not keep empty
lines around anymore.
2023-01-11 17:38:15 +01:00
Tobias Hunger
81d605e5d6 lsp: Simplify (left|right)_extend
This is simpler than the previous version and will be easier to
reuse for line-wise deletion, too.

It does sacrifice indention level based (line-) comment splitting, but I
think that will not be missed...

Any comments up to a blank line _before_ a property will be considered to
belong to that property and any comment _after_ the property that starts
without a line break are part of a property now.

There is some extra magic to work when several properties are in the
same line: Basically all comments then refer to the following property.

Update tests accordingly...
2023-01-11 17:38:15 +01:00
Tobias Hunger
47dbfb5327 lsp: Extract code to find the property binding 2023-01-11 17:38:15 +01:00
Tobias Hunger
a9aea470fd lsp: Rename delete_range to selection_range
I want to eventually use that to highlight the text the property editor
will work on. That is not done yet though.
2023-01-11 17:38:15 +01:00
Tobias Hunger
f8f8373b54 lsp: Extract code deciding whether to list a property as editable
I plan to reuse this when removing a property binding.
2023-01-11 17:38:15 +01:00
Tobias Hunger
8760262b60
lsp: Be smarter when inserting bindings (#1990)
Find the elements indentation level and make sure the following property
is indented.

This is a simplistic though as it indents 4 spaces more than the
Element's indentation level.
2023-01-11 10:31:46 +01:00
Olivier Goffart
85a98e4fb2 syntax_updater: don't duplicate transitions 2023-01-10 17:26:24 +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
Olivier Goffart
5b4d000301 syntax_updater: don't add x or y property for elements in a ListView 2023-01-07 14:18:10 +01:00
Olivier Goffart
47fbc809b8 syntax_updater: initialize the state also when visiting snippets 2023-01-07 14:18:10 +01:00
Olivier Goffart
fc11e872cf syntax_updater: only add spaces around inherits if needed 2023-01-07 14:18:10 +01:00
Olivier Goffart
4cf6690e5a syntax_updater: also parse slint,no-preview code block in md files
This include a fix to make sure the diagnostics has access to the
sources even if there is no path
2023-01-07 14:18:10 +01:00
Olivier Goffart
a0d057b8b8 Enable the new syntax by default 2023-01-07 14:18:10 +01:00
Olivier Goffart
a0d6199391 Updater: annotate pure to all function and callback that returns something 2022-12-22 00:26:27 -08:00
Olivier Goffart
1cbd61145e WIP: pure qualifier for callback and functions 2022-12-22 00:26:27 -08:00
Olivier Goffart
8c70c6c906 LSP: heuristics to avoid matching the slint macro in comments or strings 2022-12-21 11:49:09 +01:00
Olivier Goffart
a55ed47fed vscode extension: polish the slint! macro integration
- Make the browser extention preview work
 - Enable the properties tab on rust files
 - Only call `offset_to_position_mapper` if the token is valid,
   otherwise we might get an error visible in the UI.
2022-12-20 06:40:33 -08:00
Olivier Goffart
3d171320e9 LSP: support the slint! macro within slint files 2022-12-19 09:13:58 -08:00
ogoffart
ce07d078ce Bump version number to 0.3.4 2022-12-16 09:36:15 +00:00
Tobias Hunger
cf9594483e
lsp: Do not panic on invalid property definitions
Minimal example to reproduce:

```
export Demo := Rectangle { Text { text: } }
```
2022-12-15 14:32:52 +01: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
Tobias Hunger
689e42b60c LSP: Sort document symbols based on text ranges
Otherwise the symbols might get shown in the wrong order in the outline
view.
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
Olivier Goffart
4430b36623 LSP: Highlight and renaming of element id 2022-12-13 16:23:26 +01:00
Olivier Goffart
ed306acb12 LSP: don't panic when quiting when there is no preview
Ignore the error that quitting don't work if the preview event loop
hasn't been started.

We're quitting anyway
2022-12-13 16:23:26 +01:00
Tobias Hunger
27eaa50129 LSP: Make the OffsetMapper hold on to newline map
This allows the OffsetToPositionMapper to not have a lifetime and
prevents it from holding a reference to the DocumentCache.

This makes things a lot as the OffsetToPositionMapper does not block
other uses of the DocumentCache anymore!
2022-12-13 15:17:30 +01:00
Tobias Hunger
5d654a8e32 Revert "lsp: Report that we send progress information"
The LSP spec gave this as an example, I misread that to mean it is
required. Sorry for that.

This reverts commit 3c05dfe029.
2022-12-13 15:17:03 +01:00
Tobias Hunger
96bf59aa37 tools: Focus input field when activating it 2022-12-13 11:44:41 +01:00
Tobias Hunger
98378d891b LSP: Fail silently when a file is not known to the LSP
I would prefer to raise an error in that case, but VSCode will raise
havok when I do that!

Fixes: #1970
2022-12-12 13:01:04 +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
36ae662a64 lsp: Extend setBinding command to handle undefined properties
Extend the setBinding command of the LSP to also handle properties that
were declared but not defined yet.

This will enable us to add new properties (that were already declared
before).
2022-12-12 11:34:16 +01:00