Skip to content

fix: only show "Go to Definition" cell action on variables#10070

Open
akshayka wants to merge 2 commits into
mainfrom
aka/no-right-click-gtd
Open

fix: only show "Go to Definition" cell action on variables#10070
akshayka wants to merge 2 commits into
mainfrom
aka/no-right-click-gtd

Conversation

@akshayka

@akshayka akshayka commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

This PR updates the cell context menu to only show the Go to Definition action when the user right-clicks a variable that actually has a definition to jump to.

Previously, the cell context menu always offered "Go to Definition" regardless of where the user right-clicked (even if they clicked on outputs!). Worse, it resolved the target from the text caret rather than the click, so it could silently do nothing or jump somewhere unrelated to what was clicked.

This PR updates the cell context menu to only show the Go to Definition
action when the user right-clicks a variable that actually has a
definition to jump to.

Previously, the cell context menu always offered "Go to Definition" regardless
of where the user right-clicked (even if they clicked on outputs!). Worse, it
resolved the target from the text caret rather than the click, so it could
silently do nothing (no token under the caret) or jump somewhere unrelated to
what was clicked.
@akshayka akshayka requested review from Copilot and manzt July 2, 2026 20:08
@akshayka akshayka added the bug Something isn't working label Jul 2, 2026
@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jul 2, 2026 8:10pm

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found and verified against the latest diff

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="frontend/src/components/editor/cell/cell-context-menu.tsx">

<violation number="1" location="frontend/src/components/editor/cell/cell-context-menu.tsx:220">
P2: Keyboard users can lose the Go to Definition action because the menu position is derived only from mouse coordinates. Falling back to the current selection head when the event has no pointer coordinates preserves the previous accessible behavior while keeping right-click targeting.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread frontend/src/components/editor/cell/cell-context-menu.tsx

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the CodeMirror “Go to Definition” behavior so the cell context menu only offers it when the user right-clicks on a symbol that can actually be resolved to a definition, and ensures the navigation target is derived from the click position (not the current caret).

Changes:

  • Added position-based APIs (goToDefinitionAtPosition, hasDefinitionAtPosition) and refactored definition resolution to support “check without navigating”.
  • Exported reusable navigation/lookup helpers (goToPosition, findVariableDefinitionPosition) and updated call sites accordingly.
  • Updated the cell context menu to compute the right-click document position and conditionally show/execute “Go to Definition”, plus added tests for the new behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
frontend/src/core/codemirror/go-to-definition/utils.ts Adds position-based go-to-definition helpers and refactors resolution logic to support context-menu usage.
frontend/src/core/codemirror/go-to-definition/commands.ts Exposes goToPosition and adds findVariableDefinitionPosition helper used by the refactor.
frontend/src/core/codemirror/go-to-definition/tests/utils.test.ts Adds unit tests for position-based resolution and definition availability checks.
frontend/src/components/editor/cell/cell-context-menu.tsx Computes right-click position and hides/shows “Go to Definition” based on whether it resolves at that click location.

Comment on lines +40 to +46
function getWordAtPosition(state: EditorState, pos: number) {
const { startToken, endToken } = getPositionAtWordBounds(state.doc, pos);
return {
position: startToken,
word: state.doc.sliceString(startToken, endToken),
};
}
Comment thread frontend/src/core/codemirror/go-to-definition/utils.ts
Comment on lines +230 to +239
test("is a no-op when the position is not on a word", () => {
const code = "a + b";
const view = createEditor(code, 0);
views.push(view);

// The `+` operator is flanked by whitespace, so no identifier resolves.
const result = goToDefinitionAtPosition(view, code.indexOf("+"));

expect(result).toBe(false);
});
@akshayka akshayka changed the title fix: only show cell "Go to Definition" on variables fix: only show "Go to Definition" cell action on variables Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants