Skip to content

view: the edit range of an expression that starts with ( drops the ( #2062

Closed

Description

@shunichironomura

Warning

This content was written by an AI agent and must be verified by a human developer. After human verification, this alert may be removed.

Found in the review of #2057, which adds the experimental view. It does not block that PR; #2059 fixed the findings that did. Paths refer to #2059's head.

Problem

The view model's expression range (expr, expr_range) starts after an opening (, so an edit through the range leaves the ( behind.

definition_span in crates/graphcal-project/src/view_model/project.rs builds the range from the IR span of the definition and trims the text by hand. The IR span of a parenthesized expression does not include the (.

Reproduction

node a: Dimensionless = 1.0;
node y: Dimensionless = (@a + 2.0) * 3.0;
node z: Dimensionless = (@a);
assert ok = (@y) > 0.0;

graphcal view reports expr as @a + 2.0) * 3.0, @a) and @y) > 0.0. Editing z to 5.0 in the view writes (5.0;.

Impact

  • The GitHub host compiles the result, sees the syntax error, and rolls the edit back.
  • The VS Code host writes the edit into the user's document. Fix this before the VS Code integration is enabled.

Proposed fix

  • Carry the syntactic range of the expression after =, parentheses included, from the AST to the IR.
  • Delete the text trimming in definition_span.
  • Test single and nested parentheses, multi-line expressions, comments, UTF-16 columns, and param, const, node and assert.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingrustwebviewThe experimental view (web/view, graphcal view, graphcal/viewModel)

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions