Skip to content

Commit

Permalink
Experimental Indent settings still buggy.
Browse files Browse the repository at this point in the history
  • Loading branch information
oderwat committed Feb 26, 2016
1 parent 1fc678c commit 968df59
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
9 changes: 7 additions & 2 deletions README.md
Expand Up @@ -21,7 +21,14 @@ Although you can just use it as it is there is the possibility to configure some
// 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!*


The following is experimental and still buggy (do not use it :)

```
// Automatically change indent setting (tabSize / insertSpaces) for a language.
"indentRainbow.indentSetter": {} // do nothing as default
Expand All @@ -35,8 +42,6 @@ Although you can just use it as it is there is the possibility to configure some
```

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

Build with:

```
Expand Down
28 changes: 18 additions & 10 deletions extension.ts
Expand Up @@ -29,18 +29,30 @@ export function activate(context: vscode.ExtensionContext) {

var activeEditor = vscode.window.activeTextEditor;

if(activeEditor) {
indentConfig()
}

if (activeEditor && checkLanguage()) {
triggerUpdateDecorations();
}

vscode.window.onDidChangeActiveTextEditor(editor => {
activeEditor = editor;
if (editor) {
indentConfig()
}

if (editor && checkLanguage()) {
triggerUpdateDecorations();
}
}, null, context.subscriptions);

vscode.workspace.onDidChangeTextDocument(event => {
if(activeEditor) {
indentConfig()
}

if (activeEditor && event.document === activeEditor.document && checkLanguage()) {
triggerUpdateDecorations();
}
Expand All @@ -49,20 +61,16 @@ export function activate(context: vscode.ExtensionContext) {
function indentConfig() {
// Set tabSize and insertSpaces from the config if specified for this languageId
var indentSetter = vscode.workspace.getConfiguration('indentRainbow')['indentSetter'] || {};
var langCfg = indentSetter[ activeEditor.document.languageId ];

// we do nothing if we have {} to not interrupt other extensions for indent settings
if( indentSetter != {} ) {
var langCfg = indentSetter[ activeEditor.document.languageId ];
if( langCfg == undefined ) {
// if we do not have any defaults get those from the editor config itself
langCfg = vscode.workspace.getConfiguration('editor');
}
var opts = vscode.window.activeTextEditor.options;
if( opts.tabSize != langCfg.tabSize || opts.insertSpaces != langCfg.insertSpaces) {
vscode.window.activeTextEditor.options = {
"tabSize": langCfg.tabSize,
"insertSpaces": langCfg.insertSpaces
}
vscode.window.activeTextEditor.options = {
"tabSize": langCfg.tabSize,
"insertSpaces": langCfg.insertSpaces
}
}
}
Expand All @@ -73,8 +81,6 @@ export function activate(context: vscode.ExtensionContext) {
var inclang = vscode.workspace.getConfiguration('indentRainbow')['includedLanguages'] || [];
var exclang = vscode.workspace.getConfiguration('indentRainbow')['excludedLanguages'] || [];

indentConfig();

currentLanguageId = activeEditor.document.languageId;
doIt = true;
if(inclang.length != 0) {
Expand Down Expand Up @@ -102,6 +108,8 @@ export function activate(context: vscode.ExtensionContext) {
clearMe = false;
}

indentConfig();

return doIt;
}

Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "indent-rainbow",
"description": "Makes indentation easier to read",
"version": "0.3.1",
"version": "0.3.2",
"publisher": "oderwat",
"author": {
"name": "Hans Raaf"
Expand Down

0 comments on commit 968df59

Please sign in to comment.