Skip to content

Commit

Permalink
Merge pull request #174 from panoply/next
Browse files Browse the repository at this point in the history
v4.0.1
  • Loading branch information
panoply authored Nov 7, 2023
2 parents ccf49d6 + 363c6b1 commit 1563921
Show file tree
Hide file tree
Showing 22 changed files with 1,529 additions and 369 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
],
"liquid.format.rules": {
"json": {}
},
"[liquid]": {
"editor.defaultFormatter": "sissel.shopify-liquid",
"editor.formatOnSave": true
}
}
64 changes: 62 additions & 2 deletions extension/data/liquid.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import slash, { entries, keys } from 'utils';
import slash, { entries, isArray, isBoolean, isNumber, isObject, isString, keys } from 'utils';
import { basename, join, dirname } from 'node:path';
import { Filter, Tags, IObject, Type, Types, liquid, IProperty, $, p } from '@liquify/specs';
import { Filter, Tags, IObject, Type, Types, liquid, IProperty, $, p, Engine } from '@liquify/specs';
import { mdString, settingsType } from 'parse/helpers';
import { has, path } from 'rambdax';
import { Complete, SettingsSchema } from 'types';
Expand Down Expand Up @@ -249,6 +249,66 @@ export function getSettingsCompletions (uri: string, data: SettingsSchema[]) {
return liquid.shopify.objects;
};

export function getEleventyDataComponents (uri: string) {

const objects:{ [prop: string]: IProperty } = { data: { type: Type.any } };

const build = (function traverse (data, spec?: IProperty) {

if (spec) {
if (spec.type === Type.object) {

for (const prop in data) {

if (isString(data[prop])) {
spec.properties[prop] = { type: Type.string };
} else if (isBoolean(data[prop])) {
spec.properties[prop] = { type: Type.boolean };
} else if (isObject(data[prop])) {
spec.properties[prop] = { type: Type.object };
traverse(data[prop], spec.properties[prop]);
} else if (isNumber(data[prop])) {
spec.properties[prop] = { type: Type.number };
} else if (isArray(data[prop])) {
spec.properties[prop] = { type: Type.array };
traverse(data[prop], spec.properties[prop]);
}

}
}
} else {

if (isObject(data)) {

for (const item in data) {

if (isObject(data[item])) {
objects[item] = { type: Type.object, properties: {} };
traverse(data[item], objects[item]);
} else if (isArray(data[item])) {
objects[item] = { type: Type.array };
}
}

}

if (isArray(data)) {
for (const item of data) {
objects[item] = { type: Type.array };
for (const value of data[item]) {
traverse(value, objects[item]);
}
}
}
}

return objects;

})($.liquid.files.get(uri));

liquid.extend(Engine.standard, { objects: build });

}
/**
* Get Locale Completions
*
Expand Down
4 changes: 2 additions & 2 deletions extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Engines } from '@liquify/specs';
import { Config, URI, Meta, Files } from './typings/store';
import { Liquidrc, PackageJSON } from './typings/files';
import { Selectors, LanguageIds } from './typings/document';
import { ConfigurationTarget, Extension as IExtension, Uri, workspace, Disposable, EventEmitter } from 'vscode';
import { ConfigurationTarget, Extension as IExtension, Uri, workspace, EventEmitter } from 'vscode';
import { ConfigMethod } from './typings/enums';
import { Service } from './services';
import { FormatEvent } from 'providers/FormattingProvider';
Expand Down Expand Up @@ -105,7 +105,7 @@ export class Extension extends Service {
layouts: null
},
'11ty': {
data: null,
data: new Set(),
includes: new Set(),
layouts: new Set()
},
Expand Down
11 changes: 8 additions & 3 deletions extension/providers/DocumentLinkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class DocumentLinkProvider implements IDocumentLinkProvider {
/**
*The `settings_schema.json` URI
*/
settings: Uri;
settings: Uri = null;

/**
* Render Tag URI's
Expand All @@ -44,8 +44,13 @@ export class DocumentLinkProvider implements IDocumentLinkProvider {
const content = document.getText();
const links: DocumentLink[] = [];

this.getSnippetLinks(document, content, links);
this.getSettingsLinks(document, content, links);
if (this.snippets.length > 0) {
this.getSnippetLinks(document, content, links);
}

if (this.settings !== null) {
this.getSettingsLinks(document, content, links);
}

return links;

Expand Down
7 changes: 6 additions & 1 deletion extension/providers/HoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function walkProps (cursor: string, next: string[], object: IProperty) {

export function getPropertyHover (cursor: string, token: string, objects: string[]) {

if (!$.liquid.data.variation?.objects) return null;
if (!$.liquid.data.variation?.objects?.[token]) return null;

const root = $.liquid.data.variation.objects[token];

Expand All @@ -55,7 +55,12 @@ export function getPropertyHover (cursor: string, token: string, objects: string
return mdString(root.description, root.reference);
}

if (!('properties' in root)) return null;

const prop = objects.shift();

if (!(prop in root.properties)) return null;

const spec = walkProps(cursor, objects, root.properties[prop]);

return mdString(spec.description, root.reference);
Expand Down
1 change: 1 addition & 0 deletions extension/services/JSONLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export class JSONLanguageProvider {
extend (uri: Uri, shared: SharedSchema) {

this.schema = getSharedSchema(uri, shared, this.schema);
this.configure();

}

Expand Down
2 changes: 1 addition & 1 deletion extension/typings/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-unused-vars */

import { LiteralUnion, Merge } from 'type-fest';
import { LiteralUnion } from 'type-fest';
import { Position, TextDocument } from 'vscode';

export interface SchemaRegion {
Expand Down
115 changes: 89 additions & 26 deletions extension/workspace/WorkspaceSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { has, isNil, difference, hasPath, isEmpty, equals, T } from 'rambdax';
import anymatch from 'anymatch';
import { OutputChannel } from './OutputChannel';
import * as u from '../utils';
import { getSettingsCompletions } from 'data/liquid';
import { getEleventyDataComponents, getSettingsCompletions } from 'data/liquid';
import { $ } from '@liquify/specs';

export class WorkspaceSettings extends OutputChannel {
Expand Down Expand Up @@ -305,6 +305,8 @@ export class WorkspaceSettings extends OutputChannel {
}
}

if (input === undefined) return;

for (let i = 0; i < input.length; i++) {

const path = input[i];
Expand Down Expand Up @@ -456,6 +458,60 @@ export class WorkspaceSettings extends OutputChannel {
return this;
}

/**
* Set Settings File
*
* Function method for data files in Eleventy
*/
async setDataFile () {

let config: 'workspace' | '.liquidrc';
let input: string[];

if (this.config.sources.files.data === ConfigMethod.Workspace) {
config = 'workspace';
input = workspace.getConfiguration().get<string[]>('liquid.files.11ty.data');
} else {
config = '.liquidrc';
input = (this.liquidrc.files as { data: string[] }).data;
}

for (let i = 0; i < input.length; i++) {

const path = input[i];
const relative = new RelativePattern(this.uri.root, u.refineURI(path));
const paths = await workspace.findFiles(relative);

for (const entry of paths) {

const file = Uri.file(path);

if (!file.fsPath.endsWith('.json')) {
this.warn(`Unable to resolve data (File must be a JSON file type): ${path}`);
continue;
}

try {

const data = await u.parseJsonFile<any>(entry);

$.liquid.files.set(file.fsPath, data);

getEleventyDataComponents(file.fsPath);

} catch (e) {

this.catch('JSON Error', e);

}

}
}

return this;

}

/**
* Set Settings File
*
Expand Down Expand Up @@ -722,7 +778,7 @@ export class WorkspaceSettings extends OutputChannel {
]) {
if (has(v, settings) && u.isBoolean(settings[v])) {
if (v === 'schema' && this.engine !== 'shopify') {
this.warn('Hovers for {% schema %} only work in the Shopify variation');
continue;
} else {

if (settings[v] !== this.hovers.enable[v]) {
Expand Down Expand Up @@ -751,20 +807,18 @@ export class WorkspaceSettings extends OutputChannel {
const settings = workspace.getConfiguration().get<Workspace.Validate>('liquid.validate');

if (has('schema', settings) && u.isBoolean(settings.schema)) {
if (this.engine !== 'shopify') {
this.warn('Validations for {% schema %} only work when the Liquid "engine" is Shopify');
} else {
if (this.engine !== 'shopify') return;

if (settings.schema !== this.json.config.validate) {
if (settings.schema) {
this.info('Enabled {% schema %} validations');
} else {
this.info('Disable {% schema %} validations');
}
if (settings.schema !== this.json.config.validate) {
if (settings.schema) {
this.info('Enabled {% schema %} validations');
} else {
this.info('Disable {% schema %} validations');
}

this.json.config.validate = settings.schema;
}

this.json.config.validate = settings.schema;

}

}
Expand Down Expand Up @@ -796,17 +850,17 @@ export class WorkspaceSettings extends OutputChannel {

if (has(v, settings) && u.isBoolean(settings[v])) {

if (v === 'section' || v === 'objects' || v === 'schema') {
if (v === 'sections' || v === 'objects' || v === 'schema') {
if (this.engine !== 'shopify' && settings[v] === true) {
this.warn(`Completion for ${v} will not work in Liquid ${u.upcase(this.engine)}`);
continue;
}
}

if (settings[v] !== this.completion.enable[v]) {
if (settings[v]) {
this.info(`enabled ${v} completions`);
this.info(`Enabled ${v} completions`);
} else {
this.info(`disabled ${v} completions`);
this.info(`Disabled ${v} completions`);
}
}

Expand Down Expand Up @@ -1107,10 +1161,18 @@ export class WorkspaceSettings extends OutputChannel {
this.getEngine();
this.getFormatRules();

await this.getFileCompletions([ 'sections', 'snippets' ]);
await this.setLocaleFile();
await this.setSettingsFile();
await this.getSharedSchema();
if (this.engine === 'shopify') {

await this.getFileCompletions([ 'sections', 'snippets' ]);
await this.setLocaleFile();
await this.setSettingsFile();
await this.getSharedSchema();

} else if (this.engine === '11ty' || this.engine === 'eleventy') {

await this.getFileCompletions([ 'includes', 'layouts' ]);

}

}

Expand Down Expand Up @@ -1280,6 +1342,7 @@ export class WorkspaceSettings extends OutputChannel {

this.config.target = ConfigurationTarget.Workspace;
this.config.inspect = 'workspaceValue';

} else {
this.config.target = ConfigurationTarget.Global;
this.config.inspect = 'globalValue';
Expand All @@ -1305,19 +1368,19 @@ export class WorkspaceSettings extends OutputChannel {

await this.getFileSource();

if (this.engine === 'shopify') {
if (this.config.method === ConfigMethod.Workspace) {
if (this.engine === 'shopify') {

if (this.config.method === ConfigMethod.Workspace) {
await this.getFileCompletions([ 'sections', 'snippets' ]);
await this.setLocaleFile();
await this.setSettingsFile();
await this.getSharedSchema();
}

} else if (this.engine === '11ty' || this.engine === 'eleventy') {
} else if (this.engine === '11ty' || this.engine === 'eleventy') {

await this.getFileCompletions([ 'data', 'includes', 'layouts' ]);
await this.getFileCompletions([ 'includes', 'layouts' ]);

}
}

this.getCompletions();
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"publisher": "sissel",
"icon": "images/logo.png",
"author": "Νίκος Σαβίδης <[email protected]>",
"version": "4.0.0",
"version": "4.0.1",
"keywords": [
"liquid",
"shopify",
Expand Down Expand Up @@ -1293,7 +1293,7 @@
},
"scripts": {
"dev": "tsup --watch",
"build": "tsup --onSuccess \"vsce package --no-dependencies\"",
"build": "tsup --minify --onSuccess \"vsce package --no-dependencies\"",
"dry": "vsce ls package --no-dependencies",
"schema": "node ./scripts/schemas.cjs",
"grammar": "node ./scripts/grammars.cjs"
Expand Down
3 changes: 2 additions & 1 deletion releases/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ The extension is currently in the version **4.x.x** range.

## v4.0.0 ~ Latest

The extension is currently shipping on version 4.
The extension is currently shipping on version 4

- [4.0.1](/releases/v4/4.0.1.md)
- [4.0.0](/releases/v4/4.0.0.md)

## v3.0.0 ~ v3.2.2
Expand Down
Loading

0 comments on commit 1563921

Please sign in to comment.