Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@
"description": "Path to the rct-complete command. Set this to an absolute path to select from multiple installed Ruby versions.",
"isExecutable": true
},
"ruby.lintDebounceTime": {
"type": "integer",
"default": 500,
"description": "Time (ms) to wait after keypress before running enabled linters. Ensures linters are only run when typing has finished and not for every keypress"
},
"ruby.lint": {
"type": "object",
"description": "Set individual ruby linters to use",
Expand Down
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ Enable each one in your workspace or user settings:
"fasterer": true,
"debride": true,
"ruby-lint": true
}
},

// Time (ms) to wait after keypress before running enabled linters. Ensures
// linters are only run when typing has finished and not for every keypress
"ruby.lintDebounceTime": 500,

//advanced: set command line options for some linters:
"ruby.lint": {
Expand Down
7 changes: 6 additions & 1 deletion src/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { RubyDocumentFormattingEditProvider } from './format/rubyFormat';
import * as utils from './utils';
import { registerTaskProvider } from './task/rake';
import { Config as LintConfig } from './lint/lintConfig';
import * as debounce from 'lodash/debounce';

export function activate(context: ExtensionContext) {
const subs = context.subscriptions;
Expand Down Expand Up @@ -131,8 +132,12 @@ function registerLinters(ctx: ExtensionContext) {
linters.run(e.document);
}

// Debounce linting to prevent running on every keypress, only run when typing has stopped
const lintDebounceTime = vscode.workspace.getConfiguration('ruby').lintDebounceTime;
const executeDebouncedLinting = debounce(executeLinting, lintDebounceTime);

ctx.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(executeLinting));
ctx.subscriptions.push(vscode.workspace.onDidChangeTextDocument(executeLinting));
ctx.subscriptions.push(vscode.workspace.onDidChangeTextDocument(executeDebouncedLinting));
ctx.subscriptions.push(vscode.workspace.onDidChangeConfiguration(() => {
const docs = vscode.window.visibleTextEditors.map(editor => editor.document);
console.log("Config changed. Should lint:", docs.length);
Expand Down