Coder Social home page Coder Social logo

oderwat / vscode-indent-rainbow Goto Github PK

View Code? Open in Web Editor NEW
387.0 8.0 50.0 26.04 MB

Extension which shows indentation with a faint rainbow colored background to make them more readable

License: MIT License

TypeScript 85.31% JavaScript 13.29% Shell 1.40%

vscode-indent-rainbow's Introduction

Indent-Rainbow

A simple extension to make indentation more readable

If you use this plugin a lot, please consider a donation:

Buy Me A Coffee

Donate with PayPal


This extension colorizes the indentation in front of your text, alternating four different colors on each step. Some may find it helpful in writing code for Python, Nim, Yaml, and probably even filetypes that are not indentation dependent.

Note: This will also work with vscode-web (github.dev) since version 8.0.0.

Example

Get it here: Visual Studio Code Marketplace

It uses the current editor window tab size and can handle mixed tab + spaces (not recommended). In addition, it visibly marks lines where the indentation is not a multiple of the tab size. The visualization can help to find problems with the indentation in some situations.

Configuration

Although you can use it as it is, there is the possibility to configure some aspects of the extension:

  // For which languages indent-rainbow should be activated (if empty it means all).
  "indentRainbow.includedLanguages": [] // for example ["nim", "nims", "python"]

  // For which languages indent-rainbow should be deactivated (if empty it means none).
  "indentRainbow.excludedLanguages": ["plaintext"]

  // The delay in ms until the editor gets updated.
  "indentRainbow.updateDelay": 100 // 10 makes it super fast but may cost more resources

Notice: Defining both includedLanguages and excludedLanguages does not make much sense. Use one of both!

You can configure your own colors by adding and tampering with the following code:

  // Defining custom colors instead of default "Rainbow" for dark backgrounds.
  "indentRainbow.colors": [
    "rgba(255,255,64,0.07)",
    "rgba(127,255,127,0.07)",
    "rgba(255,127,255,0.07)",
    "rgba(79,236,236,0.07)"
  ]

  // The indent color if the number of spaces is not a multiple of "tabSize".
  "indentRainbow.errorColor": "rgba(128,32,32,0.6)"

  // The indent color when there is a mix between spaces and tabs.
  // To be disabled this coloring set this to an empty string.
  "indentRainbow.tabmixColor": "rgba(128,32,96,0.6)"

Notice: errorColor was renamed from error_color in earlier versions.

Light mode (new since v8.3.0)

There is a (new) alternate mode that uses lines (with a customizable width) instead of the background coloring of the whitespace. Here is an example configuration I like:

  // Using the light mode
  "indentRainbow.indicatorStyle": "light",
  // we use a simple 1 pixel wide line
  "indentRainbow.lightIndicatorStyleLineWidth": 1,
  // the same colors as above but more visible
  "indentRainbow.colors": [
    "rgba(255,255,64,0.3)",
    "rgba(127,255,127,0.3)",
    "rgba(255,127,255,0.3)",
    "rgba(79,236,236,0.3)"]

For this addition, a big thank you goes to Christian Hoock wk1. He also added the editor window reload on config changes.

Hiding error highlighting

Skip error highlighting for RegEx patterns. For example, you may want to turn off the indent errors for JSDoc's valid additional space (disabled by default), or comment lines beginning with //

  // Example of regular expression in JSON (note double backslash to escape characters)
  "indentRainbow.ignoreLinePatterns" : [
    "/[ \t]* [*]/g", // lines begining with <whitespace><space>*
    "/[ \t]+[/]{2}/g" // lines begininning with <whitespace>//
  ]

Skip error highlighting for some or all languages. For example, you may want to turn off the indent errors for markdown and haskell (which is the default)

  "indentRainbow.ignoreErrorLanguages" : [
    "markdown",
    "haskell"
  ]

If error color is disabled, indent colors will be rendered until the length of rendered characters (white spaces, tabs, and other ones) is divisible by tabsize. Turn on this option to render white spaces and tabs only.

  "indentRainbow.colorOnWhiteSpaceOnly": true // false is the default

Build with:

npm install
npm run vscode:prepublish

Running npm run compile makes the compiler recompile on file change.

vscode-indent-rainbow's People

Contributors

albinodrought avatar dependabot[bot] avatar dinubs avatar fubuchi avatar oderwat avatar petemill avatar pisatoshi avatar rchanou avatar swapnilsanghvi avatar szhu avatar tanhakabir avatar wk1 avatar wraith13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-indent-rainbow's Issues

Mistakenly considering multi line code indentation as error

Firstly, I have to say that this is a really great extension. Thanks for it! The only minor issue I have with it is that whenever I have to break long lines of code into a multi-line code (e.g. in Python, using the \ character), the extension detects such indentation as if it was an error:

image

Is there currently a way to circumvent such an issue, even if it requires minor alterations in the source code itself? If not, here's a quick thinking I had on this issue.

Obviously, the fully fledged solution to this would require individual code for each supported programming language (e.g. do not consider error if suspicious indentation appear in lines whose above line did not end with a ; in languages that require semicolons, or do not consider error if suspicious indentation appear in a line whose above line ended with a \ in Python).

