Skip to content

Commit b55ad34

Browse files
committed
Merge branch 'CommonToolExecution' into YarnAndCodeCoverage
* CommonToolExecution: Refactor parsing of environment variables (after 439) (#466) Refactor extension to remove old way of spawning python processes (#439)
2 parents 6ac63bf + f8b9eac commit b55ad34

File tree

8 files changed

+54
-49
lines changed

8 files changed

+54
-49
lines changed

src/client/interpreter/interpreterVersion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ export class InterpreterVersionService implements IInterpreterVersionService {
2525
return matches[0].trim();
2626
}
2727
}
28-
throw new Error(`Unable to determine Pip version from output '${output.stdout}'`);
28+
throw new Error(`Unable to determine pip version from output '${output.stdout}'`);
2929
}
3030
}

src/client/providers/jediProxy.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -348,27 +348,9 @@ export class JediProxy implements vscode.Disposable {
348348
return;
349349
}
350350

351-
switch (cmd.command) {
352-
case CommandType.Completions:
353-
this.onCompletion(cmd, response);
354-
break;
355-
case CommandType.Definitions:
356-
this.onDefinition(cmd, response);
357-
break;
358-
case CommandType.Hover:
359-
this.onHover(cmd, response);
360-
break;
361-
case CommandType.Symbols:
362-
this.onSymbols(cmd, response);
363-
break;
364-
case CommandType.Usages:
365-
this.onUsages(cmd, response);
366-
break;
367-
case CommandType.Arguments:
368-
this.onArguments(cmd, response);
369-
break;
370-
default:
371-
break;
351+
const handler = this.getCommandHandler(cmd.command);
352+
if (handler) {
353+
handler.call(this, cmd, response);
372354
}
373355
// Check if too many pending requests.
374356
this.checkQueueLength();
@@ -378,7 +360,24 @@ export class JediProxy implements vscode.Disposable {
378360
error => this.handleError('subscription.error', `${error}`)
379361
);
380362
}
381-
363+
private getCommandHandler(command: CommandType): undefined | ((command: IExecutionCommand<ICommandResult>, response: object) => void) {
364+
switch (command) {
365+
case CommandType.Completions:
366+
return this.onCompletion;
367+
case CommandType.Definitions:
368+
return this.onDefinition;
369+
case CommandType.Hover:
370+
return this.onHover;
371+
case CommandType.Symbols:
372+
return this.onSymbols;
373+
case CommandType.Usages:
374+
return this.onUsages;
375+
case CommandType.Arguments:
376+
return this.onArguments;
377+
default:
378+
return;
379+
}
380+
}
382381
private onCompletion(command: IExecutionCommand<ICommandResult>, response: object): void {
383382
let results = JediProxy.getProperty<IAutoCompleteItem[]>(response, 'results');
384383
results = Array.isArray(results) ? results : [];

src/test/autocomplete/base.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ const fileSuppress = path.join(autoCompPath, 'suppress.py');
2222

2323
// tslint:disable-next-line:max-func-body-length
2424
suite('Autocomplete', () => {
25-
let isPython3: boolean;
25+
let isPython2: boolean;
2626
let ioc: UnitTestIocContainer;
2727
suiteSetup(async () => {
2828
await initialize();
2929
initializeDI();
30-
const version = await ioc.getPythonVersion(rootWorkspaceUri);
31-
isPython3 = version.indexOf('3.') >= 0;
30+
isPython2 = await ioc.getPythonMajorVersion(rootWorkspaceUri) === 2;
3231
});
3332
setup(initializeTest);
3433
suiteTeardown(closeActiveWindows);
@@ -80,7 +79,7 @@ suite('Autocomplete', () => {
8079

8180
// https://github.com/DonJayamanne/pythonVSCode/issues/265
8281
test('For "lambda"', async function () {
83-
if (!isPython3) {
82+
if (isPython2) {
8483
// tslint:disable-next-line:no-invalid-this
8584
this.skip();
8685
return;

src/test/autocomplete/pep484.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ const autoCompPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pyth
99
const filePep484 = path.join(autoCompPath, 'pep484.py');
1010

1111
suite('Autocomplete PEP 484', () => {
12-
let isPython3: boolean;
12+
let isPython2: boolean;
1313
let ioc: UnitTestIocContainer;
1414
suiteSetup(async () => {
1515
await initialize();
1616
initializeDI();
17-
const version = await ioc.getPythonVersion(rootWorkspaceUri);
18-
isPython3 = version.indexOf('3.') >= 0;
17+
isPython2 = await ioc.getPythonMajorVersion(rootWorkspaceUri) === 2;
1918
});
2019
setup(initializeTest);
2120
suiteTeardown(closeActiveWindows);
@@ -31,7 +30,7 @@ suite('Autocomplete PEP 484', () => {
3130
}
3231

3332
test('argument', async function () {
34-
if (!isPython3) {
33+
if (isPython2) {
3534
// tslint:disable-next-line:no-invalid-this
3635
this.skip();
3736
return;
@@ -47,7 +46,7 @@ suite('Autocomplete PEP 484', () => {
4746
});
4847

4948
test('return value', async () => {
50-
if (!isPython3) {
49+
if (isPython2) {
5150
return;
5251
}
5352
const textDocument = await vscode.workspace.openTextDocument(filePep484);

src/test/autocomplete/pep526.test.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ const autoCompPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pyth
99
const filePep526 = path.join(autoCompPath, 'pep526.py');
1010

1111
suite('Autocomplete PEP 526', () => {
12-
let isPython3: boolean;
12+
let isPython2: boolean;
1313
let ioc: UnitTestIocContainer;
1414
suiteSetup(async () => {
1515
await initialize();
1616
initializeDI();
17-
const version = await ioc.getPythonVersion(rootWorkspaceUri);
18-
isPython3 = version.indexOf('3.') >= 0;
17+
isPython2 = await ioc.getPythonMajorVersion(rootWorkspaceUri) === 2;
1918
});
2019
setup(initializeTest);
2120
suiteTeardown(closeActiveWindows);
@@ -31,7 +30,7 @@ suite('Autocomplete PEP 526', () => {
3130
}
3231

3332
test('variable (abc:str)', async function () {
34-
if (!isPython3) {
33+
if (isPython2) {
3534
// tslint:disable-next-line:no-invalid-this
3635
this.skip();
3736
return;
@@ -47,7 +46,7 @@ suite('Autocomplete PEP 526', () => {
4746
});
4847

4948
test('variable (abc: str = "")', async function () {
50-
if (!isPython3) {
49+
if (isPython2) {
5150
// tslint:disable-next-line:no-invalid-this
5251
this.skip();
5352
}
@@ -62,7 +61,7 @@ suite('Autocomplete PEP 526', () => {
6261
});
6362

6463
test('variable (abc = UNKNOWN # type: str)', async function () {
65-
if (!isPython3) {
64+
if (isPython2) {
6665
// tslint:disable-next-line:no-invalid-this
6766
this.skip();
6867
return;
@@ -78,7 +77,7 @@ suite('Autocomplete PEP 526', () => {
7877
});
7978

8079
test('class methods', async function () {
81-
if (!isPython3) {
80+
if (isPython2) {
8281
// tslint:disable-next-line:no-invalid-this
8382
this.skip();
8483
return;
@@ -96,7 +95,7 @@ suite('Autocomplete PEP 526', () => {
9695
});
9796

9897
test('class method types', async function () {
99-
if (!isPython3) {
98+
if (isPython2) {
10099
// tslint:disable-next-line:no-invalid-this
101100
this.skip();
102101
return;

src/test/serviceRegistry.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,13 @@ export class IocContainer {
9898
this.serviceManager.addSingleton<IPathUtils>(IPathUtils, PathUtils);
9999
this.serviceManager.addSingleton<ICurrentProcess>(ICurrentProcess, MockProcess);
100100
}
101+
102+
public registerMockProcess() {
103+
this.serviceManager.addSingletonInstance<boolean>(IsWindows, IS_WINDOWS);
104+
this.serviceManager.addSingletonInstance<boolean>(Is64Bit, IS_64_BIT);
105+
106+
this.serviceManager.addSingleton<ILogger>(ILogger, Logger);
107+
this.serviceManager.addSingleton<IPathUtils>(IPathUtils, PathUtils);
108+
this.serviceManager.addSingleton<ICurrentProcess>(ICurrentProcess, MockProcess);
109+
}
101110
}

src/test/signature/signature.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ class SignatureHelpResult {
2121

2222
// tslint:disable-next-line:max-func-body-length
2323
suite('Signatures', () => {
24-
let isPython3: boolean;
24+
let isPython2: boolean;
2525
let ioc: UnitTestIocContainer;
2626
suiteSetup(async () => {
2727
await initialize();
2828
initializeDI();
29-
const version = await ioc.getPythonVersion(rootWorkspaceUri);
30-
isPython3 = version.indexOf('3.') >= 0;
29+
isPython2 = await ioc.getPythonMajorVersion(rootWorkspaceUri) === 2;
3130
});
3231
setup(initializeTest);
3332
suiteTeardown(closeActiveWindows);
@@ -86,7 +85,7 @@ suite('Signatures', () => {
8685
});
8786

8887
test('For ellipsis', async function () {
89-
if (!isPython3) {
88+
if (isPython2) {
9089
// tslint:disable-next-line:no-invalid-this
9190
this.skip();
9291
return;
@@ -110,10 +109,10 @@ suite('Signatures', () => {
110109

111110
test('For pow', async () => {
112111
let expected: SignatureHelpResult;
113-
if (isPython3) {
114-
expected = new SignatureHelpResult(0, 4, 1, 0, null);
115-
} else {
112+
if (isPython2) {
116113
expected = new SignatureHelpResult(0, 4, 1, 0, 'x');
114+
} else {
115+
expected = new SignatureHelpResult(0, 4, 1, 0, null);
117116
}
118117

119118
const document = await openDocument(path.join(autoCompPath, 'noSigPy3.py'));

src/test/unittests/serviceRegistry.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ export class UnitTestIocContainer extends IocContainer {
3030
constructor() {
3131
super();
3232
}
33-
public getPythonVersion(resource: Uri) {
33+
public getPythonMajorVersion(resource: Uri) {
3434
return this.serviceContainer.get<IPythonExecutionFactory>(IPythonExecutionFactory).create(resource)
35-
.then(pythonProcess => pythonProcess.getVersion());
35+
.then(pythonProcess => pythonProcess.exec(['-c', 'import sys;print(sys.version_info[0])'], {}))
36+
.then(output => parseInt(output.stdout.trim(), 10));
3637
}
3738
public registerTestVisitors() {
3839
this.serviceManager.add<ITestVisitor>(ITestVisitor, TestFlatteningVisitor, 'TestFlatteningVisitor');

0 commit comments

Comments
 (0)