Skip to content

fix: improve syntax precision for start of #doc blocks#771

Open
ejgallego wants to merge 2 commits intoleanprover:mainfrom
ejgallego:feat/folding-doc-start-range
Open

fix: improve syntax precision for start of #doc blocks#771
ejgallego wants to merge 2 commits intoleanprover:mainfrom
ejgallego:feat/folding-doc-start-range

Conversation

@ejgallego
Copy link
Contributor

As of today, we used a synthetic placeholder for title syntax. This confused the LSP extension as it overgeralized the start of the span, which after the TOC-merge phase made the entry to appear as the parents of all other entries, for example existing declarations.

As of today, we used a synthetic placeholder for  title syntax. This confused the LSP extension as it overgeralized the start of the  span, which after the TOC-merge phase made the  entry to appear as the parents of all other entries, for example existing  declarations.
@ejgallego ejgallego requested a review from robsimmons February 26, 2026 19:05
Copy link
Collaborator

@robsimmons robsimmons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heck yes. I wonder if there are reasons where/why it would be helpful to track the location of the #doc tag itself?

@ejgallego
Copy link
Contributor Author

Heck yes. I wonder if there are reasons where/why it would be helpful to track the location of the #doc tag itself?

Indeed I wonder what'd be best here. I just had a look at the test output and indeed it still looks a bit suspicious. Would love to pair and brainstorm any time on this!

[{"selectionRange":
{"start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 12}},
"range":
{"start": {"line": 0, "character": 0}, "end": {"line": 11, "character": 0}},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The start here looks wrong. Let me look into it.

Copy link
Contributor Author

@ejgallego ejgallego Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried a fix but introduced a LSP violation (selectionRange not within range, see below)

# Docs heading
Text
:::::::
--^ textDocument/documentSymbol
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this call is worth the effort, I'll keep it as a witness of the non-incrementality of documentSymbol

@github-actions
Copy link
Contributor

Preview for this PR is ready! 🎉

{"selectionRange":
{"start": {"line": 26, "character": 0}, "end": {"line": 33, "character": 7}},
"range":
{"start": {"line": 26, "character": 0}, "end": {"line": 33, "character": 0}},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a violation of the LSP spec here, selectionRange must be contained in range.

Working on a fix.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we should fix that. Do you plan to do that in this PR?

Copy link
Contributor Author

@ejgallego ejgallego Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the fix turned out to be more involved than I wanted, due to header{} being a synthetic token, which actually made the headings not carry location and not appear on the outline view.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed a serious violation, so I'll add a panic for this problem. In this case the origin of the issue was a little typo in the code getPos vs getTailPos.

@david-christiansen
Copy link
Collaborator

Heck yes. I wonder if there are reasons where/why it would be helpful to track the location of the #doc tag itself?

It's certainly useful for giving a good outline view and for populating the declaration ranges table.

splits the logic in this function across multiple functions.
-/
private meta def elabDoc (genre: Term) (title: StrLit) (topLevelBlocks : Array Syntax) (endPos: String.Pos.Raw) : TermElabM Term := do
private meta def elabDoc (rootStx : Syntax) (genre: Term) (title: StrLit) (topLevelBlocks : Array Syntax) (endPos: String.Pos.Raw) : TermElabM Term := do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The meaning of rootStx isn't particularly apparent to me when just reading here. How about explaining in the docstring that it's the syntax of the complete #doc ... => line?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might also want to call it ref for consistency with Lean internals if you think that makes sense

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or could we drop the parameter and just call getRef here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll find a better name, I agree.

Let me look into using getRef, as of now, in working branch, I'm doing a little bit of surgery but I agree it'd be better if we could use getRef.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants