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