Commit graph

110 commits

Author SHA1 Message Date
Tobias Hunger
c55f0a9b0e compiler: Add a snapshotter to help create snapshots of compiler state
Use this snapshot to keep a unoptimized typeloader around, so that the preview
does not need to do another parsing run.

Move the document cache in the preview over to use the snapshot.
2024-06-12 10:15:29 +02:00
Tobias Hunger
d657ee65af live-preview: Handle known components using our local DocumentCache 2024-06-12 10:15:29 +02:00
Tobias Hunger
6c034372a1 lsp: Encapsulate DocumentCache better
The Document cache is a specialized typeloader now, make it provide the
necessary APIs directly, so that we can be sure nobody will do anything
that breaks the data:-)
2024-06-12 10:15:29 +02:00
Tobias Hunger
fccb4de8a0 lsp: Move PreviewConfig out of DocumentCache 2024-06-12 10:15:29 +02:00
Tobias Hunger
a759fa72d2 lsp: Move DocumentCache into common 2024-06-12 10:15:29 +02:00
Olivier Goffart
8add2e4ebd element_ids: Can't return a SharedString by value from the vtable
also compile the LSP
2024-06-05 01:29:58 -07:00
Tobias Hunger
704cfff41f lsp: Rename components
Only handle rename requests when on the component name in the component
definition.

Handle exports/imports in the entire project as needed.
2024-06-03 16:12:31 +02:00
Olivier Goffart
b80f4552bd LSP auto-completion: suggests unimported globals in expressions
For example, propose to auto-complete Palette and add the import
statements from std-widgets
2024-06-01 10:08:17 +02:00
Aurindam Jana
3523e86359
Simplify commercial license (#3063)
Base the commercial license on the Royalty-free license adding clauses pertaining to the fees.
2024-05-31 14:06:17 +02:00
Aurindam Jana
9a3aa265d5
Update Royalty-free license (#5257)
Add clarification that Application may not expose Slint APIs.
2024-05-31 10:53:19 +02:00
Tobias Hunger
72ada5950d live-preview: Show local component types in Library
Another URL conversion fail prevented this from working :-/
2024-04-30 18:43:21 +02:00
Aurindam Jana
0cfeec1a31
Update Slint Community License (#4994)
Updated the version from 1.1 to 1.2 
Renamed the header to "Slint Royalty-free Desktop, Mobile, and Web Applications License"
Added definition of "Mobile Application" and grant of right
Moved "Limitations" to 3rd section and "License Conditions - Attributions" to 2nd section
Added flexibility to choose between showing "MadeWithSlint" as a dialog/splash screen or on a public webpage
Moved the para on copyright notices to section under "Limitations"
2024-04-15 15:18:55 +02:00
Tobias Hunger
9873cfd7c0 janitor: Run cargo clippy --fix
Only the hand-picked sensible things, not all of it ;-)

Also fix a few typos that cspell complained about when I
tried to commit and some formatting changes that cargo fmt
insisted on when commiting.
2024-03-14 13:42:38 +01:00
Olivier Goffart
b2c9c7ec2a LSP: normalize URL beofre sending to the preview
To ensure cache keys are always the same.

The problem is especially be on windows where editor such as vscode can
send `file:///c%3A/` while Url::from_path would be `file:///C:/`, which
compare differently

Fixes: #4721
2024-03-06 11:00:33 +01:00
Tobias Hunger
3ba59dad46 lsp: Use ElementRcNode when handling properties
We recently got better support for inlined elements. Use
The `ElementRcNode` when accessing properties, so that
we can actually have a better idea which SyntaxNode we
need to work on.

This is actually not too critical as the LSP does little
inlining, but I wanted to reuse this on the preview side
as well, which does inlining much more aggressively.

Do NOT access properties in the live preview though:
It is heavily optiomized, so most properties are just
gone there;-)
2024-03-05 13:10:41 +01:00
Tobias Hunger
3ad3a42656 live preview: Do import handling in drop_location
Remove the AddComponent and the AdjustSelection messages
from the communication between LSP and preview.

Also remove the code to delete an element.
2024-03-01 18:54:40 +01:00
Tobias Hunger
a0b862b096 live preview: Delete an element again
* Refactor the code a bit: Move element edit functions
  into the `element_edit` module below `language`
2024-02-28 15:53:49 +01:00
Olivier Goffart
a3c99555a0 LSP: fix compilation without the preview features
Use the format test to test this compilation
2024-02-26 11:14:02 +01:00
Olivier Goffart
fac0921579 Compiler: keep the layout debugging info next to its node 2024-02-21 11:33:37 +01:00
Tobias Hunger
08372e5a07 live preview: Implement resizing and moving of selected eleement
Much polish needed, but it is a basis to build upon.
2024-02-19 22:27:32 +01:00
Tobias Hunger
e1aefc6f16 lsp: Notify preview about text edits
Have the LS notify the live preview about changes it initiates, so
the live preview can update its selection.

This is not possible for all edits the LS generates: Many are sent
to the editor which may or may not trigger them later, but the
notification happens when the LS adds changes on top of changes
requested by the live preview (e.g. by adding an import). This
fixes having a newly added element selected once it is rendered.
2024-02-19 22:27:32 +01:00
Tobias Hunger
67c6f1ba48 live preview: Indent inserted elements (better) 2024-02-13 21:19:25 +01:00
Tobias Hunger
55d9222753 lsp: Deduplicate code inserting import statements 2024-02-13 17:03:58 +01:00
Tobias Hunger
b615baf98d live preview: Implement dropping an Element onto the canvas
... and make it show up in the code/live preview.

Currently layouts are not supported and it will try to drop
onto elements not accepting children.

But it does add the necessary import statement already.
2024-02-13 17:03:58 +01:00
Tobias Hunger
6dbbc761e4 LSP: Add some getters to common data structs
Just for convenience :-)
2024-02-12 12:44:22 +01:00
Tobias Hunger
b9ae753edd lsp: Make it clearer what is sent to the editor
Move the code that sends to the editor from within the LSP and the live
preview into a module in common.

