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

Commit 2e2ef99

Browse files
authored
Merge pull request #268 from ThirteenLtda/bundler_control_for_linters
add settings to control bundler usage for linters
2 parents 7f2e0e1 + 1be81cc commit 2e2ef99

File tree

6 files changed

+51
-14
lines changed

6 files changed

+51
-14
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@
145145
"default": "solargraph",
146146
"description": "Method to use for intellisense (go to definition, etc.)."
147147
},
148+
"ruby.useBundler": {
149+
"type": ["boolean", "null"],
150+
"default": null,
151+
"description": "Whether ruby tools should be started using Bundler"
152+
},
153+
"ruby.pathToBundler": {
154+
"type": "string",
155+
"default": "bundle",
156+
"description": "Path to the bundler executable (used if useBundler is true)"
157+
},
148158
"ruby.rctComplete.commandPath": {
149159
"type": "string",
150160
"default": "rct-complete",

src/lint/lib/linter.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ class Linter {
5959
return fs.link(sourceFile, opName).then(() => opName);
6060
}
6161
_detectBundledLinter(name, cwd) {
62+
let useBundler = this.cfg[name].useBundler;
63+
if (useBundler !== undefined) {
64+
return useBundler;
65+
}
66+
67+
let pathToBundler = this.cfg[name].pathToBundler || 'bundle';
6268
try {
63-
cp.execSync(`bundle show ${name}`, { cwd });
69+
cp.execSync(`${pathToBundler} show ${name}`, { cwd });
6470
return true;
6571
} catch (e) {
6672
return false;
@@ -79,7 +85,7 @@ class Linter {
7985
// Try bundler for the linter
8086
// otherwise fallback to the path + the exe name
8187
if (svcPath.length === 0 && this._detectBundledLinter(svc.exe, cmdOpts.dir)) {
82-
svcPath = 'bundle';
88+
svcPath = this.cfg[svc.exe].pathToBundler;
8389
args.unshift('exec', svc.exe);
8490
} else {
8591
svcPath = path.join(svcPath, svc.exe + svc.ext);

src/lint/lintCollection.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

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

67
export class LintCollection {
78
private _results: any;
89
private _docLinters: any;
9-
private _cfg: any;
10+
private _cfg: { [key: string]: Config };
1011
private _rootPath: string;
11-
private _globalConfig: any;
12+
private _globalConfig: Config;
1213

13-
constructor(globalConfig, lintConfig, rootPath) {
14+
constructor(globalConfig : Config, lintConfig : { [key: string]: Config }, rootPath) {
1415
this._results = {};
1516
this._docLinters = {};
1617
this._globalConfig = globalConfig;

src/lint/lintConfig.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export class Config
2+
{
3+
pathToRuby: string = 'ruby';
4+
pathToBundler: string = 'bundle';
5+
useBundler: boolean | undefined = undefined;
6+
}
7+
8+

src/ruby.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { LintCollection } from './lint/lintCollection';
99
import { RubyDocumentFormattingEditProvider } from './format/rubyFormat';
1010
import * as utils from './utils';
1111
import { registerTaskProvider } from './task/rake';
12+
import { Config as LintConfig } from './lint/lintConfig';
1213

1314
export function activate(context: ExtensionContext) {
1415
const subs = context.subscriptions;
@@ -34,11 +35,22 @@ export function activate(context: ExtensionContext) {
3435
utils.loadEnv();
3536
}
3637

37-
function getGlobalConfig() {
38-
let globalConfig = {};
39-
let rubyInterpreterPath = vscode.workspace.getConfiguration("ruby.interpreter").commandPath;
40-
if (rubyInterpreterPath) {
41-
globalConfig["rubyInterpreterPath"] = rubyInterpreterPath;
38+
function getGlobalLintConfig() : LintConfig {
39+
let globalConfig = new LintConfig();
40+
41+
let pathToRuby = vscode.workspace.getConfiguration("ruby.interpreter").commandPath;
42+
if (pathToRuby) {
43+
globalConfig.pathToRuby = pathToRuby;
44+
}
45+
46+
let useBundler = vscode.workspace.getConfiguration("ruby").get<boolean | null>("useBundler");
47+
if (useBundler !== null) {
48+
globalConfig.useBundler = useBundler;
49+
}
50+
51+
let pathToBundler = vscode.workspace.getConfiguration("ruby").pathToBundler;
52+
if (pathToBundler) {
53+
globalConfig.pathToBundler = pathToBundler;
4254
}
4355
return globalConfig;
4456
}
@@ -110,7 +122,7 @@ function registerHighlightProvider(ctx: ExtensionContext) {
110122
}
111123

112124
function registerLinters(ctx: ExtensionContext) {
113-
const globalConfig = getGlobalConfig();
125+
const globalConfig = getGlobalLintConfig();
114126
const linters = new LintCollection(globalConfig, vscode.workspace.getConfiguration("ruby").lint, vscode.workspace.rootPath);
115127
ctx.subscriptions.push(linters);
116128

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

0 commit comments

Comments
 (0)