Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4.1.0 #186

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c2756cb
support text_alignment completions
panoply Mar 15, 2024
9a65f6a
support completions in the 11ty data cascade
panoply Mar 15, 2024
f274fcc
support 11ty Liquid
panoply Mar 15, 2024
aa89c5f
1/2 do not expose property completions on array types
panoply Mar 15, 2024
5e4cc1d
11ty completion control
panoply Mar 15, 2024
9462fd4
11ty includes document links
panoply Mar 15, 2024
dcd5ee5
minor patches and 11ty liquid support alignments
panoply Mar 15, 2024
0a35df4
update domain name
panoply Mar 15, 2024
b314df2
release notes
panoply Mar 17, 2024
d34b7e7
notes on 11ty
panoply Mar 17, 2024
729f709
Update readme.md
panoply Mar 17, 2024
c0028e0
11ty frontmatter completions
panoply Mar 17, 2024
c152cf7
improve handling on workspace and document changes
panoply Mar 17, 2024
62e8a1b
frontmatter parse
panoply Mar 17, 2024
63c620f
TypeBasic
panoply Mar 17, 2024
2060005
prepare for validations
panoply Mar 17, 2024
ebb91ca
engine is 11ty
panoply Mar 17, 2024
a099659
completions frontmatter store
panoply Mar 17, 2024
18c7dad
Create DiagnosticProvider.ts
panoply Mar 17, 2024
e37335f
Update completions.ts
panoply Mar 17, 2024
9ce2dc1
improves internal typings
panoply Mar 17, 2024
fa8cdeb
added variation to status bar
panoply Mar 17, 2024
41bbe04
align engine names
panoply Mar 17, 2024
0aa6769
schema stores update
panoply Mar 17, 2024
51db3a4
additional grammar types
panoply Mar 17, 2024
334301e
prepare for linting and validations
panoply Mar 17, 2024
b8ac3db
1/2 completions walks
panoply Mar 17, 2024
86100c0
align schema and deps update
panoply Mar 17, 2024
87e3af8
update extension
panoply Mar 17, 2024
5507910
tests and lock
panoply Mar 17, 2024
733e7ce
v4.1.0 nightly
panoply Mar 17, 2024
aad4eeb
ensure js-yaml is bundled
panoply Mar 17, 2024
0c109fc
supports embedded <script> tag JSON syntax highlighting
panoply Apr 9, 2024
8deafec
use grammar injection for Liquid highlighting
panoply Apr 9, 2024
c7055d3
make note of Grammar improvement
panoply Apr 9, 2024
c4c9261
Update shopify-liquid-4.1.0.vsix
panoply Apr 9, 2024
0000cb5
fixes #189 and #175
panoply Jun 14, 2024
8d13aa9
support JSON comments in schema
panoply Jun 14, 2024
d957483
improves singleton completion insertion
panoply Jun 14, 2024
f22e14d
Update CompletionProvider.ts
panoply Jun 14, 2024
3bbc7f3
fixes rc change detection 1/2
panoply Jun 14, 2024
4cb423c
align with latest Æsthetic rule changes 1/2
panoply Jun 14, 2024
72e39d5
Release notes
panoply Jun 14, 2024
c947410
preparing for next release
panoply Sep 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 34 additions & 66 deletions extension/data/liquid.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import slash, { entries, isArray, isBoolean, isNumber, isObject, isString, keys } from 'utils';
import slash, { entries, keys } from 'utils';
import { basename, join, dirname } from 'node:path';
import { Filter, Tags, IObject, Type, Types, liquid, IProperty, $, p, Engine } from '@liquify/specs';
import { Filter, Tags, IObject, Type, Types, liquid, IProperty, $, p, Engine, Properties, TypeBasic } from '@liquify/specs';
import { mdString, settingsType } from 'parse/helpers';
import { has, path } from 'rambdax';
import { Complete, SettingsSchema } from 'types';
Expand Down Expand Up @@ -249,66 +249,31 @@ export function getSettingsCompletions (uri: string, data: SettingsSchema[]) {
return liquid.shopify.objects;
};

/**
* Get Eleventy Data File Completions
*
* Generates components for the 11ty data cascade. Completions will be created
* and types will be assumed in accordance with the structures. This can potentially
* be a rather heavy operation depending on the cascade itself.
*/
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]);
}
}
const properties = liquid.generate<Properties>($.liquid.files.get(uri));
const reference = `[${basename(uri)}](${uri})`;
const propName: string = basename(uri, '.json');

liquid.extend(Engine.eleventy, {
objects: {
[propName]: {
description: `11ty data file\n\n${reference}`,
global: true,
properties
}
}

return objects;

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

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

}

/**
* Get Locale Completions
*
Expand Down Expand Up @@ -375,6 +340,17 @@ export function getObjectCompletions (fsPath: string, items: Complete.Items) {

const dirn = dirname(fsPath);
const base = basename(fsPath, '.liquid');
const keys = <Complete.ItemKeys[]>[
'objects',
'object:template',
`object:${Type.any}`,
`object:${Type.array}`,
`object:${Type.string}`,
`object:${Type.constant}`,
`object:${Type.boolean}`,
`object:${Type.number}`,
`object:${Type.object}`
];

if (base === 'gift_card' || base === 'robots.txt') {
template = base + '.liquid';
Expand All @@ -384,19 +360,11 @@ export function getObjectCompletions (fsPath: string, items: Complete.Items) {
template = base;
}

items.delete('objects');
items.delete('object:template');
items.delete(`object:${Type.any}`);
items.delete(`object:${Type.array}`);
items.delete(`object:${Type.string}`);
items.delete(`object:${Type.constant}`);
items.delete(`object:${Type.boolean}`);
items.delete(`object:${Type.number}`);
items.delete(`object:${Type.object}`);
for (const key of keys) items.delete(key);

const group = p.ObjectGroups(template, (object: IObject, item: CompletionItem): CompletionItem => {

if (object.type === Type.object) item.kind = CompletionItemKind.Module;
if (object.type === TypeBasic.object) item.kind = CompletionItemKind.Module;
if (object.const) item.kind = CompletionItemKind.Constant;

item.tags = object.deprecated ? [ CompletionItemTag.Deprecated ] : [];
Expand Down
116 changes: 109 additions & 7 deletions extension/data/store.ts

Large diffs are not rendered by default.

55 changes: 48 additions & 7 deletions extension/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
} from 'vscode';
import { ConfigMethod } from 'types';
import { FormatEvent, FormatEventType } from 'providers/FormattingProvider';
import { Engine } from '@liquify/specs';
import { $, Engine, liquid } from '@liquify/specs';
import { dirty, isFunction, isObject, setEndRange } from 'utils';
import { CommandPalette } from 'workspace/CommandPalette';
import { parseSchema, parseDocument } from 'parse/document';
import { parseSchema, parseDocument, parseFrontmatter } from 'parse/document';
import { getObjectCompletions } from 'data/liquid';

/**
Expand Down Expand Up @@ -98,6 +98,9 @@ export class Events extends CommandPalette {
if (this.engine === 'shopify') {
await this.getFileCompletions([ 'snippets', 'sections' ]);
this.resetFeatures();
} else if (this.engine === '11ty') {
await this.getFileCompletions([ 'includes' ]);
this.resetFeatures();
}
}
}
Expand All @@ -120,6 +123,9 @@ export class Events extends CommandPalette {
if (this.engine === 'shopify') {
await this.getFileCompletions([ 'snippets', 'sections' ]);
this.resetFeatures();
} else if (this.engine === '11ty') {
await this.getFileCompletions([ 'includes' ]);
this.resetFeatures();
}
}
}
Expand Down Expand Up @@ -162,12 +168,37 @@ export class Events extends CommandPalette {

const change = contentChanges[contentChanges.length - 1];

if (isObject(change?.range) && this.completion.enable.variables) {
const range = setEndRange(document, change.range.end);
parseDocument(document.getText(range), this.completion.vars);
if (isObject(change?.range)) {

let content = document.getText(setEndRange(document, change.range.end));

if (this.completion.enable.frontmatter) {

const fm = this.completion.frontmatter;

if (fm.offset > 0 && document.offsetAt(change.range.end) < fm.offset) {

liquid.purge($.liquid.engine, { objects: this.completion.frontmatter.keys });

this.completion.frontmatter = parseFrontmatter(content);

if (this.completion.frontmatter.offset > 0) {
content = content.slice(this.completion.frontmatter.offset + 3);
}

}
}

if (this.completion.enable.variables) {
parseDocument(content, this.completion.vars);
}

if (this.completion.enable.objects && (this.engine === 'shopify' || this.engine === '11ty')) {
getObjectCompletions(document.uri.fsPath, this.completion.items);
}
}

if (this.completion.enable.schema && this.json.config.validate) {
if (this.engine === 'shopify' && this.completion.enable.schema && this.json.config.validate) {

const schema = await parseSchema(document);

Expand Down Expand Up @@ -227,6 +258,16 @@ export class Events extends CommandPalette {

this.status.show();

if (this.completion.enable.frontmatter && this.engine === '11ty') {

if (this.completion.frontmatter.offset > 0) {
liquid.purge($.liquid.engine, { objects: this.completion.frontmatter.keys });
}

this.completion.frontmatter = parseFrontmatter(textDocument.document.getText());

}

const schema = await parseSchema(textDocument.document);

if (schema !== false) {
Expand All @@ -240,7 +281,7 @@ export class Events extends CommandPalette {

}

if (this.completion.enable.objects && this.engine === 'shopify') {
if (this.completion.enable.objects && (this.engine === 'shopify' || this.engine === '11ty')) {
getObjectCompletions(uri.fsPath, this.completion.items);
}

Expand Down
33 changes: 18 additions & 15 deletions extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@ 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, EventEmitter } from 'vscode';
import * as vscode from 'vscode';
import { ConfigMethod } from './typings/enums';
import { Service } from './services';
import { FormatEvent } from 'providers/FormattingProvider';
import { Replace } from 'type-fest';

/**
* Extension State - Localized store for the extension
*/
export class Extension extends Service {

constructor ({ packageJSON, isActive }: IExtension<PackageJSON>) {
constructor ({ packageJSON, isActive }: vscode.Extension<PackageJSON>) {

super();

this.isActive = isActive;
this.uri.root = workspace.workspaceFolders[0].uri;
this.uri.root = vscode.workspace.workspaceFolders[0].uri;
this.uri.base = this.uri.root;
this.uri.workspace = Uri.joinPath(this.uri.root, '.vscode', 'settings.json');
this.uri.workspace = vscode.Uri.joinPath(this.uri.root, '.vscode', 'settings.json');
this.meta.version = packageJSON.version;
this.meta.displayName = packageJSON.displayName;
this.meta.estheticVersion = packageJSON.dependencies.esthetic;
this.meta.releaseNotes = Uri.parse(`${this.meta.repository}/releases/tag/v${this.meta.version}`);
this.meta.releaseNotes = vscode.Uri.parse(`${this.meta.repository}/releases/tag/v${this.meta.version}`);

}

Expand All @@ -47,7 +48,7 @@ export class Extension extends Service {
/**
* Error event
*/
listen: EventEmitter<FormatEvent> = new EventEmitter();
listen: vscode.EventEmitter<FormatEvent> = new vscode.EventEmitter();

/**
* Meta Information
Expand Down Expand Up @@ -79,7 +80,7 @@ export class Extension extends Service {
*
* @default 'shopify'
*/
engine: '11ty' | Engines = 'shopify';
engine: Replace<Engines, 'eleventy', '11ty'> = 'shopify';

/**
* Copy of the parsed `.liquidrc` file
Expand All @@ -98,16 +99,12 @@ export class Extension extends Service {
liquidrc: null,
workspace: null,
files: {
jekyll: {
collectons: null,
data: null,
includes: null,
layouts: null
},
'11ty': {
data: new Set(),
includes: new Set(),
layouts: new Set()
layouts: new Set(),
collections: new Set(),
frontmatter: new Set()
},
shopify: {
locales: null,
Expand All @@ -117,6 +114,12 @@ export class Extension extends Service {
snippets: new Set(),
sections: new Set(),
sectionGroups: new Set()
},
jekyll: {
collectons: null,
data: null,
includes: null,
layouts: null
}
}
};
Expand All @@ -127,7 +130,7 @@ export class Extension extends Service {
* @default ConfigurationTarget.Global
*/
config: Config = {
target: ConfigurationTarget.Global,
target: vscode.ConfigurationTarget.Global,
inspect: 'globalValue',
method: ConfigMethod.Liquidrc,
sources: {
Expand Down
Loading