@jupyterlab/tooltip-extension 4.0.0-alpha.8 → 4.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +20 -7
- package/lib/index.js.map +1 -1
- package/package.json +18 -16
- package/src/index.ts +340 -0
package/lib/index.js
CHANGED
|
@@ -10,7 +10,8 @@ import { IEditorTracker } from '@jupyterlab/fileeditor';
|
|
|
10
10
|
import { INotebookTracker } from '@jupyterlab/notebook';
|
|
11
11
|
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
12
12
|
import { ITooltipManager, Tooltip } from '@jupyterlab/tooltip';
|
|
13
|
-
import {
|
|
13
|
+
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
|
|
14
|
+
import { find } from '@lumino/algorithm';
|
|
14
15
|
import { Widget } from '@lumino/widgets';
|
|
15
16
|
/**
|
|
16
17
|
* The command IDs used by the tooltip plugin.
|
|
@@ -28,11 +29,14 @@ var CommandIDs;
|
|
|
28
29
|
const manager = {
|
|
29
30
|
id: '@jupyterlab/tooltip-extension:manager',
|
|
30
31
|
autoStart: true,
|
|
32
|
+
optional: [ITranslator],
|
|
31
33
|
provides: ITooltipManager,
|
|
32
|
-
activate: (app) => {
|
|
34
|
+
activate: (app, translator) => {
|
|
35
|
+
const trans = (translator !== null && translator !== void 0 ? translator : nullTranslator).load('jupyterlab');
|
|
33
36
|
let tooltip = null;
|
|
34
37
|
// Add tooltip dismiss command.
|
|
35
38
|
app.commands.addCommand(CommandIDs.dismiss, {
|
|
39
|
+
label: trans.__('Dismiss the tooltip'),
|
|
36
40
|
execute: () => {
|
|
37
41
|
if (tooltip) {
|
|
38
42
|
tooltip.dispose();
|
|
@@ -66,10 +70,13 @@ const manager = {
|
|
|
66
70
|
const consoles = {
|
|
67
71
|
id: '@jupyterlab/tooltip-extension:consoles',
|
|
68
72
|
autoStart: true,
|
|
73
|
+
optional: [ITranslator],
|
|
69
74
|
requires: [ITooltipManager, IConsoleTracker],
|
|
70
|
-
activate: (app, manager, consoles) => {
|
|
75
|
+
activate: (app, manager, consoles, translator) => {
|
|
76
|
+
const trans = (translator !== null && translator !== void 0 ? translator : nullTranslator).load('jupyterlab');
|
|
71
77
|
// Add tooltip launch command.
|
|
72
78
|
app.commands.addCommand(CommandIDs.launchConsole, {
|
|
79
|
+
label: trans.__('Open the tooltip'),
|
|
73
80
|
execute: () => {
|
|
74
81
|
var _a, _b;
|
|
75
82
|
const parent = consoles.currentWidget;
|
|
@@ -94,10 +101,13 @@ const consoles = {
|
|
|
94
101
|
const notebooks = {
|
|
95
102
|
id: '@jupyterlab/tooltip-extension:notebooks',
|
|
96
103
|
autoStart: true,
|
|
104
|
+
optional: [ITranslator],
|
|
97
105
|
requires: [ITooltipManager, INotebookTracker],
|
|
98
|
-
activate: (app, manager, notebooks) => {
|
|
106
|
+
activate: (app, manager, notebooks, translator) => {
|
|
107
|
+
const trans = (translator !== null && translator !== void 0 ? translator : nullTranslator).load('jupyterlab');
|
|
99
108
|
// Add tooltip launch command.
|
|
100
109
|
app.commands.addCommand(CommandIDs.launchNotebook, {
|
|
110
|
+
label: trans.__('Open the tooltip'),
|
|
101
111
|
execute: () => {
|
|
102
112
|
var _a, _b;
|
|
103
113
|
const parent = notebooks.currentWidget;
|
|
@@ -122,8 +132,10 @@ const notebooks = {
|
|
|
122
132
|
const files = {
|
|
123
133
|
id: '@jupyterlab/tooltip-extension:files',
|
|
124
134
|
autoStart: true,
|
|
135
|
+
optional: [ITranslator],
|
|
125
136
|
requires: [ITooltipManager, IEditorTracker, IRenderMimeRegistry],
|
|
126
|
-
activate: (app, manager, editorTracker, rendermime) => {
|
|
137
|
+
activate: (app, manager, editorTracker, rendermime, translator) => {
|
|
138
|
+
const trans = (translator !== null && translator !== void 0 ? translator : nullTranslator).load('jupyterlab');
|
|
127
139
|
// Keep a list of active ISessions so that we can
|
|
128
140
|
// clean them up when they are no longer needed.
|
|
129
141
|
const activeSessions = {};
|
|
@@ -159,7 +171,7 @@ const files = {
|
|
|
159
171
|
}
|
|
160
172
|
});
|
|
161
173
|
};
|
|
162
|
-
onRunningChanged(sessions,
|
|
174
|
+
onRunningChanged(sessions, sessions.running());
|
|
163
175
|
sessions.runningChanged.connect(onRunningChanged);
|
|
164
176
|
// Clean up after a widget when it is disposed
|
|
165
177
|
editorTracker.widgetAdded.connect((sender, widget) => {
|
|
@@ -173,6 +185,7 @@ const files = {
|
|
|
173
185
|
});
|
|
174
186
|
// Add tooltip launch command.
|
|
175
187
|
app.commands.addCommand(CommandIDs.launchFile, {
|
|
188
|
+
label: trans.__('Open the tooltip'),
|
|
176
189
|
execute: async () => {
|
|
177
190
|
const parent = editorTracker.currentWidget;
|
|
178
191
|
const kernel = parent &&
|
|
@@ -215,7 +228,7 @@ var Private;
|
|
|
215
228
|
*/
|
|
216
229
|
function fetch(options) {
|
|
217
230
|
const { detail, editor, kernel } = options;
|
|
218
|
-
const code = editor.model.
|
|
231
|
+
const code = editor.model.sharedModel.getSource();
|
|
219
232
|
const position = editor.getCursorPosition();
|
|
220
233
|
const offset = Text.jsIndexToCharIndex(editor.getOffsetAt(position), code);
|
|
221
234
|
// Clear hints if the new text value is empty or kernel is unavailable.
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAC3D;;;GAGG;AAOH,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,qBAA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AC,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE;gBACzC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAwB,CAAC;aACtD;YAED,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC;IAjCe,aAAK,QAiCpB,CAAA;AACH,CAAC,EAhES,OAAO,KAAP,OAAO,QAgEhB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlab/tooltip-extension",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.0",
|
|
4
4
|
"description": "JupyterLab - Tooltip Extension",
|
|
5
5
|
"homepage": "https://github.com/jupyterlab/jupyterlab",
|
|
6
6
|
"bugs": {
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"lib/*.js",
|
|
29
29
|
"schema/*.json",
|
|
30
30
|
"style/**/*.css",
|
|
31
|
-
"style/index.js"
|
|
31
|
+
"style/index.js",
|
|
32
|
+
"src/**/*.{ts,tsx}"
|
|
32
33
|
],
|
|
33
34
|
"scripts": {
|
|
34
35
|
"build": "tsc -b",
|
|
@@ -37,23 +38,24 @@
|
|
|
37
38
|
"watch": "tsc -b --watch"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"@jupyterlab/application": "^4.0.0-
|
|
41
|
-
"@jupyterlab/codeeditor": "^4.0.0-
|
|
42
|
-
"@jupyterlab/console": "^4.0.0-
|
|
43
|
-
"@jupyterlab/coreutils": "^6.0.0-
|
|
44
|
-
"@jupyterlab/fileeditor": "^4.0.0-
|
|
45
|
-
"@jupyterlab/notebook": "^4.0.0-
|
|
46
|
-
"@jupyterlab/rendermime": "^4.0.0-
|
|
47
|
-
"@jupyterlab/services": "^7.0.0-
|
|
48
|
-
"@jupyterlab/tooltip": "^4.0.0-
|
|
49
|
-
"@
|
|
50
|
-
"@lumino/
|
|
51
|
-
"@lumino/
|
|
41
|
+
"@jupyterlab/application": "^4.0.0-beta.0",
|
|
42
|
+
"@jupyterlab/codeeditor": "^4.0.0-beta.0",
|
|
43
|
+
"@jupyterlab/console": "^4.0.0-beta.0",
|
|
44
|
+
"@jupyterlab/coreutils": "^6.0.0-beta.0",
|
|
45
|
+
"@jupyterlab/fileeditor": "^4.0.0-beta.0",
|
|
46
|
+
"@jupyterlab/notebook": "^4.0.0-beta.0",
|
|
47
|
+
"@jupyterlab/rendermime": "^4.0.0-beta.0",
|
|
48
|
+
"@jupyterlab/services": "^7.0.0-beta.0",
|
|
49
|
+
"@jupyterlab/tooltip": "^4.0.0-beta.0",
|
|
50
|
+
"@jupyterlab/translation": "^4.0.0-beta.0",
|
|
51
|
+
"@lumino/algorithm": "^2.0.0",
|
|
52
|
+
"@lumino/coreutils": "^2.0.0",
|
|
53
|
+
"@lumino/widgets": "^2.0.0"
|
|
52
54
|
},
|
|
53
55
|
"devDependencies": {
|
|
54
56
|
"rimraf": "~3.0.0",
|
|
55
|
-
"typedoc": "~0.
|
|
56
|
-
"typescript": "~
|
|
57
|
+
"typedoc": "~0.23.25",
|
|
58
|
+
"typescript": "~5.0.2"
|
|
57
59
|
},
|
|
58
60
|
"publishConfig": {
|
|
59
61
|
"access": "public"
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
/**
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
* @module tooltip-extension
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
JupyterFrontEnd,
|
|
10
|
+
JupyterFrontEndPlugin
|
|
11
|
+
} from '@jupyterlab/application';
|
|
12
|
+
import { CodeEditor } from '@jupyterlab/codeeditor';
|
|
13
|
+
import { IConsoleTracker } from '@jupyterlab/console';
|
|
14
|
+
import { Text } from '@jupyterlab/coreutils';
|
|
15
|
+
import { IEditorTracker } from '@jupyterlab/fileeditor';
|
|
16
|
+
import { INotebookTracker } from '@jupyterlab/notebook';
|
|
17
|
+
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
18
|
+
import { Kernel, KernelMessage, Session } from '@jupyterlab/services';
|
|
19
|
+
import { ITooltipManager, Tooltip } from '@jupyterlab/tooltip';
|
|
20
|
+
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
|
|
21
|
+
import { find } from '@lumino/algorithm';
|
|
22
|
+
import { JSONObject } from '@lumino/coreutils';
|
|
23
|
+
import { Widget } from '@lumino/widgets';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The command IDs used by the tooltip plugin.
|
|
27
|
+
*/
|
|
28
|
+
namespace CommandIDs {
|
|
29
|
+
export const dismiss = 'tooltip:dismiss';
|
|
30
|
+
|
|
31
|
+
export const launchConsole = 'tooltip:launch-console';
|
|
32
|
+
|
|
33
|
+
export const launchNotebook = 'tooltip:launch-notebook';
|
|
34
|
+
|
|
35
|
+
export const launchFile = 'tooltip:launch-file';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The main tooltip manager plugin.
|
|
40
|
+
*/
|
|
41
|
+
const manager: JupyterFrontEndPlugin<ITooltipManager> = {
|
|
42
|
+
id: '@jupyterlab/tooltip-extension:manager',
|
|
43
|
+
autoStart: true,
|
|
44
|
+
optional: [ITranslator],
|
|
45
|
+
provides: ITooltipManager,
|
|
46
|
+
activate: (
|
|
47
|
+
app: JupyterFrontEnd,
|
|
48
|
+
translator: ITranslator | null
|
|
49
|
+
): ITooltipManager => {
|
|
50
|
+
const trans = (translator ?? nullTranslator).load('jupyterlab');
|
|
51
|
+
let tooltip: Tooltip | null = null;
|
|
52
|
+
|
|
53
|
+
// Add tooltip dismiss command.
|
|
54
|
+
app.commands.addCommand(CommandIDs.dismiss, {
|
|
55
|
+
label: trans.__('Dismiss the tooltip'),
|
|
56
|
+
execute: () => {
|
|
57
|
+
if (tooltip) {
|
|
58
|
+
tooltip.dispose();
|
|
59
|
+
tooltip = null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
invoke(options: ITooltipManager.IOptions): Promise<void> {
|
|
66
|
+
const detail: 0 | 1 = 0;
|
|
67
|
+
const { anchor, editor, kernel, rendermime } = options;
|
|
68
|
+
|
|
69
|
+
if (tooltip) {
|
|
70
|
+
tooltip.dispose();
|
|
71
|
+
tooltip = null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return Private.fetch({ detail, editor, kernel })
|
|
75
|
+
.then(bundle => {
|
|
76
|
+
tooltip = new Tooltip({ anchor, bundle, editor, rendermime });
|
|
77
|
+
Widget.attach(tooltip, document.body);
|
|
78
|
+
})
|
|
79
|
+
.catch(() => {
|
|
80
|
+
/* Fails silently. */
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The console tooltip plugin.
|
|
89
|
+
*/
|
|
90
|
+
const consoles: JupyterFrontEndPlugin<void> = {
|
|
91
|
+
id: '@jupyterlab/tooltip-extension:consoles',
|
|
92
|
+
autoStart: true,
|
|
93
|
+
optional: [ITranslator],
|
|
94
|
+
requires: [ITooltipManager, IConsoleTracker],
|
|
95
|
+
activate: (
|
|
96
|
+
app: JupyterFrontEnd,
|
|
97
|
+
manager: ITooltipManager,
|
|
98
|
+
consoles: IConsoleTracker,
|
|
99
|
+
translator: ITranslator | null
|
|
100
|
+
): void => {
|
|
101
|
+
const trans = (translator ?? nullTranslator).load('jupyterlab');
|
|
102
|
+
|
|
103
|
+
// Add tooltip launch command.
|
|
104
|
+
app.commands.addCommand(CommandIDs.launchConsole, {
|
|
105
|
+
label: trans.__('Open the tooltip'),
|
|
106
|
+
execute: () => {
|
|
107
|
+
const parent = consoles.currentWidget;
|
|
108
|
+
|
|
109
|
+
if (!parent) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const anchor = parent.console;
|
|
114
|
+
const editor = anchor.promptCell?.editor;
|
|
115
|
+
const kernel = anchor.sessionContext.session?.kernel;
|
|
116
|
+
const rendermime = anchor.rendermime;
|
|
117
|
+
|
|
118
|
+
// If all components necessary for rendering exist, create a tooltip.
|
|
119
|
+
if (!!editor && !!kernel && !!rendermime) {
|
|
120
|
+
return manager.invoke({ anchor, editor, kernel, rendermime });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The notebook tooltip plugin.
|
|
129
|
+
*/
|
|
130
|
+
const notebooks: JupyterFrontEndPlugin<void> = {
|
|
131
|
+
id: '@jupyterlab/tooltip-extension:notebooks',
|
|
132
|
+
autoStart: true,
|
|
133
|
+
optional: [ITranslator],
|
|
134
|
+
requires: [ITooltipManager, INotebookTracker],
|
|
135
|
+
activate: (
|
|
136
|
+
app: JupyterFrontEnd,
|
|
137
|
+
manager: ITooltipManager,
|
|
138
|
+
notebooks: INotebookTracker,
|
|
139
|
+
translator: ITranslator | null
|
|
140
|
+
): void => {
|
|
141
|
+
const trans = (translator ?? nullTranslator).load('jupyterlab');
|
|
142
|
+
|
|
143
|
+
// Add tooltip launch command.
|
|
144
|
+
app.commands.addCommand(CommandIDs.launchNotebook, {
|
|
145
|
+
label: trans.__('Open the tooltip'),
|
|
146
|
+
execute: () => {
|
|
147
|
+
const parent = notebooks.currentWidget;
|
|
148
|
+
|
|
149
|
+
if (!parent) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const anchor = parent.content;
|
|
154
|
+
const editor = anchor.activeCell?.editor;
|
|
155
|
+
const kernel = parent.sessionContext.session?.kernel;
|
|
156
|
+
const rendermime = anchor.rendermime;
|
|
157
|
+
|
|
158
|
+
// If all components necessary for rendering exist, create a tooltip.
|
|
159
|
+
if (!!editor && !!kernel && !!rendermime) {
|
|
160
|
+
return manager.invoke({ anchor, editor, kernel, rendermime });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The file editor tooltip plugin.
|
|
169
|
+
*/
|
|
170
|
+
const files: JupyterFrontEndPlugin<void> = {
|
|
171
|
+
id: '@jupyterlab/tooltip-extension:files',
|
|
172
|
+
autoStart: true,
|
|
173
|
+
optional: [ITranslator],
|
|
174
|
+
requires: [ITooltipManager, IEditorTracker, IRenderMimeRegistry],
|
|
175
|
+
activate: (
|
|
176
|
+
app: JupyterFrontEnd,
|
|
177
|
+
manager: ITooltipManager,
|
|
178
|
+
editorTracker: IEditorTracker,
|
|
179
|
+
rendermime: IRenderMimeRegistry,
|
|
180
|
+
translator: ITranslator | null
|
|
181
|
+
): void => {
|
|
182
|
+
const trans = (translator ?? nullTranslator).load('jupyterlab');
|
|
183
|
+
|
|
184
|
+
// Keep a list of active ISessions so that we can
|
|
185
|
+
// clean them up when they are no longer needed.
|
|
186
|
+
const activeSessions: {
|
|
187
|
+
[id: string]: Session.ISessionConnection;
|
|
188
|
+
} = {};
|
|
189
|
+
|
|
190
|
+
const sessions = app.serviceManager.sessions;
|
|
191
|
+
// When the list of running sessions changes,
|
|
192
|
+
// check to see if there are any kernels with a
|
|
193
|
+
// matching path for the file editors.
|
|
194
|
+
const onRunningChanged = (
|
|
195
|
+
sender: Session.IManager,
|
|
196
|
+
models: Iterable<Session.IModel>
|
|
197
|
+
) => {
|
|
198
|
+
editorTracker.forEach(file => {
|
|
199
|
+
const model = find(models, m => file.context.path === m.path);
|
|
200
|
+
if (model) {
|
|
201
|
+
const oldSession = activeSessions[file.id];
|
|
202
|
+
// If there is a matching path, but it is the same
|
|
203
|
+
// session as we previously had, do nothing.
|
|
204
|
+
if (oldSession && oldSession.id === model.id) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
// Otherwise, dispose of the old session and reset to
|
|
208
|
+
// a new CompletionConnector.
|
|
209
|
+
if (oldSession) {
|
|
210
|
+
delete activeSessions[file.id];
|
|
211
|
+
oldSession.dispose();
|
|
212
|
+
}
|
|
213
|
+
const session = sessions.connectTo({ model });
|
|
214
|
+
activeSessions[file.id] = session;
|
|
215
|
+
} else {
|
|
216
|
+
const session = activeSessions[file.id];
|
|
217
|
+
if (session) {
|
|
218
|
+
session.dispose();
|
|
219
|
+
delete activeSessions[file.id];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
onRunningChanged(sessions, sessions.running());
|
|
225
|
+
sessions.runningChanged.connect(onRunningChanged);
|
|
226
|
+
|
|
227
|
+
// Clean up after a widget when it is disposed
|
|
228
|
+
editorTracker.widgetAdded.connect((sender, widget) => {
|
|
229
|
+
widget.disposed.connect(w => {
|
|
230
|
+
const session = activeSessions[w.id];
|
|
231
|
+
if (session) {
|
|
232
|
+
session.dispose();
|
|
233
|
+
delete activeSessions[w.id];
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// Add tooltip launch command.
|
|
239
|
+
app.commands.addCommand(CommandIDs.launchFile, {
|
|
240
|
+
label: trans.__('Open the tooltip'),
|
|
241
|
+
execute: async () => {
|
|
242
|
+
const parent = editorTracker.currentWidget;
|
|
243
|
+
const kernel =
|
|
244
|
+
parent &&
|
|
245
|
+
activeSessions[parent.id] &&
|
|
246
|
+
activeSessions[parent.id].kernel;
|
|
247
|
+
if (!kernel) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const anchor = parent!.content;
|
|
251
|
+
const editor = anchor?.editor;
|
|
252
|
+
|
|
253
|
+
// If all components necessary for rendering exist, create a tooltip.
|
|
254
|
+
if (!!editor && !!kernel && !!rendermime) {
|
|
255
|
+
return manager.invoke({ anchor, editor, kernel, rendermime });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Export the plugins as default.
|
|
264
|
+
*/
|
|
265
|
+
const plugins: JupyterFrontEndPlugin<any>[] = [
|
|
266
|
+
manager,
|
|
267
|
+
consoles,
|
|
268
|
+
notebooks,
|
|
269
|
+
files
|
|
270
|
+
];
|
|
271
|
+
export default plugins;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* A namespace for private data.
|
|
275
|
+
*/
|
|
276
|
+
namespace Private {
|
|
277
|
+
/**
|
|
278
|
+
* A counter for outstanding requests.
|
|
279
|
+
*/
|
|
280
|
+
let pending = 0;
|
|
281
|
+
|
|
282
|
+
export interface IFetchOptions {
|
|
283
|
+
/**
|
|
284
|
+
* The detail level requested from the API.
|
|
285
|
+
*
|
|
286
|
+
* #### Notes
|
|
287
|
+
* The only acceptable values are 0 and 1. The default value is 0.
|
|
288
|
+
* @see http://jupyter-client.readthedocs.io/en/latest/messaging.html#introspection
|
|
289
|
+
*/
|
|
290
|
+
detail?: 0 | 1;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* The referent editor for the tooltip.
|
|
294
|
+
*/
|
|
295
|
+
editor: CodeEditor.IEditor;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* The kernel against which the API request will be made.
|
|
299
|
+
*/
|
|
300
|
+
kernel: Kernel.IKernelConnection;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Fetch a tooltip's content from the API server.
|
|
305
|
+
*/
|
|
306
|
+
export function fetch(options: IFetchOptions): Promise<JSONObject> {
|
|
307
|
+
const { detail, editor, kernel } = options;
|
|
308
|
+
const code = editor.model.sharedModel.getSource();
|
|
309
|
+
const position = editor.getCursorPosition();
|
|
310
|
+
const offset = Text.jsIndexToCharIndex(editor.getOffsetAt(position), code);
|
|
311
|
+
|
|
312
|
+
// Clear hints if the new text value is empty or kernel is unavailable.
|
|
313
|
+
if (!code || !kernel) {
|
|
314
|
+
return Promise.reject(void 0);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const contents: KernelMessage.IInspectRequestMsg['content'] = {
|
|
318
|
+
code,
|
|
319
|
+
cursor_pos: offset,
|
|
320
|
+
detail_level: detail || 0
|
|
321
|
+
};
|
|
322
|
+
const current = ++pending;
|
|
323
|
+
|
|
324
|
+
return kernel.requestInspect(contents).then(msg => {
|
|
325
|
+
const value = msg.content;
|
|
326
|
+
|
|
327
|
+
// If a newer request is pending, bail.
|
|
328
|
+
if (current !== pending) {
|
|
329
|
+
return Promise.reject(void 0) as Promise<JSONObject>;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// If request fails or returns negative results, bail.
|
|
333
|
+
if (value.status !== 'ok' || !value.found) {
|
|
334
|
+
return Promise.reject(void 0) as Promise<JSONObject>;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return Promise.resolve(value.data);
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|