GH-393: Do not use clangd from the $PATH.

Closes: arduino/arduino-pro-ide#393

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-12-15 11:02:31 +01:00 committed by Akos Kitta
parent 00a3ee34c8
commit 258b1e903e
3 changed files with 7 additions and 20 deletions

View File

@ -1,6 +1,3 @@
import * as fs from 'fs';
import * as os from 'os';
import { join } from 'path';
import { ContainerModule } from 'inversify';
import { ArduinoDaemonImpl } from './arduino-daemon-impl';
import { ILogger } from '@theia/core/lib/common/logger';
@ -128,21 +125,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
});
}));
// Set up cpp extension
if (!process.env.CPP_CLANGD_COMMAND) {
const segments = ['..', '..', 'build'];
if (os.platform() === 'win32') {
segments.push('clangd.exe');
} else {
segments.push('bin');
segments.push('clangd');
}
const clangdCommand = join(__dirname, ...segments);
if (fs.existsSync(clangdCommand)) {
process.env.CPP_CLANGD_COMMAND = clangdCommand;
}
}
// File-system extension for mapping paths to URIs
bind(NodeFileSystemExt).toSelf().inSingletonScope();
bind(FileSystemExt).toService(NodeFileSystemExt);

View File

@ -4,7 +4,12 @@ import * as semver from 'semver';
import { join } from 'path';
import { spawn } from 'child_process';
export async function getExecPath(commandName: string, onError: (error: Error) => void = (error) => console.log(error), versionArg?: string, inBinDir?: boolean): Promise<string> {
export async function getExecPath(
commandName: string,
onError: (error: Error) => void = (error) => console.log(error),
versionArg?: string | undefined,
inBinDir?: boolean): Promise<string> {
const execName = `${commandName}${os.platform() === 'win32' ? '.exe' : ''}`;
const relativePath = ['..', '..', 'build'];
if (inBinDir) {

View File

@ -14,7 +14,7 @@ export class ExecutableServiceImpl implements ExecutableService {
async list(): Promise<{ clangdUri: string, cliUri: string, lsUri: string }> {
const [ls, clangd, cli] = await Promise.all([
getExecPath('arduino-language-server', this.onError.bind(this)),
getExecPath('clangd', this.onError.bind(this), '--version', os.platform() !== 'win32'),
getExecPath('clangd', this.onError.bind(this), undefined, os.platform() !== 'win32'),
getExecPath('arduino-cli', this.onError.bind(this))
]);
return {