Skip to content

Commit 6f5c3c9

Browse files
DonJayamanneKartik Raj
authored andcommitted
Revert "Fix code lens bug (microsoft#6755)" (microsoft#6780)
This reverts commit a6330b1.
1 parent 5471379 commit 6f5c3c9

8 files changed

Lines changed: 15 additions & 355 deletions

File tree

news/2 Fixes/6303.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/client/testing/codeLenses/main.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import * as vscode from 'vscode';
2-
import { IServiceContainer } from '../../../client/ioc/types';
32
import { PYTHON } from '../../common/constants';
43
import { ITestCollectionStorageService } from '../common/types';
54
import { TestFileCodeLensProvider } from './testFiles';
65

76
export function activateCodeLenses(
87
onDidChange: vscode.EventEmitter<void>,
98
symbolProvider: vscode.DocumentSymbolProvider,
10-
testCollectionStorage: ITestCollectionStorageService,
11-
serviceContainer: IServiceContainer
9+
testCollectionStorage: ITestCollectionStorageService
1210
): vscode.Disposable {
1311
const disposables: vscode.Disposable[] = [];
14-
const codeLensProvider = new TestFileCodeLensProvider(onDidChange, symbolProvider, testCollectionStorage, serviceContainer);
12+
const codeLensProvider = new TestFileCodeLensProvider(onDidChange, symbolProvider, testCollectionStorage);
1513
disposables.push(vscode.languages.registerCodeLensProvider(PYTHON, codeLensProvider));
1614

1715
return {

src/client/testing/codeLenses/testFiles.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
// tslint:disable:no-object-literal-type-assertion
44

5-
import { CancellationToken, CancellationTokenSource, CodeLens, CodeLensProvider, DocumentSymbolProvider, Event, EventEmitter, Position, Range, SymbolInformation, SymbolKind, TextDocument, Uri } from 'vscode';
6-
import { IWorkspaceService } from '../../../client/common/application/types';
7-
import { IFileSystem } from '../../../client/common/platform/types';
8-
import { IServiceContainer } from '../../../client/ioc/types';
5+
import { CancellationToken, CancellationTokenSource, CodeLens, CodeLensProvider, DocumentSymbolProvider, Event, EventEmitter, Position, Range, SymbolInformation, SymbolKind, TextDocument, Uri, workspace } from 'vscode';
96
import * as constants from '../../common/constants';
107
import { CommandSource } from '../common/constants';
118
import { ITestCollectionStorageService, TestFile, TestFunction, TestStatus, TestsToRun, TestSuite } from '../common/types';
@@ -16,23 +13,18 @@ type FunctionsAndSuites = {
1613
};
1714

1815
export class TestFileCodeLensProvider implements CodeLensProvider {
19-
private workspaceService: IWorkspaceService;
20-
private fileSystem: IFileSystem;
2116
// tslint:disable-next-line:variable-name
2217
constructor(private _onDidChange: EventEmitter<void>,
2318
private symbolProvider: DocumentSymbolProvider,
24-
private testCollectionStorage: ITestCollectionStorageService,
25-
serviceContainer: IServiceContainer) {
26-
this.workspaceService = serviceContainer.get<IWorkspaceService>(IWorkspaceService);
27-
this.fileSystem = serviceContainer.get<IFileSystem>(IFileSystem);
19+
private testCollectionStorage: ITestCollectionStorageService) {
2820
}
2921

3022
get onDidChangeCodeLenses(): Event<void> {
3123
return this._onDidChange.event;
3224
}
3325

3426
public async provideCodeLenses(document: TextDocument, token: CancellationToken) {
35-
const wkspace = this.workspaceService.getWorkspaceFolder(document.uri);
27+
const wkspace = workspace.getWorkspaceFolder(document.uri);
3628
if (!wkspace) {
3729
return [];
3830
}
@@ -60,20 +52,16 @@ export class TestFileCodeLensProvider implements CodeLensProvider {
6052
return Promise.resolve(codeLens);
6153
}
6254

63-
public getTestFileWhichNeedsCodeLens(document: TextDocument): TestFile | undefined {
64-
const wkspace = this.workspaceService.getWorkspaceFolder(document.uri);
55+
private async getCodeLenses(document: TextDocument, token: CancellationToken, symbolProvider: DocumentSymbolProvider) {
56+
const wkspace = workspace.getWorkspaceFolder(document.uri);
6557
if (!wkspace) {
66-
return;
58+
return [];
6759
}
6860
const tests = this.testCollectionStorage.getTests(wkspace.uri);
6961
if (!tests) {
70-
return;
62+
return [];
7163
}
72-
return tests.testFiles.find(item => this.fileSystem.arePathsSame(item.fullPath, document.uri.fsPath));
73-
}
74-
75-
private async getCodeLenses(document: TextDocument, token: CancellationToken, symbolProvider: DocumentSymbolProvider) {
76-
const file = this.getTestFileWhichNeedsCodeLens(document);
64+
const file = tests.testFiles.find(item => item.fullPath === document.uri.fsPath);
7765
if (!file) {
7866
return [];
7967
}

src/client/testing/common/services/discoveredTestParser.ts

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@ import * as path from 'path';
88
import { Uri } from 'vscode';
99
import { IWorkspaceService } from '../../../common/application/types';
1010
import { traceError } from '../../../common/logger';
11-
import { IFileSystem } from '../../../common/platform/types';
1211
import { TestDataItem } from '../../types';
1312
import { getParentFile, getParentSuite, getTestType } from '../testUtils';
1413
import { FlattenedTestFunction, FlattenedTestSuite, SubtestParent, TestFile, TestFolder, TestFunction, Tests, TestSuite, TestType } from '../types';
1514
import { DiscoveredTests, ITestDiscoveredTestParser, TestContainer, TestItem } from './types';
1615

1716
@injectable()
1817
export class TestDiscoveredTestParser implements ITestDiscoveredTestParser {
19-
constructor(
20-
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
21-
@inject(IFileSystem) private readonly fileSystem: IFileSystem
22-
) { }
18+
constructor(@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService) { }
2319
public parse(resource: Uri, discoveredTests: DiscoveredTests[]): Tests {
2420
const tests: Tests = {
2521
rootTestFolders: [],
@@ -38,14 +34,8 @@ export class TestDiscoveredTestParser implements ITestDiscoveredTestParser {
3834

3935
// If the root is the workspace folder, then ignore that.
4036
for (const data of discoveredTests) {
41-
// For now we only check the current workspace.
42-
const root = this.findRoot(data.root, [workspace.uri.fsPath]);
43-
if (!root) {
44-
// For now we only support tests from the workspace.
45-
continue;
46-
}
4737
const rootFolder = {
48-
name: root, folders: [], time: 0,
38+
name: data.root, folders: [], time: 0,
4939
testFiles: [], resource: resource, nameToRun: data.rootid
5040
};
5141
tests.rootTestFolders.push(rootFolder);
@@ -68,7 +58,7 @@ export class TestDiscoveredTestParser implements ITestDiscoveredTestParser {
6858
* @param {Tests} tests
6959
* @memberof TestsDiscovery
7060
*/
71-
public buildChildren(rootFolder: TestFolder, parent: TestDataItem, discoveredTests: DiscoveredTests, tests: Tests) {
61+
protected buildChildren(rootFolder: TestFolder, parent: TestDataItem, discoveredTests: DiscoveredTests, tests: Tests) {
7262
const parentType = getTestType(parent);
7363
switch (parentType) {
7464
case TestType.testFolder: {
@@ -203,17 +193,6 @@ export class TestDiscoveredTestParser implements ITestDiscoveredTestParser {
203193
parent.functions.push(...functions);
204194
tests.testFunctions.push(...functions.map(func => createFlattenedParameterizedFunction(tests, func, parent)));
205195
}
206-
207-
/**
208-
* Returns the vscode recognized file paths which matches the pytest data test root
209-
*/
210-
private findRoot(raw: string, roots: string[]): string | undefined {
211-
for (const root of roots) {
212-
if (this.fileSystem.arePathsSame(raw, root)) {
213-
return root;
214-
}
215-
}
216-
}
217196
}
218197

219198
function createTestFolder(root: TestFolder, item: TestContainer): TestFolder {

src/client/testing/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export class UnitTestManagementService implements ITestManagementService, Dispos
324324
}
325325
});
326326
this.disposableRegistry.push(handler);
327-
this.disposableRegistry.push(activateCodeLenses(event, symbolProvider, testCollectionStorage, this.serviceContainer));
327+
this.disposableRegistry.push(activateCodeLenses(event, symbolProvider, testCollectionStorage));
328328
}
329329

330330
@captureTelemetry(EventName.UNITTEST_CONFIGURE, undefined, false)

src/test/testing/codeLenses/testFiles.unit.test.ts

Lines changed: 0 additions & 158 deletions
This file was deleted.

0 commit comments

Comments
 (0)