Skip to content

Commit

Permalink
Merge pull request #24 from ammkrn/path_check
Browse files Browse the repository at this point in the history
add user paths for version check, fix path field access
  • Loading branch information
gebner authored Apr 29, 2021
2 parents 122c7e3 + 7c1aaa1 commit faa196b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import { workspace } from 'vscode'
import { InfoViewTacticStateFilter } from './infoviewApi';
import * as path from 'path';

// TODO: does currently not contain config options for `./abbreviation`
// so that it is easy to keep it in sync with vscode-lean.

// Make a copy of the passed process environment that includes the user's
// `lean4.serverEnvPaths` in the path key, and adds the key/value pairs from
// `lean4.serverEnv`. Both of these settings can be found in the user's
// settings.json file
export function addServerEnvPaths(input_env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
let env = Object.assign({}, input_env, serverEnv());
let paths = serverEnvPaths()
if (paths.length != 0) {
if (process.platform === 'win32') {
env['Path'] = paths.join(path.delimiter) + path.delimiter + process.env.Path
} else {
env['PATH'] = paths.join(path.delimiter) + path.delimiter + process.env.PATH
}
}
return env
}

export function executablePath(): string {
return workspace.getConfiguration('lean4').get('executablePath', 'lean')
}
Expand Down
15 changes: 9 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { workspace, commands, window, languages, ExtensionContext, TextDocument } from 'vscode'
import { promisify } from 'util'
import { exec } from 'child_process'
import { execFile } from 'child_process'
import { AbbreviationFeature } from './abbreviation'
import { executablePath } from './config'
import { executablePath, addServerEnvPaths } from './config'
import { LeanClient } from './leanclient'
import { InfoProvider } from './infoview'
import { LeanTaskGutter } from './taskgutter'
Expand All @@ -13,17 +13,20 @@ async function checkLean4(): Promise<boolean> {
if (folders) {
folderPath = folders[0].uri.fsPath
}
const cmd = `${executablePath()} --version`

const env = addServerEnvPaths(process.env);
const cmd = executablePath()
const options = ['--version']
try {
// If folderPath is undefined, this will use the process environment for cwd.
// Specifically, if the extension was not opened inside of a folder, it
// looks for a global (default) installation of Lean. This way, we can support
// single file editing.
const { stdout, stderr } = await promisify(exec)(cmd, {cwd: folderPath})
const { stdout, stderr } = await promisify(execFile)(cmd, options, {cwd: folderPath, env: env })
const filterVersion = /version (\d+)\.\d+\..+/
const match = filterVersion.exec(stdout)
if (!match) {
void window.showErrorMessage(`lean4: '${cmd}' returned incorrect version string '${stdout}'.`)
void window.showErrorMessage(`lean4: '${cmd} ${options}' returned incorrect version string '${stdout}'.`)
return false
}
const major = match[1]
Expand All @@ -32,7 +35,7 @@ async function checkLean4(): Promise<boolean> {
}
return true
} catch (err) {
void window.showErrorMessage(`lean4: Could not find Lean version by running '${cmd}'.`)
void window.showErrorMessage(`lean4: Could not find Lean version by running '${cmd} ${options}'.`)
return false
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/leanclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ServerOptions
} from 'vscode-languageclient/node'
import * as ls from 'vscode-languageserver-protocol'
import { executablePath, serverEnv, serverEnvPaths, serverLoggingEnabled, serverLoggingPath } from './config'
import { executablePath, addServerEnvPaths, serverLoggingEnabled, serverLoggingPath } from './config'
import { PlainGoal, ServerProgress } from './leanclientTypes'
import { assert } from './utils/assert'
import * as path from 'path'
Expand Down Expand Up @@ -62,12 +62,7 @@ export class LeanClient implements Disposable {
if (this.isStarted()) {
await this.stop()
}
const env = Object.assign({}, process.env, serverEnv());
const paths = serverEnvPaths()
if (paths.length != 0) {
const pathKey = process.platform === 'win32' ? 'Path' : 'PATH'
env[pathKey] = paths.join(path.delimiter) + path.delimiter + process.env.Path
}
const env = addServerEnvPaths(process.env);
if (serverLoggingEnabled()) {
env.LEAN_SERVER_LOG_DIR = serverLoggingPath()
}
Expand Down

0 comments on commit faa196b

Please sign in to comment.