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

Commit 5168957

Browse files
committed
feat: add config option to specify cwd for linter commands. Resolves #717
Note that due to the simplistic config options for formatters, support will come later
1 parent 3aa7062 commit 5168957

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

packages/language-server-ruby/src/Formatter.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'path';
2-
import { Range, TextDocument, TextDocumentIdentifier, TextEdit } from 'vscode-languageserver';
2+
import { TextDocument } from 'vscode-languageserver-textdocument';
3+
import { Range, TextDocumentIdentifier, TextEdit } from 'vscode-languageserver';
34
import { RubyEnvironment } from 'vscode-ruby-common';
45
import {
56
documentConfigurationCache,
@@ -37,7 +38,10 @@ function getFormatter(
3738
): IFormatter {
3839
// Only format if we have a formatter to use and an execution root
3940
if (typeof config.format === 'string' && config.workspaceFolderUri) {
40-
const executionRoot = path.dirname(URI.parse(document.uri).fsPath);
41+
const executionRoot =
42+
config.executionRoot.toLowerCase() === 'workspace root'
43+
? URI.parse(config.workspaceFolderUri).fsPath
44+
: path.dirname(URI.parse(document.uri).fsPath);
4145
const formatterConfig: FormatterConfig = {
4246
env,
4347
executionRoot,

packages/language-server-ruby/src/Linter.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ function getLinter(
4141
if (!linter) return new NullLinter(`attempted to lint with unsupported linter: ${name}`);
4242
const lintConfig: RubyCommandConfiguration =
4343
typeof config.lint[name] === 'object' ? config.lint[name] : {};
44-
const executionRoot = path.dirname(URI.parse(document.uri).fsPath);
44+
const executionRoot =
45+
lintConfig.executionRoot.toLowerCase() === 'workspace root'
46+
? URI.parse(config.workspaceFolderUri).fsPath
47+
: path.dirname(URI.parse(document.uri).fsPath);
4548
const linterConfig: LinterConfig = {
4649
env,
4750
executionRoot,

packages/language-server-ruby/src/SettingsCache.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { LogLevelDesc } from 'loglevel';
77
export interface RubyCommandConfiguration {
88
command?: string;
99
useBundler?: boolean;
10+
executionRoot?: 'file path' | 'workspace root';
1011
}
1112

1213
export interface RuboCopLintConfiguration extends RubyCommandConfiguration {

packages/vscode-ruby-client/package.json

+18
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@
271271
"type": "boolean",
272272
"default": false,
273273
"description": "Prefix the `reek` command with `bundle exec`"
274+
},
275+
"executionRoot": {
276+
"type": "string",
277+
"default": "file path",
278+
"oneOf": ["file path", "workspace root"],
279+
"description": "Working directory in which to execute the lint functionality. Defaults to the file's path."
274280
}
275281
}
276282
},
@@ -296,6 +302,12 @@
296302
"default": false,
297303
"description": "Prefix the `rubocop` command with `bundle exec`"
298304
},
305+
"executionRoot": {
306+
"type": "string",
307+
"default": "File Path",
308+
"oneOf": ["file path", "workspace root"],
309+
"description": "Working directory in which to execute the lint functionality. Defaults to the file's path."
310+
},
299311
"lint": {
300312
"type": "boolean",
301313
"default": false,
@@ -346,6 +358,12 @@
346358
"default": false,
347359
"description": "Prefix the `standard` command with `bundle exec`"
348360
},
361+
"executionRoot": {
362+
"type": "string",
363+
"default": "File Path",
364+
"oneOf": ["file path", "workspace root"],
365+
"description": "Working directory in which to execute the lint functionality. Defaults to the file's path."
366+
},
349367
"only": {
350368
"type": "array",
351369
"description": "Run only the specified cop(s) and/or cops in the specified departments",

0 commit comments

Comments
 (0)