Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable strict null checks and other strict settings #733

Merged
merged 8 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/_example-extractor/src/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('The foo extractor', () => {
test.each(Object.entries(FIXTURES))(
'%s',
(_: string, expected: IExtractedCode) => {
const extracted = extractor.extract_foreign_code(expected.host_code);
const extracted = extractor.extract_foreign_code(expected.host_code!);
expect(extracted).to.have.length(1);
expect(extracted[0]).to.deep.equal(expected);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/code-jumpers/src/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class JumpHistory {
this.jump_history.push(JSON.stringify(position));
}

recollect(): IGlobalPosition {
recollect(): IGlobalPosition | undefined {
this.ensure_history_is_ready();
if (this.jump_history.length === 0) {
return;
Expand Down
4 changes: 2 additions & 2 deletions packages/code-jumpers/src/jumpers/fileeditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class FileEditorJumper extends CodeJumper {

// TODO: this is common
// place cursor in the line with the definition
let position = this.editor.editor.getPositionAt(token.offset);
let position = this.editor.editor.getPositionAt(token.offset)!;
this.editor.editor.setSelection({ start: position, end: position });
this.editor.editor.focus();
}
Expand All @@ -58,7 +58,7 @@ export class FileEditorJumper extends CodeJumper {
getCurrentPosition(): IGlobalPosition {
let position = this.editor.editor.getCursorPosition();
return {
editor_index: null,
editor_index: 0,
line: position.line,
column: position.column,
contents_path: this.editor.context.path,
Expand Down
8 changes: 6 additions & 2 deletions packages/code-jumpers/src/jumpers/jumper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ export abstract class CodeJumper {
let document_widget = this.document_manager.openOrReveal(
position.contents_path
);
if (!document_widget) {
console.log('Widget failed to open for jump');
return;
}
let is_symlink = position.is_symlink;

document_widget.revealed
.then(() => {
this.go_to_position(
document_widget,
document_widget!,
position.contents_path.endsWith('.ipynb') ? 'notebook' : 'fileeditor',
position.column,
position.line,
Expand All @@ -83,7 +87,7 @@ export abstract class CodeJumper {

// protect external files from accidental edition
if (is_symlink) {
this.protectFromAccidentalEditing(document_widget);
this.protectFromAccidentalEditing(document_widget!);
}
})
.catch(console.warn);
Expand Down
8 changes: 4 additions & 4 deletions packages/code-jumpers/src/jumpers/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class NotebookJumper extends CodeJumper {
super();
this.widget = notebook_widget;
this.notebook = notebook_widget.content;
this.history = new JumpHistory(this.notebook.model.modelDB);
this.history = new JumpHistory(this.notebook.model!.modelDB);
this.document_manager = document_manager;
}

Expand All @@ -33,15 +33,15 @@ export class NotebookJumper extends CodeJumper {
// Prevents event propagation issues
setTimeout(() => {
this.notebook.deselectAll();
this.notebook.activeCellIndex = index;
this.notebook.activeCellIndex = index!;
_ensureFocus(this.notebook);
this.notebook.mode = 'edit';

// find out offset for the element
let activeEditor = this.notebook.activeCell.editor;
let activeEditor = this.notebook.activeCell!.editor;

// place cursor in the line with the definition
let position = activeEditor.getPositionAt(token.offset);
let position = activeEditor.getPositionAt(token.offset)!;
activeEditor.setSelection({ start: position, end: position });
}, 0);
}
Expand Down
7 changes: 4 additions & 3 deletions packages/code-jumpers/src/positions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ export interface ILocalPosition {
*/
token: CodeEditor.IToken;
/**
* Optional number identifying the cell in a notebook
* Optional number identifying the cell in a notebook.
* 0 in widgets with single editor
*/
index?: number;
index: number;
}

export interface IGlobalPosition {
/**
* In notebooks, the index of the target editor
* In notebooks, the index of the target editor; 0 in widgets with single editor.
*/
editor_index: number;

Expand Down
2 changes: 1 addition & 1 deletion packages/completion-theme/src/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function render_themes_list(
trans: TranslationBundle,
props: {
themes: ICompletionTheme[];
current: ICompletionTheme;
current: ICompletionTheme | null;
get_set: IconSetGetter;
}
): React.ReactElement {
Expand Down
20 changes: 10 additions & 10 deletions packages/completion-theme/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
export class CompletionThemeManager implements ILSPCompletionThemeManager {
protected current_icons: Map<string, LabIcon>;
protected themes: Map<string, ICompletionTheme>;
private current_theme_id: string;
private current_theme_id: string | null = null;
private icons_cache: Map<string, LabIcon>;
private icon_overrides: Map<string, CompletionItemKindStrings>;
private trans: TranslationBundle;
Expand All @@ -50,17 +50,17 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
const dark_mode_and_dark_supported =
!this.is_theme_light() && typeof icons_sets.dark !== 'undefined';
const set: ICompletionIconSet = dark_mode_and_dark_supported
? icons_sets.dark
? icons_sets.dark!
: icons_sets.light;
const icons: Map<keyof ICompletionIconSet, LabIcon> = new Map();
let options = this.current_theme.icons.options || {};
let options = this.current_theme?.icons?.options || {};
const mode = this.is_theme_light() ? 'light' : 'dark';
for (let [completion_kind, svg] of Object.entries(set)) {
let name =
'lsp:' + theme.id + '-' + completion_kind.toLowerCase() + '-' + mode;
let icon: LabIcon;
if (this.icons_cache.has(name)) {
icon = this.icons_cache.get(name);
icon = this.icons_cache.get(name)!;
} else {
icon = new LabIcon({
name: name,
Expand All @@ -83,19 +83,19 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
this.current_icons = this.get_iconset(this.current_theme);
}

get_icon(type: string): LabIcon {
get_icon(type: string): LabIcon | null {
if (this.current_theme === null) {
return null;
}
if (type) {
if (this.icon_overrides.has(type.toLowerCase())) {
type = this.icon_overrides.get(type.toLowerCase());
type = this.icon_overrides.get(type.toLowerCase())!;
}
type =
type.substring(0, 1).toUpperCase() + type.substring(1).toLowerCase();
}
if (this.current_icons.has(type)) {
return this.current_icons.get(type);
return this.current_icons.get(type)!;
}

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

protected get current_theme(): ICompletionTheme | null {
if (this.themes.has(this.current_theme_id)) {
return this.themes.get(this.current_theme_id);
if (this.current_theme_id && this.themes.has(this.current_theme_id)) {
return this.themes.get(this.current_theme_id)!;
}
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/jupyterlab-lsp/src/adapter_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ export class WidgetAdapterManager implements ILSPAdapterManager {
this.refreshAdapterFromCurrentWidget();
}

isAnyActive() {
isAnyActive(): boolean {
return (
this.shell.currentWidget &&
this.shell.currentWidget !== null &&
this.adapterTypes.some(type => type.tracker.currentWidget) &&
this.adapterTypes.some(
type => type.tracker.currentWidget == this.shell.currentWidget
Expand Down
Loading