Skip to content
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

Warning suppression #4459

Closed
wants to merge 62 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift click to select a range
05def04
initial diagnostic identifiers
PgBiel Jun 4, 2024
f895896
warn identifier as string, categories
PgBiel Jun 5, 2024
fe860f8
initial attached comment detection
PgBiel Jun 11, 2024
e196e45
basic suppression detection
PgBiel Jun 12, 2024
3823f56
initial attempt at a local sink on call
PgBiel Jun 14, 2024
26ae1d3
fix local sink on call
PgBiel Jun 14, 2024
e69c58a
fix decorator lookup next to the span itself
PgBiel Jun 14, 2024
b559fc2
create Engine::tracepoint
PgBiel Jun 14, 2024
33588ab
add and use Sink::extend_tracked
PgBiel Jun 14, 2024
6f3166d
fix deduplication of warnings with different tracepoints
PgBiel Jun 14, 2024
849bb63
decorator syntax
PgBiel Jun 7, 2024
1623a91
initial decorator lexing
PgBiel Jun 10, 2024
ad6cc41
fix decorator lexing with wrong offsets
PgBiel Jun 18, 2024
9f9ba7b
separate DecoratorMarker from Decorator
PgBiel Jun 10, 2024
3e69560
initial decorator parsing in markup
PgBiel Jun 10, 2024
9f9e877
use lexer subtrees to parse decorators
PgBiel Jun 21, 2024
fdfd880
add decorator tests
PgBiel Jun 21, 2024
16859f5
search for 'allow' decorators
PgBiel Jun 21, 2024
a1d5861
don't swallow newlines in decorator lexing
PgBiel Jun 21, 2024
c3c3ea9
allow same line decorator search
PgBiel Jun 21, 2024
b318b0a
satisfy clippy
PgBiel Jun 21, 2024
a320e92
lexer now returns nodes
PgBiel Jun 21, 2024
7f1e2fc
more decorator tests
PgBiel Jun 21, 2024
910af83
proper decorator parsing
PgBiel Jun 24, 2024
acdd33c
remove redundant '-' identifier check
PgBiel Jun 24, 2024
c7d97a7
add doc comment regarding lexer subtrees
PgBiel Jun 24, 2024
d35a563
use proper name for paren tokens
PgBiel Jun 24, 2024
14dfb3f
create DecoratorMarker and DecoratorName
PgBiel Jun 24, 2024
65dc277
minor decorator lexing improvements
PgBiel Jun 25, 2024
1b5c6e8
no rendering in tests
PgBiel Jun 26, 2024
afaa45e
improve identifier naming, remove error id
PgBiel Jun 26, 2024
eec6a3a
diag ids: remove categories, improve docs
PgBiel Jun 26, 2024
05a40ed
lexer: make 'take_error' internal
PgBiel Jun 26, 2024
ecb0ee5
fix newline counting
PgBiel Jun 26, 2024
181c633
improve tree search
PgBiel Jun 27, 2024
866c536
simplify decorator arguments in the AST
PgBiel Jun 27, 2024
c96bf9a
dot
PgBiel Jun 27, 2024
eebd7f4
test allow with context
PgBiel Jun 27, 2024
9b311c1
add suppress on tracepoint test
PgBiel Jun 27, 2024
f8730b0
add test for decorator at end of line
PgBiel Jun 27, 2024
a74bbd8
current_kind -> current
PgBiel Jul 15, 2024
5b05e2d
Merge branch 'main' into warn-suppression
PgBiel Jul 15, 2024
19f3047
improve comments and formatting
PgBiel Jul 15, 2024
70d7e46
improve warning suppression check
PgBiel Jul 15, 2024
fd410f2
fix tests for now
PgBiel Jul 15, 2024
629375a
move around some sink functions
PgBiel Jul 15, 2024
2b442ea
remove inner node 'capped_newlines' field
PgBiel Jul 15, 2024
c1bb41d
new decorator syntax: '// @'
PgBiel Jul 15, 2024
0fb417d
add test for decorator in decorator
PgBiel Jul 16, 2024
fb77128
decorator -> annotation
PgBiel Jul 16, 2024
a5d36d6
fix annotation syntax in comments
PgBiel Jul 16, 2024
457892c
improve some var names
PgBiel Jul 16, 2024
c4c7cfc
Merge branch 'main' into warn-suppression
PgBiel Jul 22, 2024
5d60e48
use picostr for identifiers
PgBiel Jul 22, 2024
b866e58
add deprecated id for deprecations
PgBiel Jul 22, 2024
c8994d0
initial changes towards simpler syntax
PgBiel Jul 22, 2024
71f3e67
update tests with new syntax
PgBiel Jul 22, 2024
bab391a
Merge branch 'main' into warn-suppression
PgBiel Jul 23, 2024
e105cd1
improve errors in annotations
PgBiel Jul 23, 2024
46e4fbf
initial improvements to allow multiline annotations
PgBiel Jul 23, 2024
93bd46d
add parenthesized annotation linebreak support
PgBiel Jul 23, 2024
af7e258
apply suggested improvements
PgBiel Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions crates/typst-syntax/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 80,68 @@ impl<'a> Markup<'a> {
}
}

