-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix/def declaration within function #9379
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
Open
Shamik-07
wants to merge
24
commits into
marimo-team:main
Choose a base branch
from
Shamik-07:fix/def_declaration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2aa7825
fix: error: Argument 1 to add_common_config has incompatible type Lay…
Shamik-07 4ad8b3d
feat: adding command matches to the outer and inner function scope de…
Shamik-07 0a1c771
feat: get word under cursor returns both word and position
Shamik-07 8a170b1
test: checks nearest local parameters and checks across cells.
Shamik-07 bee4c91
test: local definitions are preferred over reactive gloabls and priva…
Shamik-07 0fa0c14
Merge branch 'main' into fix/def_declaration
Shamik-07 af8a66e
Merge branch 'main' into fix/def_declaration
Shamik-07 6612d01
Merge branch 'main' into fix/def_declaration
Shamik-07 2767c77
Merge branch 'main' into fix/def_declaration
Shamik-07 264c7e8
Merge branch 'main' into fix/def_declaration
Shamik-07 d3875e6
Merge branch 'main' into fix/def_declaration
Shamik-07 3475ee0
Merge branch 'main' into fix/def_declaration
Shamik-07 5f9c696
Merge branch 'main' into fix/def_declaration
Shamik-07 b8b9669
Merge branch 'main' into fix/def_declaration
Shamik-07 4a8eb4b
Merge branch 'main' into fix/def_declaration
Shamik-07 02fc173
Add failing tests for go-to-definition scope bugs
manzt bf12fd1
Merge pull request #1 from marimo-team/fix/def_declaration-tests
Shamik-07 7c634fa
fix: renaming SetComprehension to SetComprehensionExpression as Lezer…
Shamik-07 345e6e4
fix: skipping class scopes after a function boundary in getscopechain…
Shamik-07 2853f19
test: fixing the code comments in commands test.
Shamik-07 b2551f5
Merge branch 'main' into fix/def_declaration
Shamik-07 9638f27
docs: renaming pnpm build watch column name as production esque.
Shamik-07 1a458cd
Merge branch 'main' into fix/def_declaration
Shamik-07 7aa5372
Merge branch 'main' into fix/def_declaration
Shamik-07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
frontend/src/core/codemirror/go-to-definition/__tests__/utils.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /* Copyright 2026 Marimo. All rights reserved. */ | ||
|
|
||
| import { python } from "@codemirror/lang-python"; | ||
| import { EditorState } from "@codemirror/state"; | ||
| import { EditorView } from "@codemirror/view"; | ||
| import { afterEach, describe, expect, test } from "vitest"; | ||
| import { cellId, variableName } from "@/__tests__/branded"; | ||
| import { initialNotebookState, notebookAtom } from "@/core/cells/cells"; | ||
| import { store } from "@/core/state/jotai"; | ||
| import { variablesAtom } from "@/core/variables/state"; | ||
| import { goToDefinitionAtCursorPosition } from "../utils"; | ||
|
|
||
| async function tick(): Promise<void> { | ||
| await new Promise((resolve) => requestAnimationFrame(resolve)); | ||
| } | ||
|
|
||
| function createEditor(content: string, selection: number) { | ||
| const state = EditorState.create({ | ||
| doc: content, | ||
| selection: { anchor: selection }, | ||
| extensions: [python()], | ||
| }); | ||
|
|
||
| return new EditorView({ | ||
| state, | ||
| parent: document.body, | ||
| }); | ||
| } | ||
|
|
||
| const views: EditorView[] = []; | ||
|
|
||
| afterEach(() => { | ||
| for (const view of views.splice(0)) { | ||
| view.destroy(); | ||
| } | ||
|
|
||
| store.set(notebookAtom, initialNotebookState()); | ||
| store.set(variablesAtom, {}); | ||
| }); | ||
|
|
||
| describe("goToDefinitionAtCursorPosition", () => { | ||
| test("prefers the current-cell local definition over a reactive global", async () => { | ||
| const globalCell = cellId("global-cell"); | ||
| const localCell = cellId("local-cell"); | ||
| const globalCode = `\ | ||
| a = 10 | ||
| print(a)`; | ||
| const localCode = `\ | ||
| def test(): | ||
| a = 20 | ||
| print(a)`; | ||
|
|
||
| const globalView = createEditor(globalCode, globalCode.length); | ||
| const localView = createEditor(localCode, localCode.lastIndexOf("a")); | ||
| views.push(globalView, localView); | ||
|
|
||
| const notebook = initialNotebookState(); | ||
| notebook.cellHandles[globalCell] = { | ||
| current: { editorView: globalView }, | ||
| } as never; | ||
| notebook.cellHandles[localCell] = { | ||
| current: { editorView: localView }, | ||
| } as never; | ||
|
|
||
| store.set(notebookAtom, notebook); | ||
| store.set(variablesAtom, { | ||
| [variableName("a")]: { | ||
| dataType: "int", | ||
| declaredBy: [globalCell], | ||
| name: variableName("a"), | ||
| usedBy: [localCell], | ||
| value: "10", | ||
| }, | ||
| }); | ||
|
|
||
| const result = goToDefinitionAtCursorPosition(localView); | ||
|
|
||
| expect(result).toBe(true); | ||
| await tick(); | ||
| expect(localView.state.selection.main.head).toBe( | ||
| localCode.indexOf("a = 20"), | ||
| ); | ||
| expect(globalView.state.selection.main.head).toBe(globalCode.length); | ||
| }); | ||
|
|
||
| test("keeps private variables within the current cell", async () => { | ||
| const code = `\ | ||
| _x = 10 | ||
| output = _x + 10`; | ||
| const view = createEditor(code, code.lastIndexOf("_x")); | ||
| views.push(view); | ||
|
|
||
| const result = goToDefinitionAtCursorPosition(view); | ||
|
|
||
| expect(result).toBe(true); | ||
| await tick(); | ||
| expect(view.state.selection.main.head).toBe(code.indexOf("_x = 10")); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should not need to type cast here:
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.
Done