diff --git a/package.json b/package.json index 670ac118..1f89aebc 100644 --- a/package.json +++ b/package.json @@ -266,6 +266,10 @@ "both" ], "default": "both" + }, + "rubyLsp.workingFolder": { + "description": "Relative or absolute path to ruby project root", + "type": "string" } } }, diff --git a/src/client.ts b/src/client.ts index 96d6930f..2c13ee26 100644 --- a/src/client.ts +++ b/src/client.ts @@ -34,7 +34,11 @@ type SyntaxTreeResponse = { ast: string } | null; export default class Client implements ClientInterface { private client: LanguageClient | undefined; - private readonly workingFolder: string; + private readonly workspaceFolder: string; + private readonly workingFolder: string = vscode.workspace + .getConfiguration("rubyLsp") + .get("workingFolder")!; + private readonly telemetry: Telemetry; private readonly statusItems: StatusItems; private readonly outputChannel: vscode.OutputChannel; @@ -57,9 +61,18 @@ export default class Client implements ClientInterface { ruby: Ruby, testController: TestController, outputChannel: vscode.OutputChannel, - workingFolder = vscode.workspace.workspaceFolders![0].uri.fsPath, + workingFolder: string, ) { - this.workingFolder = workingFolder; + this.workspaceFolder = vscode.workspace.workspaceFolders![0].uri.fsPath; + if (workingFolder) { + this.workingFolder = workingFolder; + } else if (this.workingFolder.length > 0) { + this.workingFolder = path.isAbsolute(this.workingFolder) + ? this.workingFolder + : path.resolve(this.workspaceFolder, this.workingFolder); + } else { + this.workingFolder = this.workspaceFolder; + } this.baseFolder = path.basename(this.workingFolder); this.telemetry = telemetry; this.testController = testController; @@ -70,6 +83,10 @@ export default class Client implements ClientInterface { this.statusItems = new StatusItems(this); this.registerCommands(); this.registerAutoRestarts(); + + this.outputChannel.appendLine( + `Using working folder: ${this.workingFolder}`, + ); } async start() { @@ -505,7 +522,7 @@ export default class Client implements ClientInterface { // If the `.git` folder exists and `.git/rebase-merge` or `.git/rebase-apply` exists, then we're in the middle of a // rebase private rebaseInProgress() { - const gitFolder = path.join(this.workingFolder, ".git"); + const gitFolder = path.join(this.workspaceFolder, ".git"); return ( fs.existsSync(gitFolder) &&