diff --git a/docs/manual/troubleshooting.md b/docs/manual/troubleshooting.md index eea1ac87..f7b578f3 100644 --- a/docs/manual/troubleshooting.md +++ b/docs/manual/troubleshooting.md @@ -72,6 +72,10 @@ Also, you can view extension logs directly in VS Code: These logs are helpful when reporting issues on GitHub. +### Can't access the Tolk standard library folder + +TODO + ## Reporting Issues If you encounter an issue not covered here: diff --git a/server/src/indexing/indexing.ts b/server/src/indexing/indexing.ts index 89461763..7be55208 100644 --- a/server/src/indexing/indexing.ts +++ b/server/src/indexing/indexing.ts @@ -2,9 +2,12 @@ import {fileURLToPath} from "node:url" import * as path from "node:path" +import * as fs from "node:fs" + import {glob} from "glob" import {filePathToUri} from "@server/files" +import {showErrorMessage, troubleshootingLink} from "@server/utils/notify" export enum IndexingRootKind { Stdlib = "stdlib", @@ -40,6 +43,14 @@ export abstract class IndexingRoot { ignore: ignore, }) if (files.length === 0) { + if (!this.checkReadAccess(this.root)) { + const see = troubleshootingLink("cant-access-the-tolk-standard-library-folder") + const message = `Can't access the '${this.root}' folder in the Tolk standard library.\nSee: ${see}` + + showErrorMessage(message) + console.error(message) + } + console.warn(`No file to index in ${this.root}`) } for (const filePath of files) { @@ -50,5 +61,14 @@ export abstract class IndexingRoot { } } + private checkReadAccess(path: string): boolean { + try { + fs.accessSync(path, fs.constants.R_OK) + return true + } catch { + return false + } + } + protected abstract onFile(uri: string): Promise } diff --git a/server/src/server.ts b/server/src/server.ts index 5f9735ef..eb145303 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -135,6 +135,8 @@ import {collectFuncCodeLenses} from "@server/languages/func/lens" import {collectFiftCodeLenses} from "@server/languages/fift/lens" import {contractAbi} from "@server/languages/tolk/lang/abi/compute" +import {showErrorMessage} from "@server/utils/notify" + import {initParser} from "./parser" import {DocumentStore} from "./document-store" import {connection} from "./connection" @@ -230,13 +232,6 @@ async function handleFileOpen( } } -const showErrorMessage = (msg: string): void => { - void connection.sendNotification(lsp.ShowMessageNotification.type, { - type: lsp.MessageType.Error, - message: msg, - }) -} - async function findTolkStdlib(settings: ServerSettings, rootDir: string): Promise { if (settings.tolk.stdlib.path !== null && settings.tolk.stdlib.path.length > 0) { return settings.tolk.stdlib.path diff --git a/server/src/utils/notify.ts b/server/src/utils/notify.ts new file mode 100644 index 00000000..e9311c42 --- /dev/null +++ b/server/src/utils/notify.ts @@ -0,0 +1,21 @@ +import * as lsp from "vscode-languageserver" + +import {connection} from "@server/connection" + +export const showErrorMessage = (msg: string): void => { + void connection.sendNotification(lsp.ShowMessageNotification.type, { + type: lsp.MessageType.Error, + message: msg, + }) +} + +export const troubleshootingLink = (section?: string): string => { + const troubleshootingDocsLink = + "https://github.com/ton-blockchain/ton-language-server/blob/main/docs/manual/troubleshooting.md" + + if (section == undefined) { + return `${troubleshootingDocsLink}#${section}` + } + + return troubleshootingDocsLink +}