-
Notifications
You must be signed in to change notification settings - Fork 432
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
feat: structure auto-completion & partial InfoTrees #5835
feat: structure auto-completion & partial InfoTrees #5835
Conversation
Mathlib CI status (docs):
|
Does this work after |
"Yes" to the first question, see the test file: https://github.com/mhuisi/lean4/blob/mhuisi/constructor-field-completion-2/tests/lean/interactive/completionStructureInstance.lean It doesn't work in the second case because Lake config declarations are a separate command with its own syntax and its own elaborator. For now, whitespace completions are specific to certain syntaxes (before macro expansion). |
Does this make it easy to implement the corresponding feature in lake? This has been a long standing feature request. |
The whitespace completion triggers on the |
@mhuisi It don't think using |
No, there is not. |
@mhuisi Ah, so this new completion is hardcoded to the parser and is not a matter of creating the right info-tree nodes? (I guess that is what you meant by "whitespace completions are specific to certain syntax" -- I was not fully sure whether that was simply due to support rather than hardcoding.) |
13ae691
to
f1801c5
Compare
0901c0e
to
ec0bf8c
Compare
e0d72c6
to
b3bff80
Compare
cf91976
to
bc8d566
Compare
a33afd6
to
357faba
Compare
Co-Authored-By: Sebastian Ullrich <sebasti@nullri.ch>
357faba
to
1b7bb15
Compare
#5835 contains a brittle test that uses an FVar ID, which caused a failure on master. This PR changes that test to use a declaration instead.
This PR fixes a regression where goals that don't exist were being displayed. The regression was triggered by #5835 and originally caused by #4926. Bug originally reported at https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/tactic.20doesn't.20change.20primary.20goal.20state/near/488957772. The cause of this issue was that #5835 made certain `SourceInfo`s canonical, which was directly transferred to several `TacticInfo`s by #4926. The goal state selection mechanism would then pick up these extra `TacticInfo`s. The approach taken by this PR is to ensure that the `SourceInfo` that is being transferred by #4926 is noncanonical.
This PR adds auto-completion for the fields of structure instance notation. Specifically, querying the completions via
Ctrl+Space
in the whitespace of a structure instance notation will now bring up the full list of fields. Whitespace structure completion can be enabled for custom syntax by wrapping the parser for the list of fields in astructInstFields
parser.This PR also makes completions of partial structure fields in the bracketed structure instance notation work again (e.g. completing
a
in{ a }
). These were previously broken by the introduction of set notation.In order to facilitate language server support for ambiguous syntax where all associated elaborators fail, this PR introduces the notion of an
InfoTree
choice node and anInfoTree
PartialTermInfo
node. Choice nodes are produced by the elaborator when several overloaded elaborators fail and contain theInfoTree
s of each failed elaborator as subtrees.PartialTermInfo
s are generated when an individual elaborator fails to produce anExpr
so that the subtrees produced by that elaborator can be retained as children of thatPartialTermInfo
.Since the
InfoTree
contains more similarCompletionInfo
s after the introduction of choice nodes, this PR reworks theCompletionInfo
selection to be more effective at selecting the bestCompletionInfo
amongst multiple similar ones.Finally, this PR splits
Completion.lean
into several files and fixes #5807.Breaking changes
Lean.Elab.withInfoContext'
andLean.Elab.Term.withInfoContext'
gained a new parametermkInfoOnError
that is used to produce anInfoTree
node when the elaboratorx
fails. In cases wheremkInfo
produces aTermInfo
usingLean.Elab.Term.mkTermInfo
,Lean.Elab.Term.withTermInfoContext'
can be used instead ofLean.Elab.Term.withInfoContext'
.Lean.Elab.Info
gained two new alternatives:ofPartialTermInfo
andofChoiceInfo
.id
field of thefieldId
alternative ofLean.Elab.CompletionInfo
has been turned into anOption
withnone
representing a full field completion.structInst
andwhereStructInst
have been adjusted to use thestructInstFields
parser.Details of other changes
Init/Prelude.lean
andInit/Meta.lean
: Add two new functionsgetTrailing?
andgetTrailingTailPos?
to work with the trailing whitespace of aSourceInfo
/Syntax
.Lean/Elab/App.lean
:a.b.c
so that theCompletionInfo
s fora.b.c
reference the syntaxa
,a.b
anda.b.c
respectively, instead of all referencinga.b.c
. Before, theseCompletionInfo
s were indistinguishable and we only chose the right one by accident.mergeFailures
to produce anInfoTree
with anofChoiceInfo
root node and theInfoTree
s of all failed elaborators as subtrees instead of throwing them away.Lean/Elab/BuiltinTerm.lean
: AdjustelabCompletion
so that it always produces an identifierCompletionInfo
, even when elaborating the left hand side of a dot completion succeeds and we also add a dotCompletionInfo
to theInfoTree
. With the changes to theCompletionInfo
selection in the language server, the language server will now always pick the correct one of these two. Before, we had a special case in the language server dot completion where under certain circumstances we would treat it a dot completion as an identifier completion instead - with this change, this is now not necessary anymore.Lean/Elab/MutualDef.lean
: AdjustexpandWhereStructInst
to set reasonableSourceInfo
s for the produced bracketed structure instance notation. The structure field completion benefits from thisSourceInfo
.Lean/Server/RequestHandling.lean
: AdjusthandleCompletion
so that in the-
completion case, we also emitCompletionInfoData
. This fixes PANIC at Lean.Lsp.CompletionItem.getFileSource! Lean.Server.CompletionItemData:34:22: no data param on completion item #5807.