@@ -17,7 +17,7 @@ import { has, isNil, difference, hasPath, isEmpty, equals, T } from 'rambdax';
1717import anymatch from 'anymatch' ;
1818import { OutputChannel } from './OutputChannel' ;
1919import * as u from '../utils' ;
20- import { getSettingsCompletions } from 'data/liquid' ;
20+ import { getEleventyDataComponents , getSettingsCompletions } from 'data/liquid' ;
2121import { $ } from '@liquify/specs' ;
2222
2323export class WorkspaceSettings extends OutputChannel {
@@ -305,6 +305,8 @@ export class WorkspaceSettings extends OutputChannel {
305305 }
306306 }
307307
308+ if ( input === undefined ) return ;
309+
308310 for ( let i = 0 ; i < input . length ; i ++ ) {
309311
310312 const path = input [ i ] ;
@@ -456,6 +458,60 @@ export class WorkspaceSettings extends OutputChannel {
456458 return this ;
457459 }
458460
461+ /**
462+ * Set Settings File
463+ *
464+ * Function method for data files in Eleventy
465+ */
466+ async setDataFile ( ) {
467+
468+ let config : 'workspace' | '.liquidrc' ;
469+ let input : string [ ] ;
470+
471+ if ( this . config . sources . files . data === ConfigMethod . Workspace ) {
472+ config = 'workspace' ;
473+ input = workspace . getConfiguration ( ) . get < string [ ] > ( 'liquid.files.11ty.data' ) ;
474+ } else {
475+ config = '.liquidrc' ;
476+ input = ( this . liquidrc . files as { data : string [ ] } ) . data ;
477+ }
478+
479+ for ( let i = 0 ; i < input . length ; i ++ ) {
480+
481+ const path = input [ i ] ;
482+ const relative = new RelativePattern ( this . uri . root , u . refineURI ( path ) ) ;
483+ const paths = await workspace . findFiles ( relative ) ;
484+
485+ for ( const entry of paths ) {
486+
487+ const file = Uri . file ( path ) ;
488+
489+ if ( ! file . fsPath . endsWith ( '.json' ) ) {
490+ this . warn ( `Unable to resolve data (File must be a JSON file type): ${ path } ` ) ;
491+ continue ;
492+ }
493+
494+ try {
495+
496+ const data = await u . parseJsonFile < any > ( entry ) ;
497+
498+ $ . liquid . files . set ( file . fsPath , data ) ;
499+
500+ getEleventyDataComponents ( file . fsPath ) ;
501+
502+ } catch ( e ) {
503+
504+ this . catch ( 'JSON Error' , e ) ;
505+
506+ }
507+
508+ }
509+ }
510+
511+ return this ;
512+
513+ }
514+
459515 /**
460516 * Set Settings File
461517 *
@@ -722,7 +778,7 @@ export class WorkspaceSettings extends OutputChannel {
722778 ] ) {
723779 if ( has ( v , settings ) && u . isBoolean ( settings [ v ] ) ) {
724780 if ( v === 'schema' && this . engine !== 'shopify' ) {
725- this . warn ( 'Hovers for {% schema %} only work in the Shopify variation' ) ;
781+ continue ;
726782 } else {
727783
728784 if ( settings [ v ] !== this . hovers . enable [ v ] ) {
@@ -751,20 +807,18 @@ export class WorkspaceSettings extends OutputChannel {
751807 const settings = workspace . getConfiguration ( ) . get < Workspace . Validate > ( 'liquid.validate' ) ;
752808
753809 if ( has ( 'schema' , settings ) && u . isBoolean ( settings . schema ) ) {
754- if ( this . engine !== 'shopify' ) {
755- this . warn ( 'Validations for {% schema %} only work when the Liquid "engine" is Shopify' ) ;
756- } else {
810+ if ( this . engine !== 'shopify' ) return ;
757811
758- if ( settings . schema !== this . json . config . validate ) {
759- if ( settings . schema ) {
760- this . info ( 'Enabled {% schema %} validations' ) ;
761- } else {
762- this . info ( 'Disable {% schema %} validations' ) ;
763- }
812+ if ( settings . schema !== this . json . config . validate ) {
813+ if ( settings . schema ) {
814+ this . info ( 'Enabled {% schema %} validations' ) ;
815+ } else {
816+ this . info ( 'Disable {% schema %} validations' ) ;
764817 }
765-
766- this . json . config . validate = settings . schema ;
767818 }
819+
820+ this . json . config . validate = settings . schema ;
821+
768822 }
769823
770824 }
@@ -796,17 +850,17 @@ export class WorkspaceSettings extends OutputChannel {
796850
797851 if ( has ( v , settings ) && u . isBoolean ( settings [ v ] ) ) {
798852
799- if ( v === 'section ' || v === 'objects' || v === 'schema' ) {
853+ if ( v === 'sections ' || v === 'objects' || v === 'schema' ) {
800854 if ( this . engine !== 'shopify' && settings [ v ] === true ) {
801- this . warn ( `Completion for ${ v } will not work in Liquid ${ u . upcase ( this . engine ) } ` ) ;
855+ continue ;
802856 }
803857 }
804858
805859 if ( settings [ v ] !== this . completion . enable [ v ] ) {
806860 if ( settings [ v ] ) {
807- this . info ( `enabled ${ v } completions` ) ;
861+ this . info ( `Enabled ${ v } completions` ) ;
808862 } else {
809- this . info ( `disabled ${ v } completions` ) ;
863+ this . info ( `Disabled ${ v } completions` ) ;
810864 }
811865 }
812866
@@ -1107,10 +1161,18 @@ export class WorkspaceSettings extends OutputChannel {
11071161 this . getEngine ( ) ;
11081162 this . getFormatRules ( ) ;
11091163
1110- await this . getFileCompletions ( [ 'sections' , 'snippets' ] ) ;
1111- await this . setLocaleFile ( ) ;
1112- await this . setSettingsFile ( ) ;
1113- await this . getSharedSchema ( ) ;
1164+ if ( this . engine === 'shopify' ) {
1165+
1166+ await this . getFileCompletions ( [ 'sections' , 'snippets' ] ) ;
1167+ await this . setLocaleFile ( ) ;
1168+ await this . setSettingsFile ( ) ;
1169+ await this . getSharedSchema ( ) ;
1170+
1171+ } else if ( this . engine === '11ty' || this . engine === 'eleventy' ) {
1172+
1173+ await this . getFileCompletions ( [ 'includes' , 'layouts' ] ) ;
1174+
1175+ }
11141176
11151177 }
11161178
@@ -1280,6 +1342,7 @@ export class WorkspaceSettings extends OutputChannel {
12801342
12811343 this . config . target = ConfigurationTarget . Workspace ;
12821344 this . config . inspect = 'workspaceValue' ;
1345+
12831346 } else {
12841347 this . config . target = ConfigurationTarget . Global ;
12851348 this . config . inspect = 'globalValue' ;
@@ -1305,19 +1368,19 @@ export class WorkspaceSettings extends OutputChannel {
13051368
13061369 await this . getFileSource ( ) ;
13071370
1308- if ( this . engine === 'shopify' ) {
1371+ if ( this . config . method === ConfigMethod . Workspace ) {
1372+ if ( this . engine === 'shopify' ) {
13091373
1310- if ( this . config . method === ConfigMethod . Workspace ) {
13111374 await this . getFileCompletions ( [ 'sections' , 'snippets' ] ) ;
13121375 await this . setLocaleFile ( ) ;
13131376 await this . setSettingsFile ( ) ;
13141377 await this . getSharedSchema ( ) ;
1315- }
13161378
1317- } else if ( this . engine === '11ty' || this . engine === 'eleventy' ) {
1379+ } else if ( this . engine === '11ty' || this . engine === 'eleventy' ) {
13181380
1319- await this . getFileCompletions ( [ 'data' , 'includes' , 'layouts' ] ) ;
1381+ await this . getFileCompletions ( [ 'includes' , 'layouts' ] ) ;
13201382
1383+ }
13211384 }
13221385
13231386 this . getCompletions ( ) ;
0 commit comments