Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
TransportKind,
} = require('vscode-languageclient');


let client;

async function getThemeCheckExecutable() {
Expand Down Expand Up @@ -77,13 +78,13 @@ async function restartServer() {
if (client) await stopServer();
await startServer();
}
/** */

function onConfigChange(event) {
if (event.affectsConfiguration('themeCheck.languageServerPath')) {
restartServer();
}
}

async function activate(context) {
context.subscriptions.push(
vscode.commands.registerCommand(
Expand Down
35 changes: 35 additions & 0 deletions language-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"comments": {
"blockComment": ["{% comment %}\n", "\n{% endcomment %}"]
},
"brackets": [
["{", "}"],
["[", "]"],
["<", ">"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}" },
{ "open": "{%", "close": "%}" },
{ "open": "{%-", "close": "-%}" },
{ "open": "{{", "close": "}}" },
{ "open": "{{-", "close": "-}}" },
{ "open": "<", "close": ">" },
{ "open": "[", "close": "]" },
{ "open": "'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "\"", "close": "\"", "notIn": ["string"] }
],
"autoCloseBefore": "%-:.,=}])>` \n\t",
"surroundingPairs": [
["-", "-"],
["{", "}"],
["[", "]"],
["(", ")"],
["'", "'"],
["\"", "\""],
["`", "`"]
],
"indentationRules": {
"increaseIndentPattern": "(<(?!\\/|area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[^>]+>|{%-?\\s+(?:if|form|comment|case|when|for|unless).*?-?%}|{%(?:(?!%}).)*|{{(?:(?!}}).)*)$",
"decreaseIndentPattern": "^\\s*(<\\/[^>]+>|{%-?\\s+(?:endif|endform|endcomment|endcase|endwhen|endfor|endunless).*?-?%}|%}|}}|>)"
}
}
85 changes: 85 additions & 0 deletions make-identation-rules-regex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// These HTML elements do not require to be closed (either via </tag> or <tag />)
const voidElements = [
'area',
'base',
'br',
'col',
'embed',
'hr',
'img',
'input',
'keygen',
'link',
'menuitem',
'meta',
'param',
'source',
'track',
'wbr',
];

const openingLiquidTags = [
'if',
'form',
'comment',
'case',
'when',
'for',
'unless',
];

const closingLiquidTags = openingLiquidTags.map(
(name) => `end${name}`,
);

// https://regex101.com/r/pl3GPU/1
function increaseIndentPattern() {
const patterns = [
// Opening HTML tags that are not self closing. Here we use a negative
// lookahead (?!) to make sure that the next character after < is not /
// or one of the void elements.
String.raw`<(?!\/|${voidElements.join('|')})[^>]+>`,

// Opening liquid tags that have a corresponding end$name tag.
String.raw`{%-?\s+(?:${openingLiquidTags.join('|')}).*?-?%}`, // opening liquid tags

// Tag start not closed
String.raw`{%(?:(?!%}).)*`,

// Variable start not closed
String.raw`{{(?:(?!}}).)*`,
];

// The line must end by one of those patterns
return String.raw`(${patterns.join('|')})$`;
}

function decreaseIndentPattern() {
const patterns = [
// Closing HTML tags
String.raw`<\/[^>]+>`,

// Closing liquid tags
String.raw`{%-?\s+(?:${closingLiquidTags.join('|')}).*?-?%}`, // opening liquid tags

// Multiline tag closed
String.raw`%}`,

// Multiline variable closed
String.raw`}}`,

// Multiline HTML tag closed
String.raw`>`,
];

// The line must start by one of those patterns
return String.raw`^\s*(${patterns.join('|')})`;
}

const indentationRules = {
indentationRules: {
increaseIndentPattern: increaseIndentPattern(),
decreaseIndentPattern: decreaseIndentPattern(),
}
}
console.log(JSON.stringify(indentationRules, null, 2));
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
],
"extensions": [
".liquid"
]
],
"configuration": "./language-configuration.json"
}
]
},
Expand Down