Commit graph

110 commits

Author SHA1 Message Date
Tobias Hunger
017e02e623 lsp: No error when sending messages to the Preview fails
Some checks are pending
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, nightly) (push) Blocked by required conditions
CI / node_test (macos-14) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (macos-13) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.85) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / docs (push) Blocked by required conditions
CI / wasm (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
CI / fmt_test (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
The live-preview can get killed at any moment, so do not fail
if sending messages to it fails.
2025-09-10 19:35:47 +02:00
Olivier Goffart
5f8668d93f lsp: move find_element_ids to common 2025-09-03 22:16:34 +02:00
Olivier Goffart
860be0c410 LSP: fixup the range of code lenses and code action for "Show Preview"
- Don't have a code action to preview global
 - Include the `export` and `component` keyword in the range for both
   the lense and the action.
2025-08-28 17:10:12 +02:00
Tobias Hunger
bf66b8694d live-preview: Simplify style handling
Simplify style selection, now that we are "always up": All we need to do
is change the style when the configuration changes. That is a part
of the initial state request we send when the preview starts up, so we set
the style properly and then we do not need to do anything anymore till
somebody configures a new style.
2025-07-28 17:13:15 +02:00
Tobias Hunger
5dc9ce5204 LSP: Start external process for live preview
Start the live preview in a separate process. This simplifies
a couple of things:

* Starting the UI
* UI state handling
* Threading setup
* "Quitting" the preview on Mac

... and many more :-)
2025-07-28 17:13:15 +02:00
Yuri Astrakhan
bcb2953f00 Auto-fixed clippy::unnecessary_map_or
This is a hacky approach, but does help a lot with the tedious fixes.

See https://rust-lang.github.io/rust-clippy/master/index.html#/unnecessary_map_or

```
__CARGO_FIX_YOLO=1 cargo clippy --fix  --all-targets --workspace --exclude gstreamer-player --exclude i-slint-backend-linuxkms --exclude uefi-demo --exclude ffmpeg -- -A clippy::all -W clippy::unnecessary_map_or

cargo fmt --all
```
2025-02-07 09:02:31 +01:00
Yuri Astrakhan
5356fdcf89 Fix clippy issues, plus a few manual cleanups
* Run `cargo clippy --fix`
*  `BackendSelector` is easier to instantiate with auto `Default`
2025-02-06 17:28:51 +01:00
Yuri Astrakhan
61de4d56b0 Fix all format arg inlining
Ran this command:

```shell
cargo clippy --fix -- -A clippy::all -W clippy::uninlined_format_args
```
2025-02-06 10:16:20 +01:00
Tobias Hunger
f4b09226c4 lsp: Wire up more renaming for component, structs and enums
... and their usages and imports/exports

Use the token_info to do this.
2025-01-17 10:27:12 +01:00
Tobias Hunger
0a648dfa41 lsp: Move token_info.rs from language to common 2025-01-17 10:27:12 +01:00
Tobias Hunger
f4cca6ef24 live-preview: Do not race the LSP on config changes
When the LS gets new configuration, it will now
start to re-parse all files, sending `SetContents`
messages as it discovers files in new locations (e.g.
due to library path changes).

The live-preview will ignore those: Nothing it knows
depends on those paths.

Finally the LS will send a `SetConfiguration` request,
which will unconditionally trigger a re-rendering
in the live-preview. At this point all files
are known and the request should succeed.
2025-01-13 13:10:11 +01:00
Tobias Hunger
2bb1ec1a9d lsp: Invalidate all files in DocumentCache when config changes
We need to re-evaluate all files as the library/include resolution has changed.
2025-01-13 13:10:11 +01:00
Tasuku Suzuki
346d1c2df3 Fix typos
Ran `typos .` and fixed all typos that do make sense.
https://crates.io/crates/typos
2025-01-13 08:35:20 +01:00
Tobias Hunger
cfb2324526 lsp: Rename structs and enums
... but only when directly on the name of the struct
when it is declared.
2025-01-07 16:18:46 +01:00
Tobias Hunger
6b4db19fb0 lsp: Extract common code needed to rename a DeclaredIdentifier 2025-01-07 16:18:46 +01:00
Olivier Goffart
10510be232 LSP: Document symbol: make sure the selectionRange is contained in the full range
Otherwise we get a lot of error in vscode such as:

```
Error: selectionRange must be contained in fullRange
	at Gd.validate (file:///snap/code/178/usr/share/code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:109:33728)
	at new Gd (file:///snap/code/178/usr/share/code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:109:33936)
	at Ke (/home/olivier/.vscode/extensions/slint.slint-nightly-2025.1.109/out/extension.js:35:72279)
	at Ke (/home/olivier/.vscode/extensions/slint.slint-nightly-2025.1.109/out/extension.js:35:72456)
	at o (/home/olivier/.vscode/extensions/slint.slint-nightly-2025.1.109/out/extension.js:35:46654)
	at Object.$P [as map] (/home/olivier/.vscode/extensions/slint.slint-nightly-2025.1.109/out/extension.js:35:46740)
	at Object.Se [as asDocumentSymbols] (/home/olivier/.vscode/extensions/slint.slint-nightly-2025.1.109/out/extension.js:35:72246)
	at c (/home/olivier/.vscode/extensions/slint.slint-nightly-2025.1.109/out/extension.js:39:56055)
	at async uI.provideDocumentSymbols (file:///snap/code/178/usr/share/code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:138:126457)
[Error - 11:41:30 AM] Request textDocument/documentSymbol failed.
```

We shouldn't need to trim the whitespace from the node range.
Because the selected range might be the end of the range and it might
end up being trimmed.

In normal cases, whitespace are not part of the Node anyway
2025-01-06 10:47:05 +01:00
Olivier Goffart
61b4dcf233
Workaround panic of autocompletion of import with unicode
(As seen in the crash reporter)

Eg:
```
thread 'LanguageServer' panicked at tools/lsp/language/completion.rs:731:17:
byte index 4 is not a char boundary; it is inside '🍒' (bytes 2..6) of `./🍒🍓🍇"`
```

This can happen because offset might not be on a char boundary because
of the utf-16 / utf-8 mismatch.
2025-01-02 12:17:38 +01:00
Tobias Hunger
b7e1fb9d18
lsp: Offer to populate empty documents (#4767) 2024-12-11 19:33:24 +01:00
Tobias Hunger
b0fe8d6cfb live-preview: Handle document deletion better 2024-11-27 18:04:54 +01:00
Olivier Goffart
e44f7d7a4c LSP: fix reloading loaded dependencies
The change in https://github.com/slint-ui/slint/pull/6747
invalidated the cache, but it was only reloaded when one of the dependent was reloaded.
We need to reload the cache for all open file so that LSP feature continue to work on
open document even if they get no changes
2024-11-26 14:27:56 +01:00
Olivier Goffart
5b3ea5cdd5 LSP: record dependencies and invalid all dependents when a dependencies changes
Fixes #5797
2024-11-14 14:35:22 +01:00
Olivier Goffart
9cbc4aa6ce LSP: report that we use UTF-8 to client that supports it
Version 3.17 of the spec added a `position_encoding` field in the
ServerCapabilities, so use that.

Note that the spec says that UTF-16 is mendatory, and vscode only
support utf-16, meaning we currently have a bug when having non-ascii in
the source (#5669)
2024-11-08 12:13:26 +01:00
Olivier Goffart
e3ea25f48c LSP: Signature Help 2024-11-06 13:27:29 +01:00
Milian Wolff
69c68b22b2 Also wrap langtype::Type::Struct in an Rc
This makes copying such types much cheaper and will allow us to
intern common struct types in the future too. This further
drops the sample cost for langtype.rs from ~6.6% down to 4.0%.

We are now also able to share/intern common struct types.

Before:
```
  Time (mean ± σ):      1.073 s ±  0.021 s    [User: 0.759 s, System: 0.215 s]
  Range (min … max):    1.034 s …  1.105 s    10 runs

        allocations:            3074261
```

After:
```
  Time (mean ± σ):      1.034 s ±  0.026 s    [User: 0.733 s, System: 0.201 s]
  Range (min … max):    1.000 s …  1.078 s    10 runs

        allocations:            2917476
```
2024-10-28 09:39:54 +01:00
Milian Wolff
0f6c3a4fd7 Use SmolStr in more places of the compiler infrastructure
This removes a lot of allocations and speeds up the compiler step
a bit. Sadly, this patch is very invasive as it touches a lot of
files. That said, each individual hunk is pretty trivial.

For a non-trivial real-world example, the impact is significant,
we get rid of ~29% of all allocations and improve the runtime by
about 4.8% (measured until the viewer loop would start).

Before:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):     664.2 ms ±   6.7 ms    [User: 589.2 ms, System: 74.0 ms]
  Range (min … max):   659.0 ms … 682.4 ms    10 runs

        allocations:            4886888
        temporary allocations:  857508
```

After:
```
Benchmark 1: ./target/release/slint-viewer ../slint-perf/app.slint
  Time (mean ± σ):     639.5 ms ±  17.8 ms    [User: 556.9 ms, System: 76.2 ms]
  Range (min … max):   621.4 ms … 666.5 ms    10 runs

        allocations:            3544318
        temporary allocations:  495685
```
2024-10-17 18:04:58 +02:00
Tobias Hunger
5519efcd5a lsp: Use constant instead of repeating a slint/showPreview 2024-10-15 16:27:41 +02:00
Tobias Hunger
2008136316 lsp: Clean up language::test module use 2024-10-15 16:27:25 +02:00
Tobias Hunger
e726ee7df4 lsp: Consitently use the DocumentCache from common 2024-10-15 09:42:51 +02:00
Tobias Hunger
e6db88afbd live-preview: Reload when image resources change on disk
Reload the preview whenever the image resources change
on disk.
2024-10-14 13:41:01 +02:00
Tobias Hunger
3d3bf9f01b lsp: Pass invalidation of files on to live-preview 2024-10-10 09:31:11 +02:00
Tobias Hunger
e62d9e0695 lsp: Remember which files are open in the editor
... and ignore them on file change notifications: The
Editor manages the file content, so we do not need to
care for the on-disk content for these files.
2024-10-10 09:31:11 +02:00
Tobias Hunger
d87833a6bd lsp: Add a filesystem watch request to our LS
Get a notification of any file change/deleteion. This feels like
overdoing it a bit, but we need to reload when resources change
and those can be anything.
2024-10-10 09:31:11 +02:00
Tobias Hunger
d257bcdc9a lsp: Make live-preview preview on the type, not the base type
When writting

```slint
export component Foo inherits Bar { }
  
```

then highlight this element when the cursor is on Foo, not on Bar.

Fixes: #6409
2024-10-07 19:12:57 +02:00
Tobias Hunger
f25b180ff7 live-preview: Fix wrong highlight color for layouts
Elements are specified by theit path and start offset. So
request a highlight for that position, not for some random
position somewhere inside the Element to highlight.

That way looking up whether the element is actually
a layout or not does work -- and there is no fallback to
the "it's not a layout" case.
2024-09-10 13:31:52 +02:00
Tobias Hunger
cab41c3d0c lsp: Use more TextSize
I got carried away, I replaced `u32` with `TextSize` in one place
because that's what I got and I did not want to convert... and
then I fixed the fallout.

No functional change is intended in any of this.

FIXUP
2024-09-10 13:31:52 +02:00
Olivier Goffart
ee42f967a6 LSP: hover (tooltip) support 2024-08-28 20:50:25 +02:00
Olivier Goffart
0f2af817a0 LSP: move token_info code to its own module 2024-08-28 20:50:25 +02:00
Tobias Hunger
d28b13cbe5 lsp: Remove explicit rowan dependency from LSP
... by implementing more helpers on `parser::SyntaxNode` and
`parser::SyntaxToken`.
2024-08-26 14:51:47 +02:00
Tobias Hunger
0f0b76e952 lsp: Clippy fixes 2024-08-23 18:58:44 +02:00
Tobias Hunger
1a306dd155 live-preview: Use TextRange and TextSize in property information
The Properties are no longer sent out straight to the editor, so
we do not need to convert our internal `TextRange` and `TextSize`
to `lsp_types::Range` and `lsp_types::Position`.

We are noweadys turning that straight back into offsets -- which is
just another name for `TextSize` (or pairs of offsets).
2024-08-23 18:58:44 +02:00
Tobias Hunger
1c447db8ca lsp: Build without SourceFileInner::version()
... in preparation to removing that functionality.
2024-08-21 16:55:13 +02:00
Tobias Hunger
0bb3ad14e2 live-preview: Collect data on the file version diagnostics apply for
Collect that data in the fallback callback function.
2024-08-21 16:55:13 +02:00
Tobias Hunger
4e68aa1510 lsp: Remove custom commands for property handling
These commands are not needed anymore since we integrated
the property editor into the live preview.

Move the properties code out of `common` and into `preview`
for good measure.
2024-08-08 16:39:37 +02:00
Olivier Goffart
3c08a71d21 LSP: refactor error reporting of request
So we have accurate error code reported to the LSP when a request fails
2024-08-08 12:05:52 +02:00
Olivier Goffart
4c0bfa269d LSP: refactor send_notification to use the Notification trait
This ensure there is no typo in the method name
2024-07-23 14:18:39 +02:00
Tobias Hunger
9afb3812bf lsp: Move properties.rs into common 2024-06-25 19:51:59 +02:00
Tobias Hunger
3e117c1910 lsp: Modernize properties.rs
... to prepare moving it into common.
2024-06-25 19:51:59 +02:00
Tobias Hunger
1cc63ea428 lsp: Borrow new_name in rename_component 2024-06-21 14:40:50 +02:00
Tobias Hunger
20c6393ca3 janitor: CLippy fixes 2024-06-14 16:59:39 +02:00
Tobias Hunger
67200c81ff live-preview: Compile-test element moves in can_move function
Compile test the result of an element move in the `can_move` function
to catch all cases where the move would be problematic.

Shuffle some test code around to allow for testing this new
functionality.
2024-06-14 16:59:39 +02:00