From c015b2d090d6124327e03712a2960c4c057d2234 Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 26 Apr 2024 16:43:05 +0100 Subject: [PATCH 1/2] adding review highlight --- package-lock.json | 2 +- src/extension.js | 348 ++++++++++++++++++++++--------------- src/util.js | 428 +++++++++++++++++++++++++--------------------- test/index.js | 8 +- 4 files changed, 442 insertions(+), 344 deletions(-) diff --git a/package-lock.json b/package-lock.json index 36cf066..4952b8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3576,4 +3576,4 @@ "dev": true } } -} +} \ No newline at end of file diff --git a/src/extension.js b/src/extension.js index 8ae0439..7d6f7f6 100644 --- a/src/extension.js +++ b/src/extension.js @@ -4,174 +4,238 @@ * NOTE: each decoration type has a unique key, the highlight and clear highight functionality are based on it */ -var vscode = require('vscode'); -var util = require('./util'); +var vscode = require("vscode"); +var util = require("./util"); +const { todo } = require("node:test"); var window = vscode.window; var workspace = vscode.workspace; function activate(context) { - - var timeout = null; - var activeEditor = window.activeTextEditor; - var isCaseSensitive, assembledData, decorationTypes, pattern, styleForRegExp, keywordsPattern; - var workspaceState = context.workspaceState; - - var settings = workspace.getConfiguration('todohighlight'); - - init(settings); - - context.subscriptions.push(vscode.commands.registerCommand('todohighlight.toggleHighlight', function () { - settings.update('isEnable', !settings.get('isEnable'), true).then(function () { + var timeout = null; + var activeEditor = window.activeTextEditor; + var isCaseSensitive, + assembledData, + decorationTypes, + pattern, + styleForRegExp, + keywordsPattern; + var workspaceState = context.workspaceState; + + var settings = workspace.getConfiguration("todohighlight"); + + init(settings); + + context.subscriptions.push( + vscode.commands.registerCommand( + "todohighlight.toggleHighlight", + function () { + settings + .update("isEnable", !settings.get("isEnable"), true) + .then(function () { triggerUpdateDecorations(); - }); - })) - - context.subscriptions.push(vscode.commands.registerCommand('todohighlight.listAnnotations', function () { + }); + } + ) + ); + + context.subscriptions.push( + vscode.commands.registerCommand( + "todohighlight.listAnnotations", + function () { if (keywordsPattern.trim()) { - util.searchAnnotations(workspaceState, pattern, util.annotationsFound); + util.searchAnnotations( + workspaceState, + pattern, + util.annotationsFound + ); } else { - if (!assembledData) return; - var availableAnnotationTypes = Object.keys(assembledData); - availableAnnotationTypes.unshift('ALL'); - util.chooseAnnotationType(availableAnnotationTypes).then(function (annotationType) { - if (!annotationType) return; - var searchPattern = pattern; - if (annotationType != 'ALL') { - annotationType = util.escapeRegExp(annotationType); - searchPattern = new RegExp(annotationType, isCaseSensitive ? 'g' : 'gi'); - } - util.searchAnnotations(workspaceState, searchPattern, util.annotationsFound); + if (!assembledData) return; + var availableAnnotationTypes = Object.keys(assembledData); + availableAnnotationTypes.unshift("ALL"); + util + .chooseAnnotationType(availableAnnotationTypes) + .then(function (annotationType) { + if (!annotationType) return; + var searchPattern = pattern; + if (annotationType != "ALL") { + annotationType = util.escapeRegExp(annotationType); + searchPattern = new RegExp( + annotationType, + isCaseSensitive ? "g" : "gi" + ); + } + util.searchAnnotations( + workspaceState, + searchPattern, + util.annotationsFound + ); }); } - })); - - context.subscriptions.push(vscode.commands.registerCommand('todohighlight.showOutputChannel', function () { - var annotationList = workspaceState.get('annotationList', []); + } + ) + ); + + context.subscriptions.push( + vscode.commands.registerCommand( + "todohighlight.showOutputChannel", + function () { + var annotationList = workspaceState.get("annotationList", []); util.showOutputChannel(annotationList); - })); - - if (activeEditor) { + } + ) + ); + + if (activeEditor) { + triggerUpdateDecorations(); + } + + window.onDidChangeActiveTextEditor( + function (editor) { + activeEditor = editor; + if (editor) { triggerUpdateDecorations(); - } - - window.onDidChangeActiveTextEditor(function (editor) { - activeEditor = editor; - if (editor) { - triggerUpdateDecorations(); - } - }, null, context.subscriptions); - - workspace.onDidChangeTextDocument(function (event) { - if (activeEditor && event.document === activeEditor.document) { - triggerUpdateDecorations(); - } - }, null, context.subscriptions); - - workspace.onDidChangeConfiguration(function () { - settings = workspace.getConfiguration('todohighlight'); - - //NOTE: if disabled, do not re-initialize the data or we will not be able to clear the style immediatly via 'toggle highlight' command - if (!settings.get('isEnable')) return; - - init(settings); + } + }, + null, + context.subscriptions + ); + + workspace.onDidChangeTextDocument( + function (event) { + if (activeEditor && event.document === activeEditor.document) { triggerUpdateDecorations(); - }, null, context.subscriptions); - - function updateDecorations() { - - if (!activeEditor || !activeEditor.document) { - return; - } + } + }, + null, + context.subscriptions + ); + + workspace.onDidChangeConfiguration( + function () { + settings = workspace.getConfiguration("todohighlight"); + + //NOTE: if disabled, do not re-initialize the data or we will not be able to clear the style immediatly via 'toggle highlight' command + if (!settings.get("isEnable")) return; + + init(settings); + triggerUpdateDecorations(); + }, + null, + context.subscriptions + ); + + function updateDecorations() { + if (!activeEditor || !activeEditor.document) { + return; + } - var text = activeEditor.document.getText(); - var mathes = {}, match; - while (match = pattern.exec(text)) { - var startPos = activeEditor.document.positionAt(match.index); - var endPos = activeEditor.document.positionAt(match.index + match[0].length); - var decoration = { - range: new vscode.Range(startPos, endPos) - }; - - var matchedValue = match[0]; - if (!isCaseSensitive) { - matchedValue = matchedValue.toUpperCase(); - } - - if (mathes[matchedValue]) { - mathes[matchedValue].push(decoration); - } else { - mathes[matchedValue] = [decoration]; - } - - if (keywordsPattern.trim() && !decorationTypes[matchedValue]) { - decorationTypes[matchedValue] = window.createTextEditorDecorationType(styleForRegExp); - } - } + var text = activeEditor.document.getText(); + var mathes = {}, + match; + while ((match = pattern.exec(text))) { + var startPos = activeEditor.document.positionAt(match.index); + var endPos = activeEditor.document.positionAt( + match.index + match[0].length + ); + var decoration = { + range: new vscode.Range(startPos, endPos), + }; + + var matchedValue = match[0]; + if (!isCaseSensitive) { + matchedValue = matchedValue.toUpperCase(); + } + + if (mathes[matchedValue]) { + mathes[matchedValue].push(decoration); + } else { + mathes[matchedValue] = [decoration]; + } + + if (keywordsPattern.trim() && !decorationTypes[matchedValue]) { + decorationTypes[matchedValue] = + window.createTextEditorDecorationType(styleForRegExp); + } + } - Object.keys(decorationTypes).forEach((v) => { - if (!isCaseSensitive) { - v = v.toUpperCase(); - } - var rangeOption = settings.get('isEnable') && mathes[v] ? mathes[v] : []; - var decorationType = decorationTypes[v]; - activeEditor.setDecorations(decorationType, rangeOption); - }) + Object.keys(decorationTypes).forEach((v) => { + if (!isCaseSensitive) { + v = v.toUpperCase(); + } + var rangeOption = settings.get("isEnable") && mathes[v] ? mathes[v] : []; + var decorationType = decorationTypes[v]; + activeEditor.setDecorations(decorationType, rangeOption); + }); + } + + function init(settings) { + var customDefaultStyle = settings.get("defaultStyle"); + keywordsPattern = settings.get("keywordsPattern"); + isCaseSensitive = settings.get("isCaseSensitive", true); + + if (!window.statusBarItem) { + window.statusBarItem = util.createStatusBarItem(); + } + if (!window.outputChannel) { + window.outputChannel = window.createOutputChannel("TodoHighlight"); } - function init(settings) { - var customDefaultStyle = settings.get('defaultStyle'); - keywordsPattern = settings.get('keywordsPattern'); - isCaseSensitive = settings.get('isCaseSensitive', true); + decorationTypes = {}; - if (!window.statusBarItem) { - window.statusBarItem = util.createStatusBarItem(); + if (keywordsPattern.trim()) { + styleForRegExp = Object.assign( + {}, + util.DEFAULT_STYLE, + customDefaultStyle, + { + overviewRulerLane: vscode.OverviewRulerLane.Right, } - if (!window.outputChannel) { - window.outputChannel = window.createOutputChannel('TodoHighlight'); + ); + pattern = keywordsPattern; + } else { + assembledData = util.getAssembledData( + settings.get("keywords"), + customDefaultStyle, + isCaseSensitive + ); + Object.keys(assembledData).forEach((v) => { + if (!isCaseSensitive) { + v = v.toUpperCase(); } - decorationTypes = {}; - - if (keywordsPattern.trim()) { - styleForRegExp = Object.assign({}, util.DEFAULT_STYLE, customDefaultStyle, { - overviewRulerLane: vscode.OverviewRulerLane.Right - }); - pattern = keywordsPattern; - } else { - assembledData = util.getAssembledData(settings.get('keywords'), customDefaultStyle, isCaseSensitive); - Object.keys(assembledData).forEach((v) => { - if (!isCaseSensitive) { - v = v.toUpperCase() - } - - var mergedStyle = Object.assign({}, { - overviewRulerLane: vscode.OverviewRulerLane.Right - }, assembledData[v]); - - if (!mergedStyle.overviewRulerColor) { - // use backgroundColor as the default overviewRulerColor if not specified by the user setting - mergedStyle.overviewRulerColor = mergedStyle.backgroundColor; - } - - decorationTypes[v] = window.createTextEditorDecorationType(mergedStyle); - }); - - pattern = Object.keys(assembledData).map((v) => { - return util.escapeRegExp(v); - }).join('|'); + var mergedStyle = Object.assign( + {}, + { + overviewRulerLane: vscode.OverviewRulerLane.Right, + }, + assembledData[v] + ); + + if (!mergedStyle.overviewRulerColor) { + // use backgroundColor as the default overviewRulerColor if not specified by the user setting + mergedStyle.overviewRulerColor = mergedStyle.backgroundColor; } - pattern = new RegExp(pattern, 'gi'); - if (isCaseSensitive) { - pattern = new RegExp(pattern, 'g'); - } + decorationTypes[v] = window.createTextEditorDecorationType(mergedStyle); + }); + pattern = Object.keys(assembledData) + .map((v) => { + return util.escapeRegExp(v); + }) + .join("|"); } - function triggerUpdateDecorations() { - timeout && clearTimeout(timeout); - timeout = setTimeout(updateDecorations, 0); + pattern = new RegExp(pattern, "gi"); + if (isCaseSensitive) { + pattern = new RegExp(pattern, "g"); } + } + + function triggerUpdateDecorations() { + timeout && clearTimeout(timeout); + timeout = setTimeout(updateDecorations, 0); + } } exports.activate = activate; diff --git a/src/util.js b/src/util.js index 5e91e2f..fe72b44 100644 --- a/src/util.js +++ b/src/util.js @@ -1,261 +1,295 @@ -var vscode = require('vscode'); +var vscode = require("vscode"); var os = require("os"); var window = vscode.window; var workspace = vscode.workspace; -var defaultIcon = '$(checklist)'; -var zapIcon = '$(zap)'; -var defaultMsg = '0'; - -var DEFAULT_KEYWORDS = { - "TODO:": { - text: "TODO:", - color: '#fff', - backgroundColor: '#ffbd2a', - overviewRulerColor: 'rgba(255,189,42,0.8)' +var defaultIcon = "$(checklist)"; +var zapIcon = "$(zap)"; +var defaultMsg = "0"; + +//REVIEW: +//TODO: + + var DEFAULT_KEYWORDS = { + "TODO:": { + text: "TODO:", + color: "#fff", + backgroundColor: "#ffbd2a", + overviewRulerColor: "rgba(255,189,42,0.8)", + }, + "FIXME:": { + text: "FIXME:", + color: "#fff", + backgroundColor: "#f06292", + overviewRulerColor: "rgba(240,98,146,0.8)", }, - "FIXME:": { - text: "FIXME:", - color: '#fff', - backgroundColor: '#f06292', - overviewRulerColor: 'rgba(240,98,146,0.8)' - } -}; + "REVIEW:": { + // New keyword added + text: "REVIEW:", + color: "#fff", + backgroundColor: "#8a2be2", // Purple color for background + overviewRulerColor: "rgba(138,43,226,0.8)", // Slightly transparent purple for the overview ruler + }, + }; var DEFAULT_STYLE = { - color: "#2196f3", - backgroundColor: "#ffeb3b", + color: "#2196f3", + backgroundColor: "#ffeb3b", }; function getAssembledData(keywords, customDefaultStyle, isCaseSensitive) { - var result = {} - keywords.forEach((v) => { - v = typeof v == 'string' ? { text: v } : v; - var text = v.text; - if (!text) return;//NOTE: in case of the text is empty - - if (!isCaseSensitive) { - text = text.toUpperCase(); - } - - if (text == 'TODO:' || text == 'FIXME:') { - v = Object.assign({}, DEFAULT_KEYWORDS[text], v); - } - result[text] = Object.assign({}, DEFAULT_STYLE, customDefaultStyle, v); - }) + var result = {}; + keywords.forEach((v) => { + v = typeof v == "string" ? { text: v } : v; + var text = v.text; + if (!text) return; //NOTE: in case of the text is empty + + if (!isCaseSensitive) { + text = text.toUpperCase(); + } - Object.keys(DEFAULT_KEYWORDS).forEach((v) => { - if (!result[v]) { - result[v] = Object.assign({}, DEFAULT_STYLE, customDefaultStyle, DEFAULT_KEYWORDS[v]); - } - }); + if (text == "TODO:" || text == "FIXME:" || text == "REVIEW:") { + v = Object.assign({}, DEFAULT_KEYWORDS[text], v); + } + result[text] = Object.assign({}, DEFAULT_STYLE, customDefaultStyle, v); + }); + + Object.keys(DEFAULT_KEYWORDS).forEach((v) => { + if (!result[v]) { + result[v] = Object.assign( + {}, + DEFAULT_STYLE, + customDefaultStyle, + DEFAULT_KEYWORDS[v] + ); + } + }); - return result; + return result; } function chooseAnnotationType(availableAnnotationTypes) { - return window.showQuickPick(availableAnnotationTypes, {}); + return window.showQuickPick(availableAnnotationTypes, {}); } //get the include/exclude config function getPathes(config) { - return Array.isArray(config) ? - '{' + config.join(',') + '}' - : (typeof config == 'string' ? config : ''); + return Array.isArray(config) + ? "{" + config.join(",") + "}" + : typeof config == "string" + ? config + : ""; } function searchAnnotations(workspaceState, pattern, callback) { + var settings = workspace.getConfiguration("todohighlight"); + var includePattern = getPathes(settings.get("include")) || "{**/*}"; + var excludePattern = getPathes(settings.get("exclude")); + var limitationForSearch = settings.get("maxFilesForSearch", 5120); - var settings = workspace.getConfiguration('todohighlight'); - var includePattern = getPathes(settings.get('include')) || '{**/*}'; - var excludePattern = getPathes(settings.get('exclude')); - var limitationForSearch = settings.get('maxFilesForSearch', 5120); - - var statusMsg = ` Searching...`; - - window.processing = true; + var statusMsg = ` Searching...`; - setStatusMsg(zapIcon, statusMsg); - - workspace.findFiles(includePattern, excludePattern, limitationForSearch).then(function (files) { - - if (!files || files.length === 0) { - callback({ message: 'No files found' }); - return; - } + window.processing = true; - var totalFiles = files.length, - progress = 0, - times = 0, - annotations = {}, - annotationList = []; + setStatusMsg(zapIcon, statusMsg); - function file_iterated() { - times++; - progress = Math.floor(times / totalFiles * 100); - - setStatusMsg(zapIcon, progress + '% ' + statusMsg); + workspace.findFiles(includePattern, excludePattern, limitationForSearch).then( + function (files) { + if (!files || files.length === 0) { + callback({ message: "No files found" }); + return; + } - if (times === totalFiles || window.manullyCancel) { - window.processing = true; - workspaceState.update('annotationList', annotationList); - callback(null, annotations, annotationList); - } - } + var totalFiles = files.length, + progress = 0, + times = 0, + annotations = {}, + annotationList = []; - for (var i = 0; i < totalFiles; i++) { + function file_iterated() { + times++; + progress = Math.floor((times / totalFiles) * 100); - workspace.openTextDocument(files[i]).then(function (file) { - searchAnnotationInFile(file, annotations, annotationList, pattern); - file_iterated(); - }, function (err) { - errorHandler(err); - file_iterated(); - }); + setStatusMsg(zapIcon, progress + "% " + statusMsg); + if (times === totalFiles || window.manullyCancel) { + window.processing = true; + workspaceState.update("annotationList", annotationList); + callback(null, annotations, annotationList); } - - }, function (err) { - errorHandler(err); - }); + } + + for (var i = 0; i < totalFiles; i++) { + workspace.openTextDocument(files[i]).then( + function (file) { + searchAnnotationInFile(file, annotations, annotationList, pattern); + file_iterated(); + }, + function (err) { + errorHandler(err); + file_iterated(); + } + ); + } + }, + function (err) { + errorHandler(err); + } + ); } function searchAnnotationInFile(file, annotations, annotationList, regexp) { - var fileInUri = file.uri.toString(); - var pathWithoutFile = fileInUri.substring(7, fileInUri.length); - - for (var line = 0; line < file.lineCount; line++) { - var lineText = file.lineAt(line).text; - var match = lineText.match(regexp); - if (match !== null) { - if (!annotations.hasOwnProperty(pathWithoutFile)) { - annotations[pathWithoutFile] = []; - } - var content = getContent(lineText, match); - if (content.length > 500) { - content = content.substring(0, 500).trim() + '...'; - } - var locationInfo = getLocationInfo(fileInUri, pathWithoutFile, lineText, line, match); - - var annotation = { - uri: locationInfo.uri, - label: content, - detail: locationInfo.relativePath, - lineNum: line, - fileName: locationInfo.absPath, - startCol: locationInfo.startCol, - endCol: locationInfo.endCol - }; - annotationList.push(annotation); - annotations[pathWithoutFile].push(annotation); - } + var fileInUri = file.uri.toString(); + var pathWithoutFile = fileInUri.substring(7, fileInUri.length); + + for (var line = 0; line < file.lineCount; line++) { + var lineText = file.lineAt(line).text; + var match = lineText.match(regexp); + if (match !== null) { + if (!annotations.hasOwnProperty(pathWithoutFile)) { + annotations[pathWithoutFile] = []; + } + var content = getContent(lineText, match); + if (content.length > 500) { + content = content.substring(0, 500).trim() + "..."; + } + var locationInfo = getLocationInfo( + fileInUri, + pathWithoutFile, + lineText, + line, + match + ); + + var annotation = { + uri: locationInfo.uri, + label: content, + detail: locationInfo.relativePath, + lineNum: line, + fileName: locationInfo.absPath, + startCol: locationInfo.startCol, + endCol: locationInfo.endCol, + }; + annotationList.push(annotation); + annotations[pathWithoutFile].push(annotation); } + } } function annotationsFound(err, annotations, annotationList) { - if (err) { - console.log('todohighlight err:', err); - setStatusMsg(defaultIcon, defaultMsg); - return; - } + if (err) { + console.log("todohighlight err:", err); + setStatusMsg(defaultIcon, defaultMsg); + return; + } - var resultNum = annotationList.length; - var tooltip = resultNum + ' result(s) found'; - setStatusMsg(defaultIcon, resultNum, tooltip); - showOutputChannel(annotationList); + var resultNum = annotationList.length; + var tooltip = resultNum + " result(s) found"; + setStatusMsg(defaultIcon, resultNum, tooltip); + showOutputChannel(annotationList); } function showOutputChannel(data) { - if (!window.outputChannel) return; - window.outputChannel.clear(); - - if (data.length === 0) { - window.showInformationMessage('No results'); - return; + if (!window.outputChannel) return; + window.outputChannel.clear(); + + if (data.length === 0) { + window.showInformationMessage("No results"); + return; + } + + var settings = workspace.getConfiguration("todohighlight"); + var toggleURI = settings.get("toggleURI", false); + + data.forEach(function (v, i, a) { + // due to an issue of vscode(https://github.com/Microsoft/vscode/issues/586), in order to make file path clickable within the output channel,the file path differs from platform + var patternA = "#" + (i + 1) + "\t" + v.uri + "#" + (v.lineNum + 1); + var patternB = + "#" + + (i + 1) + + "\t" + + v.uri + + ":" + + (v.lineNum + 1) + + ":" + + (v.startCol + 1); + var patterns = [patternA, patternB]; + + //for windows and mac + var patternType = 0; + if (os.platform && os.platform() === "linux") { + // for linux + patternType = 1; } - var settings = workspace.getConfiguration('todohighlight'); - var toggleURI = settings.get('toggleURI', false); - - data.forEach(function (v, i, a) { - // due to an issue of vscode(https://github.com/Microsoft/vscode/issues/586), in order to make file path clickable within the output channel,the file path differs from platform - var patternA = '#' + (i + 1) + '\t' + v.uri + '#' + (v.lineNum + 1); - var patternB = '#' + (i + 1) + '\t' + v.uri + ':' + (v.lineNum + 1) + ':' + (v.startCol + 1); - var patterns = [patternA, patternB]; - - //for windows and mac - var patternType = 0; - if (os.platform && os.platform() === "linux") { - // for linux - patternType = 1; - } - - if (toggleURI) { - //toggle the pattern - patternType = +!patternType; - } - window.outputChannel.appendLine(patterns[patternType]); - window.outputChannel.appendLine('\t' + v.label + '\n'); - }); - window.outputChannel.show(); + if (toggleURI) { + //toggle the pattern + patternType = +!patternType; + } + window.outputChannel.appendLine(patterns[patternType]); + window.outputChannel.appendLine("\t" + v.label + "\n"); + }); + window.outputChannel.show(); } function getContent(lineText, match) { - return lineText.substring(lineText.indexOf(match[0]), lineText.length); -}; + return lineText.substring(lineText.indexOf(match[0]), lineText.length); +} function getLocationInfo(fileInUri, pathWithoutFile, lineText, line, match) { - var rootPath = workspace.rootPath + '/'; - var outputFile = pathWithoutFile.replace(rootPath, ''); - var startCol = lineText.indexOf(match[0]); - var endCol = lineText.length; - var location = outputFile + ' ' + (line + 1) + ':' + (startCol + 1); - - return { - uri: fileInUri, - absPath: pathWithoutFile, - relativePath: location, - startCol: startCol, - endCol: endCol - }; -}; + var rootPath = workspace.rootPath + "/"; + var outputFile = pathWithoutFile.replace(rootPath, ""); + var startCol = lineText.indexOf(match[0]); + var endCol = lineText.length; + var location = outputFile + " " + (line + 1) + ":" + (startCol + 1); + + return { + uri: fileInUri, + absPath: pathWithoutFile, + relativePath: location, + startCol: startCol, + endCol: endCol, + }; +} function createStatusBarItem() { - var statusBarItem = window.createStatusBarItem(vscode.StatusBarAlignment.Left); - statusBarItem.text = defaultIcon + defaultMsg; - statusBarItem.tooltip = 'List annotations'; - statusBarItem.command = 'todohighlight.showOutputChannel'; - return statusBarItem; -}; + var statusBarItem = window.createStatusBarItem( + vscode.StatusBarAlignment.Left + ); + statusBarItem.text = defaultIcon + defaultMsg; + statusBarItem.tooltip = "List annotations"; + statusBarItem.command = "todohighlight.showOutputChannel"; + return statusBarItem; +} function errorHandler(err) { - window.processing = true; - setStatusMsg(defaultIcon, defaultMsg); - console.log('todohighlight err:', err); + window.processing = true; + setStatusMsg(defaultIcon, defaultMsg); + console.log("todohighlight err:", err); } function setStatusMsg(icon, msg, tooltip) { - if (window.statusBarItem) { - window.statusBarItem.text = `${icon} ${msg}` || ''; - if (tooltip) { - window.statusBarItem.tooltip = tooltip; - } - window.statusBarItem.show(); + if (window.statusBarItem) { + window.statusBarItem.text = `${icon} ${msg}` || ""; + if (tooltip) { + window.statusBarItem.tooltip = tooltip; } + window.statusBarItem.show(); + } } function escapeRegExp(s) { - return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); + return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"); } module.exports = { - DEFAULT_STYLE, - getAssembledData, - chooseAnnotationType, - searchAnnotations, - annotationsFound, - createStatusBarItem, - setStatusMsg, - showOutputChannel, - escapeRegExp + DEFAULT_STYLE, + getAssembledData, + chooseAnnotationType, + searchAnnotations, + annotationsFound, + createStatusBarItem, + setStatusMsg, + showOutputChannel, + escapeRegExp, }; diff --git a/test/index.js b/test/index.js index 5604517..28215d1 100644 --- a/test/index.js +++ b/test/index.js @@ -10,13 +10,13 @@ // to report the results back to the caller. When the tests are finished, return // a possible error to the callback or null if none. -var testRunner = require('vscode/lib/testrunner'); +var testRunner = require("vscode/lib/testrunner"); // You can directly control Mocha options by uncommenting the following lines // See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info testRunner.configure({ - ui: 'tdd', // the TDD UI is being used in extension.test.js (suite, test, etc.) - useColors: true // colored output from test results + ui: "tdd", // the TDD UI is being used in extension.test.js (suite, test, etc.) + useColors: true, // colored output from test results }); -module.exports = testRunner; \ No newline at end of file +module.exports = testRunner; From 114e3804448bd211b9f254b64b00440b341094f4 Mon Sep 17 00:00:00 2001 From: sahar Date: Fri, 26 Apr 2024 17:01:51 +0100 Subject: [PATCH 2/2] adding review highlight --- src/extension.js | 4 +-- src/util.js | 82 +++++++++++++++++++++++------------------------- 2 files changed, 42 insertions(+), 44 deletions(-) diff --git a/src/extension.js b/src/extension.js index 7d6f7f6..3f6d1bd 100644 --- a/src/extension.js +++ b/src/extension.js @@ -4,8 +4,8 @@ * NOTE: each decoration type has a unique key, the highlight and clear highight functionality are based on it */ -var vscode = require("vscode"); -var util = require("./util"); +var vscode = require('vscode'); +var util = require('./util'); const { todo } = require("node:test"); var window = vscode.window; var workspace = vscode.workspace; diff --git a/src/util.js b/src/util.js index fe72b44..fcd78bc 100644 --- a/src/util.js +++ b/src/util.js @@ -1,11 +1,11 @@ -var vscode = require("vscode"); +var vscode = require('vscode'); var os = require("os"); var window = vscode.window; var workspace = vscode.workspace; -var defaultIcon = "$(checklist)"; -var zapIcon = "$(zap)"; -var defaultMsg = "0"; +var defaultIcon = '$(checklist)'; +var zapIcon = '$(zap)'; +var defaultMsg = '0'; //REVIEW: //TODO: @@ -32,10 +32,10 @@ var defaultMsg = "0"; }, }; -var DEFAULT_STYLE = { - color: "#2196f3", - backgroundColor: "#ffeb3b", -}; + var DEFAULT_STYLE = { + color: "#2196f3", + backgroundColor: "#ffeb3b", + }; function getAssembledData(keywords, customDefaultStyle, isCaseSensitive) { var result = {}; @@ -237,35 +237,33 @@ function getContent(lineText, match) { } function getLocationInfo(fileInUri, pathWithoutFile, lineText, line, match) { - var rootPath = workspace.rootPath + "/"; - var outputFile = pathWithoutFile.replace(rootPath, ""); - var startCol = lineText.indexOf(match[0]); - var endCol = lineText.length; - var location = outputFile + " " + (line + 1) + ":" + (startCol + 1); - - return { - uri: fileInUri, - absPath: pathWithoutFile, - relativePath: location, - startCol: startCol, - endCol: endCol, - }; -} + var rootPath = workspace.rootPath + '/'; + var outputFile = pathWithoutFile.replace(rootPath, ''); + var startCol = lineText.indexOf(match[0]); + var endCol = lineText.length; + var location = outputFile + ' ' + (line + 1) + ':' + (startCol + 1); + + return { + uri: fileInUri, + absPath: pathWithoutFile, + relativePath: location, + startCol: startCol, + endCol: endCol + }; +}; function createStatusBarItem() { - var statusBarItem = window.createStatusBarItem( - vscode.StatusBarAlignment.Left - ); - statusBarItem.text = defaultIcon + defaultMsg; - statusBarItem.tooltip = "List annotations"; - statusBarItem.command = "todohighlight.showOutputChannel"; - return statusBarItem; -} + var statusBarItem = window.createStatusBarItem(vscode.StatusBarAlignment.Left); + statusBarItem.text = defaultIcon + defaultMsg; + statusBarItem.tooltip = 'List annotations'; + statusBarItem.command = 'todohighlight.showOutputChannel'; + return statusBarItem; +}; function errorHandler(err) { - window.processing = true; - setStatusMsg(defaultIcon, defaultMsg); - console.log("todohighlight err:", err); + window.processing = true; + setStatusMsg(defaultIcon, defaultMsg); + console.log('todohighlight err:', err); } function setStatusMsg(icon, msg, tooltip) { @@ -283,13 +281,13 @@ function escapeRegExp(s) { } module.exports = { - DEFAULT_STYLE, - getAssembledData, - chooseAnnotationType, - searchAnnotations, - annotationsFound, - createStatusBarItem, - setStatusMsg, - showOutputChannel, - escapeRegExp, + DEFAULT_STYLE, + getAssembledData, + chooseAnnotationType, + searchAnnotations, + annotationsFound, + createStatusBarItem, + setStatusMsg, + showOutputChannel, + escapeRegExp };