swls_lang_turtle/
config.rs1use std::{borrow::Cow, collections::HashMap};
2
3use bevy_ecs::{
4 resource::Resource,
5 system::Res,
6 world::{CommandQueue, World},
7};
8use swls_core::{lsp_types::TextDocumentItem, prelude::*};
9
10use crate::prefix::{find, prefix_from_source, prefix_from_url};
11
12pub fn extract_known_shapes_from_config<C: Client + ClientSync + Resource + Clone>(
13 config: Res<ServerConfig>,
14 client: Res<C>,
15 fs: Res<Fs>,
16 sender: Res<CommandSender>,
17) {
18 for on in config.config.local.shapes.iter().cloned() {
19 let c = client.clone();
20 let fs = fs.clone();
21 let sender = sender.0.clone();
22
23 let fut = async move {
24 tracing::debug!("A FUTURE IS STARTING");
25 let Some(files) = find(&on, &fs, &c).await else {
26 return;
27 };
28
29 for (content, url) in files {
30 let mut command_queue = CommandQueue::default();
31 let item = TextDocumentItem {
32 version: 1,
33 uri: url.clone(),
34 language_id: String::from("turtle"),
35 text: String::new(),
36 };
37
38 let spawn = spawn_or_insert(
39 url.clone(),
40 (
41 RopeC(LineIndex::new(&content)),
42 Source(content.clone()),
43 Label(url.clone()),
44 Wrapped(item),
45 Types(HashMap::new()),
46 ),
47 Some("turtle".into()),
48 (Global,),
49 );
50
51 command_queue.push(move |world: &mut World| {
52 let span = tracing::span!(tracing::Level::INFO, "span shapes");
53 let _enter = span.enter();
54 spawn(world);
55 world.run_schedule(ParseLabel);
56 });
57
58 let _ = sender.unbounded_send(command_queue);
59 }
60 };
61
62 client.spawn(fut);
63 }
64}
65
66pub fn extract_known_prefixes_from_config<C: Client + ClientSync + Resource + Clone>(
67 config: Res<ServerConfig>,
68 client: Res<C>,
69 fs: Res<Fs>,
70 sender: Res<CommandSender>,
71) {
72 for on in config.config.local.ontologies.iter().cloned() {
73 let c = client.clone();
74 let fs = fs.clone();
75 let sender = sender.0.clone();
76
77 let fut = async move {
78 tracing::debug!("A FUTURE IS STARTING");
79 let Some(files) = find(&on, &fs, &c).await else {
80 return;
81 };
82
83 let mut queue = CommandQueue::default();
84 for (content, location) in files {
85 let Some((prefix, url)) =
86 prefix_from_source(&location, &content).or_else(|| prefix_from_url(&location))
87 else {
88 continue;
89 };
90
91 tracing::debug!(
92 "Adding local prefix from ontologies config location {} prefix {}",
93 url,
94 prefix
95 );
96
97 let lov = swls_lov::LocalPrefix {
98 location: Cow::Owned(location.to_string()),
99 namespace: Cow::Owned(url.to_string()),
100 content: Cow::Owned(content),
101 name: prefix.clone(),
102 title: prefix,
103 rank: 0,
104 };
105
106 queue.push(move |world: &mut World| {
107 world.spawn(lov);
108 });
109 }
110
111 let _ = sender.unbounded_send(queue);
112 };
113
114 client.spawn(fut);
115 }
116}