Skip to content

Commit

Permalink
Merge pull request #138 from panoply/next
Browse files Browse the repository at this point in the history
v4.0.0
  • Loading branch information
panoply authored Oct 9, 2023
2 parents 20f34c6 + 34d9c6d commit 1038cb8
Show file tree
Hide file tree
Showing 202 changed files with 28,296 additions and 11,626 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ node_modules
yarn.lock
test/components/*.html
versions
releases
docs
dist
example
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dist/
src/language/liquid.configuration.json
test/format.html
schema/
*.ts
*.js
*.cjs
Expand Down
15 changes: 6 additions & 9 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@
"name": "Attach",
"port": 9229
},

{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--disable-extensions", "--extensionDevelopmentPath=${workspaceFolder}", "${workspaceFolder}/test"]
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--disable-extensions","--extensionDevelopmentPath=${workspaceFolder}","--extensionTestsPath=${workspaceFolder}/test"]
"args": ["--disable-extensions", "--extensionDevelopmentPath=${workspaceFolder}", "${workspaceFolder}/test"],
"sourceMaps": false,
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**"
]
}
]
}
16 changes: 13 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"cSpell.words": [
"Allman",
"esbenp",
"Mansedan",
"packagejson",
"TLDR",
"VSIX"
],
"files.associations": {
Expand All @@ -13,7 +15,15 @@
"*.css.liquid": "liquid-css",
"*.scss.liquid": "liquid-scss"
},
"liquid.format.json": {
"braceAllman": true
"json.schemas": [
{
"fileMatch": [
"package.json"
],
"url": "https://unpkg.com/tsup/schema.json"
}
],
"liquid.format.rules": {
"json": {}
}
}
}
169 changes: 169 additions & 0 deletions extension/activate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import { ConfigMethod } from './types';
import { Events } from './events';
import { languages, workspace, commands, ConfigurationTarget, ExtensionContext, window } from 'vscode';
import esthetic from 'esthetic';

class VSCodeLiquid extends Events {

/**
* Activate Extension
*
* Initialize the vscode-liquid extension
*/
async activate (subscriptions: { dispose(): void; }[]) {

try {

await this.getSettings();
await this.setFeatures();

this.getWatchers();
this.getFormatter();
this.workspace(subscriptions);
this.register(subscriptions);
this.commands(subscriptions);
this.listeners(subscriptions);
this.windows(subscriptions);

if (this.config.method === ConfigMethod.Workspace) {

esthetic.settings({ logColors: false }).rules(this.formatting.rules);

this.nl();
this.info('workspace settings used for configuration');

} else if (this.config.method === ConfigMethod.Liquidrc) {

esthetic.settings({ logColors: false }).rules(this.formatting.rules);

this.nl();
this.info(`.liquidrc file used for settings: ${this.uri.liquidrc.path}`);

}

// console.log(subscriptions);

await this.onDidChangeActiveTextEditor(window.activeTextEditor);

if (!this.hasActivated) this.hasActivated = true;

} catch (e) {

this.status.error('Extension could not be initialized');

this.catch('Extension could not be initialized', e);

}

}

/**
* Restart Extension
*
* Restart the extension, re-activation applied by calling back to `activate`.
*/
private restart = (subscriptions: { dispose(): void; }[]) => async () => {

await this.status.loading('Restarting extension...');

this.info('RESTARTING EXTENSION');

this.isReady = false;
this.canFormat = false;
this.config.method = ConfigMethod.Workspace;
this.config.target = ConfigurationTarget.Workspace;
this.uri.liquidrc = null;
this.formatting.reset();
this.getWatchers(false);

for (const subscription of subscriptions) subscription.dispose();

await this.activate(subscriptions);

this.info('EXTENSION RESTARTED');

};

private listeners (subscriptions: { dispose(): void; }[]) {

this.formatting.listen.event(this.onFormattingEvent, this, subscriptions);

}

/**
* Window Events
*
* Subscribe all window related events of the client.
*/
private windows (subscriptions: { dispose(): void; }[]) {

window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this, subscriptions);

}

/**
* Workspace Events
*
* Subscribe all workspace related events of the client.
*/
private workspace (subscriptions: { dispose(): void; }[]) {

workspace.onDidRenameFiles(this.onDidRenameFiles, this, subscriptions);
workspace.onDidDeleteFiles(this.onDidDeleteFiles, this, subscriptions);
workspace.onDidCreateFiles(this.onDidCreateFiles, this, subscriptions);
workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this, subscriptions);
workspace.onDidCloseTextDocument(this.onDidCloseTextDocument, this, subscriptions);
workspace.onDidChangeTextDocument(this.onDidChangeTextDocument, this, subscriptions);
workspace.onDidSaveTextDocument(this.onDidSaveTextDocument, this, subscriptions);

}

/**
* Language Events
*
* Subscribe all language related events of the client.
*/
private register (subscriptions: { dispose(): void; }[]) {

subscriptions.push(
languages.registerDocumentLinkProvider(this.selector, this.links),
languages.registerHoverProvider(this.selector, this.hovers),
languages.registerCompletionItemProvider(this.selector, this.completion, ...this.completion.triggers),
languages.registerDocumentFormattingEditProvider(this.selector, this.formatting)
);

}

/**
* Command Events
*
* Subscribe all command related events of the client.
*/
private commands (subscriptions: { dispose(): void; }[]) {

subscriptions.push(
commands.registerCommand('liquid.generateLiquidrc', this.generateLiquidrc, this),
commands.registerCommand('liquid.openOutput', this.toggleOutput, this),
commands.registerCommand('liquid.formatDocument', this.formatDocument, this),
commands.registerCommand('liquid.enableFormatting', this.enableFormatting, this),
commands.registerCommand('liquid.disableFormatting', this.disableFormatting, this),
commands.registerCommand('liquid.releaseNotes', this.releaseNotes, this),
commands.registerCommand('liquid.restartExtension', this.restart(subscriptions))
);

}

}

/**
* vscode-liquid
*
* Language features for working with the Liquid Template Language.
*/
export async function activate ({ subscriptions, extension }: ExtensionContext) {

const liquid = new VSCodeLiquid(extension);

await liquid.activate(subscriptions);

};
Loading

0 comments on commit 1038cb8

Please sign in to comment.