Skip to content

Commit

Permalink
lsp: Add experimental feature flag and forward it to preview UI
Browse files Browse the repository at this point in the history
  • Loading branch information
hunger committed Jan 19, 2024
1 parent 610dc13 commit ad72f54
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
"vscode:prepublish": "npm run build:wasm_lsp-release && npm run compile && shx echo \"GPL-3.0-only OR LicenseRef-Slint-commercial\" > LICENSE.txt",
"build:lsp": "cargo build -p slint-lsp",
"build:lsp-release": "cargo build --release -p slint-lsp",
"build:wasm_experimental_lsp": "env-var wasm-pack build --dev --target web ../../tools/lsp --out-dir {{npm_config_local_prefix}}/out -- --no-default-features --features backend-winit,renderer-femtovg,preview,experimental",
"build:wasm_lsp": "env-var wasm-pack build --dev --target web ../../tools/lsp --out-dir {{npm_config_local_prefix}}/out -- --no-default-features --features backend-winit,renderer-femtovg,preview",
"build:wasm_lsp-release": "env-var wasm-pack build --release --target web ../../tools/lsp --out-dir {{npm_config_local_prefix}}/out -- --no-default-features --features backend-winit,renderer-femtovg,preview",
"compile": "node ./esbuild.js",
Expand Down
1 change: 1 addition & 0 deletions tools/lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ name = "slint_lsp_wasm"
[features]
# Remove once MSRV > 1.70 (1.70 does not yet work!):
slint = []
experimental = []
backend-qt = ["slint/backend-qt", "preview"]

backend-winit = ["slint/backend-winit", "preview"]
Expand Down
4 changes: 3 additions & 1 deletion tools/lsp/preview/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ pub fn create_ui(style: String) -> Result<PreviewUi, PlatformError> {
model
});

ui.on_style_changed(super::change_style);
ui.set_known_styles(style_model.into());
ui.set_current_style(style.clone().into());
#[cfg(feature = "experimental")]
ui.set_experimental(true);

ui.on_style_changed(super::change_style);
ui.on_show_document(|url, line, column| {
use lsp_types::{Position, Range};
let pos = Position::new((line as u32).saturating_sub(1), (column as u32).saturating_sub(1));
Expand Down
15 changes: 8 additions & 7 deletions tools/lsp/ui/main.slint
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ struct Selection {
}

export component PreviewUi inherits Window {
in property <[string]> known-styles;
in property <[Diagnostics]> diagnostics;
in property <string> status-text;
in property <component-factory> preview-area;
in property <[Selection]> selections;
in property <bool> show-preview-ui : true;
in property <[string]> known-styles;
in property <bool> experimental: false;
in property <bool> show-preview-ui: true;
in property <component-factory> preview-area;
in property <string> status-text;
in-out property <string> current-style;
out property <bool> design-mode;

callback style-changed();
callback show-document(/* url */ string, /* line */ int, /* column */ int);
callback select-at(/* x */ length, /* y */ length);
callback select-into(/* x */ length, /* y */ length);
callback show-document(/* url */ string, /* line */ int, /* column */ int);
callback style-changed();

property <length> border: 20px;

Expand Down Expand Up @@ -95,7 +96,7 @@ export component PreviewUi inherits Window {
viewport-height: i-drawing-rect.height;

i-drawing-rect := Rectangle {
background: Colors.white;
background: root.experimental ? Colors.pink : Colors.white;

width: max(i-scroll-view.visible-width, i-resizer.width + i-scroll-view.border);
height: max(i-scroll-view.visible-height, i-resizer.height + i-scroll-view.border);
Expand Down
1 change: 1 addition & 0 deletions tools/slintpad/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"main": "index.js",
"scripts": {
"build": "npm run clean && npx vite build",
"build:wasm_experimental_lsp": "wasm-pack build --dev --target web ../lsp -- --no-default-features --features backend-winit,renderer-femtovg,preview,experimental",
"build:wasm_lsp": "wasm-pack build --dev --target web ../lsp -- --no-default-features --features backend-winit,renderer-femtovg,preview",
"build:wasm_lsp-release": "wasm-pack build --release --target web ../lsp -- --no-default-features --features backend-winit,renderer-femtovg,preview",
"build:wasm_interpreter": "wasm-pack build --dev --target web ../../api/wasm-interpreter -- --features console_error_panic_hook",
Expand Down

0 comments on commit ad72f54

Please sign in to comment.