leanprover / leanprover/lean4

RFC: linters should be able to use try this

Open
#4,363 4 comments 14 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Proposal

It should be possible for linters to use Meta.Tactic.TryThis.addSuggestion and friends to add "Try this:" suggestions

Often, a linter can not only identify the problem, but also suggest a fix.
It would be very convenient in these cases to apply the fix with a single click, and not have to write a separate code action.
Some examples include

  • Deprecations: the suggestion can substitute the new function
  • Unused arguments: the suggestion can delete the argument
  • Syntax transformations to remove antipatterns.

Currently, when addSuggestion is used, the suggestion appears in the info view, but only as a log message and not as a widget.

An outline of how this might look:

  • runLinters should preserve infoState (and traceState for good measure?)
  • ContextInfo.runMetaM should do the same (as linters may need this to run elaborators from the info tree)
  • A top level info tree node needs to be created for linters, to avoid a panic from Lean.Elab.InfoTree.visitM; or linters need to be very conservative about accidentally creating other infotree nodes.
Community Feedback

Zulip conversation

Impact

Add 👍 to issues you consider important. If others benefit from the changes in this proposal being added, 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

Start by reading runLinters, ContextInfo.runMetaM, and Lean.Elab.InfoTree.visitM, then compare their handling of infoState and traceState with Meta.Tactic.TryThis.addSuggestion. The work is complete when linter suggestions can appear as clickable “Try this:” widgets without causing info-tree panics.

Written by the indexing model from the issue text.

Assessment

Domain
compilers, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.