-
Notifications
You must be signed in to change notification settings - Fork 101
fix: improve syntax precision for start of #doc blocks #771
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import Verso | ||
| import VersoManual | ||
|
|
||
| set_option doc.verso true | ||
|
|
||
| open Verso Genre Manual InlineLean | ||
|
|
||
| #docs (Manual) docsSymOne "Docs heading one" := | ||
| ::::::: | ||
| # Docs heading one | ||
| Text one | ||
|
|
||
| ## Docs subheading one | ||
| More text one | ||
| ::::::: | ||
| --^ textDocument/documentSymbol | ||
|
|
||
| #docs (Manual) docsSymTwo "Docs heading two" := | ||
| ::::::: | ||
| # Docs heading two | ||
| Text two | ||
|
|
||
| ## Docs subheading two | ||
| More text two | ||
| ::::::: | ||
|
|
||
| #docs (Manual) docsSymThree "Docs heading three" := | ||
| ::::::: | ||
| # Docs heading three | ||
| Text three | ||
|
|
||
| ## Docs subheading three | ||
| More text three | ||
| ::::::: | ||
| --^ textDocument/foldingRange | ||
| --^ textDocument/documentSymbol | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| {"textDocument": | ||
| {"uri": "file:///src/tests/interactive/test-cases/symbols_verso.lean"}, | ||
| "position": {"line": 14, "character": 2}} | ||
| [] | ||
| {"textDocument": | ||
| {"uri": "file:///src/tests/interactive/test-cases/symbols_verso.lean"}, | ||
| "position": {"line": 33, "character": 2}} | ||
| [{"startLine": 7, "endLine": 13}, | ||
| {"startLine": 9, "endLine": 13}, | ||
| {"startLine": 12, "endLine": 13}, | ||
| {"startLine": 17, "endLine": 23}, | ||
| {"startLine": 19, "endLine": 23}, | ||
| {"startLine": 22, "endLine": 23}, | ||
| {"startLine": 26, "endLine": 32}, | ||
| {"startLine": 28, "endLine": 32}, | ||
| {"startLine": 31, "endLine": 32}, | ||
| {"startLine": 0, "kind": "imports", "endLine": 1}, | ||
| {"startLine": 7, "kind": "region", "endLine": 14}, | ||
| {"startLine": 17, "kind": "region", "endLine": 24}, | ||
| {"startLine": 26, "kind": "region", "endLine": 33}] | ||
| {"textDocument": | ||
| {"uri": "file:///src/tests/interactive/test-cases/symbols_verso.lean"}, | ||
| "position": {"line": 33, "character": 2}} | ||
| [{"selectionRange": | ||
| {"start": {"line": 7, "character": 0}, "end": {"line": 14, "character": 7}}, | ||
| "range": | ||
| {"start": {"line": 7, "character": 0}, "end": {"line": 14, "character": 0}}, | ||
| "name": "Docs heading one", | ||
| "kind": 15}, | ||
| {"selectionRange": | ||
| {"start": {"line": 17, "character": 0}, "end": {"line": 24, "character": 7}}, | ||
| "range": | ||
| {"start": {"line": 17, "character": 0}, "end": {"line": 24, "character": 0}}, | ||
| "name": "Docs heading two", | ||
| "kind": 15}, | ||
| {"selectionRange": | ||
| {"start": {"line": 26, "character": 0}, "end": {"line": 33, "character": 7}}, | ||
| "range": | ||
| {"start": {"line": 26, "character": 0}, "end": {"line": 33, "character": 0}}, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| "name": "Docs heading three", | ||
| "kind": 15}] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,13 +79,13 @@ All-at-once elaboration of verso document syntax to syntax denoting a verso `Par | |
| elaboration of the `#docs` command and `#doc` term. The `#doc` command is incremental, and thus | ||
| 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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The meaning of
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might also want to call it
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or could we drop the parameter and just call
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| let env ← getEnv | ||
| let titleParts ← stringToInlines title | ||
| let titleString := inlinesToString env titleParts | ||
| let ctx ← DocElabContext.fromGenreTerm genre | ||
| let initDocState : DocElabM.State := { highlightDeduplicationTable := .some {} } | ||
| let initPartState : PartElabM.State := .init (.node .none nullKind titleParts) | ||
| let initPartState : PartElabM.State := .init rootStx | ||
|
|
||
| let ((), docElabState, partElabState) ← | ||
| PartElabM.run ctx initDocState initPartState <| do | ||
|
|
@@ -118,7 +118,8 @@ elab "#docs" "(" genre:term ")" n:ident title:str ":=" ":::::::" text:document " | |
| | some x => x | ||
| | none => panic! "No final token!" | ||
| | _ => panic! "Nothing" | ||
| let doc ← Command.runTermElabM fun _ => elabDoc genre title text.raw.getArgs endTok.getPos! | ||
| let rootStx ← getRef | ||
| let doc ← Command.runTermElabM fun _ => elabDoc rootStx genre title text.raw.getArgs endTok.getPos! | ||
| Command.elabCommand (← `(def $n : VersoDoc $genre := $doc)) | ||
|
|
||
| public syntax docTermBody := | ||
|
|
@@ -147,17 +148,17 @@ elab_rules : term | |
| if let some g := genre then | ||
| findGenreTm g.raw | ||
| pure g | ||
| else | ||
| else | ||
| `((_ : Genre)) | ||
| let endPos := body.raw.getTailPos? |>.getD (← getFileMap).source.rawEndPos | ||
| let docu ← elabDoc genre title body.raw[0][1].getArgs endPos | ||
| let docu ← elabDoc (← getRef) genre title body.raw[0][1].getArgs endPos | ||
| Term.elabTerm (← ``( ($(docu) : VersoDoc $genre))) none | ||
|
|
||
|
|
||
| elab "#doc" "(" genre:term ")" title:str "=>" text:completeDocument eoi : term => do | ||
| findGenreTm genre | ||
| let endPos := (← getFileMap).source.rawEndPos | ||
| let doc ← elabDoc genre title text.raw.getArgs endPos | ||
| let doc ← elabDoc (← getRef) genre title text.raw.getArgs endPos | ||
| Term.elabTerm (← `( ($(doc) : Part $genre))) none | ||
|
|
||
|
|
||
|
|
@@ -322,13 +323,13 @@ in `elabDoc` across three functions: the prelude in `startDoc`, the loop body in | |
| and the postlude in `finishDoc`. | ||
| -/ | ||
|
|
||
| private meta def startDoc (genreSyntax : Term) (title: StrLit) : Command.CommandElabM Unit := do | ||
| private meta def startDoc (docStx : Syntax) (genreSyntax : Term) (title: StrLit) : Command.CommandElabM Unit := do | ||
| let env ← getEnv | ||
| let titleParts ← stringToInlines title | ||
| let titleString := inlinesToString env titleParts | ||
| let ctx ← Command.runTermElabM fun _ => DocElabContext.fromGenreTerm genreSyntax | ||
| let initDocState : DocElabM.State := { highlightDeduplicationTable := .some {} } | ||
| let initPartState : PartElabM.State := .init (.node .none nullKind titleParts) | ||
| let initPartState : PartElabM.State := .init docStx | ||
|
|
||
| modifyEnv (docEnvironmentExt.setState · ⟨genreSyntax, ctx, initDocState, initPartState⟩) | ||
| runPartElabInEnv <| do | ||
|
|
@@ -361,7 +362,7 @@ elab_rules : command | |
| | `(command|#doc ( $genreSyntax:term ) $title:str =>%$tok) => open Lean Parser Elab Command in do | ||
| elabCommand <| ← `(open scoped Lean.Doc.Syntax) | ||
|
|
||
| startDoc genreSyntax title | ||
| startDoc (← getRef) genreSyntax title | ||
|
|
||
| -- Sets up basic incremental evaluation of documents by replacing Lean's command-by-command parser | ||
| -- with a top-level-block parser. | ||
|
|
||
There was a problem hiding this comment.
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