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 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 0 additions & 75 deletions examples/maps/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,81 +16,6 @@ use std::rc::Rc;

const TILE_SIZE: isize = 256;

slint::slint! {
import { Slider } from "std-widgets.slint";
export struct Tile { x: length, y: length, tile: image}

export component MainUI inherits Window {
callback flicked(length, length);
callback zoom-changed(float);
callback zoom-in(length, length);
callback zoom-out(length, length);
callback link-clicked();
min-height: 500px;
min-width: 500px;

out property <length> visible_width: fli.width;
out property <length> visible_height: fli.height;

in-out property <float> zoom <=> sli.value;

in property <[Tile]> tiles;

public function set_viewport(ox: length, oy: length, width: length, height: length) {
fli.viewport-x = ox;
fli.viewport-y = oy;
fli.viewport-width = width;
fli.viewport-height = height;
}

VerticalLayout {
fli := Flickable {
for t in tiles: Image {
x: t.x;
y: t.y;
source: t.tile;
}
flicked => {
root.flicked(fli.viewport-x, fli.viewport-y);
}
TouchArea {
scroll-event(e) => {
if e.delta-y > 0 {
root.zoom-in(self.mouse-x + fli.viewport-x, self.mouse-y + fli.viewport-y);
return accept;
} else if e.delta-y < 0 {
root.zoom-out(self.mouse-x + fli.viewport-x, self.mouse-y + fli.viewport-y);
return accept;
}
return reject;
}
}
}

HorizontalLayout {
sli := Slider {
minimum: 1;
maximum: 19;
released => {
zoom-changed(self.value);
}
}
}
}

Text {
text: "Map data from OpenStreetMap";
x: fli.x + (fli.width) - (self.width) - 3px;
y: fli.y + (fli.height) - (self.height) - 3px;
TouchArea {
clicked => {
root.link-clicked();
}
}
}
}
}

#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
struct TileCoordinate {
z: u32,
Expand Down
15 changes: 13 additions & 2 deletions internal/compiler/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn lex_whitespace(text: &str, _: &mut LexState) -> usize {
let mut len = 0;
let chars = text.chars();
for c in chars {
if !c.is_whitespace() {
if !c.is_whitespace() && !['\u{0002}', '\u{0003}'].contains(&c) {
break;
}
len += c.len_utf8();
Expand Down Expand Up @@ -415,13 +415,24 @@ fn test_locate_rust_macro() {
/// string to preserve line and column number.
pub fn extract_rust_macro(rust_source: String) -> Option<String> {
let core::ops::Range { start, end } = locate_slint_macro(&rust_source).next()?;
eprintln!("slint macro covers offsets: {start} - {end}");
let mut bytes = rust_source.into_bytes();
for c in &mut bytes[..start] {
if *c != b'\n' {
*c = b' '
}
}
for c in &mut bytes[end..] {

if start > 0 {
eprintln!("Placed SOT at {}", start - 1);
bytes[start - 1] = 2;
}
if end < bytes.len() {
eprintln!("Placed EOT at {}", end);
bytes[end] = 3;
}

for c in &mut bytes[end + 1..] {
if *c != b'\n' {
*c = b' '
}
Expand Down
Loading
Loading