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
290 lines (257 loc) · 11.4 KB
/
types.ts
File metadata and controls
290 lines (257 loc) · 11.4 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { nbformat } from '@jupyterlab/coreutils';
import { Kernel, KernelMessage } from '@jupyterlab/services/lib/kernel';
import { JSONObject } from '@phosphor/coreutils';
import { Observable } from 'rxjs/Observable';
import { CancellationToken, CodeLens, CodeLensProvider, Disposable, Event, Range, TextDocument, TextEditor } from 'vscode';
import { ICommandManager } from '../common/application/types';
import { ExecutionResult, ObservableExecutionResult, SpawnOptions } from '../common/process/types';
import { IAsyncDisposable, IDataScienceSettings } from '../common/types';
import { PythonInterpreter } from '../interpreter/contracts';
// Main interface
export const IDataScience = Symbol('IDataScience');
export interface IDataScience extends Disposable {
activationStartTime: number;
activate(): Promise<void>;
}
export const IDataScienceCommandListener = Symbol('IDataScienceCommandListener');
export interface IDataScienceCommandListener {
register(commandManager: ICommandManager): void;
}
// Connection information for talking to a jupyter notebook process
export interface IConnection extends Disposable {
baseUrl: string;
token: string;
localLaunch: boolean;
localProcExitCode: number | undefined;
disconnected: Event<number>;
}
export enum InterruptResult {
Success = 0,
TimedOut = 1,
Restarted = 2
}
// Information used to launch a notebook server
export interface INotebookServerLaunchInfo
{
connectionInfo: IConnection;
currentInterpreter: PythonInterpreter | undefined;
uri: string | undefined; // Different from the connectionInfo as this is the setting used, not the result
kernelSpec: IJupyterKernelSpec | undefined;
usingDarkTheme: boolean;
workingDir: string | undefined;
purpose: string | undefined; // Purpose this server is for
}
// Talks to a jupyter ipython kernel to retrieve data for cells
export const INotebookServer = Symbol('INotebookServer');
export interface INotebookServer extends IAsyncDisposable {
connect(launchInfo: INotebookServerLaunchInfo, cancelToken?: CancellationToken) : Promise<void>;
executeObservable(code: string, file: string, line: number, id: string, silent: boolean) : Observable<ICell[]>;
execute(code: string, file: string, line: number, id: string, cancelToken?: CancellationToken, silent?: boolean) : Promise<ICell[]>;
restartKernel() : Promise<void>;
waitForIdle() : Promise<void>;
shutdown() : Promise<void>;
interruptKernel(timeoutInMs: number) : Promise<InterruptResult>;
setInitialDirectory(directory: string): Promise<void>;
waitForConnect(): Promise<INotebookServerLaunchInfo | undefined>;
getConnectionInfo(): IConnection | undefined;
getSysInfo() : Promise<ICell | undefined>;
}
export interface INotebookServerOptions {
uri?: string;
usingDarkTheme?: boolean;
useDefaultConfig?: boolean;
workingDir?: string;
purpose: string;
}
export const IJupyterExecution = Symbol('IJupyterExecution');
export interface IJupyterExecution extends IAsyncDisposable {
sessionChanged: Event<void> ;
isNotebookSupported(cancelToken?: CancellationToken) : Promise<boolean>;
isImportSupported(cancelToken?: CancellationToken) : Promise<boolean>;
isKernelCreateSupported(cancelToken?: CancellationToken): Promise<boolean>;
isKernelSpecSupported(cancelToken?: CancellationToken): Promise<boolean>;
isSpawnSupported(cancelToken?: CancellationToken): Promise<boolean>;
connectToNotebookServer(options?: INotebookServerOptions, cancelToken?: CancellationToken) : Promise<INotebookServer | undefined>;
spawnNotebook(file: string) : Promise<void>;
importNotebook(file: string, template: string | undefined) : Promise<string>;
getUsableJupyterPython(cancelToken?: CancellationToken) : Promise<PythonInterpreter | undefined>;
getServer(options?: INotebookServerOptions) : Promise<INotebookServer | undefined>;
}
export const IJupyterSession = Symbol('IJupyterSession');
export interface IJupyterSession extends IAsyncDisposable {
onRestarted: Event<void>;
restart() : Promise<void>;
interrupt() : Promise<void>;
waitForIdle() : Promise<void>;
requestExecute(content: KernelMessage.IExecuteRequest, disposeOnDone?: boolean, metadata?: JSONObject) : Kernel.IFuture | undefined;
}
export const IJupyterSessionManager = Symbol('IJupyterSessionManager');
export interface IJupyterSessionManager {
startNew(connInfo: IConnection, kernelSpec: IJupyterKernelSpec | undefined, cancelToken?: CancellationToken) : Promise<IJupyterSession>;
getActiveKernelSpecs(connInfo: IConnection) : Promise<IJupyterKernelSpec[]>;
}
export interface IJupyterKernelSpec extends IAsyncDisposable {
name: string | undefined;
language: string | undefined;
path: string | undefined;
}
export const INotebookImporter = Symbol('INotebookImporter');
export interface INotebookImporter extends Disposable {
importFromFile(file: string) : Promise<string>;
}
export const INotebookExporter = Symbol('INotebookExporter');
export interface INotebookExporter extends Disposable {
translateToNotebook(cells: ICell[], directoryChange?: string) : Promise<JSONObject | undefined>;
}
export const IHistoryProvider = Symbol('IHistoryProvider');
export interface IHistoryProvider {
onExecutedCode: Event<string>;
getActive() : IHistory | undefined;
getOrCreateActive(): Promise<IHistory>;
getNotebookOptions() : Promise<INotebookServerOptions>;
}
export const IHistory = Symbol('IHistory');
export interface IHistory extends Disposable {
closed: Event<IHistory>;
ready: Promise<void>;
onExecutedCode: Event<string>;
show() : Promise<void>;
addCode(code: string, file: string, line: number, editor?: TextEditor) : Promise<void>;
// tslint:disable-next-line:no-any
postMessage(type: string, payload?: any): void;
undoCells(): void;
redoCells(): void;
removeAllCells(): void;
interruptKernel(): void;
restartKernel(): void;
expandAllCells(): void;
collapseAllCells(): void;
exportCells(): void;
}
// Wraps the vscode API in order to send messages back and forth from a webview
export const IPostOffice = Symbol('IPostOffice');
export interface IPostOffice {
// tslint:disable-next-line:no-any
post(message: string, params: any[] | undefined): void;
// tslint:disable-next-line:no-any
listen(message: string, listener: (args: any[] | undefined) => void) : void;
}
// Wraps the vscode CodeLensProvider base class
export const IDataScienceCodeLensProvider = Symbol('IDataScienceCodeLensProvider');
export interface IDataScienceCodeLensProvider extends CodeLensProvider {
getCodeWatcher(document: TextDocument) : ICodeWatcher | undefined;
}
// Wraps the Code Watcher API
export const ICodeWatcher = Symbol('ICodeWatcher');
export interface ICodeWatcher {
setDocument(document: TextDocument): void;
getFileName() : string;
getVersion() : number;
getCodeLenses() : CodeLens[];
getCachedSettings() : IDataScienceSettings | undefined;
runAllCells(): Promise<void>;
runCell(range: Range): Promise<void>;
runCurrentCell(): Promise<void>;
runCurrentCellAndAdvance(): Promise<void>;
runSelectionOrLine(activeEditor: TextEditor | undefined): Promise<void>;
runToLine(targetLine: number): Promise<void>;
runFromLine(targetLine: number): Promise<void>;
runAllCellsAbove(stopLine: number, stopCharacter: number): Promise<void>;
runCellAndAllBelow(startLine: number, startCharacter: number): Promise<void>;
runFileInteractive(): Promise<void>;
}
export enum CellState {
editing = -1,
init = 0,
executing = 1,
finished = 2,
error = 3
}
// Basic structure for a cell from a notebook
export interface ICell {
id: string; // This value isn't unique. File and line are needed to.
file: string;
line: number;
state: CellState;
data: nbformat.ICodeCell | nbformat.IRawCell | nbformat.IMarkdownCell | ISysInfo;
}
export interface IHistoryInfo {
cellCount: number;
undoCount: number;
redoCount: number;
}
export interface ISysInfo extends nbformat.IBaseCell {
cell_type: 'sys_info';
version: string;
notebook_version: string;
path: string;
message: string;
connection: string;
}
export const ICodeCssGenerator = Symbol('ICodeCssGenerator');
export interface ICodeCssGenerator {
generateThemeCss() : Promise<string>;
}
export const IThemeFinder = Symbol('IThemeFinder');
export interface IThemeFinder {
findThemeRootJson(themeName: string) : Promise<string | undefined>;
isThemeDark(themeName: string) : Promise<boolean | undefined>;
}
export const IStatusProvider = Symbol('IStatusProvider');
export interface IStatusProvider {
// call this function to set the new status on the active
// history window. Dispose of the returned object when done.
set(message: string, timeout?: number) : Disposable;
// call this function to wait for a promise while displaying status
waitWithStatus<T>(promise: () => Promise<T>, message: string, timeout?: number, canceled?: () => void, skipHistory?: boolean) : Promise<T>;
}
export interface IJupyterCommand {
interpreter() : Promise<PythonInterpreter | undefined>;
execObservable(args: string[], options: SpawnOptions): Promise<ObservableExecutionResult<string>>;
exec(args: string[], options: SpawnOptions): Promise<ExecutionResult<string>>;
}
export const IJupyterCommandFactory = Symbol('IJupyterCommandFactory');
export interface IJupyterCommandFactory {
createInterpreterCommand(args: string[], interpreter: PythonInterpreter) : IJupyterCommand;
createProcessCommand(exe: string, args: string[]) : IJupyterCommand;
}
// Config settings we pass to our react code
export interface IDataScienceExtraSettings extends IDataScienceSettings {
extraSettings: {
terminalCursor: string;
};
}
// Get variables from the currently running active Jupyter server
// Note: This definition is used implicitly by getJupyterVariableValue.py file
// Changes here may need to be reflected there as well
export interface IJupyterVariable {
name: string;
value: string | undefined;
type: string;
size: number;
shape: string;
count: number;
truncated: boolean;
expensive: boolean;
columns?: { key: string; type: string }[];
rowCount?: number;
}
export const IJupyterVariables = Symbol('IJupyterVariables');
export interface IJupyterVariables {
getVariables(): Promise<IJupyterVariable[]>;
getValue(targetVariable: IJupyterVariable): Promise<IJupyterVariable>;
getDataFrameInfo(targetVariable: IJupyterVariable) : Promise<IJupyterVariable>;
getDataFrameRows(targetVariable: IJupyterVariable, start: number, end: number) : Promise<JSONObject>;
}
export const IDataExplorerProvider = Symbol('IDataExplorerProvider');
export interface IDataExplorerProvider {
create(variable: string) : Promise<IDataExplorer>;
getPandasVersion() : Promise<{major: number; minor: number; build: number} | undefined>;
}
export const IDataExplorer = Symbol('IDataExplorer');
export interface IDataExplorer extends IAsyncDisposable {
show(variable: IJupyterVariable) : Promise<void>;
}