From 9ec4fbddd559d93b3d6b072dc8f56d2a572585bd Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 13 Oct 2026 06:02:56 +0000 Subject: feat(plugin): color bracket pairs and mark unmatched brackets red Co-Authored-By: Claude Fable 5.1 --- plugin/src/extension.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'plugin/src/extension.js') diff --git a/plugin/src/extension.js b/plugin/src/extension.js index a7b4834..bfc51a1 100644 --- a/plugin/src/extension.js +++ b/plugin/src/extension.js @@ -3,6 +3,7 @@ const vscode = require('vscode'); const { indentationEdits } = require('./indentation'); const { codeOnly } = require('./lexical'); +const { unmatchedBrackets } = require('./brackets'); const languageId = 'cie-pseudocode'; function formatLines(document, startLine, endLine, keepBlankIndent = false) { @@ -12,7 +13,31 @@ function formatLines(document, startLine, endLine, keepBlankIndent = false) { } function activate(context) { + const invalidBracket = vscode.window.createTextEditorDecorationType({ + dark: { color: '#F44747' } + }); + function refreshBrackets(document) { + const rangesByDocument = new Map(); + for (const editor of vscode.window.visibleTextEditors) { + if (document && editor.document !== document) continue; + if (editor.document.languageId !== languageId) { + editor.setDecorations(invalidBracket, []); + continue; + } + if (!rangesByDocument.has(editor.document)) { + const ranges = unmatchedBrackets(editor.document.getText()).map(offset => + new vscode.Range(editor.document.positionAt(offset), editor.document.positionAt(offset + 1))); + rangesByDocument.set(editor.document, ranges); + } + editor.setDecorations(invalidBracket, rangesByDocument.get(editor.document)); + } + } context.subscriptions.push( + invalidBracket, + vscode.workspace.onDidChangeTextDocument(event => refreshBrackets(event.document)), + // Changing a document's language closes/reopens it without a text edit. + vscode.workspace.onDidOpenTextDocument(() => refreshBrackets()), + vscode.window.onDidChangeVisibleTextEditors(() => refreshBrackets()), vscode.languages.registerDocumentRangeFormattingEditProvider(languageId, { provideDocumentRangeFormattingEdits(document, range) { const endLine = range.end.character === 0 && range.end.line > range.start.line @@ -28,6 +53,7 @@ function activate(context) { } }, '\n', 'E', 'F', 'L', 'T', 'N') ); + refreshBrackets(); } module.exports = { activate }; -- cgit v1.3.1-4-g156e