Repository navigation
Add syntax warnings - #8188
Add syntax warnings#8188
Conversation
8356e78 to
c9594ae
Compare
|
As discussed synchronously, I have made a few changes:
I also added a commit that renames the |
9d9d422 to
d7c18a1
Compare
|
Oops! I wasn't careful about cleaning up from previewing |
546516c to
c880f16
Compare
saecki
left a comment
There was a problem hiding this comment.
Not sure, if there was any more feedback from Laurenz, but apart from the few remarks this looks good to me!
Could this in combination with the sub ranges be used to better report unclosed delimiters? For example adding a hint to the opening delimiter, or the location where it was popped off the stack (#5906).
| /// | ||
| /// Builds the string if this is an inner node. | ||
| pub fn into_text(self) -> EcoString { | ||
| // This isn't fully efficient for warnings, but the efficient |
There was a problem hiding this comment.
Not fully related to this PR, but is there really a benefit that into_text takes the node by value? Cloning of EcoString should be cheap, either just a bitwise copy for the inline representation up to 15 bytes, which should be a good amount of leaf nodes, and an increment of the atomic refcount for other ones. Since the returned string never seems to be modified, increasing the refcount seems like a non issue.
Most use sites of into_text seem to clone the SyntaxNode anyway, which clones the LeafNode::text, and also needlessly increments and decrements the refcount of inner and error nodes.
Maybe the functions should have more descriptive names like leaf_text and full_text to clear up the intent?
There was a problem hiding this comment.
I agree. I'll open another PR that renames them after this one.
I will mention that Laurenz once commented that we should really have a summarize method that would add ellipses in a smart location instead of generating the full text, perhpas based on an expected or maximum length. I would be in favor of it, but I'm not sure how exactly I would go about implementing it. Thoughts?
There was a problem hiding this comment.
I'm not sure how I'd approach this, but it would definitely be nice to have some syntax aware summary function, that'll also handle cases like: #8339
| pub(super) fn is_leaf(&self) -> bool { | ||
| matches!(self.0, NodeKind::Leaf(_)) | ||
| matches!(self.node(), Node::Leaf(_)) | ||
| // TODO: Should we also treat non-empty errors as leaves? |
There was a problem hiding this comment.
I think a problem could be that the error nodes always return SyntaxKind::Error, which could negatively impact completion?
Aside from the |
|
Oh, I just saw that this was mislabelled. Are we on the same page that we'll want to change the code to avoid the perf regression in some way (e.g. something like your |
|
Yes exactly. I've been a bit busy this week, but have been planning to bring the commits from that branch into this PR, just been doing some cleanup on it. |
|
I've added the four commits from my The reason This should now be ready to review. |
0a2dba0 to
9f65176
Compare
|
Thank you! |
Part of the Typst 0.15 cleanup stack. This slice covers diagnostics/span migration and the minimal query prerequisites needed before the later export and text accessor slices. ## Upstream Typst Changes - [`typst/typst#8052`](typst/typst#8052) makes diagnostic hints carry span metadata. Tinymist renders the hint message payload instead of formatting the whole spanned wrapper. - [`typst/typst#8254`](typst/typst#8254) changes diagnostic, user-action, and test-range span handling. Tinymist updates LSP diagnostics, user-action conversion, and range-sensitive tests for the new span shape. - [`typst/typst#8188`](typst/typst#8188) changes syntax diagnostics. Tinymist updates syntax matchers and diagnostics conversion paths that inspect syntax-side errors. - [`typst/typst#8307`](typst/typst#8307) changes bibliography lookup. Tinymist now finds bibliography elements through the document introspector and packs them back to `BibliographyElem`. - Typst 0.15 deprecates rooted virtual-path access through `as_rooted_path`; diagnostics now use the slash-form virtual path accessor for extension checks. ## Tinymist Changes - Updates `tinymist-world` diagnostic rendering for spanned hint values. - Updates `tinymist-query`, `tinymist-analysis`, `tinymist-lint`, and debug-facing syntax diagnostics for the new span and syntax diagnostic APIs. - Updates user-action span conversion and affected test ranges. - Updates code-context path evaluation to construct `RangeMapper` from an iterator, matching the lint expectations of the current toolchain. - Carries the small bibliography lookup prerequisite in this slice so later query-oriented slices build on the updated Typst API. --------- Co-authored-by: paran3xus <[email protected]>
Part of the Typst 0.15 cleanup stack. This slice covers diagnostics/span migration and the minimal query prerequisites needed before the later export and text accessor slices. ## Upstream Typst Changes - [`typst/typst#8052`](typst/typst#8052) makes diagnostic hints carry span metadata. Tinymist renders the hint message payload instead of formatting the whole spanned wrapper. - [`typst/typst#8254`](typst/typst#8254) changes diagnostic, user-action, and test-range span handling. Tinymist updates LSP diagnostics, user-action conversion, and range-sensitive tests for the new span shape. - [`typst/typst#8188`](typst/typst#8188) changes syntax diagnostics. Tinymist updates syntax matchers and diagnostics conversion paths that inspect syntax-side errors. - [`typst/typst#8307`](typst/typst#8307) changes bibliography lookup. Tinymist now finds bibliography elements through the document introspector and packs them back to `BibliographyElem`. - Typst 0.15 deprecates rooted virtual-path access through `as_rooted_path`; diagnostics now use the slash-form virtual path accessor for extension checks. ## Tinymist Changes - Updates `tinymist-world` diagnostic rendering for spanned hint values. - Updates `tinymist-query`, `tinymist-analysis`, `tinymist-lint`, and debug-facing syntax diagnostics for the new span and syntax diagnostic APIs. - Updates user-action span conversion and affected test ranges. - Updates code-context path evaluation to construct `RangeMapper` from an iterator, matching the lint expectations of the current toolchain. - Carries the small bibliography lookup prerequisite in this slice so later query-oriented slices build on the updated Typst API. --------- Co-authored-by: paran3xus <[email protected]>
Part of the Typst 0.15 cleanup stack. This slice covers diagnostics/span migration and the minimal query prerequisites needed before the later export and text accessor slices. ## Upstream Typst Changes - [`typst/typst#8052`](typst/typst#8052) makes diagnostic hints carry span metadata. Tinymist renders the hint message payload instead of formatting the whole spanned wrapper. - [`typst/typst#8254`](typst/typst#8254) changes diagnostic, user-action, and test-range span handling. Tinymist updates LSP diagnostics, user-action conversion, and range-sensitive tests for the new span shape. - [`typst/typst#8188`](typst/typst#8188) changes syntax diagnostics. Tinymist updates syntax matchers and diagnostics conversion paths that inspect syntax-side errors. - [`typst/typst#8307`](typst/typst#8307) changes bibliography lookup. Tinymist now finds bibliography elements through the document introspector and packs them back to `BibliographyElem`. - Typst 0.15 deprecates rooted virtual-path access through `as_rooted_path`; diagnostics now use the slash-form virtual path accessor for extension checks. ## Tinymist Changes - Updates `tinymist-world` diagnostic rendering for spanned hint values. - Updates `tinymist-query`, `tinymist-analysis`, `tinymist-lint`, and debug-facing syntax diagnostics for the new span and syntax diagnostic APIs. - Updates user-action span conversion and affected test ranges. - Updates code-context path evaluation to construct `RangeMapper` from an iterator, matching the lint expectations of the current toolchain. - Carries the small bibliography lookup prerequisite in this slice so later query-oriented slices build on the updated Typst API. --------- Co-authored-by: paran3xus <[email protected]>
This PR allows us to add warning messages to the syntax tree generated when parsing, and it moves the warnings for
**and__to the parser.Since warnings do not act like errors in stopping the evaluation of the file, I've chosen to implement them as transparent wrappers around existing syntax nodes, accessible only via the
errors_and_warningsmethod onSyntaxNode. This method was expanded from theerrorsmethod, and required adding a newErroneousstruct to differentiate between errors and warnings instead of just having a singleboolfor errors. And I renamedSyntaxErrortoSyntaxDiagnosticand gave it a boolean to distinguish the two (no enum because it felt weird to have a pure duplicate ofdiag::Severityhoused intypst-syntax).Also, the debug output for warnings inspired the new debug output for errors, but is a bit weirder since warnings directly contain a child node. LMK if anyone has thoughts on improving the debug outputs, or if we should just radically alter them at a later time.
The first four commits help prepare for the addition of warnings:
Debugimpl ofSyntaxNodewhich we should've had a long time agoDebugimpl for error nodes to include hints, but falls back to a shorter version if the error only contains a message (no text or hints)ErrorNodevariables so that we can call errorserrand warningswarnsince calling bothnodewould be confusingnode.rsthat I thought deserved it. This notably includes removing theSyntaxError::newmethod in favor of just havingSyntaxNode::errortake a message as a string to create errors (sinceSyntaxErroris renaming toSyntaxDiagnosticand because I just preferSyntaxNode::errortaking a string)Then the fifth commit adds warnings themselves.
Note that I am also planning on separately adding an abstraction for attaching sub-ranges to diagnostics. This would allow warnings and errors to target ranges of text that aren't necessarily contained directly by a Span in the syntax tree, greatly increasing the utility of syntax warnings (since this PR otherwise has little real benefit). However I am still working on that, but I wanted to push this set of changes now since they are ready to review.