Commit 30fda89e authored by Phil Jones's avatar Phil Jones

Clean up type annotations.

parent 40ea1f47
import { ICodeMirror } from '@jupyterlab/codemirror';
import { defineMultiplexingMode } from './codemirror-my-multiplex';
import { defineFinesse2Mode } from './codemirror-finesse2';
export function setupFinesseCodeMirror(CodeMirror: any): void {
defineMultiplexingMode(CodeMirror);
defineFinesse2Mode(CodeMirror);
export function setupFinesseCodeMirror(codemirror: ICodeMirror): void {
const cm = codemirror.CodeMirror;
defineMultiplexingMode(codemirror);
defineFinesse2Mode(codemirror);
CodeMirror.defineMode('finesse-python', (config: any) => {
const pmode = CodeMirror.getMode(config, 'python');
return CodeMirror.myMultiplexingMode(pmode, {
cm.defineMode('finesse-python', (config: any) => {
const pmode = cm.getMode(config, 'python');
return cm.myMultiplexingMode(pmode, {
open: /(?=#kat2code)/,
close: /(?=""")/, // Match string end without consuming it
mode: CodeMirror.getMode(config, 'text/x-finesse2'),
mode: cm.getMode(config, 'text/x-finesse2'),
delimStyle: 'delim'
});
});
CodeMirror.defineMIME('text/x-finesse-python', 'finesse-python');
cm.defineMIME('text/x-finesse-python', 'finesse-python');
CodeMirror.modeInfo.push({
cm.modeInfo.push({
name: 'Finesse Python',
mime: 'text/x-finesse-python',
mode: 'finesse-python',
......
import { ICodeMirror } from '@jupyterlab/codemirror';
const components = [
'bs[12]?',
'dbs',
......@@ -117,8 +119,9 @@ const regex = {
* link
*/
export function defineFinesse2Mode(CodeMirror: any): void {
CodeMirror.defineMode('finesse2', () => {
export function defineFinesse2Mode(codemirror: ICodeMirror): void {
const cm = codemirror.CodeMirror;
cm.defineMode('finesse2', () => {
function tokenBase(stream: CodeMirror.StringStream, state: any) {
return 'line-background-finesse ' + tokenLex(stream, state);
}
......@@ -134,12 +137,12 @@ export function defineFinesse2Mode(CodeMirror: any): void {
stream.skipToEnd();
return 'comment';
}
if (stream.peek() == '$') {
if (stream.peek() === '$') {
stream.next();
}
stream.eatWhile(/[^\s]/);
let style = null;
let cur = stream.current();
const cur = stream.current();
if (state.firstOnLine) {
if (regex['component'].test(cur) || regex['detector'].test(cur)) {
......@@ -163,7 +166,7 @@ export function defineFinesse2Mode(CodeMirror: any): void {
} else if (regex['variable'].test(cur)) {
style = 'variable-2';
}
if (style != null) {
if (style !== null) {
state.firstOnLine = false;
return style;
}
......@@ -181,11 +184,11 @@ export function defineFinesse2Mode(CodeMirror: any): void {
blankLine: function (state: any) {
return 'line-background-finesse';
},
token: function (stream: any, state: any) {
token: function (stream: CodeMirror.StringStream, state: any) {
return state.tokenize(stream, state);
}
};
});
CodeMirror.defineMIME('text/x-finesse2', 'finesse2');
cm.defineMIME('text/x-finesse2', 'finesse2');
}
import { ICodeMirror } from '@jupyterlab/codemirror';
declare module 'codemirror' {
function myMultiplexingMode(outer: any, ...others: any): any
}
export function defineMultiplexingMode(
CodeMirror: any,
codemirror: ICodeMirror,
): void
......@@ -5,8 +5,9 @@
// original blankLine function doesn't return the style returned by its
// sub-modes, so we have to copy the whole thing in here -_-
export function defineMultiplexingMode(CodeMirror) {
CodeMirror.myMultiplexingMode = function (outer /*, others */) {
export function defineMultiplexingMode(codemirror) {
const cm = codemirror.CodeMirror;
cm.myMultiplexingMode = function (outer /*, others */) {
// Others should be {open, close, mode [, delimStyle] [, innerStyle]} objects
var others = Array.prototype.slice.call(arguments, 1);
......@@ -22,7 +23,7 @@ export function defineMultiplexingMode(CodeMirror) {
return {
startState: function () {
return {
outer: CodeMirror.startState(outer),
outer: cm.startState(outer),
innerActive: null,
inner: null,
startingInner: false
......@@ -31,11 +32,11 @@ export function defineMultiplexingMode(CodeMirror) {
copyState: function (state) {
return {
outer: CodeMirror.copyState(outer, state.outer),
outer: cm.copyState(outer, state.outer),
innerActive: state.innerActive,
inner:
state.innerActive &&
CodeMirror.copyState(state.innerActive.mode, state.inner),
cm.copyState(state.innerActive.mode, state.inner),
startingInner: state.startingInner
};
},
......@@ -52,15 +53,15 @@ export function defineMultiplexingMode(CodeMirror) {
state.startingInner = !!other.parseDelimiters;
state.innerActive = other;
// Get the outer indent, making sure to handle CodeMirror.Pass
// Get the outer indent, making sure to handle cm.Pass
var outerIndent = 0;
if (outer.indent) {
var possibleOuterIndent = outer.indent(state.outer, '', '');
if (possibleOuterIndent !== CodeMirror.Pass)
if (possibleOuterIndent !== cm.Pass)
outerIndent = possibleOuterIndent;
}
state.inner = CodeMirror.startState(other.mode, outerIndent);
state.inner = cm.startState(other.mode, outerIndent);
return (
other.delimStyle &&
other.delimStyle + ' ' + other.delimStyle + '-open'
......@@ -116,7 +117,7 @@ export function defineMultiplexingMode(CodeMirror) {
indent: function (state, textAfter, line) {
var mode = state.innerActive ? state.innerActive.mode : outer;
if (!mode.indent) return CodeMirror.Pass;
if (!mode.indent) return cm.Pass;
return mode.indent(
state.innerActive ? state.inner : state.outer,
textAfter,
......@@ -135,7 +136,7 @@ export function defineMultiplexingMode(CodeMirror) {
var other = others[i];
if (other.open === '\n') {
state.innerActive = other;
state.inner = CodeMirror.startState(
state.inner = cm.startState(
other.mode,
mode.indent ? mode.indent(state.outer, '', '') : 0
);
......
......@@ -26,8 +26,8 @@ function activate(
app: JupyterFrontEnd,
tracker: INotebookTracker,
codemirror: ICodeMirror
) {
setupFinesseCodeMirror(codemirror.CodeMirror);
): void {
setupFinesseCodeMirror(codemirror);
const style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = '.finesse { background-color: rgba(0, 0, 0, 0.04); }';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment