Skip to content

Commit 9dd08e8

Browse files
Consolidate util code to src/util/*. (#2489)
This is a follow-up to #2456. I've pulled many of the "util" modules out of src/client/common into a new sibling package to client: utils. This helps us separate the extension-specific code from the generic code we use for the extension.
1 parent 162f58b commit 9dd08e8

136 files changed

Lines changed: 1575 additions & 1410 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/client/activation/activationService.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
import { inject, injectable } from 'inversify';
77
import { ConfigurationChangeEvent, Disposable, OutputChannel, Uri } from 'vscode';
8+
import { OSDistro, OSType } from '../../utils/platform';
89
import { IApplicationShell, ICommandManager, IWorkspaceService } from '../common/application/types';
910
import { isLanguageServerTest, STANDARD_OUTPUT_CHANNEL } from '../common/constants';
1011
import '../common/extensions';
11-
import { IPlatformService, OSDistro, OSType } from '../common/platform/types';
12+
import { IPlatformService } from '../common/platform/types';
1213
import { IConfigurationService, IDisposableRegistry, IOutputChannel, IPythonSettings } from '../common/types';
1314
import { IServiceContainer } from '../ioc/types';
1415
import { PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED } from '../telemetry/constants';
@@ -103,7 +104,7 @@ function isLSSupported(services: IServiceContainer): boolean {
103104
const platform = services.get<IPlatformService>(IPlatformService);
104105
let minVer = '';
105106
for (const [osType, distro, ver] of LS_MIN_OS_VERSIONS) {
106-
if (platform.os.type === osType && platform.os.distro === distro) {
107+
if (platform.info.type === osType && platform.info.distro === distro) {
107108
minVer = ver;
108109
break;
109110
}
@@ -112,7 +113,7 @@ function isLSSupported(services: IServiceContainer): boolean {
112113
return true;
113114
}
114115
minVer = normalizeVersion(minVer);
115-
return platform.os.version.compare(minVer) >= 0;
116+
return platform.info.version.compare(minVer) >= 0;
116117
}
117118

118119
function normalizeVersion(ver: string): string {

src/client/activation/downloader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as path from 'path';
77
import * as requestProgress from 'request-progress';
88
import { ProgressLocation, window } from 'vscode';
9-
import { createDeferred } from '../common/helpers';
9+
import { createDeferred } from '../../utils/async';
1010
import { IFileSystem } from '../common/platform/types';
1111
import { IExtensionContext, IOutputChannel } from '../common/types';
1212
import { PlatformData, PlatformName } from './platformData';

src/client/activation/hashVerifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { createHash } from 'crypto';
55
import * as fs from 'fs';
6-
import { createDeferred } from '../common/helpers';
6+
import { createDeferred } from '../../utils/async';
77

88
export class HashVerifier {
99
public async verifyHash(filePath: string, platformString: string, expectedDigest: string): Promise<boolean> {

src/client/activation/interpreterDataService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { createHash } from 'crypto';
55
import * as fs from 'fs';
66
import * as path from 'path';
77
import { ExtensionContext, Uri } from 'vscode';
8+
import { createDeferred } from '../../utils/async';
89
import { IApplicationShell } from '../common/application/types';
910
import '../common/extensions';
10-
import { createDeferred } from '../common/helpers';
1111
import { IPlatformService } from '../common/platform/types';
1212
import { IPythonExecutionFactory, IPythonExecutionService } from '../common/process/types';
1313
import { IServiceContainer } from '../ioc/types';

src/client/activation/languageServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import {
1111
Disposable, LanguageClient, LanguageClientOptions,
1212
ProvideCompletionItemsSignature, ServerOptions
1313
} from 'vscode-languageclient';
14+
import { createDeferred, Deferred } from '../../utils/async';
15+
import { StopWatch } from '../../utils/stopWatch';
1416
import {
1517
IApplicationShell, ICommandManager, IWorkspaceService
1618
} from '../common/application/types';
1719
import { PythonSettings } from '../common/configSettings';
1820
// tslint:disable-next-line:ordered-imports
1921
import { isTestExecution, STANDARD_OUTPUT_CHANNEL } from '../common/constants';
20-
import { createDeferred, Deferred } from '../common/helpers';
2122
import { IFileSystem, IPlatformService } from '../common/platform/types';
22-
import { StopWatch } from '../common/stopWatch';
2323
import {
2424
BANNER_NAME_LS_SURVEY, DeprecatedFeatureInfo, IConfigurationService,
2525
IExtensionContext, IFeatureDeprecationManager, ILogger, IOutputChannel,

src/client/activation/progress.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { Progress, ProgressLocation, window } from 'vscode';
55
import { Disposable, LanguageClient } from 'vscode-languageclient';
6-
import { createDeferred, Deferred } from '../common/helpers';
6+
import { createDeferred, Deferred } from '../../utils/async';
77

88
export class ProgressReporting {
99
private statusBarMessage: Disposable | undefined;

src/client/common/enumUtils.ts

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

src/client/common/helpers.ts

Lines changed: 5 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
16
import { ModuleNotInstalledError } from './errors/moduleNotInstalledError';
2-
// tslint:disable-next-line:no-require-imports no-var-requires
3-
const tmp = require('tmp');
47

58
export function isNotInstalledError(error: Error): boolean {
69
const isError = typeof (error) === 'object' && error !== null;
@@ -16,73 +19,3 @@ export function isNotInstalledError(error: Error): boolean {
1619
const isModuleNoInstalledError = error.message.indexOf('No module named') >= 0;
1720
return errorObj.code === 'ENOENT' || errorObj.code === 127 || isModuleNoInstalledError;
1821
}
19-
20-
// tslint:disable-next-line:interface-name
21-
export interface Deferred<T> {
22-
readonly promise: Promise<T>;
23-
readonly resolved: boolean;
24-
readonly rejected: boolean;
25-
readonly completed: boolean;
26-
resolve(value?: T | PromiseLike<T>);
27-
// tslint:disable-next-line:no-any
28-
reject(reason?: any);
29-
}
30-
31-
class DeferredImpl<T> implements Deferred<T> {
32-
private _resolve!: (value?: T | PromiseLike<T>) => void;
33-
// tslint:disable-next-line:no-any
34-
private _reject!: (reason?: any) => void;
35-
private _resolved: boolean = false;
36-
private _rejected: boolean = false;
37-
private _promise: Promise<T>;
38-
// tslint:disable-next-line:no-any
39-
constructor(private scope: any = null) {
40-
// tslint:disable-next-line:promise-must-complete
41-
this._promise = new Promise<T>((res, rej) => {
42-
this._resolve = res;
43-
this._reject = rej;
44-
});
45-
}
46-
public resolve(value?: T | PromiseLike<T>) {
47-
this._resolve.apply(this.scope ? this.scope : this, arguments);
48-
this._resolved = true;
49-
}
50-
// tslint:disable-next-line:no-any
51-
public reject(reason?: any) {
52-
this._reject.apply(this.scope ? this.scope : this, arguments);
53-
this._rejected = true;
54-
}
55-
get promise(): Promise<T> {
56-
return this._promise;
57-
}
58-
get resolved(): boolean {
59-
return this._resolved;
60-
}
61-
get rejected(): boolean {
62-
return this._rejected;
63-
}
64-
get completed(): boolean {
65-
return this._rejected || this._resolved;
66-
}
67-
}
68-
// tslint:disable-next-line:no-any
69-
export function createDeferred<T>(scope: any = null): Deferred<T> {
70-
return new DeferredImpl<T>(scope);
71-
}
72-
73-
export function createTemporaryFile(extension: string, temporaryDirectory?: string): Promise<{ filePath: string; cleanupCallback: Function }> {
74-
// tslint:disable-next-line:no-any
75-
const options: any = { postfix: extension };
76-
if (temporaryDirectory) {
77-
options.dir = temporaryDirectory;
78-
}
79-
80-
return new Promise<{ filePath: string; cleanupCallback: Function }>((resolve, reject) => {
81-
tmp.file(options, (err, tmpFile, fd, cleanupCallback) => {
82-
if (err) {
83-
return reject(err);
84-
}
85-
resolve({ filePath: tmpFile, cleanupCallback: cleanupCallback });
86-
});
87-
});
88-
}

src/client/common/installer/moduleInstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import * as fs from 'fs';
88
import { injectable } from 'inversify';
99
import * as path from 'path';
1010
import * as vscode from 'vscode';
11+
import { noop } from '../../../utils/misc';
1112
import { IInterpreterService, InterpreterType } from '../../interpreter/contracts';
1213
import { IServiceContainer } from '../../ioc/types';
1314
import { STANDARD_OUTPUT_CHANNEL } from '../constants';
14-
import { noop } from '../core.utils';
1515
import { ITerminalServiceFactory } from '../terminal/types';
1616
import { ExecutionInfo, IConfigurationService, IOutputChannel } from '../types';
1717

src/client/common/net/socket/socketServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { EventEmitter } from 'events';
22
import { injectable } from 'inversify';
33
import * as net from 'net';
4-
import { noop } from '../../core.utils';
5-
import { createDeferred, Deferred } from '../../helpers';
4+
import { createDeferred, Deferred } from '../../../../utils/async';
5+
import { noop } from '../../../../utils/misc';
66
import { ISocketServer } from '../../types';
77

88
@injectable()

0 commit comments

Comments
 (0)