Skip to content

Commit c862125

Browse files
committed
type fixes
1 parent 387df22 commit c862125

3 files changed

Lines changed: 25 additions & 33 deletions

File tree

packages/javascript-kernel/src/display.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4+
import type { KernelMessage } from '@jupyterlab/services';
5+
46
/**
57
* MIME bundle for rich display.
68
*/
@@ -11,13 +13,12 @@ export interface IMimeBundle {
1113
/**
1214
* Display request from display().
1315
*/
14-
export interface IDisplayData {
16+
export type IDisplayData = Omit<
17+
KernelMessage.IDisplayDataMsg['content'],
18+
'data'
19+
> & {
1520
data: IMimeBundle;
16-
metadata: Record<string, any>;
17-
transient?: {
18-
display_id?: string;
19-
};
20-
}
21+
};
2122

2223
/**
2324
* Callbacks for display operations.

packages/javascript-kernel/src/executor.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4+
import type { KernelMessage } from '@jupyterlab/services';
5+
46
import { parseScript } from 'meriyah';
57
import { generate } from 'astring';
68

@@ -61,19 +63,14 @@ export interface ICompletionResult {
6163
/**
6264
* Result of code completeness check.
6365
*/
64-
export interface IIsCompleteResult {
65-
status: 'complete' | 'incomplete' | 'invalid' | 'unknown';
66-
indent?: string;
67-
}
66+
export type IIsCompleteResult =
67+
| KernelMessage.IIsCompleteReplyIncomplete
68+
| KernelMessage.IIsCompleteReplyOther;
6869

6970
/**
7071
* Result of code inspection.
7172
*/
72-
export interface IInspectResult {
73-
found: boolean;
74-
data: IMimeBundle;
75-
metadata: Record<string, any>;
76-
}
73+
export type IInspectResult = KernelMessage.IInspectReply;
7774

7875
/**
7976
* Registry for tracking code declarations across cells.
@@ -904,13 +901,14 @@ export class JavaScriptExecutor {
904901
inspect(
905902
code: string,
906903
cursorPos: number,
907-
detailLevel: number = 0
904+
detailLevel: KernelMessage.IInspectRequestMsg['content']['detail_level'] = 0
908905
): IInspectResult {
909906
// Extract the word/expression at cursor position
910907
const expression = this._extractExpressionAtCursor(code, cursorPos);
911908

912909
if (!expression) {
913910
return {
911+
status: 'ok',
914912
found: false,
915913
data: {},
916914
metadata: {}
@@ -933,6 +931,7 @@ export class JavaScriptExecutor {
933931
);
934932

935933
return {
934+
status: 'ok',
936935
found: true,
937936
data: inspectionData,
938937
metadata: {}
@@ -965,6 +964,7 @@ export class JavaScriptExecutor {
965964
const doc = this.getBuiltinDocumentation(expression);
966965
if (doc) {
967966
return {
967+
status: 'ok',
968968
found: true,
969969
data: {
970970
'text/plain': `${expression}: ${doc}`,
@@ -978,6 +978,7 @@ export class JavaScriptExecutor {
978978
const suggestions = this._findSimilarNames(expression);
979979
if (suggestions.length > 0) {
980980
return {
981+
status: 'ok',
981982
found: true,
982983
data: {
983984
'text/plain': `'${expression}' not found. Did you mean: ${suggestions.join(', ')}?`,
@@ -988,6 +989,7 @@ export class JavaScriptExecutor {
988989
}
989990

990991
return {
992+
status: 'ok',
991993
found: false,
992994
data: {},
993995
metadata: {}
@@ -1870,14 +1872,14 @@ export class JavaScriptExecutor {
18701872

18711873
for (const part of parts) {
18721874
if (value === null || value === undefined) {
1873-
return { found: false, data: {}, metadata: {} };
1875+
return { status: 'ok', found: false, data: {}, metadata: {} };
18741876
}
18751877
const hasProp =
18761878
part in value || Object.prototype.hasOwnProperty.call(value, part);
18771879
if (hasProp) {
18781880
value = value[part];
18791881
} else {
1880-
return { found: false, data: {}, metadata: {} };
1882+
return { status: 'ok', found: false, data: {}, metadata: {} };
18811883
}
18821884
}
18831885

@@ -1898,12 +1900,13 @@ export class JavaScriptExecutor {
18981900
}
18991901

19001902
return {
1903+
status: 'ok',
19011904
found: true,
19021905
data: inspectionData,
19031906
metadata: {}
19041907
};
19051908
} catch {
1906-
return { found: false, data: {}, metadata: {} };
1909+
return { status: 'ok', found: false, data: {}, metadata: {} };
19071910
}
19081911
}
19091912

packages/javascript-kernel/src/runtime_evaluator.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,26 +131,14 @@ export class JavaScriptRuntimeEvaluator {
131131
cursorPos: number,
132132
detailLevel: KernelMessage.IInspectRequestMsg['content']['detail_level']
133133
): KernelMessage.IInspectReplyMsg['content'] {
134-
const result = this._executor.inspect(code, cursorPos, detailLevel);
135-
136-
return {
137-
status: 'ok',
138-
found: result.found,
139-
data: result.data,
140-
metadata: result.metadata
141-
};
134+
return this._executor.inspect(code, cursorPos, detailLevel);
142135
}
143136

144137
/**
145138
* Check whether the provided code is complete.
146139
*/
147140
isComplete(code: string): KernelMessage.IIsCompleteReplyMsg['content'] {
148-
const result = this._executor.isComplete(code);
149-
150-
return {
151-
status: result.status,
152-
indent: result.indent || ''
153-
};
141+
return this._executor.isComplete(code);
154142
}
155143

156144
/**

0 commit comments

Comments
 (0)