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

Commit

Permalink
feat: add config option to specify cwd for linter commands. Resolves #…
Browse files Browse the repository at this point in the history
…717

Note that due to the simplistic config options for formatters, support will come later
  • Loading branch information
wingrunr21 committed Mar 12, 2022
1 parent 3aa7062 commit 5168957
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/language-server-ruby/src/Formatter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import { Range, TextDocument, TextDocumentIdentifier, TextEdit } from 'vscode-languageserver';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { Range, TextDocumentIdentifier, TextEdit } from 'vscode-languageserver';
import { RubyEnvironment } from 'vscode-ruby-common';
import {
documentConfigurationCache,
Expand Down Expand Up @@ -37,7 +38,10 @@ function getFormatter(
): IFormatter {
// Only format if we have a formatter to use and an execution root
if (typeof config.format === 'string' && config.workspaceFolderUri) {
const executionRoot = path.dirname(URI.parse(document.uri).fsPath);
const executionRoot =
config.executionRoot.toLowerCase() === 'workspace root'
? URI.parse(config.workspaceFolderUri).fsPath
: path.dirname(URI.parse(document.uri).fsPath);
const formatterConfig: FormatterConfig = {
env,
executionRoot,
Expand Down
5 changes: 4 additions & 1 deletion packages/language-server-ruby/src/Linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ function getLinter(
if (!linter) return new NullLinter(`attempted to lint with unsupported linter: ${name}`);
const lintConfig: RubyCommandConfiguration =
typeof config.lint[name] === 'object' ? config.lint[name] : {};
const executionRoot = path.dirname(URI.parse(document.uri).fsPath);
const executionRoot =
lintConfig.executionRoot.toLowerCase() === 'workspace root'
? URI.parse(config.workspaceFolderUri).fsPath
: path.dirname(URI.parse(document.uri).fsPath);
const linterConfig: LinterConfig = {
env,
executionRoot,
Expand Down
1 change: 1 addition & 0 deletions packages/language-server-ruby/src/SettingsCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LogLevelDesc } from 'loglevel';
export interface RubyCommandConfiguration {
command?: string;
useBundler?: boolean;
executionRoot?: 'file path' | 'workspace root';
}

export interface RuboCopLintConfiguration extends RubyCommandConfiguration {
Expand Down
18 changes: 18 additions & 0 deletions packages/vscode-ruby-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@
"type": "boolean",
"default": false,
"description": "Prefix the `reek` command with `bundle exec`"
},
"executionRoot": {
"type": "string",
"default": "file path",
"oneOf": ["file path", "workspace root"],
"description": "Working directory in which to execute the lint functionality. Defaults to the file's path."
}
}
},
Expand All @@ -296,6 +302,12 @@
"default": false,
"description": "Prefix the `rubocop` command with `bundle exec`"
},
"executionRoot": {
"type": "string",
"default": "File Path",
"oneOf": ["file path", "workspace root"],
"description": "Working directory in which to execute the lint functionality. Defaults to the file's path."
},
"lint": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -346,6 +358,12 @@
"default": false,
"description": "Prefix the `standard` command with `bundle exec`"
},
"executionRoot": {
"type": "string",
"default": "File Path",
"oneOf": ["file path", "workspace root"],
"description": "Working directory in which to execute the lint functionality. Defaults to the file's path."
},
"only": {
"type": "array",
"description": "Run only the specified cop(s) and/or cops in the specified departments",
Expand Down

0 comments on commit 5168957

Please sign in to comment.