diff options
| author | hardliner66 <hardliner66@gmail.com> | 2025-03-09 17:03:43 +0100 |
|---|---|---|
| committer | hardliner66 <hardliner66@gmail.com> | 2025-03-09 17:03:43 +0100 |
| commit | 45ed358bbee2febc0bbfcd6525cce26fb263bda7 (patch) | |
| tree | 9d1810757636a3b58fef8b0b79492465cebe2d7d /editors/vscode/src/toolchain.ts | |
| parent | a0694cb331571e2cb31512af7da75756ef984ec2 (diff) | |
read odin_command from ols.json to check if it exists
Diffstat (limited to 'editors/vscode/src/toolchain.ts')
| -rw-r--r-- | editors/vscode/src/toolchain.ts | 87 |
1 files changed, 47 insertions, 40 deletions
diff --git a/editors/vscode/src/toolchain.ts b/editors/vscode/src/toolchain.ts index 3a559de..d62f6ba 100644 --- a/editors/vscode/src/toolchain.ts +++ b/editors/vscode/src/toolchain.ts @@ -4,60 +4,67 @@ import * as path from "path"; import * as fs from "fs"; import { execute, log, memoize } from './util'; +import { Config } from "./config"; -export function isOdinInstalled(): boolean { - return getPathForExecutable("odin") !== ""; +export function isOdinInstalled(config: Config): boolean { + return vscode.workspace.workspaceFolders?.some(folder => { + if (config.odinCommand) { + let command = path.isAbsolute(config.odinCommand) ? config.odinCommand : + path.join(folder.uri.fsPath, config.odinCommand); + return isFile(command) && fs.existsSync(command); + } + }) || getPathForExecutable("odin") !== ""; } export const getPathForExecutable = memoize( - // We apply caching to decrease file-system interactions - (executableName: "odin"): string => { - { - const envVar = process.env[executableName.toUpperCase()]; - if (envVar) { + // We apply caching to decrease file-system interactions + (executableName: "odin"): string => { + { + const envVar = process.env[executableName.toUpperCase()]; + if (envVar) { return envVar; } - } + } - const path = lookupInPath(executableName); - if (path != undefined) { + const path = lookupInPath(executableName); + if (path != undefined) { return path; } - return ""; - } + return ""; + } ); function lookupInPath(exec: string): string | undefined { - const paths = process.env.PATH ?? ""; - - const candidates = paths.split(path.delimiter).flatMap(dirInPath => { - const candidate = path.join(dirInPath, exec); - return os.type() === "Windows_NT" - ? [candidate, `${candidate}.exe`] - : [candidate]; - }); - - for (let i = 0; i < candidates.length; i += 1) { - try { - const pathToOdin = fs.realpathSync(candidates[i]); - if (!!pathToOdin) { - return pathToOdin; - } - } catch (realpathError) { - console.debug("couldn't find odin at", candidates[i], "on account of", realpathError) - } - } - - return undefined; + const paths = process.env.PATH ?? ""; + + const candidates = paths.split(path.delimiter).flatMap(dirInPath => { + const candidate = path.join(dirInPath, exec); + return os.type() === "Windows_NT" + ? [candidate, `${candidate}.exe`] + : [candidate]; + }); + + for (let i = 0; i < candidates.length; i += 1) { + try { + const pathToOdin = fs.realpathSync(candidates[i]); + if (!!pathToOdin) { + return pathToOdin; + } + } catch (realpathError) { + console.debug("couldn't find odin at", candidates[i], "on account of", realpathError) + } + } + + return undefined; } function isFile(suspectPath: string): boolean { - // It is not mentionned in docs, but `statSync()` throws an error when - // the path doesn't exist - try { - return fs.statSync(suspectPath).isFile(); - } catch { - return false; - } + // It is not mentionned in docs, but `statSync()` throws an error when + // the path doesn't exist + try { + return fs.statSync(suspectPath).isFile(); + } catch { + return false; + } }
\ No newline at end of file |