Commit graph

65 commits

Author SHA1 Message Date
Olivier Goffart
f6e4f16a14 LSP: Dont detect slint::slint! as slint macro in comments or stings
We already detected that `slint!` in a comment should not be interpreted
as a slint macro, but that detection failed for `slint::slint!` or if
`slint` was twice in the same line.
2023-02-09 08:52:51 +01:00
Olivier Goffart
3a1c515200 LSP: Fix calculation of element position
Basically same as e88b07997f but in the
set_binding_command function.
(made the code more similar to remove_binding_command, I think the two
function should be merged in the future)

This fix editing binding within the root component when it inherits from
something.
2023-01-25 10:27:40 +01:00
Tobias Hunger
e88b07997f LSP: Fix calculation of element position
Use map_node as that trimms out stray whitespaces.
2023-01-24 21:02:17 +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
Olivier Goffart
32c99177b8 LSP: fix document outline with vscode
Currently, the reported range is the range of the root element, which
doesn't include the name of the component itself.
While the Name of the component itself is used as the selection range.
Vscode assrts that the selection range is within the range:

```
ERR selectionRange must be contained in fullRange: Error: selectionRange must be contained in fullRange
```

So use the full component range for the range instead
2023-01-23 15:51:01 +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
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
f0b4bce3d6 janitor: Make LSP clippy clean 2023-01-16 14:42:36 +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
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
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
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
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
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
59380e8a25 lsp: Improve ProgressReporter API
Make finish() consume self.
2022-12-05 15:13:14 +01:00
Tobias Hunger
2c472a34ab lsp: Reset token on call to finish in ProgressReporter
We would send the end token twice otherwise as the Drop trait will send
an end report if none was sent before.
2022-12-05 15:13:14 +01:00
Tobias Hunger
3c05dfe029 lsp: Report that we send progress information 2022-12-05 15:13:14 +01:00
Tobias Hunger
b6f36e7ce1 lsp: Add removeBinding command
Add a command to remove a proerty binding from an element.
2022-12-01 14:04:30 +01:00
Tobias Hunger
0dee4fa486 lsp: Add option to report progress information 2022-12-01 11:15:57 +01:00
Olivier Goffart
017e203653 LSP: don't query configuration if the client don't advertize we can do it 2022-11-28 15:59:53 +01:00
Tobias Hunger
f54c2d188b LSP: Cleanup error handling 2022-11-23 13:19:07 +01:00
Tobias Hunger
86f6636815 LSP: Drop document_cache handle before sending more requests
This works around the setBinding calling back into the client, which
would cause the LSP to panic as there already was a mutable reference to
the document cahce held.
2022-11-23 13:19:07 +01:00
Tobias Hunger
edd4e81033 lsp: Add setBinding custom command 2022-11-21 15:01:09 +01:00
Olivier Goffart
2523a6b74c lsp: Make the LSP async 2022-11-21 09:13:21 +01:00
Olivier Goffart
ab4c6bd0e9 Janitor: fix araning when building the vscode extension 2022-11-17 20:02:39 +01:00
Olivier Goffart
baf1e6ef0f Polish the highlight of the preview in the LSP 2022-11-17 12:23:23 +01:00
Olivier Goffart
1884750960 WIP: LSP: highlight selected element in the preview 2022-11-17 12:23:23 +01:00
Olivier Goffart
cbe2d6d631 LSP: add a setting to change the style
... and the include paths
2022-11-13 14:22:27 +01:00
Tobias Hunger
8f29f22c6c lsp: Use proper LSP types for queryProperties 2022-11-11 20:19:35 +01:00
Tobias Hunger
56750e0287 lsp: Report source version in queryPropertyresponse
Also make `source_uri` non-optional: We get an Uri with the request, so
we always have one.
2022-11-11 19:44:08 +01:00
Tobias Hunger
0b97c04c17
lsp: Define a helper struct to map offsets to positions (#1839)
Update the code to use this.
2022-11-11 15:35:29 +01:00
Tobias Hunger
67712d2b46 LSP: Keep current document version around
This will become helpful when actually updating the documents as it can
help to detect races.
2022-11-11 10:34:18 +01:00
Tobias Hunger
4c8b9856b5 lsp: Borrow Position and Url
No need to transfer ownership!

Also use `Url` directly instead of wrapping that into a
`TextDocumentIdentifier`. That way we can burrow the URL and do not need
to clone a `Url` into a `TextDocumentIdentifier` just so we can borrow
that.
2022-11-03 14:54:45 +01:00
Tobias Hunger
268edcf07d LSP: Unify LSP server initialize result
Report the same LSP server `InitializeResult` to all users. This
improves on what was reported from the WASM LSP flavor to its users
before.
2022-11-03 11:41:54 +01:00
Olivier Goffart
d84516b843 lsp: janitor: return None instead of Some with an empty vec when the operation is not supported
https://github.com/slint-ui/slint/pull/1809#pullrequestreview-1165414494
2022-11-03 08:29:29 +01:00
Tobias Hunger
217fa9a337 LSP: features overhaul
* Do not use wasm build in conjunction with `preview` to keep code lense
  support on. Add `preview-lense` feature instead.
* Improve which parts of the LSP are kept based on these features.

With this patch a LSP built for the online-editor is about 10KB smaller
than before.
2022-11-02 15:48:26 +01:00
Olivier Goffart
9fea518ee8 lsp: fix compiler warning when the preview is disabled
Warnings about unused parameters.
Just disable the whole function instead
2022-10-28 11:47:05 +02:00
Olivier Goffart
659cb3a06c LSP: fix property call on invalid base or non-main component
- We should not panic if the base type is invalid
 - We should try to keep bindings in the Element even if the base type
   is invalid
 - Fix querying the element at a position in case it is not in the last
   component of a file
2022-10-21 12:50:42 +02:00
Simon Hausmann
bd412623ab
Online editor: Fix binding expression text shown in the properties view (#1753)
Use the zero-line based lsp range/position types for the QueryProperties
lsp command results and convert them to monaco editor ranges for correct
text extraction.
2022-10-20 15:49:23 +02:00
Tobias Hunger
c994502ce9 LSP: Improve data reported by queryProperties
Report more and better ranges for the expression in an property.
2022-09-22 10:51:26 +02:00
Tobias Hunger
04420b9e65 lsp: Polish the queryProperties command
Make it not error out when no element is selected.
2022-09-22 10:51:26 +02:00
Tobias Hunger
deee971b76 Implement suggestions from @ogoffart 2022-09-02 17:48:31 +02:00
Tobias Hunger
75b02530a9 LSP: Add tests for element_at_position and get_properties 2022-09-02 17:48:31 +02:00