slint-lsp 1.16.1

A language server protocol implementation for Slint
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

/// Basic information on a known component
export struct ComponentItem {
    name: string,
    index: int,
    defined-at: string,
    pretty-location: string,
    is-user-defined: bool,
    is-currently-shown: bool,
    is-exported: bool,
}

/// A `category` with a lost of `ComponentItem`s that belong into it.
///
/// File url is either an empty string or a URL to some document
export struct ComponentListItem {
    category: string,
    file_url: string,
    components: [ComponentItem]
}

/// Some `Diagnostics` as raised by the compiler
export enum DiagnosticSummary {
    NothingDetected,
    Warnings,
    Errors,
}

/// What kind of layout we are working with
export enum LayoutKind {
    None,
    Horizontal,
    Vertical,
    Grid,
}

/// A rectangular region that is selected
export struct SelectionRectangle {
    x: length,
    y: length,
    width: length,
    height: length,
    angle: angle,
}

/// A `Selection`
export struct Selection {
    highlight-index: int,
    layout-data: LayoutKind,
    is-interactive: bool,
    is-moveable: bool,
    is-resizable: bool,
}

/// A mark showing where an element will show up when dropped into the current location
export struct DropMark {
    x1: length,
    y1: length,
    x2: length,
    y2: length,
}

export struct SelectionStackFrame {
    width: percent,
    height: percent,
    x: percent,
    y: percent,
    is-in-root-component: bool,
    is-layout: bool,
    is-interactive: bool,
    is-selected: bool,
    type-name: string,
    file-name: string,
    element-path: string,
    element-offset: int,
    id: string,
}

export enum SelectionStackFilter {
    Nothing,
    Layouts,
    Interactive,
    Others,
    LayoutsAndInteractive,
    LayoutsAndOthers,
    InteractiveAndOthers,
    Everything,
}

/// A Range in a source
export struct Range {
    start: int,
    end: int,
}

export struct ColorData {
    r: int,
    g: int,
    b: int,
    a: int,
    text: string,
    short-text: string,
}

export enum PropertyValueKind {
    boolean,
    brush,
    code,
    color,
    enum,
    float,
    integer,
    string,
}

export enum BrushKind {
    solid,
    linear,
    radial,
    conic,
}

export struct GradientStop {
    position: float, // between 0 and 1!
    color: color,
}

/// Data about the property value for use in "simple" mode
export struct PropertyValue {
    display-string: string, // ALLWAYS, its a string description of what is there
    value-bool: bool, // boolean
    is-translatable: bool, // string
    kind: PropertyValueKind, // Defines what to display this as
    value-kind: PropertyValueKind, // If kind == code, then this is the real kind of data
    brush-kind: BrushKind, // brush
    gradient-stops: [GradientStop], // brush
    value-brush: brush, // brush, color
    value-float: float, // float, brush (angle)
    value-int: int, // integer, enum/float (current index into visual_items)
    default-selection: int, // enum/float (default index into visual_items)
    value-string: string, // enum (name), string, brush (palette name or empty)
    visual-items: [string], // enum (enum members), float (units)
    tr-context: string, // string
    tr-plural: string, // string
    tr-plural-expression: string, // string
    code: string, // ALWAYS, empty if property is not explicitly defined
    accessor-path: string, // set for struct members and such
    was-edited: bool, // Used by preview dataonly!
    edited-value: string, // Used in preview dataonly!
}

export struct PropertyValueTable {
    is-array: bool,
    headers: [string],
    values: [[PropertyValue]],
}

/// Important Ranges in the property definition
///
/// The URL and version is the same as in the Element it belongs to
export struct PropertyDefinition {
    definition-range: Range,
    selection-range: Range,
    expression-range: Range,
    expression-value: string,
}

/// The Property Declaration
export struct PropertyDeclaration {
    defined-at: PropertyDefinition,

    source-path: string,
    source-version: int,
    range: Range,
}

/// Information on one Property
export struct PropertyInformation {
    name: string,
    type-name: string,
    value: PropertyValue,
    display-priority: int,
}

/// Grouping for properties
export struct PropertyGroup {
    group-name: string,
    properties: [PropertyInformation],
}

export enum PreviewDataKind {
    Value,
    Json,
    Table,
}

export struct PreviewData {
    name: string,
    has-getter: bool,
    has-setter: bool,
    kind: PreviewDataKind,
}

