Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsp: Offer to populate empty documents #4767

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hunger
Copy link
Member

@hunger hunger commented Mar 6, 2024

So when snippets do not work: Let's try something else to get started from scratch:-)

image

@hunger
Copy link
Member Author

hunger commented Mar 6, 2024

Of course this only shows while the file does not contain anything but whitespace:-)

Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I like it.

I think only one option is enough though.
Probably the Hello World like so:

import { AboutSlint, VerticalBox } from "std-widgets.slint";

export component MainWindow inherits Window {
    VerticalBox {
        alignment: start;
        Text { text: "Hello World!"; }
        AboutSlint { preferred-height: 150px; }
    }
}

Make it a window by default. But keep it as short as possible while still have something somehow visual.

Did you try if it worked in a slint!{} macro?

tools/lsp/language.rs Outdated Show resolved Hide resolved
tools/lsp/language.rs Outdated Show resolved Hide resolved
@hunger
Copy link
Member Author

hunger commented Mar 6, 2024

We need to remember which area of the document we are actually touching... otherwise this just can not work.

@hunger
Copy link
Member Author

hunger commented Aug 20, 2024

The latest set of commits add an ASCII start-of-text and end-of-text byte around the area covered by slint! macros.

It then limits the actions to the range between these markers (if present). That way it works with the slint! macro

BUT there is a bug still: When you remove the slint macro, the LSP will not update its document cache accordingly and will insist that the code lense needs to continue to exist. That needs fixing :-/

This is so we can use the ASCII Start-of-Text and End-of-Text
control characters as markers in files containing blocks of Slint
code embedded into other things.

SOT and EOT are ASCII control characters, so they are one byte and
thus will basically fit into whatever markup is used to separate
Slint code form whatever else surrounds it.
@hunger
Copy link
Member Author

hunger commented Nov 29, 2024

We have document invalidation now, so I needed to rebase this PR and take a look again.

The code lens now goes away again when the slint! macro gets removed.

@hunger
Copy link
Member Author

hunger commented Nov 29, 2024

... and now we actually invalidate rust files that loose their slint! macro :-)

Add `Start-of-text` ASCII value in the place of the opening brace
of the slint macro and `End-of-text` in place of the closing bracket.

ASCII chars are one byte, so they will always work :-)
... so we do not keep stray code lenses around (and probably
not end up having other issues down the line).
Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No tests?

content = match i_slint_compiler::lexer::extract_rust_macro(content) {
Some(content) => content,

let action = if path.extension().map_or(false, |e| e == "rs") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let action = if path.extension().map_or(false, |e| e == "rs") {
let action = if path.extension().is_some_and(|e| e == "rs") {

FileAction::InvalidateFile => {
if let Some(ctx) = ctx {
ctx.server_notifier.send_message_to_preview(
common::LspToPreviewMessage::FileLost { url: url.clone() },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileLost? How can we lose a file? 😉

command: Some(create_populate_command(
text_document.uri.clone(),
version.clone(),
"Start with fixed size Window".to_string(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure we need that. I don't think we should confuse the user with too many choices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants