UNPKG

@krassowski/jupyterlab_go_to_definition

Version:

Jump to definition of a variable or function in JupyterLab

36 lines 1.14 kB
import { CodeJumper } from './jumpers/jumper'; export function matchToken(tokens, tokenName, tokenOccurrence = 1, tokenType = 'variable') { let matchedTokens = tokens.filter(token => token.value === tokenName && token.type === tokenType); return matchedTokens[tokenOccurrence - 1]; } // TODO: refactor into a factory which accepts language and cwd as options export class Jumper extends CodeJumper { constructor(editor) { super(); this.cwd = ''; this.language = 'python'; this.editor = editor; } get editors() { return [this.editor]; } jump_to_definition(jump) { let { token } = this._findLastDefinition(jump.token, 0); // nothing found if (!token) { return; } let position = this.editor.getPositionAt(token.offset); this.editor.setSelection({ start: position, end: position }); } jump(position) { // nothing here yet } getOffset(position, cell) { return 0; } getJumpPosition(position, input_number) { return undefined; } } //# sourceMappingURL=testutils.js.map