diff --git a/packages/language-server-ruby/src/Formatter.ts b/packages/language-server-ruby/src/Formatter.ts index 822a4750..6ee9f1b0 100644 --- a/packages/language-server-ruby/src/Formatter.ts +++ b/packages/language-server-ruby/src/Formatter.ts @@ -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, @@ -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, diff --git a/packages/language-server-ruby/src/Linter.ts b/packages/language-server-ruby/src/Linter.ts index 4df9ccad..da17088a 100644 --- a/packages/language-server-ruby/src/Linter.ts +++ b/packages/language-server-ruby/src/Linter.ts @@ -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, diff --git a/packages/language-server-ruby/src/SettingsCache.ts b/packages/language-server-ruby/src/SettingsCache.ts index 111ac0e6..d13db44d 100644 --- a/packages/language-server-ruby/src/SettingsCache.ts +++ b/packages/language-server-ruby/src/SettingsCache.ts @@ -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 { diff --git a/packages/vscode-ruby-client/package.json b/packages/vscode-ruby-client/package.json index 4e00dabb..d5e07da2 100644 --- a/packages/vscode-ruby-client/package.json +++ b/packages/vscode-ruby-client/package.json @@ -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." } } }, @@ -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, @@ -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",