Commit graph

34 commits

Author SHA1 Message Date
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
J-P Nurmi
c5248c005e Allow specifying paths for @library imports 2023-10-20 16:47:00 +02:00
Tobias Hunger
caee0b2f9d janitor: Fix a semi-random selection of clippy warnings
Nothing serious in there.
2023-10-16 13:44:37 +02:00
J-P Nurmi
400404623d LSP: fix typo in "slint.includePaths" config 2023-10-12 11:10:14 +02:00
Tobias Hunger
0ff8e2cdb6 compiler: Rework path handling
Add some code to do platform-independent path processing.

This is necessary aas WASM does e.g. not have any absolute paths and
such and the compiler tended to produce wrong results in that case.

Side-effect: We no longer need to depend on `dunce`
2023-10-10 20:04:47 +02:00
J-P Nurmi
8284674d4d VSCode: add "Remove element" code action 2023-09-08 16:38:16 +02:00
Olivier Goffart
24d3ac9e0d LSP: handle empty string as component name in the showPreview command
Somehow the vscode extension started to send an empty string for the showPreview
command instead of nothing. Resulting in the showPreview command from the command
palette not working anymore.

Fix #3412
2023-09-07 15:01:59 +02:00
J-P Nurmi
5ce11e302a
vscode: add "wrap in element" code action (#3420) 2023-09-07 12:11:14 +02:00
Tobias Hunger
3023393fa1 lsp: Use same conversion from URL to PathBuf everywhere
This makes sure paths match up with each other. Highlighting broke for
me since the paths in the DocumentCache were canonicalized while the path
the LSP wanted the preview to highlight was not.
2023-08-31 13:08:30 +02:00
Tobias Hunger
d5cc147644 lsp: Use one common Error type (where possible) 2023-08-30 10:31:55 +02:00
Tobias Hunger
4dda627d14 LSP: Move code around
No behavior should change in this patch!

Move all the code directly related to the LSP into a `language` module,
with `server_loop.rs` becoming `language.rs`, managing that module.

All the preview related code is moved into `preview`, with `preview.rs`
basically forwarding to `native.rs` and `wasm.rs`.

Code accessed from both `language` and `preview` stayed where it was.
2023-08-28 13:34:35 +02:00
Renamed from tools/lsp/server_loop.rs (Browse further)