/// Information on exported components and their properties
export struct PropertyContainer {
    container-name: string,
    container-id: string,
    properties: [PreviewData],
}

/// Information on an Element a Property belongs to
export struct ElementInformation {
    id: string,
    component-name: string,
    type-name: string,
    source-uri: string,
    source-version: int,
    /// The offset within source-uri
    offset: int,
}

export struct PaletteEntry {
    name: string,
    value: PropertyValue,
}

export enum LogMessageLevel {
    Debug,
    Warning,
    Error,
    Note,
}

export struct LogMessage {
    file: string,
    line: int,
    column: int,
    message: string,
    level: LogMessageLevel,
}

/// A node in the outline tree
export struct OutlineTreeNode {
    indent-level: int,
    has-children: bool,
    is-expanded: bool,
    is-last-child: bool,
    element-type: string,
    element-id: string,
    uri: string,
    offset: int,

}

export enum DropLocation {
    onto,
    before,
    after,
}

export global Api {
    // # Properties
    // ## General preview state:
    // enable editing mode
    in property <bool> show-preview-ui: true;
    // std-widgets are used (=> show style dropdown)
    in-out property <bool> uses-widgets;
    in-out property <bool> always-on-top;
    in property <bool> focus-previewed-element;

    // ## Component Data for ComponentList:
    // All the components
    in property <[ComponentListItem]> known-components;
    callback library-search(string);
    // The component currently viewed
    out property <ComponentItem> visible-component;

    // ## Kinds of diagnostics seen in the last compiler run
    in property <DiagnosticSummary> diagnostic-summary;
    // status message text
    in property <string> status-text;

    // ## Style:
    // All the known styles
    in property <[string]> known-styles;
    // The current style
    in-out property <string> current-style;
    // control, but command on macOS
    in-out property <string> control-key-name: "control";

    // ## Log Output
    in-out property <[LogMessage]> log-output;
    in-out property <bool> auto-clear-console: true;

    // ## Drawing Area
    // Borders around things
    pure callback highlight-positions(source-uri: string, offset: int) -> [SelectionRectangle];
    in-out property <Selection> selection;
    in-out property <DropMark> drop-mark;
    // The actual preview
    in-out property <component-factory> preview-area;

    // set to true to resize
    in property <bool> resize-to-preferred-size: false;

    // ## Palette data:
    in-out property <[PaletteEntry]> palettes;
    in-out property <[color]> recent-colors;

    // ## Property Editor
    in-out property <ElementInformation> current-element;
    in-out property <[PropertyGroup]> properties: [
        {
            group-name: "Geometry",
            properties: [
                {
                    name: "width",
                    type-name: "length",
                    value: {
                        kind: PropertyValueKind.float,
                        value-float: 100,
                        visual-items: ["px", "cm", "mm", "in", "pt", "phx"],
                    }
                },
                {
                    name: "height",
                    type-name: "length",
                    value: {
                        kind: PropertyValueKind.float,
                        value-float: 200,
                        visual-items: ["px", "cm", "mm", "in", "pt", "phx"],
                    }
                },
                { name: "z", type-name: "float", value: {
                    kind: PropertyValueKind.float,
                    value-float: 10,
                } },
                {
                    name: "combobox",
                    type-name: "string",
                    value: {
                        kind: PropertyValueKind.enum,
                        value-int: 1,
                        default-selection: 0,
                        visual-items: ["one", "twenty two", "one hundred", "infinite"],
                    }
                },
            ]
        },
        {
            group-name: "Button",
            properties: [
                {
                    name: "text",
                    type-name: "string",
                    value: {
                        is-translatable: true,
                        kind: PropertyValueKind.string,
                    }
                },
                { name: "checkable", type-name: "bool", value: {
                    kind: PropertyValueKind.boolean,
                } },
                { name: "icon", type-name: "image", value: {
                    kind: PropertyValueKind.code,
                } },
                {
                    name: "brush",
                    type-name: "brush",
                    value: { kind: PropertyValueKind.brush, value-brush: Colors.green, value-string: "#00ff00" },
                },
                {
                    name: "text-between",
                    type-name: "string",
                    value: {
                        is-translatable: true,
                        kind: PropertyValueKind.string,
                    }
                },
                {
                    name: "color",
                    type-name: "color",
                    value: { kind: PropertyValueKind.color, value-brush: Colors.green, value-string: "#00ff00" },
                },
                {
                    name: "a-really-long-named-attribute",
                    type-name: "float",
                    value: {
                        kind: PropertyValueKind.float,
                        value-float: 10,
                    }
                },
                {
                    name: "bar",
                    type-name: "float",
                    value: {
                        kind: PropertyValueKind.code,
                        value-float: 10.5,
                        code: 10 / 2,
                    }
                },
                {
                    name: "baz",
                    type-name: "float",
                    value: {
                        kind: PropertyValueKind.code,
                        value-float: 10.5,
                        code: "",
                    }
                }
            ]
        },
        {
            group-name: "Other",
            properties: [
                {
                    name: "text",
                    type-name: "string",
                    value: {
                        is-translatable: true,
                        kind: PropertyValueKind.string,
                    }
                },
                { name: "checkable", type-name: "bool", value: {
                    kind: PropertyValueKind.boolean,
                } },
                { name: "icon", type-name: "image", value: {
                    kind: PropertyValueKind.code,
                } },
                {
                    name: "color",
                    type-name: "brush",
                    value: { kind: PropertyValueKind.brush, value-brush: Colors.magenta, value-string: "#ff00ff" },
                },
                {
                    name: "a-really-long-named-attribute",
                    type-name: "float",
                    value: {
                        kind: PropertyValueKind.float,
                        value-float: 10,
                    }
                },
                {
                    name: "bar",
                    type-name: "float",
                    value: {
                        kind: PropertyValueKind.code,
                        value-float: 10.5,
                        code: 10 / 2,
                    }
                },
                {
                    name: "baz",
                    type-name: "float",
                    value: {
                        kind: PropertyValueKind.code,
                        value-float: 10.5,
                        code: "",
                    }
                }
            ]
        }
    ];
    callback properties-search(string);

    // ## Outline
    in-out property <[OutlineTreeNode]> outline;
    callback outline-select-element(uri: string, offset: int);
    // Data is either a "file:offset" for an element to move, or just a component index.
    callback outline-drop(data: string, uri: string, offset: int, location: DropLocation);
    callback outline-can-drop(data: string, uri: string, offset: int, location: DropLocation) -> bool;

    // ## preview data

    in-out property <[PropertyContainer]> preview-data;

    // # Callbacks

    // ## Custom conversion functions:
    pure callback string-is-color(string) -> bool;
    pure callback string-to-color(string) -> color;
    pure callback color-to-data(color) -> ColorData;
    pure callback rgba_to_color(r: int, g: int, b: int, a: int) -> color;

    // ## Style:
    callback style-changed();

    // ## Component life-cycle:

    // Create a new component
    callback add-new-component();

    // Add an existing component
    pure callback can-drop(component-index: int, x: length, y: length, on-drop-area: bool) -> bool;
    callback drop(component-index: int, x: length, y: length);

    callback rename-component(old-name: string, defined-at: string, new-name: string);

    callback selected-element-can-move-to(x: length, y: length, mouse-x: length, mouse-y: length) -> bool;
    callback selected-element-move(x: length, y: length, mouse-x: length, mouse-y: length);

    callback selected-element-resize(x: length, y: length, width: length, height: length);

    callback selected-element-delete();

    // ## Element selection:
    callback selection-stack-at(x: length, y: length) -> [SelectionStackFrame];
    pure callback filter-sort-selection-stack(model: [SelectionStackFrame], filter_text: string, filter: SelectionStackFilter) -> [SelectionStackFrame];
    pure callback find-selected-selection-stack-frame([SelectionStackFrame]) -> SelectionStackFrame;
    callback select-element(file: string, offset: int, x: length, y: length);

    callback select-at(x: length, y: length, enter-component: bool);
    callback select-behind(x: length, y: length, enter-component: bool, reverse: bool);
    callback reselect();
    callback unselect();

    // ## Change Editor:

    // Show a component in the editor
    callback show-component(name: string, url: string);
    // Show a position consisting of `line` and `column` in a `file` in the editor
    callback show-document(file: string, line: int, column: int);
    // Show a position consisting of `line` and `column` in a `file` in the editor
    callback show-document-offset-range(url: string, start_offset: int, end_offset: int, take-focus: bool);

    // ## Drawing Area
    // Preview some other component
    callback show-preview-for(name: string, url: string);
    callback reload-preview();

    // ## Property Editor
    pure callback test-code-binding(element-url: string, element-version: int, element-offset: int, property-name: string, property-value: string) -> bool;
    pure callback set-code-binding(element-url: string, element-version: int, element-offset: int, property-name: string, property-value: string);
    pure callback set-color-binding(element-url: string, element-version: int, element-offset: int, property-name: string, property-value: color);
    callback set-element-id(element-url: string, element-version: int, element-offset: int, new-id: string);

    pure callback string-to-code(value: string, is_translatable: bool, tr_context: string, tr_plural: string, tr_plural_expression: string) -> string;

    pure callback as-slint-brush(kind: BrushKind, angle: float, color: color, stops: [GradientStop]) -> string;

    // ## preview data
    pure callback get-property-value(component: string, name: string) -> PropertyValue;
    pure callback get-property-value-table(component: string, name: string) -> PropertyValueTable;
    pure callback set-property-value-table(component: string, name: string, table: [[PropertyValue]], is-array: bool) -> string;

    pure callback insert-row-into-value-table(table: PropertyValueTable, insert-before: int);
    pure callback remove-row-from-value-table(table: PropertyValueTable, remove-row: int);

    pure callback set-json-preview-data(component: string, name: string, json-value: string, send-telemetry: bool) -> string;

    pure callback as-json-brush(kind: BrushKind, angle: float, color: color, stops: [GradientStop]) -> string;

    pure callback add-gradient-stop(stops: [GradientStop], value: GradientStop) -> int;
    pure callback remove-gradient-stop(stops: [GradientStop], row: int);
    // returns the new index of the gradient stop in the sorted list of GradientStops
    pure callback move-gradient-stop(stops: [GradientStop], row: int, new_position: float) -> int;
    pure callback suggest-gradient-stop-at-row(stops: [GradientStop], row: int) -> GradientStop;
    pure callback suggest-gradient-stop-at-position(stops: [GradientStop], position: float) -> GradientStop;
    pure callback clone-gradient-stops(stops: [GradientStop]) -> [GradientStop];

    pure callback create-brush(kind: BrushKind, angle: float, color: color, stops: [GradientStop]) -> brush;

    // Get the property declaration/definition ranges
    callback property-declaration-ranges(property-name: string) -> PropertyDeclaration;

    // Palettes:
    pure callback filter-palettes(palettes: [PaletteEntry], pattern: string) -> [PaletteEntry];
    callback add-recent-color(color);
    pure callback is-css-color(code: string) -> bool;

    // ## Console / LogMessages
    pure callback filter-log-messages(messages: [LogMessage], pattern: string) -> [LogMessage];
    callback clear-log-messages();

    // ## Undo/Redo
    callback undo();
    callback redo();
    in-out property <bool> undo-enabled: false;
    in-out property <bool> redo-enabled: false;

    // ## SlintPad related APIs
    in-out property <bool> runs-in-slintpad;
    in-out property <[{title: string, url: string}]> demos: [
        { url: "", title: "Hello World!" },
        { url: "examples/gallery/gallery.slint", title: "Gallery" },
        { url: "demos/home-automation/ui/demo-debug.slint", title: "Home Automation" },
        { url: "demos/usecases/ui/app.slint", title: "Use Cases Demo" },
        { url: "demos/printerdemo/ui/printerdemo.slint", title: "Printer Demo" },
        { url: "demos/energy-monitor/ui/desktop_window.slint", title: "Energy Monitor" },
        { url: "examples/todo/ui/todo.slint", title: "Todo Demo" },
        { url: "examples/iot-dashboard/main.slint", title: "IOT Dashboard" },
        { url: "examples/fancy-switches/demo.slint", title: "Fancy Switches" },
        { url: "examples/dial/dial.slint", title: "Fanncy Dial" },
        { url: "examples/orbit-animation/demo.slint", title: "Fancy Animations" },
        { url: "examples/repeater/demo.slint", title: "Fancy Repeater" },
        { url: "examples/sprite-sheet/demo.slint", title: "Spritesheet Demo" },
    ];
    callback new-file();
    callback share-permalink-to-clipboard();
    callback load-demo(url: string);
    callback show-about-slint();
}