-
Notifications
You must be signed in to change notification settings - Fork 151
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
feat: go-to-definition with cmd+click #1425
Conversation
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
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.
Hey @mscolnick - I've reviewed your changes and they look great!
Here's what I looked at during the review
- π‘ General issues: 7 issues found
- π’ Security: all looks good
- π‘ Testing: 1 issue found
- π’ Complexity: all looks good
Help me be more useful! Please click π or π on each comment to tell me if it was helpful.
import { store } from "@/core/state/jotai"; | ||
import { findReplaceAtom } from "./state"; | ||
import { getAllEditorViews } from "@/core/cells/cells"; | ||
import { syntaxTree } from "@codemirror/language"; |
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.
suggestion: Unused import removed
The removal of the syntaxTree
import is appropriate since it is no longer used in this file. This helps in keeping the code clean and avoiding unnecessary imports.
beforeAdjustedCursorPos, | ||
); | ||
const afterCursorCode = getEditorCodeAsPython( | ||
const { beforeCursorCode, afterCursorCode } = splitEditor( |
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.
suggestion: Refactored splitCell function
The refactoring of the splitCell
function to use splitEditor
is a good improvement. However, ensure that splitEditor
handles all edge cases correctly, especially with different cursor positions and document states.
const { beforeCursorCode, afterCursorCode } = splitEditor( | |
const { beforeCursorCode, afterCursorCode } = splitEditor( | |
cellHandle.editorView, | |
beforeAdjustedCursorPos, | |
afterAdjustedCursorPos, | |
); |
@@ -1,10 +1,10 @@ | |||
/* Copyright 2024 Marimo. All rights reserved. */ | |||
import { RefObject } from "react"; | |||
import type { RefObject } from "react"; |
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.
suggestion: Type import for RefObject
Using import type
for RefObject
is a good practice to ensure that only the type information is imported, which can help with tree-shaking and reducing bundle size.
@@ -0,0 +1,157 @@ | |||
/* Copyright 2024 Marimo. All rights reserved. */ |
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.
question: New underline feature
The new underline feature for variable names when the meta key is pressed is a useful addition. However, it would be helpful to have more documentation or comments explaining the rationale behind certain design choices, such as the use of requestAnimationFrame
in the click
method.
@@ -0,0 +1,104 @@ | |||
/* Copyright 2024 Marimo. All rights reserved. */ | |||
import type { EditorState } from "@codemirror/state"; |
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.
suggestion: Utility functions for go-to-definition
The utility functions for go-to-definition are well-structured. Consider adding more unit tests to cover edge cases, such as handling private variables and variables declared in different cells.
view: EditorView, | ||
variableName: string, | ||
): boolean { | ||
const state = view.state; |
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.
suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring
)
const state = view.state; | |
const {state} = view; |
Explanation
Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.From the Airbnb Javascript Style Guide
const cursor: TreeCursor = tree.cursorAt(pos); | ||
|
||
if (cursor.name === "VariableName") { | ||
const from = cursor.from; |
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.
suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring
)
const from = cursor.from; | |
const {from} = cursor; |
Explanation
Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.From the Airbnb Javascript Style Guide
|
||
if (cursor.name === "VariableName") { | ||
const from = cursor.from; | ||
const to = cursor.to; |
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.
suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring
)
const to = cursor.to; | |
const {to} = cursor; |
Explanation
Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.From the Airbnb Javascript Style Guide
const focusCellId = variable.declaredBy[0]; | ||
return focusCellId; |
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.
suggestion (code-quality): Inline variable that is immediately returned (inline-immediately-returned-variable
)
const focusCellId = variable.declaredBy[0]; | |
return focusCellId; | |
return variable.declaredBy[0]; | |
Explanation
Something that we often see in people's code is assigning to a result variableand then immediately returning it.
Returning the result directly shortens the code and removes an unnecessary
variable, reducing the mental load of reading the function.
Where intermediate variables can be useful is if they then get used as a
parameter or a condition, and the name can act like a comment on what the
variable represents. In the case where you're returning it from a function, the
function name is there to tell you what the result is, so the variable name
is unnecessary.
* @param view The editor view at which the command was invoked. | ||
*/ | ||
export function goToDefinitionAtCursorPosition(view: EditorView): boolean { | ||
const state = view.state; |
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.
suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring
)
const state = view.state; | |
const {state} = view; |
Explanation
Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.From the Airbnb Javascript Style Guide
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.
Wow β this is awesome!!
Maybe we add a line in guides > editor features about how to use this feature?
π Development release published. You may be able to view the changes at https://marimo.app?v=0.6.1-dev20 |
Pull Request Template
π Summary
This adds go-to-definition with cmd+click
π Description of Changes
Uses a codemirror decorator with underline and builds off some existing go-to-definition logic we have. Most of this work is just the codemirror plugin and some tests.
π οΈ Additional Information
π Checklist Before Submitting
𧩠Related Issues
Further fixes #1126
π Who Can Review?
@akshayka