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

Make extension work on Windows #712

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
RevealOutputChannelOn,
CodeLens,
Range,
ExecutableOptions,
} from "vscode-languageclient/node";

import { Telemetry } from "./telemetry";
Expand Down Expand Up @@ -78,9 +79,10 @@ export default class Client implements ClientInterface {
return;
}

const executableOptions = {
const executableOptions: ExecutableOptions = {
cwd: this.workingFolder,
env: this.ruby.env,
shell: true,
};

const executable: Executable = {
Expand Down Expand Up @@ -436,27 +438,20 @@ export default class Client implements ClientInterface {
// If a custom Gemfile was configured outside of the project, use that. Otherwise, prefer our custom bundle over the
// app's bundle
if (customBundleGemfile.length > 0) {
bundleGemfile = `BUNDLE_GEMFILE=${customBundleGemfile}`;
bundleGemfile = customBundleGemfile;
} else if (
fs.existsSync(path.join(this.workingFolder, ".ruby-lsp", "Gemfile"))
) {
bundleGemfile = `BUNDLE_GEMFILE=${path.join(
this.workingFolder,
".ruby-lsp",
"Gemfile",
)}`;
bundleGemfile = path.join(this.workingFolder, ".ruby-lsp", "Gemfile");
} else {
bundleGemfile = `BUNDLE_GEMFILE=${path.join(
this.workingFolder,
"Gemfile",
)}`;
bundleGemfile = path.join(this.workingFolder, "Gemfile");
bitwise-aiden marked this conversation as resolved.
Show resolved Hide resolved
}

const result = await asyncExec(
`${bundleGemfile} bundle exec ruby -e "require 'ruby-lsp'; print RubyLsp::VERSION"`,
`bundle exec ruby -e "require 'ruby-lsp'; print RubyLsp::VERSION"`,
{
cwd: this.workingFolder,
env: this.ruby.env,
env: { ...this.ruby.env, BUNDLE_GEMFILE: bundleGemfile },
},
);

Expand Down
17 changes: 13 additions & 4 deletions src/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,12 @@ export class Ruby {
}

private async activate(ruby: string) {
let command = this.shell ? `${this.shell} -ic ` : "";
command += `'${ruby} -rjson -e "printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump(ENV.to_h))"'`;
let command = this.shell ? `${this.shell} -ic '` : "";
command += `${ruby} -rjson -e "printf(%{RUBY_ENV_ACTIVATE%sRUBY_ENV_ACTIVATE}, JSON.dump(ENV.to_h))"`;

if (this.shell) {
command += "'";
}

const result = await asyncExec(command, { cwd: this.workingFolder });

Expand Down Expand Up @@ -276,8 +280,13 @@ export class Ruby {

private async toolExists(tool: string) {
try {
let command = this.shell ? `${this.shell} -ic ` : "";
command += `'${tool} --version'`;
let command = this.shell ? `${this.shell} -ic '` : "";
command += `${tool} --version`;

if (this.shell) {
command += "'";
}

await asyncExec(command, { cwd: this.workingFolder });
return true;
} catch {
Expand Down