forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
625 lines (565 loc) · 19 KB
/
types.ts
File metadata and controls
625 lines (565 loc) · 19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { Socket } from 'net';
import { Request as RequestResult } from 'request';
import {
CancellationToken,
ConfigurationTarget,
DiagnosticSeverity,
Disposable,
DocumentSymbolProvider,
Event,
Extension,
ExtensionContext,
OutputChannel,
Uri,
WorkspaceEdit,
} from 'vscode';
import { LanguageServerType } from '../activation/types';
import { LogLevel } from '../logging/levels';
import type { CommandsWithoutArgs } from './application/commands';
import type { ExtensionChannels } from './insidersBuild/types';
import type { InterpreterUri } from './installer/types';
import { EnvironmentVariables } from './variables/types';
import { ITestingSettings } from '../testing/configuration/types';
export const IOutputChannel = Symbol('IOutputChannel');
export interface IOutputChannel extends OutputChannel {}
export const IDocumentSymbolProvider = Symbol('IDocumentSymbolProvider');
export interface IDocumentSymbolProvider extends DocumentSymbolProvider {}
export const IsWindows = Symbol('IS_WINDOWS');
export const IDisposableRegistry = Symbol('IDisposableRegistry');
export type IDisposableRegistry = Disposable[];
export const IMemento = Symbol('IGlobalMemento');
export const GLOBAL_MEMENTO = Symbol('IGlobalMemento');
export const WORKSPACE_MEMENTO = Symbol('IWorkspaceMemento');
export type Resource = Uri | undefined;
export interface IPersistentState<T> {
readonly value: T;
updateValue(value: T): Promise<void>;
}
export type Version = {
raw: string;
major: number;
minor: number;
patch: number;
build: string[];
prerelease: string[];
};
export type ReadWrite<T> = {
-readonly [P in keyof T]: T[P];
};
export const IPersistentStateFactory = Symbol('IPersistentStateFactory');
export interface IPersistentStateFactory {
createGlobalPersistentState<T>(key: string, defaultValue?: T, expiryDurationMs?: number): IPersistentState<T>;
createWorkspacePersistentState<T>(key: string, defaultValue?: T, expiryDurationMs?: number): IPersistentState<T>;
}
export type ExecutionInfo = {
execPath?: string;
moduleName?: string;
args: string[];
product?: Product;
};
export enum InstallerResponse {
Installed,
Disabled,
Ignore,
}
export enum ProductInstallStatus {
Installed,
NotInstalled,
NeedsUpgrade,
}
export enum ProductType {
Linter = 'Linter',
Formatter = 'Formatter',
TestFramework = 'TestFramework',
RefactoringLibrary = 'RefactoringLibrary',
WorkspaceSymbols = 'WorkspaceSymbols',
DataScience = 'DataScience',
TensorBoard = 'TensorBoard',
}
export enum Product {
pytest = 1,
nosetest = 2,
pylint = 3,
flake8 = 4,
pycodestyle = 5,
pylama = 6,
prospector = 7,
pydocstyle = 8,
yapf = 9,
autopep8 = 10,
mypy = 11,
unittest = 12,
ctags = 13,
rope = 14,
isort = 15,
black = 16,
bandit = 17,
jupyter = 18,
ipykernel = 19,
notebook = 20,
kernelspec = 21,
nbconvert = 22,
pandas = 23,
tensorboard = 24,
}
export enum ModuleNamePurpose {
install = 1,
run = 2,
}
export const IInstaller = Symbol('IInstaller');
export interface IInstaller {
promptToInstall(
product: Product,
resource?: InterpreterUri,
cancel?: CancellationToken,
isUpgrade?: boolean,
): Promise<InstallerResponse>;
install(product: Product, resource?: InterpreterUri, cancel?: CancellationToken): Promise<InstallerResponse>;
isInstalled(product: Product, resource?: InterpreterUri): Promise<boolean | undefined>;
isProductVersionCompatible(
product: Product,
semVerRequirement: string,
resource?: InterpreterUri,
): Promise<ProductInstallStatus | undefined>;
translateProductToModuleName(product: Product, purpose: ModuleNamePurpose): string;
}
// TODO: Drop IPathUtils in favor of IFileSystemPathUtils.
// See https://github.com/microsoft/vscode-python/issues/8542.
export const IPathUtils = Symbol('IPathUtils');
export interface IPathUtils {
readonly delimiter: string;
readonly home: string;
/**
* The platform-specific file separator. '\\' or '/'.
* @type {string}
* @memberof IPathUtils
*/
readonly separator: string;
getPathVariableName(): 'Path' | 'PATH';
basename(pathValue: string, ext?: string): string;
getDisplayName(pathValue: string, cwd?: string): string;
}
export const IRandom = Symbol('IRandom');
export interface IRandom {
getRandomInt(min?: number, max?: number): number;
}
export const ICurrentProcess = Symbol('ICurrentProcess');
export interface ICurrentProcess {
readonly env: EnvironmentVariables;
readonly argv: string[];
readonly stdout: NodeJS.WriteStream;
readonly stdin: NodeJS.ReadStream;
readonly execPath: string;
// eslint-disable-next-line @typescript-eslint/ban-types
on(event: string | symbol, listener: Function): this;
}
export interface IPythonSettings {
readonly pythonPath: string;
readonly venvPath: string;
readonly venvFolders: string[];
readonly condaPath: string;
readonly pipenvPath: string;
readonly poetryPath: string;
readonly insidersChannel: ExtensionChannels;
readonly downloadLanguageServer: boolean;
readonly showStartPage: boolean;
readonly jediPath: string;
readonly jediMemoryLimit: number;
readonly devOptions: string[];
readonly linting: ILintingSettings;
readonly formatting: IFormattingSettings;
readonly testing: ITestingSettings;
readonly autoComplete: IAutoCompleteSettings;
readonly terminal: ITerminalSettings;
readonly sortImports: ISortImportSettings;
readonly workspaceSymbols: IWorkspaceSymbolSettings;
readonly envFile: string;
readonly disableInstallationChecks: boolean;
readonly globalModuleInstallation: boolean;
readonly analysis: IAnalysisSettings;
readonly autoUpdateLanguageServer: boolean;
readonly onDidChange: Event<void>;
readonly experiments: IExperiments;
readonly languageServer: LanguageServerType;
readonly defaultInterpreterPath: string;
readonly logging: ILoggingSettings;
readonly useIsolation: boolean;
}
export interface ISortImportSettings {
readonly path: string;
readonly args: string[];
}
export interface IPylintCategorySeverity {
readonly convention: DiagnosticSeverity;
readonly refactor: DiagnosticSeverity;
readonly warning: DiagnosticSeverity;
readonly error: DiagnosticSeverity;
readonly fatal: DiagnosticSeverity;
}
export interface IPycodestyleCategorySeverity {
readonly W: DiagnosticSeverity;
readonly E: DiagnosticSeverity;
}
export interface Flake8CategorySeverity {
readonly F: DiagnosticSeverity;
readonly E: DiagnosticSeverity;
readonly W: DiagnosticSeverity;
}
export interface IMypyCategorySeverity {
readonly error: DiagnosticSeverity;
readonly note: DiagnosticSeverity;
}
export type LoggingLevelSettingType = 'off' | 'error' | 'warn' | 'info' | 'debug';
export interface ILoggingSettings {
readonly level: LogLevel | 'off';
}
export interface ILintingSettings {
readonly enabled: boolean;
readonly ignorePatterns: string[];
readonly prospectorEnabled: boolean;
readonly prospectorArgs: string[];
readonly pylintEnabled: boolean;
readonly pylintArgs: string[];
readonly pycodestyleEnabled: boolean;
readonly pycodestyleArgs: string[];
readonly pylamaEnabled: boolean;
readonly pylamaArgs: string[];
readonly flake8Enabled: boolean;
readonly flake8Args: string[];
readonly pydocstyleEnabled: boolean;
readonly pydocstyleArgs: string[];
readonly lintOnSave: boolean;
readonly maxNumberOfProblems: number;
readonly pylintCategorySeverity: IPylintCategorySeverity;
readonly pycodestyleCategorySeverity: IPycodestyleCategorySeverity;
readonly flake8CategorySeverity: Flake8CategorySeverity;
readonly mypyCategorySeverity: IMypyCategorySeverity;
prospectorPath: string;
pylintPath: string;
pycodestylePath: string;
pylamaPath: string;
flake8Path: string;
pydocstylePath: string;
mypyEnabled: boolean;
mypyArgs: string[];
mypyPath: string;
banditEnabled: boolean;
banditArgs: string[];
banditPath: string;
readonly pylintUseMinimalCheckers: boolean;
}
export interface IFormattingSettings {
readonly provider: string;
autopep8Path: string;
readonly autopep8Args: string[];
blackPath: string;
readonly blackArgs: string[];
yapfPath: string;
readonly yapfArgs: string[];
}
export interface IAutoCompleteSettings {
readonly addBrackets: boolean;
readonly extraPaths: string[];
readonly showAdvancedMembers: boolean;
readonly typeshedPaths: string[];
}
export interface IWorkspaceSymbolSettings {
readonly enabled: boolean;
tagFilePath: string;
readonly rebuildOnStart: boolean;
readonly rebuildOnFileSave: boolean;
readonly ctagsPath: string;
readonly exclusionPatterns: string[];
}
export interface ITerminalSettings {
readonly executeInFileDir: boolean;
readonly launchArgs: string[];
readonly activateEnvironment: boolean;
readonly activateEnvInCurrentTerminal: boolean;
}
export interface IExperiments {
/**
* Return `true` if experiments are enabled, else `false`.
*/
readonly enabled: boolean;
/**
* Experiments user requested to opt into manually
*/
readonly optInto: string[];
/**
* Experiments user requested to opt out from manually
*/
readonly optOutFrom: string[];
}
export enum AnalysisSettingsLogLevel {
Information = 'Information',
Error = 'Error',
Warning = 'Warning',
}
export type LanguageServerDownloadChannels = 'stable' | 'beta' | 'daily';
export interface IAnalysisSettings {
readonly downloadChannel?: LanguageServerDownloadChannels;
readonly typeshedPaths: string[];
readonly cacheFolderPath: string | null;
readonly errors: string[];
readonly warnings: string[];
readonly information: string[];
readonly disabled: string[];
readonly traceLogging: boolean;
readonly logLevel: AnalysisSettingsLogLevel;
}
export interface IVariableQuery {
language: string;
query: string;
parseExpr: string;
}
export const IConfigurationService = Symbol('IConfigurationService');
export interface IConfigurationService {
getSettings(resource?: Uri): IPythonSettings;
isTestExecution(): boolean;
updateSetting(setting: string, value?: unknown, resource?: Uri, configTarget?: ConfigurationTarget): Promise<void>;
updateSectionSetting(
section: string,
setting: string,
value?: unknown,
resource?: Uri,
configTarget?: ConfigurationTarget,
): Promise<void>;
}
/**
* Carries various tool execution path settings. For eg. pipenvPath, condaPath, pytestPath etc. These can be
* potentially used in discovery, autoselection, activation, installers, execution etc. And so should be a
* common interface to all the components.
*/
export const IToolExecutionPath = Symbol('IToolExecutionPath');
export interface IToolExecutionPath {
readonly executable: string;
}
export enum ToolExecutionPath {
pipenv = 'pipenv',
// Gradually populate this list with tools as they come up.
}
export const ISocketServer = Symbol('ISocketServer');
export interface ISocketServer extends Disposable {
readonly client: Promise<Socket>;
Start(options?: { port?: number; host?: string }): Promise<number>;
}
export type DownloadOptions = {
/**
* Prefix for progress messages displayed.
*
* @type {('Downloading ... ' | string)}
*/
progressMessagePrefix: 'Downloading ... ' | string;
/**
* Output panel into which progress information is written.
*
* @type {IOutputChannel}
*/
outputChannel?: IOutputChannel;
/**
* Extension of file that'll be created when downloading the file.
*
* @type {('tmp' | string)}
*/
extension: 'tmp' | string;
};
export const IFileDownloader = Symbol('IFileDownloader');
/**
* File downloader, that'll display progress in the status bar.
*
* @export
* @interface IFileDownloader
*/
export interface IFileDownloader {
/**
* Download file and display progress in statusbar.
* Optionnally display progress in the provided output channel.
*
* @param {string} uri
* @param {DownloadOptions} options
* @returns {Promise<string>}
* @memberof IFileDownloader
*/
downloadFile(uri: string, options: DownloadOptions): Promise<string>;
}
export const IHttpClient = Symbol('IHttpClient');
export interface IHttpClient {
downloadFile(uri: string): Promise<RequestResult>;
/**
* Downloads file from uri as string and parses them into JSON objects
* @param uri The uri to download the JSON from
* @param strict Set `false` to allow trailing comma and comments in the JSON, defaults to `true`
*/
getJSON<T>(uri: string, strict?: boolean): Promise<T>;
/**
* Returns the url is valid (i.e. return status code of 200).
*/
exists(uri: string): Promise<boolean>;
}
export const IExtensionContext = Symbol('ExtensionContext');
export interface IExtensionContext extends ExtensionContext {}
export const IExtensions = Symbol('IExtensions');
export interface IExtensions {
/**
* All extensions currently known to the system.
*/
readonly all: readonly Extension<unknown>[];
/**
* An event which fires when `extensions.all` changes. This can happen when extensions are
* installed, uninstalled, enabled or disabled.
*/
readonly onDidChange: Event<void>;
/**
* Get an extension by its full identifier in the form of: `publisher.name`.
*
* @param extensionId An extension identifier.
* @return An extension or `undefined`.
*/
getExtension(extensionId: string): Extension<unknown> | undefined;
/**
* Get an extension its full identifier in the form of: `publisher.name`.
*
* @param extensionId An extension identifier.
* @return An extension or `undefined`.
*/
getExtension<T>(extensionId: string): Extension<T> | undefined;
}
export const IBrowserService = Symbol('IBrowserService');
export interface IBrowserService {
launch(url: string): void;
}
export const IPythonExtensionBanner = Symbol('IPythonExtensionBanner');
export interface IPythonExtensionBanner {
readonly enabled: boolean;
showBanner(): Promise<void>;
}
export const BANNER_NAME_PROPOSE_LS = 'ProposePylance';
export type DeprecatedSettingAndValue = {
setting: string;
values?: unknown[];
};
export type DeprecatedFeatureInfo = {
doNotDisplayPromptStateKey: string;
message: string;
moreInfoUrl: string;
commands?: CommandsWithoutArgs[];
setting?: DeprecatedSettingAndValue;
};
export const IFeatureDeprecationManager = Symbol('IFeatureDeprecationManager');
export interface IFeatureDeprecationManager extends Disposable {
initialize(): void;
registerDeprecation(deprecatedInfo: DeprecatedFeatureInfo): void;
}
export const IEditorUtils = Symbol('IEditorUtils');
export interface IEditorUtils {
getWorkspaceEditsFromPatch(originalContents: string, patch: string, uri: Uri): WorkspaceEdit;
}
export interface IDisposable {
dispose(): void | undefined;
}
export interface IAsyncDisposable {
dispose(): Promise<void>;
}
/**
* Stores hash formats
*/
export interface IHashFormat {
number: number; // If hash format is a number
string: string; // If hash format is a string
}
/**
* Interface used to implement cryptography tools
*/
export const ICryptoUtils = Symbol('ICryptoUtils');
export interface ICryptoUtils {
/**
* Creates hash using the data and encoding specified
* @returns hash as number, or string
* @param data The string to hash
* @param hashFormat Return format of the hash, number or string
* @param [algorithm]
*/
createHash<E extends keyof IHashFormat>(
data: string,
hashFormat: E,
algorithm?: 'SHA512' | 'SHA256' | 'FNV',
): IHashFormat[E];
}
export const IAsyncDisposableRegistry = Symbol('IAsyncDisposableRegistry');
export interface IAsyncDisposableRegistry extends IAsyncDisposable {
push(disposable: IDisposable | IAsyncDisposable): void;
}
/* ABExperiments field carries the identity, and the range of the experiment,
where the experiment is valid for users falling between the number 'min' and 'max'
More details: https://en.wikipedia.org/wiki/A/B_testing
*/
export type ABExperiments = {
name: string; // Name of the experiment
salt: string; // Salt string for the experiment
min: number; // Lower limit for the experiment
max: number; // Upper limit for the experiment
}[];
/**
* Interface used to implement AB testing
*/
export const IExperimentsManager = Symbol('IExperimentsManager');
/**
* @deprecated Use IExperimentService instead
*/
export interface IExperimentsManager {
/**
* Checks if experiments are enabled, sets required environment to be used for the experiments, logs experiment groups
*/
activate(): Promise<void>;
/**
* Checks if user is in experiment or not
* @param experimentName Name of the experiment
* @returns `true` if user is in experiment, `false` if user is not in experiment
*/
inExperiment(experimentName: string): boolean;
/**
* Sends experiment telemetry if user is in experiment
* @param experimentName Name of the experiment
*/
sendTelemetryIfInExperiment(experimentName: string): void;
}
/**
* Experiment service leveraging VS Code's experiment framework.
*/
export const IExperimentService = Symbol('IExperimentService');
export interface IExperimentService {
inExperiment(experimentName: string): Promise<boolean>;
getExperimentValue<T extends boolean | number | string>(experimentName: string): Promise<T | undefined>;
}
export type InterpreterConfigurationScope = { uri: Resource; configTarget: ConfigurationTarget };
export type InspectInterpreterSettingType = {
globalValue?: string;
workspaceValue?: string;
workspaceFolderValue?: string;
};
/**
* Interface used to access current Interpreter Path
*/
export const IInterpreterPathService = Symbol('IInterpreterPathService');
export interface IInterpreterPathService {
onDidChange: Event<InterpreterConfigurationScope>;
get(resource: Resource): string;
inspect(resource: Resource): InspectInterpreterSettingType;
update(resource: Resource, configTarget: ConfigurationTarget, value: string | undefined): Promise<void>;
copyOldInterpreterStorageValuesToNew(resource: Uri | undefined): Promise<void>;
}
/**
* Interface used to retrieve the default language server to use when in experiment
*
* Note: This is added to get around a problem that the config service is not `async`.
* Adding experiment check there would mean touching the entire extension. For simplicity
* this is a solution.
*/
export const IDefaultLanguageServer = Symbol('IDefaultLanguageServer');
export interface IDefaultLanguageServer {
readonly defaultLSType: LanguageServerType;
}