leanprover / leanprover/lean4

Incorrect environment in command snaps for code action

Open
#3,250 0 comments 0 reactions 1 assignee View on GitHub

@mhuisi is already working on this.

Since Feb 3, 2024.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

import Lean
open Lean Server

@[code_action_provider] def holeCodeActionProvider : CodeActionProvider := fun _ snap => do
  panic! toString <| snap.cmdState.env.contains `foo
  pure #[]

def foo : Nat := 
  -- here
  1

Placing the cursor at the indicated location results in true being printed, meaning that the environment passed in the snap corresponds to the one after the command is executed. This results in incorrect behavior when traversing the info trees, because unless the environment is overridden in the context info it will still say that we are in the new environment, not the original environment used for the actual elaboration. I believe this issue was preexisting but exacerbated by #3159, because previously all info tree context nodes would override the environment and now most of them don't.

This is causing problems for the implementation of https://github.com/leanprover/std4/pull/577 , which needs to be able to determine whether an instance exists prior to the command to mimic the behavior of the structure instance notation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.