diff --git a/client/src/extension.ts b/client/src/extension.ts index 881b8bc..f27da30 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -1,12 +1,15 @@ import * as path from 'path'; import { getConfigLogLevel, Logger } from './logging'; -import { workspace, ExtensionContext } from 'vscode'; +import { workspace, ExtensionContext, window, commands } from 'vscode'; import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node'; +import { existsSync } from 'fs'; +import { isAbsolute } from 'path'; +import { which } from './utils'; export const SERVER_ID = 'cmakeIntelliSence'; @@ -14,15 +17,33 @@ export const SERVER_NAME = 'CMake Language Server'; let client: LanguageClient; -export function activate(context: ExtensionContext) { +async function checkCMakePath(cmakePath: string) { + if (!existsSync(cmakePath)) { + if (which(cmakePath) === null) { + let select = await window.showErrorMessage(`Can not find cmakePath: ${cmakePath}`, + 'Open Settings', 'Ignore'); + if (select === 'Open Settings') { + commands.executeCommand('workbench.action.openSettings', 'cmakeIntelliSence.cmakePath'); + } + } + } +} + +export async function activate(context: ExtensionContext) { const config = workspace.getConfiguration(SERVER_ID); const logger = new Logger(); logger.setLogLevel(getConfigLogLevel(config)); + checkCMakePath(config.cmakePath); context.subscriptions.push(workspace.onDidChangeConfiguration((e) => { if (e.affectsConfiguration(`${SERVER_ID}.loggingLevel`)) { logger.setLogLevel(getConfigLogLevel(config)); } + + if (e.affectsConfiguration(`${SERVER_ID}.cmakePath`)) { + const cmakePath = workspace.getConfiguration(SERVER_ID).get('cmakePath'); + checkCMakePath(cmakePath); + } })); const serverModule = context.asAbsolutePath( diff --git a/client/src/utils.ts b/client/src/utils.ts new file mode 100644 index 0000000..7d39c60 --- /dev/null +++ b/client/src/utils.ts @@ -0,0 +1,26 @@ +import * as os from 'os'; +import * as path from 'path'; +import { existsSync } from 'fs'; + +export function which(cmd: string): string { + let command: string; + let pathEnvSep: string; + if (os.type() === 'Windows_NT') { + if (!cmd.endsWith('.exe')) { + command = cmd + ".exe"; + } + pathEnvSep = ';'; + } else { + command = cmd; + pathEnvSep = ':'; + } + + for (const dir of process.env.PATH.split(pathEnvSep)) { + const absPath: string = dir + path.sep + command; + if (existsSync(absPath)) { + return absPath; + } + } + + return null; +} \ No newline at end of file diff --git a/server/src/utils.ts b/server/src/utils.ts index 6aea714..0a7a0db 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -94,11 +94,13 @@ export function getIncludeFileUri(baseDir: URI, includeFileName: string): URI { return null; } -function which(cmd: string): string { +export function which(cmd: string): string { let command: string; let pathEnvSep: string; if (os.type() === 'Windows_NT') { - command = cmd + ".exe"; + if (!cmd.endsWith('.exe')) { + command = cmd + ".exe"; + } pathEnvSep = ';'; } else { command = cmd;