@@ -280,7 +280,110 @@ pub struct LocalConfig {
280280 pub shapes : HashSet < String > ,
281281 /// Features to disable
282282 pub disabled : HashSet < Disabled > ,
283+ /// disable which prefices from prefix.cc to show
283284 pub prefix_disabled : HashSet < String > ,
285+ /// confiure completion behavior
286+ pub completion : CompletionConfig ,
287+ }
288+
289+ /// Lets the user configure how the property completion should happen.
290+ /// There are two main modes: strict and loose (default)
291+ /// On loose, the editor will suggest anything, not caring about the domain.
292+ /// On strict, the editor will only suggest property that have a matching domain or anything if the
293+ /// type could not be determined.
294+ ///
295+ /// Both options can be specialized, ie only strict on these properties or only loose on these
296+ /// properties.
297+ ///
298+ /// For example { loose: ["http://www.w3.org/2000/01/rdf-schema#"] }, here the editor will be strict, and show properties
299+ /// from rdfs
300+ /// On the other hand { strict: ["http://www.w3.org/ns/shacl#"] }, here the editor will be loose,
301+ /// and only show shacl properties if the objects is the correct type
302+ #[ derive( Debug , Clone , PartialEq , Eq , Deserialize ) ]
303+ #[ serde( untagged) ]
304+ pub enum CompletionConfig {
305+ // "strict" | "loose" | "none"
306+ Mode ( CompletionMode ) ,
307+
308+ // { "except": [...] }
309+ Except ( ExceptRules ) ,
310+
311+ // { "strict": [...] }
312+ Strict ( StrictRules ) ,
313+ }
314+
315+ impl Default for CompletionConfig {
316+ fn default ( ) -> Self {
317+ Self :: Mode ( CompletionMode :: None )
318+ }
319+ }
320+
321+ impl CompletionConfig {
322+ fn combine ( & mut self , other : CompletionConfig ) {
323+ use CompletionConfig :: * ;
324+
325+ if matches ! ( other, Mode ( CompletionMode :: None ) ) {
326+ return ;
327+ }
328+
329+ if matches ! ( self , Mode ( CompletionMode :: None ) ) {
330+ * self = other;
331+ return ;
332+ }
333+
334+ if let Strict ( r) = self {
335+ if let Strict ( r2) = other {
336+ r. strict . extend ( r2. strict ) ;
337+ return ;
338+ }
339+ }
340+
341+ if let Except ( r) = self {
342+ if let Except ( r2) = other {
343+ r. loose . extend ( r2. loose ) ;
344+ return ;
345+ }
346+ }
347+
348+ * self = other;
349+ }
350+ pub fn correct_domain_required ( & self , property : & str ) -> bool {
351+ match self {
352+ CompletionConfig :: Mode ( CompletionMode :: Loose )
353+ | CompletionConfig :: Mode ( CompletionMode :: None ) => false ,
354+ CompletionConfig :: Mode ( CompletionMode :: Strict ) => true ,
355+ CompletionConfig :: Except ( completion_rules) => !completion_rules
356+ . loose
357+ . iter ( )
358+ . any ( |x| property. starts_with ( x) ) ,
359+ CompletionConfig :: Strict ( completion_rules) => completion_rules
360+ . strict
361+ . iter ( )
362+ . any ( |x| property. starts_with ( x) ) ,
363+ }
364+ }
365+ }
366+
367+ #[ derive( Debug , Clone , PartialEq , Eq , Default , Deserialize ) ]
368+ #[ serde( rename_all = "lowercase" ) ]
369+ pub enum CompletionMode {
370+ #[ default]
371+ None ,
372+ Loose ,
373+ Strict ,
374+ }
375+
376+ #[ derive( Debug , Clone , PartialEq , Eq , Deserialize , Default ) ]
377+ #[ serde( deny_unknown_fields) ]
378+ pub struct ExceptRules {
379+ #[ serde( default ) ]
380+ pub loose : Vec < String > ,
381+ }
382+ #[ derive( Debug , Clone , PartialEq , Eq , Deserialize , Default ) ]
383+ #[ serde( deny_unknown_fields) ]
384+ pub struct StrictRules {
385+ #[ serde( default ) ]
386+ pub strict : Vec < String > ,
284387}
285388
286389impl LocalConfig {
@@ -290,11 +393,13 @@ impl LocalConfig {
290393 self . shapes . extend ( other. shapes ) ;
291394 self . disabled . extend ( other. disabled ) ;
292395 self . prefix_disabled . extend ( other. prefix_disabled ) ;
396+ self . completion . combine ( other. completion ) ;
293397 }
294398 #[ cfg( target_arch = "wasm32" ) ]
295399 pub async fn global ( _: & Fs ) -> Option < Self > {
296400 None
297401 }
402+
298403 #[ cfg( not( target_arch = "wasm32" ) ) ]
299404 pub async fn global ( fs : & Fs ) -> Option < Self > {
300405 let global_path = dirs:: config_dir ( )
0 commit comments