slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.55k stars 601 forks source link

VSCode live preview not working #3412

Closed fuzing closed 1 year ago

fuzing commented 1 year ago

We're unable to get even the simplest live preview to work with VS-code under linux

This simple demo runs fine with cargo run/build/etc, but the live-preview in vs-code does not.

When in the ui/demo.slint file (below), and using: Slint: Show Preview from the VS code command palette, the following error appears in the problems tab:

Syntax error: expected identifier [Ln 19, Col 37] Where line number 19 is after EOF for the ui/demo.slint file

No preview window appears

Dev Machine Config: i9 X86_64 - 64GB memory Ubuntu 22.04 with current updates rustc and cargo 1.71.1 VS code slint plugin v1.2.0 (nightly also fails in the same way)

// ui/demo.slint file
import { Button, VerticalBox } from "std-widgets.slint";

export component DemoWindow inherits Window {
    VerticalBox {
        alignment: start;
        Text {
            text: "Hello World!";
            font-size: 2rem;
            horizontal-alignment: center;
        }
        HorizontalLayout {
            alignment: center;
            Button { text: "OK"; }
        }
    }
}
// src/bin/demo.rs file
slint::include_modules!();

fn main() {
    let demo_window = DemoWindow::new().unwrap();
    demo_window.run().unwrap();
}
// build.rs
fn main() {
   slint_build::compile("ui/demo.slint").unwrap();
}
# extract from Cargo.toml with relevant info
[package]
name = "demo"
version = "0.1.0"
edition = "2021"

[dependencies]
slint = "1.2.0"

[build-dependencies]
slint-build = "1.2.0"
tronical commented 1 year ago

Hi! Thanks for the report. Would it be possible for you the attach the exact file that reproduces this for you? (Copy and paste from the issue produces a file that works for me)

I suspect that it's something perhaps related to the content, maybe some stray BOM marker or so.

Alternatively, if you clone the Slint repo and open examples/gallery/gallery.slint and click on "show preview", do you get the same error?

fuzing commented 1 year ago

Just tried cloning the repo and got the same error (also sent you my file via a separate email).

Just in case, here are my VS-code specs:

Version: 1.81.1 Commit: 6c3e3dba23e8fadc360aed75ce363ba185c49794 Date: 2023-08-09T22:18:39.991Z Electron: 22.3.18 ElectronBuildId: 22689846 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Linux x64 6.2.0-31-generic

tronical commented 1 year ago

Okay, this is really bizarre. The demo.slint that you sent me works for me, too - on a stock Ubuntu 23.04 (but 22.04 should not make a difference). The fact that you see this also on gallery.slint excludes the possibility of this being a corrupted file or so.

Since you cloned the repo, could you try the following?

cargo run --bin slint-viewer -- ./examples/gallery/gallery.slint

What's the output of the locale command for you?

ogoffart commented 1 year ago

I can reproduce: This happens when using the "Slint: show preview" from the command palette, but not the preview lense to preview a single component.

Thanks for reporting the bug

tronical commented 1 year ago

Ahh, it's the command from the command palette that's not working. Indeed!

tronical commented 1 year ago

So the best workaround at this point is not to use the command from the palette but to click on "show preview" via the code sense:

Screenshot 2023-09-06 at 14 39 51
fuzing commented 1 year ago

Appreciate the quick followup - that works for me too - an easy workaround! Closing this out in lieu of #3418 - Thank you!

jasper-clarke commented 9 months ago

So the best workaround at this point is not to use the command from the palette but to click on "show preview" via the code sense

There is no code sense for me in my Slint file. I tested and neither the nightly or non-nightly versions work in the command pallete, and there is no code sense above the component. How can i fix this?

hunger commented 9 months ago

@jasper-at-windswept: That suggests that the Slint LSP is not running at all :-/

Can you please check the Output pane in VSCode (bottom). There should be "Slint LSP" in the dropdown on the right side of the top bar. Is there anything suspicious in there about slint-lsp failing to start? I run VScose in a minimum install environment and for me slint-lsp likes to error out due to a missing libinput.

jasper-clarke commented 9 months ago

@hunger ~I just checked and the output shows the below:~ ~[Error - 9:34:30 PM] Slint LSP client: couldn't create connection to server. Message: write EPIPE Code: -32099 [Error - 9:34:30 PM] Restarting server failed Message: write EPIPE Code: -32099 [Error - 9:34:30 PM] The Slint LSP server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information. Could not start dynamically linked executable: /home/allusive/.vscode-oss/extensions/slint.slint-1.4.1-universal/bin/slint-lsp-x86_64-unknown-linux-gnu NixOS cannot run dynamically linked executables intended for generic linux environments out of the box. For more information, see:~

Good News, i resolved the issue of the lsp not starting by setting up Nix-ld. For any other nix users here in the future just add the below to your configuration.nix

  programs = {
    nix-ld = {
      enable = true;
      libraries = with pkgs; [
        stdenv.cc.cc
        fuse3
        openssl
        curl
        libxkbcommon
        libudev-zero
        libappindicator-gtk3
        libdrm
        libglvnd
        libusb1
        libuuid
        libxml2
        libinput
        mesa
        fontconfig
        freetype
      ];
    };
  };

HOWEVER I now have this bug, #4619