diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 61884d9..bd3bd85 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1ede7b6..c0cce21 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 }} @@ -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 diff --git a/src/parse_assertions.rs b/src/parse_assertions.rs index 913ad85..428d7bf 100644 --- a/src/parse_assertions.rs +++ b/src/parse_assertions.rs @@ -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 = - 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 = 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(), + }); } } }