Skip to content

Commit f2f9c23

Browse files
Drop PlatformService as a dependency of FileSystem. (#9784)
(for #8995) The dependency is unnecessary and adds complication to various places that FileSystem is used. Dropping it simplifies things going forward.
1 parent 0a9a7b7 commit f2f9c23

18 files changed

+29
-50
lines changed

src/client/common/platform/fileSystem.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { createHash } from 'crypto';
66
import * as fs from 'fs-extra';
77
import * as glob from 'glob';
8-
import { inject, injectable } from 'inversify';
8+
import { injectable } from 'inversify';
99
import { promisify } from 'util';
1010
import * as vscode from 'vscode';
1111
import { createDeferred } from '../utils/async';
@@ -16,7 +16,7 @@ import { TemporaryFileSystem } from './fs-temp';
1616
// prettier-ignore
1717
import {
1818
FileStat, FileType,
19-
IFileSystem, IFileSystemPaths, IPlatformService, IRawFileSystem,
19+
IFileSystem, IFileSystemPaths, IRawFileSystem,
2020
ReadStream, TemporaryFile, WriteStream
2121
} from './types';
2222

@@ -282,14 +282,8 @@ export class FileSystem implements IFileSystem {
282282
private readonly paths: IFileSystemPaths;
283283
private readonly pathUtils: FileSystemPathUtils;
284284
private readonly tmp: TemporaryFileSystem;
285-
// prettier-ignore
286-
constructor(
287-
@inject(IPlatformService) platformService: IPlatformService
288-
) {
289-
// prettier-ignore
290-
this.paths = FileSystemPaths.withDefaults(
291-
platformService.isWindows
292-
);
285+
constructor() {
286+
this.paths = FileSystemPaths.withDefaults();
293287
this.pathUtils = FileSystemPathUtils.withDefaults(this.paths);
294288
this.tmp = TemporaryFileSystem.withDefaults();
295289
this.raw = RawFileSystem.withDefaults(this.paths);

src/client/common/utils/localize.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import * as path from 'path';
77
import { EXTENSION_ROOT_DIR } from '../../constants';
88
import { FileSystem } from '../platform/fileSystem';
9-
import { PlatformService } from '../platform/platformService';
109

1110
// External callers of localize use these tables to retrieve localized values.
1211
export namespace Diagnostics {
@@ -688,7 +687,7 @@ function getString(key: string, defValue?: string) {
688687
}
689688

690689
function load() {
691-
const fs = new FileSystem(new PlatformService());
690+
const fs = new FileSystem();
692691

693692
// Figure out our current locale.
694693
loadedLocale = parseLocale();

src/client/sourceMapSupport.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { WorkspaceConfiguration } from 'vscode';
88
import './common/extensions';
99
import { traceError } from './common/logger';
1010
import { FileSystem } from './common/platform/fileSystem';
11-
import { PlatformService } from './common/platform/platformService';
1211
import { EXTENSION_ROOT_DIR } from './constants';
1312

1413
type VSCode = typeof import('vscode');
@@ -59,7 +58,7 @@ export class SourceMapSupport {
5958
}
6059
}
6160
protected async rename(sourceFile: string, targetFile: string) {
62-
const fs = new FileSystem(new PlatformService());
61+
const fs = new FileSystem();
6362
if (await fs.fileExists(targetFile)) {
6463
return;
6564
}

src/test/common/crypto.unit.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import { assert, expect } from 'chai';
77
import * as path from 'path';
88
import { CryptoUtils } from '../../client/common/crypto';
99
import { FileSystem } from '../../client/common/platform/fileSystem';
10-
import { PlatformService } from '../../client/common/platform/platformService';
1110
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../constants';
1211

1312
// tslint:disable-next-line: max-func-body-length
1413
suite('Crypto Utils', async () => {
1514
let crypto: CryptoUtils;
16-
const fs = new FileSystem(new PlatformService());
15+
const fs = new FileSystem();
1716
const file = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test', 'common', 'randomWords.txt');
1817
setup(() => {
1918
crypto = new CryptoUtils();

src/test/common/net/fileDownloader.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ suite('File Downloader', () => {
9393
httpClient = mock(HttpClient);
9494
appShell = mock(ApplicationShell);
9595
when(httpClient.downloadFile(anything())).thenCall(request);
96-
fs = new FileSystem(new PlatformService());
96+
fs = new FileSystem();
9797
});
9898
teardown(() => {
9999
rewiremock.disable();

src/test/common/platform/filesystem.functional.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as fs from 'fs-extra';
88
import * as path from 'path';
99
import { convertStat, FileSystem, RawFileSystem } from '../../../client/common/platform/fileSystem';
1010
import { FileSystemPaths, FileSystemPathUtils } from '../../../client/common/platform/fs-paths';
11-
import { PlatformService } from '../../../client/common/platform/platformService';
1211
import { FileType } from '../../../client/common/platform/types';
1312
import { sleep } from '../../../client/common/utils/async';
1413
// prettier-ignore
@@ -796,9 +795,7 @@ suite('FileSystem', () => {
796795
let fix: FSFixture;
797796
setup(async () => {
798797
// prettier-ignore
799-
fileSystem = new FileSystem(
800-
new PlatformService()
801-
);
798+
fileSystem = new FileSystem();
802799
fix = new FSFixture();
803800

804801
await assertDoesNotExist(DOES_NOT_EXIST);

src/test/common/platform/filesystem.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import * as fsextra from 'fs-extra';
1010
import {
1111
convertStat, FileSystem, RawFileSystem
1212
} from '../../../client/common/platform/fileSystem';
13-
import { PlatformService } from '../../../client/common/platform/platformService';
1413
// prettier-ignore
1514
import {
1615
FileType, IFileSystem, IRawFileSystem
@@ -99,10 +98,7 @@ suite('FileSystem', () => {
9998
let filesystem: IFileSystem;
10099
let fix: FSFixture;
101100
setup(async () => {
102-
// prettier-ignore
103-
filesystem = new FileSystem(
104-
new PlatformService()
105-
);
101+
filesystem = new FileSystem();
106102
fix = new FSFixture();
107103

108104
await assertDoesNotExist(DOES_NOT_EXIST);

src/test/common/terminals/environmentActivationProviders/terminalActivation.testvirtualenvs.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as fs from 'fs-extra';
88
import * as path from 'path';
99
import * as vscode from 'vscode';
1010
import { FileSystem } from '../../../../client/common/platform/fileSystem';
11-
import { PlatformService } from '../../../../client/common/platform/platformService';
1211
import { PYTHON_VIRTUAL_ENVS_LOCATION } from '../../../ciConstants';
1312
import { PYTHON_PATH, restorePythonPathInWorkspaceRoot, setPythonPathInWorkspaceRoot, updateSetting, waitForCondition } from '../../../common';
1413
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../../constants';
@@ -20,7 +19,7 @@ suite('Activation of Environments in Terminal', () => {
2019
const file = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'smokeTests', 'testExecInTerminal.py');
2120
let outputFile = '';
2221
let outputFileCounter = 0;
23-
const fileSystem = new FileSystem(new PlatformService());
22+
const fileSystem = new FileSystem();
2423
const outputFilesCreated: string[] = [];
2524
const envsLocation =
2625
PYTHON_VIRTUAL_ENVS_LOCATION !== undefined

src/test/common/variables/envVarsService.functional.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { expect, use } from 'chai';
99
import * as chaiAsPromised from 'chai-as-promised';
1010
import { FileSystem } from '../../../client/common/platform/fileSystem';
1111
import { PathUtils } from '../../../client/common/platform/pathUtils';
12-
import { PlatformService } from '../../../client/common/platform/platformService';
1312
import { IPathUtils } from '../../../client/common/types';
1413
import { OSType } from '../../../client/common/utils/platform';
1514
import { EnvironmentVariablesService } from '../../../client/common/variables/environment';
@@ -26,7 +25,7 @@ suite('Environment Variables Service', () => {
2625
let variablesService: IEnvironmentVariablesService;
2726
setup(() => {
2827
pathUtils = new PathUtils(getOSType() === OSType.Windows);
29-
const fs = new FileSystem(new PlatformService());
28+
const fs = new FileSystem();
3029
variablesService = new EnvironmentVariablesService(pathUtils, fs);
3130
});
3231

src/test/common/variables/envVarsService.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import * as chaiAsPromised from 'chai-as-promised';
1010
import * as path from 'path';
1111
import { FileSystem } from '../../../client/common/platform/fileSystem';
1212
import { PathUtils } from '../../../client/common/platform/pathUtils';
13-
import { PlatformService } from '../../../client/common/platform/platformService';
1413
import { IPathUtils } from '../../../client/common/types';
1514
import { OSType } from '../../../client/common/utils/platform';
1615
import { EnvironmentVariablesService } from '../../../client/common/variables/environment';
@@ -29,7 +28,7 @@ suite('Environment Variables Service', () => {
2928
let variablesService: IEnvironmentVariablesService;
3029
setup(() => {
3130
pathUtils = new PathUtils(getOSType() === OSType.Windows);
32-
const fs = new FileSystem(new PlatformService());
31+
const fs = new FileSystem();
3332
variablesService = new EnvironmentVariablesService(pathUtils, fs);
3433
});
3534

src/test/common/webPanel/webPanel.unit.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ chai.use(chaiHttp);
1212

1313
import { WebPanelServer } from '../../../client/common/application/webPanels/webPanelServer';
1414
import { FileSystem } from '../../../client/common/platform/fileSystem';
15-
import { PlatformService } from '../../../client/common/platform/platformService';
1615
import { EXTENSION_ROOT_DIR } from '../../../client/constants';
1716

1817
// tslint:disable:no-any
@@ -24,7 +23,7 @@ suite('WebPanelServer', () => {
2423
const historyBundle = path.join(EXTENSION_ROOT_DIR, 'out', 'datascience-ui', 'history-react', 'index_bundle.js');
2524
setup(async () => {
2625
// So these are effectively functional tests rather than unit tests...
27-
const fs = new FileSystem(new PlatformService());
26+
const fs = new FileSystem();
2827
host = new WebPanelServer(await portfinder.getPortPromise(), token, fs);
2928
server = host.start();
3029
});

src/test/datascience/color.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { IWorkspaceService } from '../../client/common/application/types';
1010
import { PythonSettings } from '../../client/common/configSettings';
1111
import { Logger } from '../../client/common/logger';
1212
import { FileSystem } from '../../client/common/platform/fileSystem';
13-
import { PlatformService } from '../../client/common/platform/platformService';
1413
import { CurrentProcess } from '../../client/common/process/currentProcess';
1514
import { IConfigurationService } from '../../client/common/types';
1615
import { CodeCssGenerator } from '../../client/datascience/codeCssGenerator';
@@ -34,7 +33,7 @@ suite('Theme colors', () => {
3433
extensions = new Extensions();
3534
currentProcess = new CurrentProcess();
3635
logger = new Logger();
37-
const fs = new FileSystem(new PlatformService());
36+
const fs = new FileSystem();
3837
themeFinder = new ThemeFinder(extensions, currentProcess, logger, fs);
3938

4039
workspaceConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
@@ -158,7 +157,7 @@ suite('Theme colors', () => {
158157
mockThemeFinder.setup(m => m.isThemeDark(TypeMoq.It.isAnyString())).returns(() => Promise.resolve(false));
159158
mockThemeFinder.setup(m => m.findThemeRootJson(TypeMoq.It.isAnyString())).returns(() => Promise.resolve(undefined));
160159

161-
const fs = new FileSystem(new PlatformService());
160+
const fs = new FileSystem();
162161
cssGenerator = new CodeCssGenerator(workspaceService.object, mockThemeFinder.object, configService.object, logger, fs);
163162

164163
const colors = await cssGenerator.generateThemeCss(false, 'Kimbie Dark');

src/test/interpreters/condaService.unit.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as TypeMoq from 'typemoq';
88
import { Disposable, EventEmitter } from 'vscode';
99

1010
import { IWorkspaceService } from '../../client/common/application/types';
11-
import { FileSystem } from '../../client/common/platform/fileSystem';
11+
import { FileSystemPaths, FileSystemPathUtils } from '../../client/common/platform/fs-paths';
1212
import { IFileSystem, IPlatformService } from '../../client/common/platform/types';
1313
import { IProcessService, IProcessServiceFactory } from '../../client/common/process/types';
1414
import { ITerminalActivationCommandProvider } from '../../client/common/terminal/types';
@@ -91,7 +91,11 @@ suite('Interpreters Conda Service', () => {
9191
fileSystem
9292
.setup(fs => fs.arePathsSame(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
9393
.returns((p1, p2) => {
94-
return new FileSystem(platformService.object).arePathsSame(p1, p2);
94+
// prettier-ignore
95+
const utils = FileSystemPathUtils.withDefaults(
96+
FileSystemPaths.withDefaults(platformService.object.isWindows)
97+
);
98+
return utils.arePathsSame(p1, p2);
9599
});
96100

97101
condaService = new CondaService(

src/test/linters/lint.functional.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class TestFixture extends BaseTestFixture {
248248
serviceContainer.setup(s => s.get(TypeMoq.It.isValue(IProcessLogger), TypeMoq.It.isAny())).returns(() => processLogger.object);
249249

250250
const platformService = new PlatformService();
251-
const filesystem = new FileSystem(platformService);
251+
const filesystem = new FileSystem();
252252

253253
super(
254254
platformService,

src/test/serviceRegistry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
import * as fsextra from 'fs-extra';
5-
import { Container, inject } from 'inversify';
5+
import { Container } from 'inversify';
66
import { anything, instance, mock, when } from 'ts-mockito';
77
import * as TypeMoq from 'typemoq';
88
import { Disposable, Memento, OutputChannel, Uri } from 'vscode';
@@ -95,8 +95,8 @@ class FakeVSCodeFileSystemAPI {
9595
}
9696
}
9797
class LegacyFileSystem extends FileSystem {
98-
constructor(@inject(IPlatformService) platformService: IPlatformService) {
99-
super(platformService);
98+
constructor() {
99+
super();
100100
const vscfs = new FakeVSCodeFileSystemAPI();
101101
this.raw = RawFileSystem.withDefaults(undefined, vscfs);
102102
}

src/test/sourceMapSupport.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { expect } from 'chai';
99
import * as fs from 'fs';
1010
import { ConfigurationTarget, Disposable } from 'vscode';
1111
import { FileSystem } from '../client/common/platform/fileSystem';
12-
import { PlatformService } from '../client/common/platform/platformService';
1312
import { Diagnostics } from '../client/common/utils/localize';
1413
import { SourceMapSupport } from '../client/sourceMapSupport';
1514
import { noop } from './core';
@@ -62,7 +61,7 @@ suite('Source Map Support', () => {
6261
});
6362
});
6463
test('When disabling source maps, the map file is renamed and vice versa', async () => {
65-
const fileSystem = new FileSystem(new PlatformService());
64+
const fileSystem = new FileSystem();
6665
const jsFile = await fileSystem.createTemporaryFile('.js');
6766
disposables.push(jsFile);
6867
const mapFile = `${jsFile.filePath}.map`;

src/test/testing/display/picker.functional.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { ApplicationShell } from '../../../client/common/application/application
99
import { CommandManager } from '../../../client/common/application/commandManager';
1010
import { IApplicationShell, ICommandManager } from '../../../client/common/application/types';
1111
import { FileSystem } from '../../../client/common/platform/fileSystem';
12-
import { PlatformService } from '../../../client/common/platform/platformService';
1312
import { IFileSystem } from '../../../client/common/platform/types';
1413
import { ServiceContainer } from '../../../client/ioc/container';
1514
import { IServiceContainer } from '../../../client/ioc/types';
@@ -75,7 +74,7 @@ suite('Testing - TestDisplay', () => {
7574

7675
setup(() => {
7776
tests = createEmptyResults();
78-
when(mockedServiceContainer.get<IFileSystem>(IFileSystem)).thenReturn(new FileSystem(new PlatformService()));
77+
when(mockedServiceContainer.get<IFileSystem>(IFileSystem)).thenReturn(new FileSystem());
7978
when(mockedTestCollectionStorage.getTests(wkspace)).thenReturn(tests);
8079
when(mockedAppShell.showQuickPick(anything(), anything())).thenResolve();
8180
});

src/test/testing/pytest/pytest.testMessageService.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { IWorkspaceService } from '../../../client/common/application/types';
1313
import { EXTENSION_ROOT_DIR } from '../../../client/common/constants';
1414
import { ProductNames } from '../../../client/common/installer/productNames';
1515
import { FileSystem } from '../../../client/common/platform/fileSystem';
16-
import { PlatformService } from '../../../client/common/platform/platformService';
1716
import { Product } from '../../../client/common/types';
1817
import { ICondaService, IInterpreterService } from '../../../client/interpreter/contracts';
1918
import { InterpreterService } from '../../../client/interpreter/interpreterService';
@@ -97,8 +96,7 @@ async function getExpectedLocationStackFromTestDetails(testDetails: ITestDetails
9796

9897
suite('Unit Tests - PyTest - TestMessageService', () => {
9998
let ioc: UnitTestIocContainer;
100-
const platformService = new PlatformService();
101-
const filesystem = new FileSystem(platformService);
99+
const filesystem = new FileSystem();
102100
const configTarget = IS_MULTI_ROOT_TEST ? vscode.ConfigurationTarget.WorkspaceFolder : vscode.ConfigurationTarget.Workspace;
103101
suiteSetup(async () => {
104102
await initialize();

0 commit comments

Comments
 (0)