Skip to content

Commit cd80f81

Browse files
committed
search for binaries in $PATH
1 parent 0f6b207 commit cd80f81

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
### 0.2.4
4+
5+
- Fix search for binaries in $PATH
6+
37
### 0.2.3
48

59
- Better notifications

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "elpi-lang",
33
"displayName": "Elpi lang",
44
"publisher": "gares",
5-
"description": "Syntax highlighting for Elpi",
6-
"version": "0.2.3",
5+
"description": "Elpi programming language support",
6+
"version": "0.2.4",
77
"homepage": "https://github.com/LPCIC/elpi-lang",
88
"repository": {
99
"type": "git",

src/provider.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from 'vscode';
22
import * as parser from './trace';
3+
import * as path from 'path';
34

45
import os = require('node:os');
56
import cp = require('child_process');
@@ -220,6 +221,21 @@ export class TraceProvider implements vscode.WebviewViewProvider {
220221
});
221222
}
222223

224+
private findFileOnPath(name: string) {
225+
if (name.startsWith('/')) { return true };
226+
227+
const paths = (process.env.PATH || '')
228+
.split(path.delimiter)
229+
.map(x => path.resolve(x, name));
230+
231+
for (const p of paths) {
232+
if (fs.existsSync(p)) {
233+
return true;
234+
}
235+
}
236+
return false;
237+
}
238+
223239
private exec(command: string) {
224240

225241
let result = cp.execSync(command).toString();
@@ -251,7 +267,7 @@ export class TraceProvider implements vscode.WebviewViewProvider {
251267

252268
this._elpi_trace_elaborator = configuration.elpi_trace_elaborator.path;
253269

254-
if(!fs.existsSync(this._elpi_trace_elaborator.replace('$HOME', os.homedir()))) {
270+
if(!this.findFileOnPath(this._elpi_trace_elaborator)) {
255271
vscode.window
256272
.showInformationMessage(`Failed to find elpi trace elaborator`, 'Go to settings')
257273
.then(action => {
@@ -322,7 +338,7 @@ export class TraceProvider implements vscode.WebviewViewProvider {
322338
this._elpi = configuration.elpi.path;
323339
this._elpi_trace_elaborator = configuration.elpi_trace_elaborator.path;
324340

325-
if(!fs.existsSync(this._elpi.replace('$HOME', os.homedir()))) {
341+
if(!this.findFileOnPath(this._elpi)) {
326342
vscode.window
327343
.showInformationMessage(`Failed to find elpi`, 'Go to settings')
328344
.then(action => {
@@ -332,7 +348,7 @@ export class TraceProvider implements vscode.WebviewViewProvider {
332348
return;
333349
}
334350

335-
if(!fs.existsSync(this._elpi_trace_elaborator.replace('$HOME', os.homedir()))) {
351+
if(!this.findFileOnPath(this._elpi_trace_elaborator)) {
336352
vscode.window
337353
.showInformationMessage(`Failed to find elpi trace elaborator`, 'Go to settings')
338354
.then(action => {
@@ -394,7 +410,7 @@ export class TraceProvider implements vscode.WebviewViewProvider {
394410
this._elpi = configuration.elpi.path;
395411
this._elpi_trace_elaborator = configuration.elpi_trace_elaborator.path;
396412

397-
if(!fs.existsSync(this._elpi.replace('$HOME', os.homedir()))) {
413+
if(!this.findFileOnPath(this._elpi)) {
398414
vscode.window
399415
.showInformationMessage(`Failed to find elpi`, 'Go to settings')
400416
.then(action => {
@@ -404,7 +420,7 @@ export class TraceProvider implements vscode.WebviewViewProvider {
404420
return;
405421
}
406422

407-
if(!fs.existsSync(this._elpi_trace_elaborator.replace('$HOME', os.homedir()))) {
423+
if(!this.findFileOnPath(this._elpi_trace_elaborator)) {
408424
vscode.window
409425
.showInformationMessage(`Failed to find elpi trace elaborator`, 'Go to settings')
410426
.then(action => {

0 commit comments

Comments
 (0)