This makes it clearer what actually happens and allows to remove some
code from the preview that does not really belong there.
2024-02-09 15:24:13 +01:00
Tobias Hunger
a329a7312b lsp: Factor out common code to create WorkspaceEdits
Removes some duplication and lends itself for resue in the previewer :-)

Side-effect: We now consitently use versioned text documents, so the
editor will notice when the LSP refactored outdated data.
2024-02-07 14:51:20 +01:00
Waqar Ahmed
70fe0df97f lsp: Support textDocument/formatting request 2024-02-06 13:47:06 +01:00
Olivier Goffart
46be4e6804 Small tweak to the document outline
- Make sure that the element id is part of the element range.
   So that when selecting element in the preview, the right item
   in the outline is selected
 - fixup the selection_range for enum and struct
2024-01-26 14:39:19 +01:00
Olivier Goffart
5b0ee206be LSP: Simplify the lsp to preview messaging
Don't use a trait, but always dispatch through  a LspToPreviewMessage
2024-01-25 18:55:15 +01:00
Olivier Goffart
09dc25f107 Keep all nodes for a given element (even if it is optimized out) 2024-01-25 14:45:22 +01:00
Tobias Hunger
7754fccdd4 lsp: Add Sidebar showing available Components
Just show what all the components currently available.
2024-01-19 09:14:02 +01:00
Tobias Hunger
192f805586 lsp: Find images not loading in native preview
I broke that when using URLs more consistently. Our path is either a
path or a URL is so easy to break.
2024-01-16 10:49:23 +01:00
Tobias Hunger
fe0ac9d6e8 FIX: lsp: Improve URL encoding 2024-01-15 14:46:39 +01:00
Tobias Hunger
19cf90a319 lsp: Send document versions from lsp to previewer
We want the previewer to become interactive, so we need to pass on the
document versions so we can detect the editor, lsp and previewer going
out of sync.
2024-01-15 14:46:39 +01:00
Tobias Hunger
2ae760c8b9 lsp: Add helper functions to extract data on components
Add helper functions into a new `element_catalog` module that extract
information on components used in a piece of Slint code on the LSP side
of the LSP.

Eventually this information will be passed on to the Preview side and
can then be used there to show available components.
2024-01-15 14:46:39 +01:00
Olivier Goffart
4243040453 LSP: implement code action to add missing component import 2024-01-05 09:17:48 +01:00
Tobias Hunger
d785f2d5df compiler: Store an optional version number with the document
A None value means the file on disk is the golden version.

We have an editor, the LSP and the preview that all need to at least
notice when they have newer data then their peers. So IMHO it makes
sense to have an optional document version around.

The language server protocol makes use of a version number already. This
patch moves that code into the compiler so that it is stored with the
actual data getting versioned.
2023-12-18 14:21:50 +01:00
Olivier Goffart
184cb5f580 LSP: Simplify the preview config handling
- Put the config in a struct so its easier to pass around
 - respect the command line args as default for the style
 - fix compilation without the preview feature
2023-11-24 14:08:06 +01:00
Olivier Goffart
26e8d308b7 LSP: rename and fix the hide toolbar option
- rename the command line option to --no-toolbar
 - Make it default to not hide the toolbar (so it is visible by default)
2023-11-24 14:08:06 +01:00
Tobias Hunger
548f10be2b lsp: Add option to show/hide preview ui
... and use that option in VSCode configuration.
2023-11-23 20:44:06 +01:00
Olivier Goffart
77e5c40ce2 LSP: don't expose symbols with empty names
Empty symbol names causes error in vscode

Fix #3979

Also fix the ranges of enums
2023-11-22 11:59:36 +01:00
Tobias Hunger
d758735241
janitor: clippy and typo fixes in the LSP 2023-11-08 18:39:52 +01:00
Tobias Hunger
0774d01a59 lsp: Send contents to preview for implicitly loaded slint files
This fixes the no preview in slintpad issue when retrieving the contents
of files is slow (e.g. when loaded from the web).

Fixes: #3855
2023-11-08 17:50:18 +01:00
Tobias Hunger
5bf5b7b02d lsp: Clean up PreviewApi
request_state went the wrong way around wrt. communication flow, so
remove and deduplicate it.
2023-11-03 22:14:20 +01:00
Tobias Hunger
d53cebd3e1 lsp: Get signalled by the preview 2023-11-03 22:14:20 +01:00
Tobias Hunger
55cc1ae31f lsp: Remove the PostLoadBehavior
We always update if we have a UI and we never update if not. So this
flag does not help.
2023-11-03 22:14:20 +01:00
Tobias Hunger
a0cc85bfb4 LSP: Remove design mode custom commands 2023-11-03 22:14:20 +01:00
Tobias Hunger
55d0f5d473 lsp: Make native UI work
The UI is ugly and does not include the Design Mode button yet, but it
is a bit of progress.
2023-11-03 22:14:20 +01:00
J-P Nurmi
0d366e0087 LSP: add "Repeat element" and "Make conditional" code actions 2023-10-23 15:58:24 +02:00