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
13 changes: 8 additions & 5 deletions .github/workflows/external-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
env:
CARGO_TERM_COLOR: always
MACOSX_DEPLOYMENT_TARGET: "13"
# Force Node 24 for all JS-based actions to avoid the libuv
# process_title assertion crash on Windows (known Node 20 bug).
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

jobs:
lua-tests:
Expand All @@ -20,12 +23,12 @@ jobs:
fail-fast: false
matrix:
include:
# - os: ubuntu-latest TODO uncomment once bun stop crashing
- os: ubuntu-latest
- os: macos-latest
- os: windows-latest
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: oven-sh/setup-bun@v2

- name: Install Zig
Expand All @@ -34,11 +37,11 @@ jobs:
version: 0.15.2

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
uses: actions-rust-lang/setup-rust-toolchain@v1.15.4
with:
cache: true
cache-on-failure: true
cache-key: "v1-lua-e2e"
cache-on-failure: false
cache-key: "v2-lua-e2e"
rustflags: ""
target: ${{ matrix.target || '' }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lua.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: lua-language-server type check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Install Neovim
run: |
Expand All @@ -38,7 +38,7 @@ jobs:
name: luacheck lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Install luacheck
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
id-token: "write"
contents: "read"
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- uses: DeterminateSystems/flake-checker-action@main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/panvimdoc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
# fetch last 2 commits required for auto force push back
fetch-depth: 2
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches: [main, feat/mcp-ai]
pull_request:

env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

jobs:
build-nvim:
name: Build Neovim ${{ matrix.target }}
Expand Down Expand Up @@ -62,7 +65,7 @@ jobs:
ext: dll

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
persist-credentials: false

Expand Down Expand Up @@ -193,7 +196,7 @@ jobs:
ext: dll

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
persist-credentials: false

Expand Down Expand Up @@ -306,7 +309,7 @@ jobs:
artifact_name: target/aarch64-pc-windows-msvc/release/fff-mcp.exe

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
persist-credentials: false

Expand Down Expand Up @@ -360,7 +363,7 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Download artifacts
uses: actions/download-artifact@v4
Expand Down Expand Up @@ -469,7 +472,7 @@ jobs:
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

# Zig is required to compile zlob
- name: Install Zig
Expand All @@ -29,7 +29,7 @@ jobs:
version: 0.15.2

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
uses: actions-rust-lang/setup-rust-toolchain@v1.15.4
with:
cache: true
cache-on-failure: true
Expand All @@ -45,7 +45,7 @@ jobs:
name: cargo fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
Expand All @@ -58,7 +58,7 @@ jobs:
name: cargo clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5

# Zig is required to compile zlob
- name: Install Zig
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/spelling.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
name: Spell Check with Typos
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
persist-credentials: false

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stylua.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
name: Check lua files using Stylua
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
persist-credentials: false

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ parking_lot = "0.12"
pathdiff = "0.2.1"
rayon = "1.8.0"
regex = "1.11"
smallvec = { version = "1.13", features = ["const_generics", "union"] }
smallvec = { version = "1.13", features = [
"const_generics",
"union",
"may_dangle",
] }
thiserror = "2.0.10"
tracing = "0.1"

Expand Down
8 changes: 3 additions & 5 deletions crates/fff-c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ pub unsafe extern "C" fn fff_search(

let results = FilePicker::fuzzy_search(
picker.get_files(),
query_str,
parsed,
&parsed,
FuzzySearchOptions {
max_threads: opts.max_threads.unwrap_or(0),
current_file: opts.current_file.as_deref(),
Expand Down Expand Up @@ -349,8 +348,7 @@ pub unsafe extern "C" fn fff_live_grep(
classify_definitions: opts.classify_definitions.unwrap_or(false),
};

let result =
fff_core::grep::grep_search(picker.get_files(), query_str, parsed.as_ref(), &options);
let result = fff_core::grep::grep_search(picker.get_files(), &parsed, &options);

let json_result = ffi_types::GrepResultJson::from_grep_result(&result);
match serde_json::to_string(&json_result) {
Expand Down Expand Up @@ -406,7 +404,7 @@ pub unsafe extern "C" fn fff_multi_grep(
let is_ai = picker.mode().is_ai();

// Parse constraints from the optional string (e.g. "*.rs /src/")
let parsed_constraints = opts.constraints.as_deref().and_then(|c| {
let parsed_constraints = opts.constraints.as_deref().map(|c| {
if is_ai {
fff_core::QueryParser::new(fff_query_parser::AiGrepConfig).parse(c)
} else {
Expand Down
71 changes: 55 additions & 16 deletions crates/fff-core/src/background_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,30 @@ use notify::event::{AccessKind, AccessMode};
use notify::{Config, EventKind, RecursiveMode};
use notify_debouncer_full::{DebounceEventResult, DebouncedEvent, NoCache, new_debouncer_opt};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Duration;
use tracing::{Level, debug, error, info, warn};

type Debouncer = notify_debouncer_full::Debouncer<notify::RecommendedWatcher, NoCache>;

/// Owns the file-system watcher and guarantees that all background threads
/// are fully joined before `stop()` / `Drop` returns.
///
/// Architecture:
/// - The debouncer (and its internal watcher) live inside an **owner thread**
/// that we spawn and hold the `JoinHandle` for.
/// - `stop()` sets a flag, unparks the owner thread, and **joins** it.
/// - Inside the owner thread, `Debouncer::stop()` is called which joins the
/// debouncer's event-processing thread.
/// - On Windows an additional short sleep is added after `Debouncer::stop()`
/// because `notify`'s `ReadDirectoryChangesWatcher` discards its thread
/// `JoinHandle`, so we cannot join it directly. The watcher's `Drop` does
/// signal the thread via semaphore so it exits almost immediately, but we
/// need to give the OS a moment to reclaim it.
pub struct BackgroundWatcher {
debouncer: Arc<Mutex<Option<Debouncer>>>,
stop_signal: Arc<AtomicBool>,
owner_thread: Option<std::thread::JoinHandle<()>>,
}

const DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(250);
Expand Down Expand Up @@ -43,8 +59,33 @@ impl BackgroundWatcher {
Self::create_debouncer(base_path, git_workdir, shared_picker, shared_frecency, mode)?;
info!("Background file watcher initialized successfully");

let stop_signal = Arc::new(AtomicBool::new(false));
let stop_clone = Arc::clone(&stop_signal);

// The owner thread keeps the debouncer alive and ensures proper
// cleanup: `Debouncer::stop()` joins its internal thread, then the
// watcher `Drop` signals its I/O thread to exit.
let owner_thread = std::thread::Builder::new()
.name("fff-watcher-owner".into())
.spawn(move || {
while !stop_clone.load(Ordering::Acquire) {
std::thread::park_timeout(Duration::from_secs(1));
}
// Debouncer::stop() joins the debouncer's event thread, then
// drops the watcher (whose Drop signals the I/O thread).
debouncer.stop();
// On Windows the notify crate discards the ReadDirectoryChangesW
// thread's JoinHandle — we cannot join it. Its Drop signals the
// thread via semaphore so it exits almost immediately; give the
// OS a moment to fully reclaim it.
#[cfg(windows)]
std::thread::sleep(Duration::from_millis(250));
})
.expect("failed to spawn fff-watcher-owner thread");

Ok(Self {
debouncer: Arc::new(Mutex::new(Some(debouncer))),
stop_signal,
owner_thread: Some(owner_thread),
})
}

Expand Down Expand Up @@ -130,25 +171,23 @@ impl BackgroundWatcher {
Ok(debouncer)
}

pub fn stop(&self) {
if let Ok(Some(debouncer)) = self.debouncer.lock().map(|mut debouncer| debouncer.take()) {
drop(debouncer);
info!("Background file watcher stopped successfully");
} else {
error!("Failed to stop background watcher");
pub fn stop(&mut self) {
self.stop_signal.store(true, Ordering::Release);
if let Some(handle) = self.owner_thread.take() {
handle.thread().unpark();

if let Err(e) = handle.join() {
error!("Watcher owner thread panicked: {:?}", e);
}
}

info!("Background file watcher stopped successfully");
}
}

impl Drop for BackgroundWatcher {
fn drop(&mut self) {
if let Ok(mut debouncer_guard) = self.debouncer.lock() {
if let Some(debouncer) = debouncer_guard.take() {
drop(debouncer);
}
} else {
error!("Failed to acquire debouncer lock to drop");
}
self.stop();
}
}

Expand Down
Loading