-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor jump-to functionality, remove unused code #423
Changes from 14 commits
7a70799
3f4bee5
6ea82f0
72a4927
6a4b4fe
02e475f
01fbf12
9dc2e1a
90dd71d
c2f6eac
faeda52
b5f696b
58748aa
9c871dc
47962d6
218e85d
8ccdac8
f02c1ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
a_variable = 1 | ||
|
||
|
||
a_variable |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,13 +38,14 @@ | |
"private": true, | ||
"scripts": { | ||
"bootstrap": "jlpm --no-optional --prefer-offline && lerna bootstrap && jlpm lint && jlpm clean && jlpm build", | ||
"build": "jlpm build:schema && jlpm build:completion-theme && jlpm build:theme-material && jlpm build:theme-vscode && jlpm build:meta && jlpm build:ws", | ||
"build": "jlpm build:schema && jlpm build:completion-theme && jlpm build:theme-material && jlpm build:theme-vscode && jlpm build:jump && jlpm build:meta && jlpm build:ws", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. honestly would love to get rid of this command, as |
||
"build:schema": "lerna run build:schema --stream", | ||
"build:meta": "lerna run build --stream --scope @krassowski/jupyterlab-lsp-metapackage", | ||
"build:completion-theme": "lerna run build --stream --scope @krassowski/completion-theme", | ||
"build:theme-vscode": "lerna run build --stream --scope @krassowski/theme-vscode", | ||
"build:theme-material": "lerna run build --stream --scope @krassowski/theme-material", | ||
"build:ws": "lerna run build --stream --scope lsp-ws-connection", | ||
"build:jump": "lerna run build --stream --scope @krassowski/code-jumpers", | ||
"watch": "lerna run --parallel watch", | ||
"bundle": "lerna run --parallel bundle", | ||
"clean": "lerna run --parallel clean", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Code Jumpers | ||
|
||
Implementation underlying the jump to definition functionality in [JupyterLab-LSP](https://github.com/krassowski/jupyterlab-lsp). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"name": "@krassowski/code-jumpers", | ||
"version": "1.0.0", | ||
"description": "Implementation underlying the jump to definition functionality in JupyterLab-LSP", | ||
"keywords": [ | ||
"jupyter", | ||
"jupyterlab", | ||
"lsp", | ||
"language-server-protocol" | ||
], | ||
"homepage": "https://github.com/krassowski/jupyterlab-lsp", | ||
"bugs": { | ||
"url": "https://github.com/krassowski/jupyterlab-lsp/issues" | ||
}, | ||
"license": "BSD-3-Clause", | ||
"author": "JupyterLab-LSP Development Team", | ||
"files": [ | ||
"{lib,style,schema,src}/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf,css,json,ts,tsx}" | ||
], | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/krassowski/jupyterlab-lsp.git" | ||
}, | ||
"scripts": { | ||
"build": "tsc -b", | ||
"bundle": "npm pack .", | ||
"clean": "rimraf lib", | ||
"lab:link": "jupyter labextension link . --no-build" | ||
}, | ||
"peerDependencies": { | ||
"@jupyterlab/apputils": "~2.2.0", | ||
"@jupyterlab/codeeditor": "~2.2.0", | ||
"@jupyterlab/coreutils": "~4.2.0", | ||
"@jupyterlab/docmanager": "~2.2.0", | ||
"@jupyterlab/docregistry": "~2.2.0", | ||
"@jupyterlab/fileeditor": "~2.2.0", | ||
"@jupyterlab/notebook": "~2.2.0", | ||
"@jupyterlab/observables": "~3.2.0" | ||
}, | ||
"devDependencies": { | ||
"@jupyterlab/apputils": "~2.2.0", | ||
"@jupyterlab/codeeditor": "~2.2.0", | ||
"@jupyterlab/coreutils": "~4.2.0", | ||
"@jupyterlab/docmanager": "~2.2.0", | ||
"@jupyterlab/docregistry": "~2.2.0", | ||
"@jupyterlab/fileeditor": "~2.2.0", | ||
"@jupyterlab/notebook": "~2.2.0", | ||
"@jupyterlab/observables": "~3.2.0", | ||
"@jupyterlab/testutils": "~2.2.0", | ||
"rimraf": "^2.6.1", | ||
"typescript": "~4.0.2", | ||
"@babel/preset-env": "^7.4.3" | ||
}, | ||
"jupyterlab": { | ||
"extension": false | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { CodeJumper } from './jumpers/jumper'; | ||
import { NotebookJumper } from './jumpers/notebook'; | ||
import { FileEditorJumper } from './jumpers/fileeditor'; | ||
|
||
export { CodeJumper, NotebookJumper, FileEditorJumper }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { FileEditor } from '@jupyterlab/fileeditor'; | ||
import { IGlobalPosition, ILocalPosition } from '../positions'; | ||
import { CodeJumper, jumpers } from './jumper'; | ||
import { JumpHistory } from '../history'; | ||
import { IDocumentManager } from '@jupyterlab/docmanager'; | ||
import { IDocumentWidget } from '@jupyterlab/docregistry'; | ||
import { CodeEditor } from '@jupyterlab/codeeditor'; | ||
|
||
export class FileEditorJumper extends CodeJumper { | ||
editor: FileEditor; | ||
widget: IDocumentWidget; | ||
|
||
constructor( | ||
editor_widget: IDocumentWidget<FileEditor>, | ||
document_manager: IDocumentManager | ||
) { | ||
super(); | ||
this.widget = editor_widget; | ||
this.document_manager = document_manager; | ||
this.editor = editor_widget.content; | ||
this.history = new JumpHistory(this.editor.model.modelDB); | ||
} | ||
|
||
get path() { | ||
return this.widget.context.path; | ||
} | ||
|
||
get editors() { | ||
return [this.editor.editor]; | ||
} | ||
|
||
jump(jump_position: ILocalPosition) { | ||
let { token } = jump_position; | ||
|
||
// 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: CodeEditor.IPosition) { | ||
return this.editor.editor.getOffsetAt(position); | ||
} | ||
|
||
getJumpPosition(position: CodeEditor.IPosition): ILocalPosition { | ||
return { | ||
token: { | ||
offset: this.getOffset(position), | ||
value: '' | ||
}, | ||
index: 0 | ||
}; | ||
} | ||
|
||
getCurrentPosition(): IGlobalPosition { | ||
let position = this.editor.editor.getCursorPosition(); | ||
console.log('file path: ', this.editor.context.path); | ||
return { | ||
editor_index: null, | ||
line: position.line, | ||
column: position.column, | ||
contents_path: this.editor.context.path, | ||
is_symlink: false | ||
}; | ||
} | ||
} | ||
|
||
jumpers.set('fileeditor', FileEditorJumper); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why side-effect? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. legacy, keeping as is for now, but needs a refactor in future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You think 🍎 people will expect ⌘ ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed,
it seems sothere was a failure on this. Should we mention it in readme, or is it typically obvious to 🍎 people?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting post: https://nuclide.io/blog/2017/02/27/Command-Click-You-Have-One-Job/
I forgot about the multi-cursor placement! Ah, this is difficult to settle. If we keep Ctrl as default it might break workflow for some users; at least there is a setting for this; though indeed many IDEs use Ctrl + click for jump, and I think that fewer use for placement of additional cursors - so that seems like a tie to me.