slint-ui / slint

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

Bug: LSP server crash in Visual Studio Code if preview is started for GUI in if statement in GridLayout. #3729

Closed BoolPurist closed 11 months ago

BoolPurist commented 11 months ago

Used platform:

Happens with Visual studio code extension I foucus on desktop development for my application

Using following extension: "Slint" Version: 1.2.2 Identifier: slint.slint

My OS:

OS: Fedora Linux 38 (Cinnamon) x86_64 Kernel: 6.5.7-200.fc38.x86_64

Programming language

Rust

Problem

LSP sever crashes if the preview of the GUI is started in Visual studio Code. I seem to happen if I wrap my imported element in a if statemt which produces a Row within a GridLayout.

Steps to reproduce

  1. I click on the "Show Preview" button in Visaul Studio Code to show a preview of the GUI, slint files, posted as code snippets below.
  2. No preview is shown.
  3. I get the following error message from the slint LSP Server.

Error message in Slint LPS output:

thread 'main' panicked at 'Error caught at element lookup time', internal/compiler/passes/lower_layout.rs:101:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[Error - 12:18:45 AM] Connection to server got closed. Server will not be restarted.
The Slint Language Server crashed. This is a bug.
Please open an issue on https://github.com/slint-ui/slint/issues

What I expected

I want to see a preview window for the GUI.

Slint code

Code of main.slint file Note: Left many other parts out and it stills causes the error.

import {CiffDiffGUI, CiffDiffGUIProperty} from "date_diff.slint";

export enum CalcDiffStatus{ 
  Success,
  Failed,
  NotOnce,
}

export component App inherits Window {
    background: #8384a2;
    preferred-height: 640px;
    preferred-width: 480px;

    in property <CalcDiffStatus> status: CalcDiffStatus.Success;
    in property <CiffDiffGUIProperty> calc_diff_result;

            GridLayout {
                  if status == CalcDiffStatus.Success : Row {

                    CiffDiffGUI {input: calc_diff_result;}
                  }
                }

}

Code of date_diff.slint file which imported by the main.slint file:

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

export struct CiffDiffGUIProperty {
    is_negative: bool,
    secs: string,
    mins: string,
    hours: string,
    day: string,
    year: string,
}

export component CiffDiffGUI inherits Rectangle  {
    in property <CiffDiffGUIProperty> input: {hours: "02", mins: "45", hours: "12", is_negative: true, day: "125", year: "1899"};
    property <length> sign-size: 70px;
    background: #319e5f;

    HorizontalBox { 
      padding: 5px;
      if root.input.is_negative : Text {
        text: "-";
        color: #ff0000;
        font-size: sign-size;
      }
      if !root.input.is_negative : Text {
        text: "+";
        color: #00e400;
        font-size: sign-size;
      }
      VerticalBox {
        Text {
          text: input.year + "." + input.day;
          horizontal-alignment: TextHorizontalAlignment.center;
        }
        Text {
          text: input.hours + ":" + input.mins + ":"  + input.day;
          horizontal-alignment: TextHorizontalAlignment.center;
        }
        Rectangle {
          border-radius: 2px;
          border-width: 2px;
          border-color: #000;
          background: #8d893a;
          Text {
            text: "Years.Months";
            horizontal-alignment: TextHorizontalAlignment.center;
          }
        }
        Text {
          text: "Hours:Minutes:Seconds";
          horizontal-alignment: TextHorizontalAlignment.center;
        }
      }
    }
}
ogoffart commented 11 months ago

Thanks for the bug report. I can reproduce it.

Simpler testcase:

export component Demo {
    GridLayout {
        if false: Row {}
    }
}
ogoffart commented 11 months ago

Note: if is currently not supported in GridLayout. Next version will show a proper error instead of a panic. Thanks for reporting the panic.