Skip to main content

swls_core/components/
document.rs

1use std::collections::HashSet;
2
3use bevy_ecs::prelude::*;
4use derive_more::{AsMut, AsRef, Deref, DerefMut};
5
6use crate::{
7    lang::{Lang, LangHelper},
8    lsp_types::Position,
9    prelude::*,
10    systems::TypeId,
11};
12
13#[derive(Component, Default, Debug, Clone, Eq, PartialEq)]
14pub struct CurrentType(pub HashSet<TypeId>);
15
16/// [`Component`] that contains the parsed semantic element (i.e. Turtle, JSONLD).
17#[derive(Component, AsRef, Deref, AsMut, DerefMut, Debug)]
18pub struct Element<L: Lang>(pub Spanned<L::Element>);
19
20/// Simple wrapper structure that derives [`Component`]
21#[derive(Component, AsRef, Deref, AsMut, DerefMut, Debug)]
22pub struct Wrapped<E>(pub E);
23
24/// Simple wrapper for errors that derives [`Component`]
25#[derive(Component, AsRef, Deref, AsMut, DerefMut, Debug)]
26pub struct Errors<E>(pub Vec<E>);
27
28/// [`Component`] containing the current source code as [`String`]
29#[derive(Component, AsRef, Deref, AsMut, DerefMut, Debug)]
30pub struct Source(pub String);
31
32/// [`Component`] containing the current source code as [`ropey::Rope`]
33#[derive(Component, AsRef, Deref, AsMut, DerefMut, Debug)]
34pub struct RopeC(pub ropey::Rope);
35
36/// [`Component`] that allows for language specific implementation for certain things, reducing
37/// code duplication.
38#[derive(Component, Debug, AsRef, Deref)]
39pub struct DynLang(pub Box<dyn LangHelper + 'static + Send + Sync>);
40
41/// [`Component`] indicating whether or not the document is actually open.
42///
43/// Documents that are not [`Open`] don't publish diagnostics for example
44#[derive(Component, Debug)]
45pub struct Open;
46
47/// [`Component`] indicating whether or not the document is dirty, a dirty document parsed with
48/// errors.
49///
50/// A document is often Dirty, computational intens calculation can be done on documents that are
51/// not dirty, like [`derive_classes`](crate::prelude::systems::derive_classes) and [`derive_properties`](crate::prelude::systems::derive_properties).
52#[derive(Component, Debug)]
53pub struct Dirty;
54
55/// Indicates that this should be a global entity, linked to all other documents
56#[derive(Component, Debug)]
57pub struct Global;
58
59/// [`Component`] containing the [`lsp_types::Url`] of the current document.
60#[derive(Component, AsRef, Deref, AsMut, DerefMut, Debug)]
61pub struct Label(pub crate::lsp_types::Url);
62
63/// [`Component`] used to remember the linked documents.
64///
65/// This is used, for example, to only suggest properties defined in a linked document.
66/// Or only validate with shapes found in linked documents.
67#[derive(Component, AsRef, Deref, AsMut, DerefMut, Debug, Clone)]
68pub struct DocumentLinks(pub Vec<(crate::lsp_types::Url, &'static str)>);
69
70/// [`Component`] used to wrap an incoming [`lsp_types::Position`].
71///
72/// This component is translated into [`TokenComponent`] and [`TripleComponent`]
73/// with [`get_current_token`]
74/// and [get_current_triple] respectively.
75#[derive(Component, AsRef, Deref, AsMut, DerefMut, Debug)]
76pub struct PositionComponent(pub Position);
77
78/// [`Component`] containing the typical keywords for the current language.
79#[derive(Component, AsRef, Deref, AsMut, DerefMut, Debug)]
80pub struct KeyWords(pub Vec<&'static str>);