forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor parsing of environment variables (after 439) (#466)
Refactor how environment variables are parsed and used in tools, language server and debugger Fixes #316 (PYTHONPATH not used as extra path for auto complete) Fixes #183 (changes to .env file requires restarts of vscode) Fixes #436 (Path variables not inherited when debugging) Fixes #435 (Virtual environment name is same as the default environment file)
- Loading branch information
1 parent
aec4fb3
commit 576d50d
Showing
28 changed files
with
1,115 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as _ from 'lodash'; | ||
|
||
type AsyncVoidAction = (...params: {}[]) => Promise<void>; | ||
type VoidAction = (...params: {}[]) => void; | ||
|
||
/** | ||
* Debounces a function execution. Function must return either a void or a promise that resolves to a void. | ||
* @export | ||
* @param {number} [wait] Wait time. | ||
* @returns void | ||
*/ | ||
export function debounce(wait?: number) { | ||
// tslint:disable-next-line:no-any no-function-expression | ||
return function (_target: any, _propertyName: string, descriptor: TypedPropertyDescriptor<VoidAction> | TypedPropertyDescriptor<AsyncVoidAction>) { | ||
const originalMethod = descriptor.value!; | ||
// tslint:disable-next-line:no-invalid-this no-any | ||
(descriptor as any).value = _.debounce(function () { return originalMethod.apply(this, arguments); }, wait); | ||
}; | ||
} | ||
|
||
/** | ||
* Swallows exceptions thrown by a function. Function must return either a void or a promise that resolves to a void. | ||
* @export | ||
* @param {string} [scopeName] Scope for the error message to be logged along with the error. | ||
* @returns void | ||
*/ | ||
export function swallowExceptions(scopeName: string) { | ||
// tslint:disable-next-line:no-any no-function-expression | ||
return function (_target: any, propertyName: string, descriptor: TypedPropertyDescriptor<VoidAction> | TypedPropertyDescriptor<AsyncVoidAction>) { | ||
const originalMethod = descriptor.value!; | ||
const errorMessage = `Python Extension (Error in ${scopeName}, method:${propertyName}):`; | ||
// tslint:disable-next-line:no-any no-function-expression | ||
descriptor.value = function (...args: any[]) { | ||
try { | ||
// tslint:disable-next-line:no-invalid-this no-use-before-declare no-unsafe-any | ||
const result = originalMethod.apply(this, args); | ||
|
||
// If method being wrapped returns a promise then wait and swallow errors. | ||
if (result && typeof result.then === 'function' && typeof result.catch === 'function') { | ||
return (result as Promise<void>).catch(error => console.error(errorMessage, error)); | ||
} | ||
} catch (error) { | ||
console.error(errorMessage, error); | ||
} | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { injectable } from 'inversify'; | ||
import { ICurrentProcess } from '../types'; | ||
import { EnvironmentVariables } from '../variables/types'; | ||
|
||
@injectable() | ||
export class CurrentProcess implements ICurrentProcess { | ||
public get env(): EnvironmentVariables { | ||
return process.env; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.