Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 58ec1aa

Browse files
authored
Fix Windows link.exe not found (#78)
Include process.env in rls env Add windows env.path implementation Use process.env RUST_BACKTRACE if available
1 parent 07a49ad commit 58ec1aa

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

lib/index.js

+22-13
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,9 @@ const {
1515
/** @type {number} interval between toolchain update checks, milliseconds */
1616
const PERIODIC_UPDATE_CHECK_MILLIS = 6 * 60 * 60 * 1000
1717

18-
function getPath() {
19-
// Make sure the cargo directory is in PATH
20-
let { PATH } = process.env
21-
PATH = PATH + ":" + path.join(os.homedir(), ".cargo/bin")
22-
return PATH
23-
}
24-
2518
async function exec(command) {
2619
return new Promise((resolve, reject) => {
27-
cp.exec(command, { env: { PATH: getPath() } }, (err, stdout, stderr) => {
20+
cp.exec(command, { env: { PATH: envPath() } }, (err, stdout, stderr) => {
2821
if (err != null) {
2922
reject(err)
3023
return
@@ -101,16 +94,23 @@ async function rustcSysroot(toolchain) {
10194
return stdout.trim()
10295
}
10396

97+
/** @return {string} environment variable path */
98+
let envPath = () => {
99+
// Make sure the cargo directory is in PATH
100+
let envPath = process.env.PATH || ''
101+
if (!envPath.includes(".cargo/bin"))
102+
envPath += `:${path.join(os.homedir(), ".cargo/bin")}`
103+
return envPath
104+
}
105+
104106
/**
105107
* @param {string} [toolchain]
106108
* @return {Promise<object>} environment vars
107109
*/
108110
async function serverEnv(toolchain) {
109-
const env = {
110-
PATH: getPath(),
111-
RUST_BACKTRACE: '1',
112-
RUST_LOG: process.env.RUST_LOG,
113-
}
111+
const env = process.env
112+
env.PATH = envPath()
113+
env.RUST_BACKTRACE = env.RUST_BACKTRACE || "1"
114114

115115
if (!env.RUST_LOG && atom.config.get('core.debugLSP')) {
116116
env.RUST_LOG = 'rls=warn'
@@ -631,6 +631,15 @@ if (process.platform === "win32") {
631631
!filePath.includes('\\target\\release\\')
632632
}
633633

634+
// handle different slashes & path separator
635+
envPath = () => {
636+
// Make sure the cargo directory is in PATH
637+
let envPath = process.env.PATH || ''
638+
if (!envPath.includes(".cargo\\bin"))
639+
envPath += `;${path.join(os.homedir(), ".cargo", "bin")}`
640+
return envPath
641+
}
642+
634643
// curl | sh is not valid for windows, users must install rustup manually
635644
RustLanguageClient.prototype._handleMissingRustup = () => {
636645
atomPrompt("`rustup` is not available", {

0 commit comments

Comments
 (0)