From cc87d1633b2274bbab426a961b83efa7e78761ce Mon Sep 17 00:00:00 2001 From: Jose Fabio Date: Mon, 8 Sep 2025 12:29:10 -0600 Subject: [PATCH 1/3] Disable editor formatting --- .vscode/settings.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 3f5aa9c..d6f4133 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,5 +6,10 @@ "search.exclude": { "out": true // set this to false to include "out" folder in search results }, - "typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version + "typescript.tsdk": "./node_modules/typescript/lib", // we want to use the TS server from our node_modules folder to control its version + "editor.formatOnSave": false, + "editor.formatOnPaste": false, + "editor.formatOnType": false, + "editor.defaultFormatter": null, + "eslint.enable": false } \ No newline at end of file From 18f0d6fcc791fb065174a6c4433bfc30a46c741b Mon Sep 17 00:00:00 2001 From: Jose Fabio Date: Mon, 8 Sep 2025 12:37:59 -0600 Subject: [PATCH 2/3] maxLinesInFile --- package.json | 5 +++++ src/extension.ts | 56 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 94d0d70..8670499 100644 --- a/package.json +++ b/package.json @@ -96,6 +96,11 @@ "type": "number", "default": 1, "description": "This property defines the indent indicator lineWidth when using light mode." + }, + "indentRainbow.maxLinesInFile": { + "type": "integer", + "default": null, + "description": "Maximum number of lines in a file for indent-rainbow to be active. When not set or null, there is no limit." } } } diff --git a/src/extension.ts b/src/extension.ts index 147ae4e..16eb7ea 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -15,25 +15,29 @@ export function activate(context: vscode.ExtensionContext) { let activeEditor = vscode.window.activeTextEditor; + let config = vscode.workspace.getConfiguration('indentRainbow'); + + let maxLinesInFile = config.maxLinesInFile || null; + // Error color gets shown when tabs aren't right, // e.g. when you have your tabs set to 2 spaces but the indent is 3 spaces - const error_color = vscode.workspace.getConfiguration('indentRainbow')['errorColor'] || "rgba(128,32,32,0.3)"; + const error_color = config['errorColor'] || "rgba(128,32,32,0.3)"; const error_decoration_type = vscode.window.createTextEditorDecorationType({ backgroundColor: error_color }); - const tabmix_color = vscode.workspace.getConfiguration('indentRainbow')['tabmixColor'] || ""; + const tabmix_color = config['tabmixColor'] || ""; const tabmix_decoration_type = "" !== tabmix_color ? vscode.window.createTextEditorDecorationType({ backgroundColor: tabmix_color }) : null; - const ignoreLinePatterns = vscode.workspace.getConfiguration('indentRainbow')['ignoreLinePatterns'] || []; - const colorOnWhiteSpaceOnly = vscode.workspace.getConfiguration('indentRainbow')['colorOnWhiteSpaceOnly'] || false; - const indicatorStyle = vscode.workspace.getConfiguration('indentRainbow')['indicatorStyle'] || 'classic'; - const lightIndicatorStyleLineWidth = vscode.workspace.getConfiguration('indentRainbow')['lightIndicatorStyleLineWidth'] || 1; + const ignoreLinePatterns = config['ignoreLinePatterns'] || []; + const colorOnWhiteSpaceOnly = config['colorOnWhiteSpaceOnly'] || false; + const indicatorStyle = config['indicatorStyle'] || 'classic'; + const lightIndicatorStyleLineWidth = config['lightIndicatorStyleLineWidth'] || 1; // Colors will cycle through, and can be any size that you want - const colors = vscode.workspace.getConfiguration('indentRainbow')['colors'] || [ + const colors = config['colors'] || [ "rgba(255,255,64,0.07)", "rgba(127,255,127,0.07)", "rgba(255,127,255,0.07)", @@ -104,7 +108,7 @@ export function activate(context: vscode.ExtensionContext) { } function indentConfig() { - var skiplang = vscode.workspace.getConfiguration('indentRainbow')['ignoreErrorLanguages'] || []; + var skiplang = config['ignoreErrorLanguages'] || []; skipAllErrors = false; if(skiplang.length !== 0) { if(skiplang.indexOf('*') !== -1 || skiplang.indexOf(currentLanguageId) !== -1) { @@ -116,8 +120,8 @@ export function activate(context: vscode.ExtensionContext) { function checkLanguage() { if (activeEditor) { if(currentLanguageId !== activeEditor.document.languageId) { - var inclang = vscode.workspace.getConfiguration('indentRainbow')['includedLanguages'] || []; - var exclang = vscode.workspace.getConfiguration('indentRainbow')['excludedLanguages'] || []; + var inclang = config['includedLanguages'] || []; + var exclang = config['excludedLanguages'] || []; currentLanguageId = activeEditor.document.languageId; doIt = true; @@ -154,7 +158,7 @@ export function activate(context: vscode.ExtensionContext) { if (timeout) { clearTimeout(timeout); } - var updateDelay = vscode.workspace.getConfiguration('indentRainbow')['updateDelay'] || 100; + var updateDelay = config['updateDelay'] || 100; timeout = setTimeout(updateDecorations, updateDelay); } @@ -162,6 +166,21 @@ export function activate(context: vscode.ExtensionContext) { if (!activeEditor) { return; } + + // Check if file exceeds maximum line limit + if (maxLinesInFile !== null && activeEditor.document.lineCount > maxLinesInFile) { + // Clear any existing decorations when file is too large + var decor: vscode.DecorationOptions[] = []; + for (let decorationType of decorationTypes) { + activeEditor.setDecorations(decorationType, decor); + } + activeEditor.setDecorations(error_decoration_type, decor); + if (tabmix_decoration_type) { + activeEditor.setDecorations(tabmix_decoration_type, decor); + } + return; + } + var regEx = /^[\t ]+/gm; var text = activeEditor.document.getText(); var tabSizeRaw = activeEditor.options.tabSize; @@ -268,6 +287,11 @@ export function activate(context: vscode.ExtensionContext) { tabmix_decoration_type && activeEditor.setDecorations(tabmix_decoration_type, tabmix_decorator); clearMe = true; } + function updateConfig() { + config = vscode.workspace.getConfiguration('indentRainbow'); + maxLinesInFile = config.maxLinesInFile || null; + } + /** * Listen for configuration change in indentRainbow section * When anything changes in the section, show a prompt to reload @@ -276,6 +300,16 @@ export function activate(context: vscode.ExtensionContext) { vscode.workspace.onDidChangeConfiguration(configChangeEvent => { if (configChangeEvent.affectsConfiguration('indentRainbow')) { + // Update maxLinesInFile immediately without requiring reload + if (configChangeEvent.affectsConfiguration('indentRainbow.maxLinesInFile')) { + updateConfig(); + // Trigger decoration update with new settings + if (activeEditor && checkLanguage()) { + triggerUpdateDecorations(); + } + return; // Don't show reload prompt for this setting + } + const actions = ['Reload now', 'Later']; vscode.window From 268f04cb8501dfd17763d7e5ee9c88bfea55a315 Mon Sep 17 00:00:00 2001 From: Jose Fabio Date: Mon, 8 Sep 2025 12:41:25 -0600 Subject: [PATCH 3/3] Update readme to add indentRainbow.maxLinesInFile --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 7be3105..e20c8f1 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,10 @@ Although you can use it as it is, there is the possibility to configure some asp // The delay in ms until the editor gets updated. "indentRainbow.updateDelay": 100 // 10 makes it super fast but may cost more resources + + // Maximum number of lines for indent-rainbow to be active. When not set or null, there is no limit. + // By default it's set to null (no limit). + "indentRainbow.maxLinesInFile": 10000 // Improve performance by disabling on very large files ``` *Notice: Defining both `includedLanguages` and `excludedLanguages` does not make much sense. Use one of both!*