leanprover / leanprover/lean4

Goto definition failing with multiple libraries

Open
#4,962 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

In a configuration with multiple libraries, "go to definition" fails in some circumstances.

Context

I had noticed intermittent failures of "go to definition" while working on Verso. Another user experienced them, so I took the time to minimize it and produce a bug report.

Steps to Reproduce
  1. Check out the branch goto-def-minimized of Verso
  2. Open the file verso-blog/Verso/Genre/Blog/Template.lean
  3. Try to use "go to definition" on the occurrence of MonadPath on line 13

Expected behavior:

A jump to the definition of MonadPath

(or, alternatively, I would expect a "variable out of scope" error message, but the file elaborates without errors)

Actual behavior:

It fails to do so in Codium:
image

and also Emacs:
Screenshot 2024-08-08 at 16 28 32

so I suspect the language server is at fault, rather than the editor plugin.

Versions

I can reproduce this in the following Lean versions:

  • leanprover/lean4:nightly-2024-08-08
  • leanprover/lean4:v4.11.0-rc1
  • leanprover/lean4:v4.10.0
  • leanprover/lean4:v4.9.0
  • leanprover/lean4:v4.8.0
  • leanprover/lean4:v4.1.0

I didn't try the intervening versions.

Additional Information

Editing the Lakefile to remove the first library and restarting the language server:

import Lake
open Lake DSL

package verso where


@[default_target]
lean_lib VersoBlog where
  srcDir := "src/verso-blog"
  roots := #[`Verso.Genre.Blog]

makes it so that the feature works correctly.

I suspected that the problem might be from one library's roots containing another, but the following Lakefile still exhibits the bug:

import Lake
open Lake DSL

package verso where

@[default_target]
lean_lib Verso where
  srcDir := "src/verso"
  roots := #[`Verso.A]

@[default_target]
lean_lib VersoBlog where
  srcDir := "src/verso-blog"
  roots := #[`Verso.Genre.Blog]

as does one in which the library is renamed to VersoA.

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

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.

Research direction

Reproduce the failure using the goto-def-minimized Verso branch, opening verso-blog/Verso/Genre/Blog/Template.lean and targeting MonadPath on line 13. Compare behavior with the reduced Lakefiles in the report and inspect the language-server handling of multiple libraries. Done means go-to-definition reaches Verso/Genre/Blog/Site.lean, or reports a clear out-of-scope error.

Written by the indexing model from the issue text.

Assessment

Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.