Skip to content

Commit 1a6b76c

Browse files
committed
Improve regex optimizing
1 parent 44e0ce2 commit 1a6b76c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Providers/CodeActionsProvider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,13 @@ async function optimizeRegex(edit: vscode.WorkspaceEdit, regexNode: webTreeSitte
229229
rules: {
230230
// Follow `vscode-oniguruma` which enables this Oniguruma option by default
231231
captureGroup: true,
232+
// end/while rules might reference begin rules OR the rule simply isn't finished being written, so we allow orphan backreferences
232233
allowOrphanBackrefs: true,
233234
},
234235
}).pattern;
235236

236237
const replacedText = JSON.stringify(optimized).slice(1, -1); // remove surrounding "double quotes"
237-
if (text != optimized) {
238+
if (regexNode.text != replacedText) {
238239
edit.replace(uri, range, replacedText);
239240
return;
240241
}
@@ -419,6 +420,8 @@ function sortJSON(edit: vscode.WorkspaceEdit, jsonTree: webTreeSitter.Tree, uri:
419420
const rootNode = jsonTree.rootNode;
420421
let newRootText = rootNode.text;
421422

423+
// https://github.com/microsoft/vscode-textmate/blob/main/src/rawGrammar.ts
424+
// https://github.com/textmate/textmate/blob/master/Frameworks/BundleEditor/src/BundleEditor.mm#L67
422425
const sortOrder = vscode.workspace.getConfiguration('json.textmate').get('sortOrder', [
423426
"version",
424427
"$schema",

0 commit comments

Comments
 (0)