@jupyter-lsp/code-jumpers
Version:
Implementation underlying the jump to definition functionality in JupyterLab-LSP
49 lines • 1.53 kB
JavaScript
import { JumpHistory } from '../history';
import { CodeJumper, jumpers } from './jumper';
export class FileEditorJumper extends CodeJumper {
constructor(editorWidget, documentManager) {
super();
this.widget = editorWidget;
this.documentManager = documentManager;
this.editor = editorWidget.content;
this.history = new JumpHistory();
}
get path() {
return this.widget.context.path;
}
get editors() {
return [this.editor.editor];
}
jump(jumpPosition) {
let { token } = jumpPosition;
// TODO: this is common
// place cursor in the line with the definition
let position = this.editor.editor.getPositionAt(token.offset);
this.editor.editor.setSelection({ start: position, end: position });
this.editor.editor.focus();
}
getOffset(position) {
return this.editor.editor.getOffsetAt(position);
}
getJumpPosition(position) {
return {
token: {
offset: this.getOffset(position),
value: ''
},
index: 0
};
}
getCurrentPosition() {
let position = this.editor.editor.getCursorPosition();
return {
editorIndex: 0,
line: position.line,
column: position.column,
contentsPath: this.editor.context.path,
isSymlink: false
};
}
}
jumpers.set('fileeditor', FileEditorJumper);
//# sourceMappingURL=fileeditor.js.map