But perhaps there is a less troublesome approach. You could give the user the ability to specify, for each desired language, an ending character and whether it closes a code statement (like ; in C++) or keeps a code statement open (like \ in Python). Then generically, the extension would just use that to check whether a line should be marked for error. Of course, that would still not handle languages like R, which do not require a special character neither to close code statements nor to keep them open, but it would cover a lot of ground.

Change text color also?

Its possible to change the text color to make the readability better?
fe. Change color based on identation level (level 0 has one color, level 1 other different, and so on )
Btw, congrats for your extension !

Request: Display rainbow across empty lines

Our code style often breaks up sections with an empty line, which will have zero tabs or spaces, while the line before and after will have matching tabs or spaces. The break in the rainbow is distracting. Is there a current way to make the rainbow show up despite having zero tabs on the line? I only need it on empty lines where the indenting on the line before and after match.

Request: Option to use rainbow colors even when indentation doesn't match

I use clang-format and it doesn't always align things nicely to the 2 or 4 spaces, so there's a lot of red in my code.

I get why the error color is there, but for my use case it doesn't quite work. I can come up with three ways to configure the setting:

  1. "color-full-error-line" (standard, what it ships with today)
  2. "color-last-indent" (uses rainbow colors for all indent levels except for the very last, where the error is)
  3. "color-error-disabled" (this is what I want, at least for a few projects)

(Feel free to come up with better names. :) And number 2 is very optional but I think it could be nice.)

Light theme support

Hi, would it be possible to color the indents depending on the body background color?

If you have a light theme it looks a bit weird…

image

Breaks VS Code's built-in indentation detection

  • indent-rainbow version: 0.3.2
  • VSCode version: 1.1.0
  • OS Version: Win7 SP1 x64

How to reproduce:

  1. Make sure option editor.detectIndentation is set to true and editor.tabSize is set to 4.
  2. Open a text file with 2, 6, or 8 space indentation. Notice the status bar reports "Spaces: 4" rather than the detected indentation size.
  3. Select the "Detect Indentation from Content" action. Notice the status bar now reports the correct indentation size.
  4. Type any text into the file. Notice the status bar has returned to "Spaces: 4".

indentRainbow.colors size should be flexible

I'd love to be able to specify 1+ colors and have them loop around as expected, right now 4 colors are enforced.

image

Specifically I want to implement indent guides of a slightly transparent and completely transparent. This is possible right now using:

  "indentRainbow.colors": [
    "rgba(255,255,255,0.05)",
    "rgba(0,0,0,0)",
    "rgba(255,255,255,0.05)",
    "rgba(0,0,0,0)"
  ]

But should be using:

  "indentRainbow.colors": [
    "rgba(255,255,255,0.05)",
    "rgba(0,0,0,0)"
  ]

python combination of tab and spaces showing up with an error

In whitespace sensitive languages like Python, besides using only spaces or only tabs there is a mixed use alignment formatting style which goes like below

line1
<tab>->indent1
<tab>-><s><s>indent1+space to align with content above

this is being detected as mixed presence of tabs and spaces.
any suggestions or take as an enhancement request?
basically if the tab indent is same as the line above then allow arbitrary spaces after that ...it could be a preference to be enabled for languages

Use color of first word above

Instead of using random colors it might actually be even more useful to take the average color of the first word above (to avoid using parentheses and other 'neutral' element colors), that way it'll be easier to identify which indentation belongs to which line.

Only error color used

Hi,

since very recently I see only error color being used instead of the configured colors.
screen shot 2016-09-24 at 12 21 49 pm

This applies to both, VScode (Version 1.5.3) and VScode (Version 1.6.0-insider).

{
...
// Indent-Rainbow configuration

  // For which languages indent-rainbow should be activated (if empty it means all).
  "indentRainbow.includedLanguages": [],

  // For which languages indent-rainbow should be deactivated (if empty it means none).
  "indentRainbow.excludedLanguages": [],

  // The delay in ms until the editor gets updated.
  "indentRainbow.updateDelay": 100,

  // Automatically change indent settings for languages (see README.md for details).
  "indentRainbow.indentSetter": {},

  // An array with rgba strings which are used as colors.
  "indentRainbow.colors": [
    "rgba(64,64,16,0.3)",
    "rgba(32,64,32,0.3)",
    "rgba(64,32,64,0.3)",
    "rgba(16,48,48,0.3)",
    "rgba(128,32,32,0.3)"
  ],
...
}

wrong / broken indent detection

Hello,

I came across some weird error:

image

This is from the vscode settings.json

{
  "editor.renderWhitespace": "boundary",
  "editor.wordSeparators": "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?",
}

This is due to the * in the editor.wordSeparators setting. If I remove the * it works:

image

vsc

  • Extension Name: indent-rainbow
  • Extension Version: 7.2.4
  • OS Version: Windows_NT x64 10.0.17763
  • VSCode version: 1.28.0

We have written the needed data into your clipboard. Please paste:

Output window is colourised

The text output window is colourised (for example build output). This isn't much use. Could you disable it (possibly add a toggle for in case it desired).

Disable all errors

untitled

thanks for the great addon
any way to disable all errors? they show in addon output too? so cannot disable with ignoreErrorLanguages?
thanks

No license

Public repositories on GitHub are often used to share open source software. For your repository to truly be open source, you'll need to license it so that others are free to use, change, and distribute the software.

Refer to the following URL to read about how to determine a license that is appropriate for this application and how to apply it.

https://help.github.com/articles/licensing-a-repository/

All tab indents are shown as errors

I use tabs for indents in my C++ files. Recently I started seeing all such indents in error color. If I retype them as spaces, they are colored as normal.
I tried to change the VS Code settings to define indents as spaces or not - it seems that the extension just ignores this.

JSDoc comment block shown as indentation error

When writing javascript and documenting via JSDoc, normally there is an extra space after the indentation. This extra space is highlighted as red, which is correct, but not very intuitive.

class MyClass {
	/**
	 * Creates an instance of MyClass.
	 * 
	 * @memberof MyClass
	 */
	constructor() {}
}

Example:
image

Is it possible to add a setting to ignore tab errors for comment blocks or have some heuristics to detect if it is a JSDoc comment block?

Allow configuration of colors

Specifying an array of rgba colors would be a great way to allow users to customize:

{
  "indentRainbow.colors": [
    "rgba(255, 0, 0, .2)",
    "rgba(0, 255, 0, .2)",
    "rgba(0, 0, 255, .2)"
  ]
}

Configure extension ?

Where do you configure indent-rainbow; the settings.json file doesn't recognize any of this extensions settings ?

HSLA in default configuration.

I'm using hsla for the colors.
you should use them in the defaults :)
"indentRainbow.colors": [ "hsla( 70, 100%, 50%, 0.35)", "hsla(130, 100%, 50%, 0.35)", "hsla(190, 100%, 50%, 0.35)", "hsla(250, 100%, 50%, 0.35)", "hsla(310, 100%, 50%, 0.35)", "hsla( 10, 100%, 50%, 0.35)" ]

continue indentation on blank line

Is it possible to paint blank lines to the indentation level of the last non-blank line?

That way, blocks with blank lines in them still look like a coherent whole.

Mismatch between Prettier and indent-rainbow logic

There seems to be a disconnect between the logic applied by Prettier and indent rainbow.

image

In a multi-line object in a multi-line ternary Prettier will start counting its desired indentation starting from the {, where indent-rainbow counts from the default multiple of 4 spaces.

I understand why both Prettier and indent-rainbow do what they do.

I also understand there is probably little you can do about this.

For people looking for the same issue, I worked around the issue with this setting.

{
  "indentRainbow.errorColor": "rgba(0,0,0,0)",
}

This is better, though not ideal either, as it hides the default indent colors.

Would it be possible to add an option to disable the errorColor? A possible fallback would be to colorize the indentation as usual (per multiple of 4 spaces) and not colorize the last 2 erroneous spaces.

A more discrete way to highlight

i was trying to get this to color a vertical line using
vscode.window.createTextEditorDecorationType
but the API offers nothing in CSS like
content:'|'
to add new characters as decorators.
Neither
borderLeftColor: colors[i]
Work
So I hacked the generated JS to ad this instead of the background color

decorationType[i] = vscode.window.createTextEditorDecorationType({ color: colors[i], textDecoration: 'line-through' });

indent errors

under a couple of circumstances I get the indent error when maybe I should not

2018-10-06 6

c# linq is formatted differently by default by vscode and shows as an error
even when 'fixed' it just reverts to this indent when saved or formatted
maybe this could be detected and bypassed somehow or

2018-10-06 8

markdown must use 2 spaces for indentation I think otherwise markdown lint will flag it as error
so even tho I use tab4 normally and in settings I still must use space2 for *.md
I guess if I used space2 for everything I would not notice this but maybe possible not to use settings on md files and instead check for 2 spaces like markdown lint does?

thanks!

File types configuration support

It will be fine provide some configuration to include or exclude file types from indent coloring. for example to apply indent coloring only for nim, python file types

Pull colors from color theme

This plugin has been super helpful, it's way quicker to find where blocks open/start with this than it is with just thin vertical lines of the same color. Thanks for building/sharing!

I change my theme fairly frequently, b/c it helps me get a fresh look at my code. It would be great if Indent Rainbow could pull from the theme's colors so that it matches. As it is now, I find it a little distracting.

vsc

  • Extension Name: indent-rainbow
  • Extension Version: 7.2.4
  • OS Version: Windows_NT x64 10.0.17763
  • VSCode version: 1.28.0

We have written the needed data into your clipboard. Please paste:

Colorizes terminal and output windows

When using indent-rainbow, it colorizes the output window and the terminal window if there are any tabs in those. I know this is a duplicate of a closed error, but you asked for a screen shot. I'm happy to show you this.
screen shot 2019-02-20 at 10 59 28 am

Wrong detection tabs

If line have '*' in it (pointer in C for example), extension colorise it wrong.

void My_Function_Name(var_0_t var_0
                      var_1_t * var_1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.