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
176 lines (153 loc) · 6.24 KB
/
types.ts
File metadata and controls
176 lines (153 loc) · 6.24 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { nbformat } from '@jupyterlab/coreutils';
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 { IDisposable } from '../common/types';
import { PythonInterpreter } from '../interpreter/contracts';
// Main interface
export const IDataScience = Symbol('IDataScience');
export interface IDataScience extends Disposable {
activate(): Promise<void>;
}
export const IDataScienceCommandListener = Symbol('IDataScienceCommandListener');
export interface IDataScienceCommandListener {
register(commandManager: ICommandManager);
}
// Connection information for talking to a jupyter notebook process
export interface IConnection extends Disposable {
baseUrl: string;
token: string;
localLaunch: boolean;
}
export enum InterruptResult {
Success = 0,
TimedOut = 1,
Restarted = 2
}
// Talks to a jupyter ipython kernel to retrieve data for cells
export const INotebookServer = Symbol('INotebookServer');
export interface INotebookServer extends Disposable {
onStatusChanged: Event<boolean>;
connect(conninfo: IConnection, kernelSpec: IJupyterKernelSpec, cancelToken?: CancellationToken, workingDir?: string) : Promise<void>;
getCurrentState() : Promise<ICell[]>;
executeObservable(code: string, file: string, line: number) : Observable<ICell[]>;
execute(code: string, file: string, line: number, cancelToken?: CancellationToken) : Promise<ICell[]>;
restartKernel() : Promise<void>;
waitForIdle() : Promise<void>;
shutdown() : Promise<void>;
interruptKernel(timeoutInMs: number) : Promise<InterruptResult>;
setInitialDirectory(directory: string): Promise<void>;
getConnectionInfo(): IConnection | undefined;
}
export const IJupyterExecution = Symbol('IJupyterExecution');
export interface IJupyterExecution {
isNotebookSupported(cancelToken?: CancellationToken) : Promise<boolean>;
isImportSupported(cancelToken?: CancellationToken) : Promise<boolean>;
isKernelCreateSupported(cancelToken?: CancellationToken): Promise<boolean>;
connectToNotebookServer(uri: string | undefined, useDefaultConfig: boolean, cancelToken?: CancellationToken, workingDir?: string) : Promise<INotebookServer | undefined>;
spawnNotebook(file: string) : Promise<void>;
importNotebook(file: string, template: string) : Promise<string>;
getUsableJupyterPython(cancelToken?: CancellationToken) : Promise<PythonInterpreter | undefined>;
}
export interface IJupyterKernelSpec extends IDisposable {
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 {
getActive() : IHistory | undefined;
getOrCreateActive(): IHistory;
}
export const IHistory = Symbol('IHistory');
export interface IHistory extends Disposable {
closed: Event<IHistory>;
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);
undoCells();
redoCells();
removeAllCells();
interruptKernel();
restartKernel();
expandAllCells();
collapseAllCells();
exportCells();
}
// 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);
// tslint:disable-next-line:no-any
listen(message: string, listener: (args: any[] | undefined) => 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 {
addFile(document: TextDocument);
getFileName() : string;
getVersion() : number;
getCodeLenses() : CodeLens[];
runAllCells();
runCell(range: Range);
runCurrentCell();
runCurrentCellAndAdvance();
}
export enum CellState {
init = 0,
executing = 1,
finished = 2,
error = 3
}
// Basic structure for a cell from a notebook
export interface ICell {
id: string;
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 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) : Promise<T>;
}