Skip to content
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

Merged
merged 5 commits into from
May 21, 2024
Merged

feat: go-to-definition with cmd+click #1425

merged 5 commits into from
May 21, 2024

Conversation

mscolnick
Copy link
Contributor

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

  • I have read the contributor guidelines and the Pull Request section.
  • This PR fixes an issue (If applicable, specify issue number #).
  • This change was discussed or approved through an issue or the community discussions (Please provide a link if applicable).
  • I have added necessary tests for the changes made.
  • I have run the code and verified that it works as expected.

🧩 Related Issues

Further fixes #1126

πŸ“œ Who Can Review?

@akshayka

Copy link

vercel bot commented May 21, 2024

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
marimo-docs βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback May 21, 2024 0:49am
marimo-storybook βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback May 21, 2024 0:49am

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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";
Copy link
Contributor

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(
Copy link
Contributor

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.

Suggested change
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";
Copy link
Contributor

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. */
Copy link
Contributor

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";
Copy link
Contributor

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;
Copy link
Contributor

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)

Suggested change
const state = view.state;
const {state} = view;


ExplanationObject 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;
Copy link
Contributor

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)

Suggested change
const from = cursor.from;
const {from} = cursor;


ExplanationObject 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;
Copy link
Contributor

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)

Suggested change
const to = cursor.to;
const {to} = cursor;


ExplanationObject destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.

From the Airbnb Javascript Style Guide

Comment on lines 40 to 41
const focusCellId = variable.declaredBy[0];
return focusCellId;
Copy link
Contributor

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)

Suggested change
const focusCellId = variable.declaredBy[0];
return focusCellId;
return variable.declaredBy[0];


ExplanationSomething that we often see in people's code is assigning to a result variable
and 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;
Copy link
Contributor

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)

Suggested change
const state = view.state;
const {state} = view;


ExplanationObject destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.

From the Airbnb Javascript Style Guide

akshayka
akshayka previously approved these changes May 21, 2024
Copy link
Contributor

@akshayka akshayka left a 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?

Copy link

πŸš€ Development release published. You may be able to view the changes at https://marimo.app?v=0.6.1-dev20

akshayka added a commit that referenced this pull request May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Go to cell defining something
2 participants