Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
64 changes: 33 additions & 31 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,44 @@ jobs:
name: cargo build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@1.94.0
id: toolchain
with:
toolchain: nightly
override: true
default: true
- uses: actions-rs/cargo@v1
with:
command: build
args: --release --all-features
clippy:
name: cargo clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
default: true
components: clippy
- uses: actions-rs/cargo@v1
- uses: actions/cache@v4
with:
command: clippy
args: --release --all-features
fmt:
name: cargo fmt
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
target/
key: ${{ runner.os }}-cargo-debug-${{ hashFiles('**/Cargo.lock') }}
- run: cargo clippy --tests --no-deps -- -D warnings

format:
name: Format
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@1.94.0
id: toolchain
with:
toolchain: nightly
override: true
default: true
components: rustfmt
- uses: actions-rs/cargo@v1
- run: cargo fmt --check

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@1.94.0
id: toolchain
- uses: actions/cache@v4
with:
command: fmt
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
target/
key: ${{ runner.os }}-cargo-debug-${{ hashFiles('**/Cargo.lock') }}
- run: cargo build --release
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
create-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -34,7 +34,8 @@ jobs:
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@1.94.0

# Upload Rust binaries
- uses: taiki-e/upload-rust-binary-action@v1
Expand Down
67 changes: 33 additions & 34 deletions src/parse_assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,42 +45,41 @@ pub fn parse_position_comments(
let node = cursor.node();

// Find every comment node.
if node.kind().contains(comment_node) {
if let Ok(text) = node.utf8_text(source) {
let mut position = node.start_position();
if position.row > 0 {
// Find the arrow character ("^" or '<-") in the comment. A left arrow
// refers to the column where the comment node starts. An up arrow refers
// to its own column.
let mut has_left_caret = false;
let mut has_arrow = false;
let mut arrow_end = 0;
for (i, c) in text.char_indices() {
arrow_end = i + 1;
if c == '-' && has_left_caret {
has_arrow = true;
break;
}
if c == '^' {
has_arrow = true;
position.column += i;
break;
}
has_left_caret = c == '<';
if node.kind().contains(comment_node)
&& let Ok(text) = node.utf8_text(source)
{
let mut position = node.start_position();
if position.row > 0 {
// Find the arrow character ("^" or '<-") in the comment. A left arrow
// refers to the column where the comment node starts. An up arrow refers
// to its own column.
let mut has_left_caret = false;
let mut has_arrow = false;
let mut arrow_end = 0;
for (i, c) in text.char_indices() {
arrow_end = i + 1;
if c == '-' && has_left_caret {
has_arrow = true;
break;
}
static REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new("[!\\w_\\-.]+").unwrap());

// If the comment node contains an arrow and a highlight name, record the
// highlight name and the position.
if let (true, Some(mat)) = (has_arrow, REGEX.find(&text[arrow_end..])) {
assertion_ranges.push((node.start_position(), node.end_position()));
let tree_sitter::Point { row, column } = position;
result.push(Assertion {
position: Point { row, column },
expected_capture_name: mat.as_str().to_string(),
});
if c == '^' {
has_arrow = true;
position.column += i;
break;
}
has_left_caret = c == '<';
}
static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new("[!\\w_\\-.]+").unwrap());

// If the comment node contains an arrow and a highlight name, record the
// highlight name and the position.
if let (true, Some(mat)) = (has_arrow, REGEX.find(&text[arrow_end..])) {
assertion_ranges.push((node.start_position(), node.end_position()));
let tree_sitter::Point { row, column } = position;
result.push(Assertion {
position: Point { row, column },
expected_capture_name: mat.as_str().to_string(),
});
}
}
}
Expand Down
Loading