forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jupyterlab:main' into master
- Loading branch information
Showing
27 changed files
with
286 additions
and
62 deletions.
There are no files selected for viewing
Binary file modified
BIN
-8 Bytes
(100%)
examples/notebook/example.spec.ts-snapshots/example-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.75 KB
(100%)
...chmark/notebook.spec.ts-snapshots/large-code-notebook-ipynb-benchmark-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.47 KB
(69%)
...ugger.test.ts-snapshots/start-debug-session-script-sources-jupyterlab-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.42 KB
(69%)
...lab/debugger.test.ts-snapshots/start-debug-session-sources-jupyterlab-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+38 Bytes
(100%)
...jupyterlab/notebook-mobile.test.ts-snapshots/mobile-layout-jupyterlab-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+82 Bytes
(100%)
...erlab/notebook-search.test.ts-snapshots/search-new-outputs-jupyterlab-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+44 Bytes
(100%)
...erlab/notebook-search.test.ts-snapshots/search-on-new-cell-jupyterlab-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-10.1 KB
(71%)
...ab/notebook-search.test.ts-snapshots/search-within-outputs-jupyterlab-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+196 Bytes
(100%)
...ut-scrolling.test.ts-snapshots/prompt-overlay-hover-normal-jupyterlab-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-2.33 KB
(72%)
...ut-scrolling.test.ts-snapshots/prompt-overlay-hover-scroll-jupyterlab-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/* | ||
* Copyright (c) Jupyter Development Team. | ||
* Distributed under the terms of the Modified BSD License. | ||
*/ | ||
|
||
import { Language, syntaxTree } from '@codemirror/language'; | ||
import { RangeSetBuilder } from '@codemirror/state'; | ||
import { | ||
Decoration, | ||
DecorationSet, | ||
EditorView, | ||
ViewPlugin, | ||
ViewUpdate | ||
} from '@codemirror/view'; | ||
import { NodeProp, SyntaxNodeRef, Tree } from '@lezer/common'; | ||
|
||
export class PythonBuiltin { | ||
decorations: DecorationSet; | ||
decoratedTo: number; | ||
langPython: Language; | ||
tree: Tree; | ||
mark: Decoration; | ||
|
||
constructor(view: EditorView, langPython: Language) { | ||
this.langPython = langPython; | ||
this.tree = syntaxTree(view.state); | ||
this.mark = Decoration.mark({ class: 'cm-builtin' }); | ||
this.decorations = this.buildDeco(view); | ||
this.decoratedTo = view.viewport.to; | ||
} | ||
|
||
update(update: ViewUpdate) { | ||
let tree = syntaxTree(update.state); | ||
let { viewport } = update.view, | ||
decoratedToMapped = update.changes.mapPos(this.decoratedTo, 1); | ||
if ( | ||
tree.length < viewport.to && | ||
tree.type == this.tree.type && | ||
decoratedToMapped >= viewport.to | ||
) { | ||
this.decorations = this.decorations.map(update.changes); | ||
this.decoratedTo = decoratedToMapped; | ||
} else if (tree != this.tree || update.viewportChanged) { | ||
this.tree = tree; | ||
this.decorations = this.buildDeco(update.view); | ||
this.decoratedTo = viewport.to; | ||
} | ||
} | ||
|
||
buildDeco(view: EditorView) { | ||
if (!this.tree.length) return Decoration.none; | ||
|
||
let builder = new RangeSetBuilder<Decoration>(); | ||
const enter = (node: SyntaxNodeRef) => { | ||
const cursor = node.node.cursor(); | ||
// Handle nested language, e.g. Markdown | ||
const mounted = cursor.tree && cursor.tree.prop(NodeProp.mounted); | ||
if (mounted && mounted.overlay) { | ||
node.node | ||
.enter(mounted.overlay[0].from + node.from, 1) | ||
?.cursor() | ||
.iterate(enter); | ||
} | ||
if ( | ||
this.langPython.isActiveAt(view.state, node.from + 1) && | ||
node.name === 'VariableName' | ||
) { | ||
const variableName = view.state.sliceDoc(node.from, node.to); | ||
if (builtins.includes(variableName)) { | ||
builder.add(node.from, node.to, this.mark); | ||
} | ||
} | ||
}; | ||
for (let { from, to } of view.visibleRanges) { | ||
this.tree.iterate({ enter, from, to }); | ||
} | ||
return builder.finish(); | ||
} | ||
} | ||
|
||
export function pythonBuiltin(langPython: Language) { | ||
return ViewPlugin.define(view => new PythonBuiltin(view, langPython), { | ||
decorations: v => v.decorations | ||
}); | ||
} | ||
|
||
const builtins = [ | ||
'abs', | ||
'aiter', | ||
'all', | ||
'any', | ||
'anext', | ||
'ascii', | ||
'bin', | ||
'bool', | ||
'breakpoint', | ||
'bytearray', | ||
'bytes', | ||
'callable', | ||
'chr', | ||
'classmethod', | ||
'compile', | ||
'complex', | ||
'delattr', | ||
'dict', | ||
'dir', | ||
'divmod', | ||
'enumerate', | ||
'eval', | ||
'exec', | ||
'filter', | ||
'float', | ||
'format', | ||
'frozenset', | ||
'getattr', | ||
'globals', | ||
'hasattr', | ||
'hash', | ||
'help', | ||
'hex', | ||
'id', | ||
'input', | ||
'int', | ||
'isinstance', | ||
'issubclass', | ||
'iter', | ||
'len', | ||
'list', | ||
'locals', | ||
'map', | ||
'max', | ||
'memoryview', | ||
'min', | ||
'next', | ||
'object', | ||
'oct', | ||
'open', | ||
'ord', | ||
'pow', | ||
'print', | ||
'property', | ||
'range', | ||
'repr', | ||
'reversed', | ||
'round', | ||
'set', | ||
'setattr', | ||
'slice', | ||
'sorted', | ||
'staticmethod', | ||
'str', | ||
'sum', | ||
'super', | ||
'tuple', | ||
'type', | ||
'vars', | ||
'zip', | ||
'__import__' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.