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

Load Python CM parser asynchronously #14198

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 10 additions & 13 deletions packages/codemirror/src/language.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { IEditorMimeTypeService } from '@jupyterlab/codeeditor';
import { PathExt } from '@jupyterlab/coreutils';
import {
LanguageDescription,
LanguageSupport,
LRLanguage,
StreamLanguage,
StreamParser
} from '@codemirror/language';
import { IEditorMimeTypeService } from '@jupyterlab/codeeditor';
import { PathExt } from '@jupyterlab/coreutils';
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
import { buildParser } from '@lezer/generator';
import { highlightTree } from '@lezer/highlight';

// This ensures the language spec for python will be loaded when
// we instantiate a new editor instance, which is required since
// python is the default language and we don't want to split
// the editor constructor because of asynchronous loading.
import { python } from '@codemirror/lang-python';
import { jupyterHighlightStyle } from './theme';
import { IEditorLanguage, IEditorLanguageRegistry } from './token';
import { buildParser } from '@lezer/generator';
import { ITranslator, nullTranslator } from '@jupyterlab/translation';

/**
* CodeMirror language registry
Expand Down Expand Up @@ -476,19 +471,21 @@ export namespace EditorLanguageRegistry {
mime: 'text/x-python',
extensions: ['BUILD', 'bzl', 'py', 'pyw'],
filename: /^(BUCK|BUILD)$/,
load() {
return Promise.resolve(python());
async load() {
const m = await import('@codemirror/lang-python');
return m.python();
}
},
{
name: 'ipython',
displayName: trans.__('ipython'),
mime: 'text/x-ipython',
load: () => {
async load() {
// FIXME Restore '?' operator - using the default python LanguageSupport allows
// to activate feature such as code folding.
// return Promise.resolve(legacy(mkPython({ singleOperators: /\?/ })));
return Promise.resolve(python());
const m = await import('@codemirror/lang-python');
return m.python();
}
},
{
Expand Down