Skip to content

Commit

Permalink
Load Python CM parser asynchronously (#14198)
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Mar 16, 2023
1 parent 539af95 commit 4947d6d
Showing 1 changed file with 10 additions and 13 deletions.
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

0 comments on commit 4947d6d

Please sign in to comment.