Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Allow working directory to be specified
Browse files Browse the repository at this point in the history
  • Loading branch information
jprosevear committed Nov 4, 2023
1 parent f66b178 commit 758892d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@
"both"
],
"default": "both"
},
"rubyLsp.workingFolder": {
"description": "Relative or absolute path to ruby project root",
"type": "string"
}
}
},
Expand Down
25 changes: 21 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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) &&
Expand Down

0 comments on commit 758892d

Please sign in to comment.