-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add some basic Grit patterns (#2)
Co-authored-by: Lars Kappert <[email protected]>
- Loading branch information
Showing
6 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
target | ||
.grit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.gritmodules* | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: 0.0.1 | ||
patterns: | ||
- name: github.com/getgrit/stdlib#* | ||
- name: no_println_in_lsp | ||
description: Don't use println!() in LSP code, it breaks the LSP stdio protocol. | ||
level: error | ||
body: | | ||
engine marzano(0.1) | ||
language rust | ||
`println!($_)` => . where { | ||
$filename <: not includes "test.rs", | ||
$absolute_filename <: includes "apps/marzano/lsp", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Force flushing | ||
|
||
Prevent returning without flushing the emitter in `apply_pattern.rs`. | ||
|
||
```grit | ||
language rust | ||
pattern flushable_return() { | ||
`$expression?` where { | ||
$expression <: not includes "flush", | ||
$expression <: not within `let mut emitter: MessengerVariant = $_;`, | ||
$expression => `flushable_unwrap!(emitter, $expression)` | ||
} | ||
} | ||
file(name=includes "apply_pattern.rs", $body) where { | ||
$body <: contains `pub(crate) async fn run_apply_pattern( | ||
$_ | ||
) -> Result<()> { $func }` where { | ||
$func <: contains flushable_return() | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
level: info | ||
--- | ||
|
||
# Avoid panic | ||
|
||
Panics should be avoided in core Grit code. Instead, use `?` to propagate errors. | ||
|
||
```grit | ||
language rust | ||
file($name, $body) where { | ||
$name <: includes "marzano/lsp", | ||
$body <: contains `$foo.unwrap()` => `$foo?`, | ||
} | ||
``` | ||
|
||
## Sample | ||
|
||
```rust | ||
// @filename: marzano/lsp/foo.rs | ||
let x = bar().unwrap(); | ||
``` | ||
|
||
```rust | ||
// @filename: marzano/lsp/foo.rs | ||
let x = bar()?; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters