Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
add settings to control bundler usage for linters
Browse files Browse the repository at this point in the history
The pathToBundler and useBundler settings allow to control whether
and how linters will be using bundler. Not setting useBundler retains
the current auto-detection behavior, but setting it to either true
or false will avoid the call to bundler altogether.
  • Loading branch information
doudou committed Feb 19, 2018
1 parent 7f2e0e1 commit 1be81cc
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@
"default": "solargraph",
"description": "Method to use for intellisense (go to definition, etc.)."
},
"ruby.useBundler": {
"type": ["boolean", "null"],
"default": null,
"description": "Whether ruby tools should be started using Bundler"
},
"ruby.pathToBundler": {
"type": "string",
"default": "bundle",
"description": "Path to the bundler executable (used if useBundler is true)"
},
"ruby.rctComplete.commandPath": {
"type": "string",
"default": "rct-complete",
Expand Down
10 changes: 8 additions & 2 deletions src/lint/lib/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ class Linter {
return fs.link(sourceFile, opName).then(() => opName);
}
_detectBundledLinter(name, cwd) {
let useBundler = this.cfg[name].useBundler;
if (useBundler !== undefined) {
return useBundler;
}

let pathToBundler = this.cfg[name].pathToBundler || 'bundle';
try {
cp.execSync(`bundle show ${name}`, { cwd });
cp.execSync(`${pathToBundler} show ${name}`, { cwd });
return true;
} catch (e) {
return false;
Expand All @@ -79,7 +85,7 @@ class Linter {
// Try bundler for the linter
// otherwise fallback to the path + the exe name
if (svcPath.length === 0 && this._detectBundledLinter(svc.exe, cmdOpts.dir)) {
svcPath = 'bundle';
svcPath = this.cfg[svc.exe].pathToBundler;
args.unshift('exec', svc.exe);
} else {
svcPath = path.join(svcPath, svc.exe + svc.ext);
Expand Down
7 changes: 4 additions & 3 deletions src/lint/lintCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

const Linter = require('./lib/linter');
const LintResults = require('./lib/lintResults');
import { Config } from './lintConfig';

export class LintCollection {
private _results: any;
private _docLinters: any;
private _cfg: any;
private _cfg: { [key: string]: Config };
private _rootPath: string;
private _globalConfig: any;
private _globalConfig: Config;

constructor(globalConfig, lintConfig, rootPath) {
constructor(globalConfig : Config, lintConfig : { [key: string]: Config }, rootPath) {
this._results = {};
this._docLinters = {};
this._globalConfig = globalConfig;
Expand Down
8 changes: 8 additions & 0 deletions src/lint/lintConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class Config
{
pathToRuby: string = 'ruby';
pathToBundler: string = 'bundle';
useBundler: boolean | undefined = undefined;
}


26 changes: 19 additions & 7 deletions src/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { LintCollection } from './lint/lintCollection';
import { RubyDocumentFormattingEditProvider } from './format/rubyFormat';
import * as utils from './utils';
import { registerTaskProvider } from './task/rake';
import { Config as LintConfig } from './lint/lintConfig';

export function activate(context: ExtensionContext) {
const subs = context.subscriptions;
Expand All @@ -34,11 +35,22 @@ export function activate(context: ExtensionContext) {
utils.loadEnv();
}

function getGlobalConfig() {
let globalConfig = {};
let rubyInterpreterPath = vscode.workspace.getConfiguration("ruby.interpreter").commandPath;
if (rubyInterpreterPath) {
globalConfig["rubyInterpreterPath"] = rubyInterpreterPath;
function getGlobalLintConfig() : LintConfig {
let globalConfig = new LintConfig();

let pathToRuby = vscode.workspace.getConfiguration("ruby.interpreter").commandPath;
if (pathToRuby) {
globalConfig.pathToRuby = pathToRuby;
}

let useBundler = vscode.workspace.getConfiguration("ruby").get<boolean | null>("useBundler");
if (useBundler !== null) {
globalConfig.useBundler = useBundler;
}

let pathToBundler = vscode.workspace.getConfiguration("ruby").pathToBundler;
if (pathToBundler) {
globalConfig.pathToBundler = pathToBundler;
}
return globalConfig;
}
Expand Down Expand Up @@ -110,7 +122,7 @@ function registerHighlightProvider(ctx: ExtensionContext) {
}

function registerLinters(ctx: ExtensionContext) {
const globalConfig = getGlobalConfig();
const globalConfig = getGlobalLintConfig();
const linters = new LintCollection(globalConfig, vscode.workspace.getConfiguration("ruby").lint, vscode.workspace.rootPath);
ctx.subscriptions.push(linters);

Expand All @@ -124,7 +136,7 @@ function registerLinters(ctx: ExtensionContext) {
ctx.subscriptions.push(vscode.workspace.onDidChangeConfiguration(() => {
const docs = vscode.window.visibleTextEditors.map(editor => editor.document);
console.log("Config changed. Should lint:", docs.length);
const globalConfig = getGlobalConfig();
const globalConfig = getGlobalLintConfig();
linters.cfg(vscode.workspace.getConfiguration("ruby").lint, globalConfig);
docs.forEach(doc => linters.run(doc));
}));
Expand Down

0 comments on commit 1be81cc

Please sign in to comment.