From 25a691fb9d97f55b2917196d0d742de1c41d46ef Mon Sep 17 00:00:00 2001 From: "Matthew A. Pearon" Date: Mon, 20 Jan 2020 17:54:06 -0600 Subject: [PATCH] Whole-line Highlighting - Added check for supported language - Rebuilt decorationOptions to add lineDecorations and wordDecorations - Added logic to style the line/word with their respective decorations --- out/extension.js | 86 +++++++++++++++++++++++++++------------- out/extension.js.map | 2 +- src/extension.ts | 94 ++++++++++++++++++++++++++------------------ 3 files changed, 115 insertions(+), 67 deletions(-) diff --git a/out/extension.js b/out/extension.js index 3e9fe6c..bea041e 100644 --- a/out/extension.js +++ b/out/extension.js @@ -10,6 +10,9 @@ function activate(context) { // No active edit is open if (!vscode_1.window.activeTextEditor) return; + if ((vscode_1.window.activeTextEditor.document.languageId) !== 'log') { + return; + } // Display a StatusBar message vscode_1.window.setStatusBarMessage('Show Trigger Words activated'); // Read in document text @@ -18,58 +21,87 @@ function activate(context) { var decorationOptions = [ { name: 'error', - expression: '(err(or)?|fail(ure)?|crit(ical)?)', - decoration: { - color: 'white', - backgroundColor: 'red', - fontWeight: 'bold' + expression: 'err(or)?|fail(ure)?|crit(ical)?', + lineDecoration: { + backgroundColor: '#FF000030' + }, + wordDecoration: { + color: 'black', + fontWeight: 'bolder', + backgroundColor: '#FF0000' } }, { name: 'warning', expression: 'warn(ing)?', - decoration: { - color: "black", - backgroundColor: "orange", - fontWeight: "bold" + lineDecoration: { + backgroundColor: '#FFFF0030' + }, + wordDecoration: { + color: 'black', + fontWeight: 'bolder', + backgroundColor: '#FFFF00' } }, { name: 'information', expression: 'info(rmation)?', - decoration: { - color: "white", - backgroundColor: "blue", - fontWeight: "bold" + lineDecoration: { + backgroundColor: '#007FFF30' + }, + wordDecoration: { + color: 'black', + fontWeight: 'bolder', + backgroundColor: '#007FFF' } }, { name: 'success', expression: 'succe(ssful|eded|ss)', - decoration: { - color: "white", - backgroundColor: "green", - fontWeight: "bold" + lineDecoration: { + backgroundColor: '#00ff0030' + }, + wordDecoration: { + color: 'black', + fontWeight: "bolder", + backgroundColor: '#00ff00' } } ]; // Loop through each decoration option decorationOptions.forEach(option => { console.log('Show-TriggerWords: Processing ' + option.name); - let optionDecoration = vscode_1.window.createTextEditorDecorationType(option.decoration); - let optionRanges = []; - let optionMatch; - let optionExpression = new RegExp(option.expression, 'gim'); + let optionWordDecoration = vscode_1.window.createTextEditorDecorationType(option.wordDecoration); + let optionWordRanges = []; + let optionWord; + let optionLineDecoration = vscode_1.window.createTextEditorDecorationType(option.lineDecoration); + let optionLineRanges = []; + let optionLine; + let optionLineExpression = new RegExp(('.+(' + option.expression + ').+'), 'gim'); + let optionWordExpression = new RegExp(option.expression, 'gim'); if (vscode_1.window.activeTextEditor) { - while (optionMatch = optionExpression.exec(editorText)) { - let optionStartIndex = vscode_1.window.activeTextEditor.document.positionAt(optionMatch.index); - let optionEndIndex = vscode_1.window.activeTextEditor.document.positionAt(optionMatch.index + optionMatch[0].length); - let optionRange = (new vscode_1.Range(optionStartIndex, optionEndIndex)); - optionRanges.push(optionRange); + while (optionLine = optionLineExpression.exec(editorText)) { + // Higlight Line + let lineStart = vscode_1.window.activeTextEditor.document.positionAt(optionLine.index); + let lineStop = vscode_1.window.activeTextEditor.document.positionAt(optionLine.index + optionLine[0].length); + let lineRange = (new vscode_1.Range(lineStart, lineStop)); + optionLineRanges.push(lineRange); + // Highlight Word + while (optionWord = optionWordExpression.exec(editorText)) { + let wordStart = vscode_1.window.activeTextEditor.document.positionAt(optionWord.index); + let wordStop = vscode_1.window.activeTextEditor.document.positionAt(optionWord.index + optionWord[0].length); + let wordRange = (new vscode_1.Range(wordStart, wordStop)); + optionWordRanges.push(wordRange); + continue; + } + ; continue; } ; - vscode_1.window.activeTextEditor.setDecorations(optionDecoration, optionRanges); + // Highlight the line + vscode_1.window.activeTextEditor.setDecorations(optionLineDecoration, optionLineRanges); + // Highlight the match + vscode_1.window.activeTextEditor.setDecorations(optionWordDecoration, optionWordRanges); } ; }); diff --git a/out/extension.js.map b/out/extension.js.map index 08d1f39..582ffbe 100644 --- a/out/extension.js.map +++ b/out/extension.js.map @@ -1 +1 @@ -{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;AAAA,mCAKgB;AAChB,SAAgB,QAAQ,CAAC,OAAyB;IACjD,OAAO,CAAC,GAAG,CAAC,qDAAqD,CAAC,CAAC;IACnE,iCAAiC;IACjC,IAAI,CAAC,eAAM,CAAC,gBAAgB;QAC3B,OAAO;IAER,IAAI,iBAAiB,GAAG,UAAU,OAAO,GAAG,KAAK;QAChD,yBAAyB;QACzB,IAAI,CAAC,eAAM,CAAC,gBAAgB;YAC3B,OAAO;QACR,8BAA8B;QAC9B,eAAM,CAAC,mBAAmB,CAAC,8BAA8B,CAAC,CAAC;QAE3D,wBAAwB;QACxB,IAAI,UAAU,GAAG,eAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QAE5D,yBAAyB;QACzB,IAAI,iBAAiB,GAAG;YACvB;gBACC,IAAI,EAAE,OAAO;gBACb,UAAU,EAAE,mCAAmC;gBAC/C,UAAU,EAAE;oBACX,KAAK,EAAE,OAAO;oBACd,eAAe,EAAE,KAAK;oBACtB,UAAU,EAAE,MAAM;iBAClB;aACD;YACD;gBACC,IAAI,EAAE,SAAS;gBACf,UAAU,EAAE,YAAY;gBACxB,UAAU,EAAE;oBACX,KAAK,EAAE,OAAO;oBACd,eAAe,EAAE,QAAQ;oBACzB,UAAU,EAAE,MAAM;iBAClB;aACD;YACD;gBACC,IAAI,EAAE,aAAa;gBACnB,UAAU,EAAE,gBAAgB;gBAC5B,UAAU,EAAE;oBACX,KAAK,EAAE,OAAO;oBACd,eAAe,EAAE,MAAM;oBACvB,UAAU,EAAE,MAAM;iBAClB;aACD;YACD;gBACC,IAAI,EAAE,SAAS;gBACf,UAAU,EAAE,sBAAsB;gBAClC,UAAU,EAAE;oBACX,KAAK,EAAE,OAAO;oBACd,eAAe,EAAE,OAAO;oBACxB,UA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CAAC,oBAAoB,EAAE,gBAAgB,CAAC,CAAC;gBAC/E,sBAAsB;gBACtB,eAAM,CAAC,gBAAgB,CAAC,cAAc,CAAC,oBAAoB,EAAE,gBAAgB,CAAC,CAAC;aAC/E;YAAA,CAAC;QACH,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC;IAEF,0BAA0B;IAC1B,IAAI,eAAM,CAAC,gBAAgB,EAAE;QAC5B,iBAAiB,EAAE,CAAC;KACpB;IAED,4BAA4B;IAC5B,eAAM,CAAC,2BAA2B,CAAC,MAAM,CAAC,EAAE;QAC3C,IAAI,MAAM,EAAE;YACX,iBAAiB,EAAE,CAAC;SACpB;IACF,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAEhC,2EAA2E;IAC3E,IAAI,UAAU,GAAG,iBAAQ,CAAC,eAAe,CAAC,4BAA4B,EAAE,GAAG,EAAE;QAC5E,iBAAiB,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACxC,CAAC;AA7HD,4BA6HC;AACD,SAAgB,UAAU,KAAK,CAAC;AAAhC,gCAAgC"} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index df84e2a..e7c8a50 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -14,6 +14,9 @@ export function activate(context: ExtensionContext) { // No active edit is open if (!window.activeTextEditor) return; + if((window.activeTextEditor.document.languageId) !== 'log'){ + return + } // Display a StatusBar message window.setStatusBarMessage('Show Trigger Words activated'); @@ -24,54 +27,50 @@ export function activate(context: ExtensionContext) { var decorationOptions = [ { name: 'error', - expression: '(err(or)?|fail(ure)?|crit(ical)?)', - wholeLine: true, - lineDeocoration: { - backgroundColor: "lightred" + expression: 'err(or)?|fail(ure)?|crit(ical)?', + lineDecoration: { + backgroundColor: '#FF000030' }, - matchDecoration: { - color: 'white', - backgroundColor: 'red', - fontWeight: 'bold' + wordDecoration: { + color: 'black', + fontWeight: 'bolder', + backgroundColor: '#FF0000' } }, { name: 'warning', expression: 'warn(ing)?', - wholeLine: true, - lineDeocoration: { - backgroundColor: "lightorange" + lineDecoration: { + backgroundColor: '#FFFF0030' }, - matchDecoration: { - color: "black", - backgroundColor: "orange", - fontWeight: "bold" + wordDecoration: { + color: 'black', + fontWeight: 'bolder', + backgroundColor: '#FFFF00' } }, { name: 'information', expression: 'info(rmation)?', - wholeLine: true, - lineDeocoration: { - backgroundColor: "lightblue" + lineDecoration: { + backgroundColor: '#007FFF30' }, - matchDecoration: { - color: "white", - backgroundColor: "blue", - fontWeight: "bold" + wordDecoration: { + color: 'black', + fontWeight: 'bolder', + backgroundColor: '#007FFF' } }, { name: 'success', expression: 'succe(ssful|eded|ss)', - wholeLine: true, - lineDeocoration: { - backgroundColor: "lightgreen" + lineDecoration: { + backgroundColor: '#00ff0030' }, - matchDecoration: { - color: "white", - backgroundColor: "green", - fontWeight: "bold" + wordDecoration: { + color: 'black', + fontWeight: "bolder", + backgroundColor: '#00ff00' } } ] @@ -79,19 +78,36 @@ export function activate(context: ExtensionContext) { // Loop through each decoration option decorationOptions.forEach(option => { console.log('Show-TriggerWords: Processing ' + option.name); - let optionMatchDecoration = window.createTextEditorDecorationType(option.matchDecoration); - let optionRanges = []; - let optionMatch; - let optionExpression = new RegExp(option.expression, 'gim'); + let optionWordDecoration = window.createTextEditorDecorationType(option.wordDecoration); + let optionWordRanges = []; + let optionWord; + let optionLineDecoration = window.createTextEditorDecorationType(option.lineDecoration); + let optionLineRanges = []; + let optionLine; + let optionLineExpression = new RegExp(('.+(' + option.expression + ').+'),'gim'); + let optionWordExpression = new RegExp(option.expression,'gim'); if (window.activeTextEditor) { - while (optionMatch = optionExpression.exec(editorText)) { - let optionStartIndex = window.activeTextEditor.document.positionAt(optionMatch.index); - let optionEndIndex = window.activeTextEditor.document.positionAt(optionMatch.index + optionMatch[0].length); - let optionRange = (new Range(optionStartIndex, optionEndIndex)); - optionRanges.push(optionRange); + while (optionLine = optionLineExpression.exec(editorText)) { + // Higlight Line + let lineStart = window.activeTextEditor.document.positionAt(optionLine.index); + let lineStop = window.activeTextEditor.document.positionAt(optionLine.index + optionLine[0].length); + let lineRange = (new Range(lineStart, lineStop)); + optionLineRanges.push(lineRange); + // Highlight Word + while (optionWord = optionWordExpression.exec(editorText)) { + let wordStart = window.activeTextEditor.document.positionAt(optionWord.index); + let wordStop = window.activeTextEditor.document.positionAt(optionWord.index + optionWord[0].length); + let wordRange = (new Range(wordStart, wordStop)); + optionWordRanges.push(wordRange); + continue; + + }; continue; }; - window.activeTextEditor.setDecorations(optionMatchDecoration, optionRanges); + // Highlight the line + window.activeTextEditor.setDecorations(optionLineDecoration, optionLineRanges); + // Highlight the match + window.activeTextEditor.setDecorations(optionWordDecoration, optionWordRanges); }; }); };