Skip to content

Commit d51e4a8

Browse files
committed
improve tree-sitter cli missing error msg
1 parent 5caf67d commit d51e4a8

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/Installer.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { parserFinishedInit } from "./extension";
1111
import which from "which";
1212

1313
const NPM_INSTALL_URL = "https://nodejs.org/en/download";
14-
const TREE_SITTER_CLI_INSTALL_URL = "https://github.com/tree-sitter/tree-sitter/blob/master/cli/README.md";
1514
const EMCC_INSTALL_URL = "https://emscripten.org/docs/getting_started/downloads.html#download-and-install";
1615
const DOCKER_INSTALL_URL = "https://docs.docker.com/get-docker/";
1716

@@ -62,11 +61,13 @@ export async function downloadAndBuildParser(
6261
}
6362

6463
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
65-
const treeSitterCliOk = (await which(treeSitterCli, { nothrow: true })) !== null;
66-
// auto install tree-sitter cli to parsersDir if not present
67-
if (!treeSitterCliOk) {
64+
const treeSitterCliOk = await runCmd(`${treeSitterCli} --version`);
65+
if (treeSitterCliOk.status === "err") {
6866
return err(
69-
`tree-sitter cli command: '${treeSitterCli}' is not in PATH, try installing it from: ${TREE_SITTER_CLI_INSTALL_URL}`
67+
`
68+
tree-sitter cli command '${treeSitterCli}' failed:
69+
${treeSitterCliOk.result[0].name} ${treeSitterCliOk.result[0].message.replace("\n", " > ")}.` +
70+
(treeSitterCliOk.result[1].length > 1 ? ` Logs: ${treeSitterCliOk.result[1].join(">")}` : "")
7071
);
7172
}
7273
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
@@ -77,7 +78,7 @@ export async function downloadAndBuildParser(
7778

7879
if (dockerOk && !emccOk) {
7980
void vscode.window.showInformationMessage(
80-
`tree-sitter requirement emcc not found, but docker was found and will be used. Note that using emcc is much faster, try installing if from: ${EMCC_INSTALL_URL}`
81+
`tree-sitter requirement emcc not found, but docker was found and is being used. Note that using emcc is much faster, try installing if from: ${EMCC_INSTALL_URL}`
8182
);
8283
} else if (!dockerOk && !emccOk) {
8384
return err(
@@ -137,7 +138,7 @@ export async function downloadAndBuildParser(
137138

138139
async function runCmd(
139140
cmd: string,
140-
options: ExecOptions,
141+
options: ExecOptions = {},
141142
onData?: (data: string) => void
142143
): Promise<Result<string, [ExecException, string[]]>> {
143144
const logs: string[] = [];

0 commit comments

Comments
 (0)