Skip to content

Commit ed88a08

Browse files
authored
Merge pull request #733 from jupyter-lsp/enable-strict-null-checks
Enable strict null checks and other strict settings
2 parents 75a5187 + 1b857b5 commit ed88a08

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+876
-529
lines changed

packages/_example-extractor/src/api.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('The foo extractor', () => {
3737
test.each(Object.entries(FIXTURES))(
3838
'%s',
3939
(_: string, expected: IExtractedCode) => {
40-
const extracted = extractor.extract_foreign_code(expected.host_code);
40+
const extracted = extractor.extract_foreign_code(expected.host_code!);
4141
expect(extracted).to.have.length(1);
4242
expect(extracted[0]).to.deep.equal(expected);
4343
}

packages/code-jumpers/src/history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class JumpHistory {
3030
this.jump_history.push(JSON.stringify(position));
3131
}
3232

33-
recollect(): IGlobalPosition {
33+
recollect(): IGlobalPosition | undefined {
3434
this.ensure_history_is_ready();
3535
if (this.jump_history.length === 0) {
3636
return;

packages/code-jumpers/src/jumpers/fileeditor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class FileEditorJumper extends CodeJumper {
3636

3737
// TODO: this is common
3838
// place cursor in the line with the definition
39-
let position = this.editor.editor.getPositionAt(token.offset);
39+
let position = this.editor.editor.getPositionAt(token.offset)!;
4040
this.editor.editor.setSelection({ start: position, end: position });
4141
this.editor.editor.focus();
4242
}
@@ -58,7 +58,7 @@ export class FileEditorJumper extends CodeJumper {
5858
getCurrentPosition(): IGlobalPosition {
5959
let position = this.editor.editor.getCursorPosition();
6060
return {
61-
editor_index: null,
61+
editor_index: 0,
6262
line: position.line,
6363
column: position.column,
6464
contents_path: this.editor.context.path,

packages/code-jumpers/src/jumpers/jumper.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ export abstract class CodeJumper {
6969
let document_widget = this.document_manager.openOrReveal(
7070
position.contents_path
7171
);
72+
if (!document_widget) {
73+
console.log('Widget failed to open for jump');
74+
return;
75+
}
7276
let is_symlink = position.is_symlink;
7377

7478
document_widget.revealed
7579
.then(() => {
7680
this.go_to_position(
77-
document_widget,
81+
document_widget!,
7882
position.contents_path.endsWith('.ipynb') ? 'notebook' : 'fileeditor',
7983
position.column,
8084
position.line,
@@ -83,7 +87,7 @@ export abstract class CodeJumper {
8387

8488
// protect external files from accidental edition
8589
if (is_symlink) {
86-
this.protectFromAccidentalEditing(document_widget);
90+
this.protectFromAccidentalEditing(document_widget!);
8791
}
8892
})
8993
.catch(console.warn);

packages/code-jumpers/src/jumpers/notebook.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class NotebookJumper extends CodeJumper {
1919
super();
2020
this.widget = notebook_widget;
2121
this.notebook = notebook_widget.content;
22-
this.history = new JumpHistory(this.notebook.model.modelDB);
22+
this.history = new JumpHistory(this.notebook.model!.modelDB);
2323
this.document_manager = document_manager;
2424
}
2525

@@ -33,15 +33,15 @@ export class NotebookJumper extends CodeJumper {
3333
// Prevents event propagation issues
3434
setTimeout(() => {
3535
this.notebook.deselectAll();
36-
this.notebook.activeCellIndex = index;
36+
this.notebook.activeCellIndex = index!;
3737
_ensureFocus(this.notebook);
3838
this.notebook.mode = 'edit';
3939

4040
// find out offset for the element
41-
let activeEditor = this.notebook.activeCell.editor;
41+
let activeEditor = this.notebook.activeCell!.editor;
4242

4343
// place cursor in the line with the definition
44-
let position = activeEditor.getPositionAt(token.offset);
44+
let position = activeEditor.getPositionAt(token.offset)!;
4545
activeEditor.setSelection({ start: position, end: position });
4646
}, 0);
4747
}

packages/code-jumpers/src/positions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ export interface ILocalPosition {
66
*/
77
token: CodeEditor.IToken;
88
/**
9-
* Optional number identifying the cell in a notebook
9+
* Optional number identifying the cell in a notebook.
10+
* 0 in widgets with single editor
1011
*/
11-
index?: number;
12+
index: number;
1213
}
1314

1415
export interface IGlobalPosition {
1516
/**
16-
* In notebooks, the index of the target editor
17+
* In notebooks, the index of the target editor; 0 in widgets with single editor.
1718
*/
1819
editor_index: number;
1920

packages/completion-theme/src/about.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function render_themes_list(
6969
trans: TranslationBundle,
7070
props: {
7171
themes: ICompletionTheme[];
72-
current: ICompletionTheme;
72+
current: ICompletionTheme | null;
7373
get_set: IconSetGetter;
7474
}
7575
): React.ReactElement {

packages/completion-theme/src/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
export class CompletionThemeManager implements ILSPCompletionThemeManager {
2424
protected current_icons: Map<string, LabIcon>;
2525
protected themes: Map<string, ICompletionTheme>;
26-
private current_theme_id: string;
26+
private current_theme_id: string | null = null;
2727
private icons_cache: Map<string, LabIcon>;
2828
private icon_overrides: Map<string, CompletionItemKindStrings>;
2929
private trans: TranslationBundle;
@@ -50,17 +50,17 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
5050
const dark_mode_and_dark_supported =
5151
!this.is_theme_light() && typeof icons_sets.dark !== 'undefined';
5252
const set: ICompletionIconSet = dark_mode_and_dark_supported
53-
? icons_sets.dark
53+
? icons_sets.dark!
5454
: icons_sets.light;
5555
const icons: Map<keyof ICompletionIconSet, LabIcon> = new Map();
56-
let options = this.current_theme.icons.options || {};
56+
let options = this.current_theme?.icons?.options || {};
5757
const mode = this.is_theme_light() ? 'light' : 'dark';
5858
for (let [completion_kind, svg] of Object.entries(set)) {
5959
let name =
6060
'lsp:' + theme.id + '-' + completion_kind.toLowerCase() + '-' + mode;
6161
let icon: LabIcon;
6262
if (this.icons_cache.has(name)) {
63-
icon = this.icons_cache.get(name);
63+
icon = this.icons_cache.get(name)!;
6464
} else {
6565
icon = new LabIcon({
6666
name: name,
@@ -83,19 +83,19 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
8383
this.current_icons = this.get_iconset(this.current_theme);
8484
}
8585

86-
get_icon(type: string): LabIcon {
86+
get_icon(type: string): LabIcon | null {
8787
if (this.current_theme === null) {
8888
return null;
8989
}
9090
if (type) {
9191
if (this.icon_overrides.has(type.toLowerCase())) {
92-
type = this.icon_overrides.get(type.toLowerCase());
92+
type = this.icon_overrides.get(type.toLowerCase())!;
9393
}
9494
type =
9595
type.substring(0, 1).toUpperCase() + type.substring(1).toLowerCase();
9696
}
9797
if (this.current_icons.has(type)) {
98-
return this.current_icons.get(type);
98+
return this.current_icons.get(type)!;
9999
}
100100

101101
if (type === KernelKind) {
@@ -112,7 +112,7 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
112112
if (this.current_theme_id) {
113113
document.body.classList.remove(this.current_theme_class);
114114
}
115-
if (!this.themes.has(id)) {
115+
if (id && !this.themes.has(id)) {
116116
console.warn(
117117
`[LSP][Completer] Icons theme ${id} cannot be set yet (it may be loaded later).`
118118
);
@@ -123,8 +123,8 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
123123
}
124124

125125
protected get current_theme(): ICompletionTheme | null {
126-
if (this.themes.has(this.current_theme_id)) {
127-
return this.themes.get(this.current_theme_id);
126+
if (this.current_theme_id && this.themes.has(this.current_theme_id)) {
127+
return this.themes.get(this.current_theme_id)!;
128128
}
129129
return null;
130130
}

packages/jupyterlab-lsp/src/adapter_manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ export class WidgetAdapterManager implements ILSPAdapterManager {
132132
this.refreshAdapterFromCurrentWidget();
133133
}
134134

135-
isAnyActive() {
135+
isAnyActive(): boolean {
136136
return (
137-
this.shell.currentWidget &&
137+
this.shell.currentWidget !== null &&
138138
this.adapterTypes.some(type => type.tracker.currentWidget) &&
139139
this.adapterTypes.some(
140140
type => type.tracker.currentWidget == this.shell.currentWidget

0 commit comments

Comments
 (0)