node! {
AnnotationName
}

impl<'a> AnnotationName<'a> {
/// Get the annotation name.
pub fn get(self) -> &'a EcoString {
self.0.text()
}

/// Get the annotation name as a string slice.
pub fn as_str(self) -> &'a str {
self.get()
}
}

node! {
/// An annotation: `// @allow("warning")`.
Annotation
}

impl<'a> Annotation<'a> {
/// The name of the annotation, e.g. `allow`.
pub fn name(self) -> AnnotationName<'a> {
self.0.cast_first_match().unwrap_or_default()
}

/// The annotation's arguments, which are always either identifiers or
/// strings.
pub fn arguments(self) -> impl DoubleEndedIterator<Item = AnnotationArg<'a>> {
self.0.children().filter_map(AnnotationArg::from_untyped)
}
}

/// An annotation argument, which always corresponds to a simple string, which,
/// however, may be abbreviated and specified as a valid identifier directly.
pub enum AnnotationArg<'a> {
/// An identifier specified directly, without quotes.
Ident(Ident<'a>),
/// A string specified with double quotes.
Str(Str<'a>),
}

impl<'a> AnnotationArg<'a> {
/// Casts an untyped node to an annotation argument, if possible.
pub fn from_untyped(node: &'a SyntaxNode) -> Option<Self> {
match node.kind() {
SyntaxKind::Ident => node.cast().map(Self::Ident),
SyntaxKind::Str => node.cast().map(Self::Str),
_ => Option::None,
}
}

/// Gets the text specified for this argument.
pub fn get(self) -> EcoString {
match self {
Self::Ident(ident) => ident.get().clone(),
Self::Str(str) => str.get(),
}
}
}

/// An expression in markup, math or code.
#[derive(Debug, Copy, Clone, Hash)]
pub enum Expr<'a> {
Expand Down
4 changes: 4 additions & 0 deletions crates/typst-syntax/src/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 286,10 @@ pub fn highlight(node: &LinkedNode) -> Option<Tag> {
SyntaxKind::Destructuring => None,
SyntaxKind::DestructAssignment => None,

SyntaxKind::Annotation => None,
SyntaxKind::AnnotationMarker => None,
SyntaxKind::AnnotationName => None,

SyntaxKind::LineComment => Some(Tag::Comment),
SyntaxKind::BlockComment => Some(Tag::Comment),
SyntaxKind::Error => Some(Tag::Error),
Expand Down
16 changes: 15 additions & 1 deletion crates/typst-syntax/src/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 13,8 @@ pub enum SyntaxKind {
LineComment,
/// A block comment: `/* ... */`.
BlockComment,
/// An annotation: `// @allow("warning")`.
Annotation,

/// The contents of a file or content block.
Markup,
Expand Down Expand Up @@ -278,6 280,11 @@ pub enum SyntaxKind {
Destructuring,
/// A destructuring assignment expression: `(x, y) = (1, 2)`.
DestructAssignment,

/// An annotation's marker: `// @`.
AnnotationMarker,
/// An annotation's name: `allow`.
AnnotationName,
}

impl SyntaxKind {
Expand Down Expand Up @@ -355,7 362,11 @@ impl SyntaxKind {
pub fn is_trivia(self) -> bool {
matches!(
self,
Self::LineComment | Self::BlockComment | Self::Space | Self::Parbreak
Self::LineComment
| Self::BlockComment
| Self::Space
| Self::Parbreak
| Self::Annotation
)
}

Expand All @@ -371,6 382,7 @@ impl SyntaxKind {
Self::Error => "syntax error",
Self::LineComment => "line comment",
Self::BlockComment => "block comment",
Self::Annotation => "annotation",
Self::Markup => "markup",
Self::Text => "text",
Self::Space => "space",
Expand Down Expand Up @@ -498,6 510,8 @@ impl SyntaxKind {
Self::FuncReturn => "`return` expression",
Self::Destructuring => "destructuring pattern",
Self::DestructAssignment => "destructuring assignment expression",
Self::AnnotationMarker => "annotation marker",
Self::AnnotationName => "annotation name",
}
}
}
Loading