Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b2864e4b1 | |||
| 2c9cae2e0f | |||
| a166255d8f | |||
| ffd8eb9c08 | |||
| ed6b40a591 | |||
| c4f6c600d6 | |||
| 787a9b1cb7 | |||
| 6398d32c0c | |||
| c6194b848d | |||
| b71b7cf4ac | |||
| cc289f0f93 | |||
| 2107f038dc | |||
| 9441cbc5ae | |||
| dd87489d6b | |||
| d4c416c2fc |
@@ -55,7 +55,7 @@ jobs:
|
||||
|
||||
- name: Build Rust binary
|
||||
shell: bash
|
||||
run: make build
|
||||
run: make build-e2e
|
||||
|
||||
- name: Verify Windows DLL has no unexpected dependencies
|
||||
if: matrix.os == 'windows-latest'
|
||||
@@ -200,6 +200,10 @@ jobs:
|
||||
{ "name": "@ff-labs/fff-bin-linux-x64-musl", "version": "0.0.0" }
|
||||
JSON
|
||||
|
||||
# fff-node builds with bun; the npm `bun` package ships musl binaries
|
||||
- name: Install bun
|
||||
run: npm install -g bun
|
||||
|
||||
- name: Build fff-node
|
||||
working-directory: packages/fff-node
|
||||
run: npm run build
|
||||
|
||||
@@ -15,6 +15,8 @@ on:
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
MACOSX_DEPLOYMENT_TARGET: "13.0"
|
||||
CARGO_PROFILE_RELEASE_LTO: thin
|
||||
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 16
|
||||
|
||||
jobs:
|
||||
test:
|
||||
@@ -31,7 +33,11 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1.15.4
|
||||
with:
|
||||
cache: true
|
||||
cache-on-failure: true
|
||||
cache-key: "v1-rust-python"
|
||||
|
||||
- name: Setup uv
|
||||
uses: astral-sh/setup-uv@v5
|
||||
@@ -43,6 +49,8 @@ jobs:
|
||||
working-directory: packages/fff-python
|
||||
shell: bash
|
||||
run: |
|
||||
uv sync --all-extras
|
||||
# --no-install-project: uv would otherwise build the wheel via
|
||||
# maturin's PEP 517 backend, then `maturin develop` builds it again.
|
||||
uv sync --all-extras --no-install-project
|
||||
uv run maturin develop --release
|
||||
uv run pytest -v
|
||||
|
||||
@@ -612,7 +612,7 @@ jobs:
|
||||
|
||||
Update mcp via:
|
||||
```sh
|
||||
curl -fsSL https://raw.githubusercontent.com/dmtrKovalenko/fff.nvim/main/install-mcp.sh | bash
|
||||
curl -fsSL https://raw.githubusercontent.com/dmtrKovalenko/fff/main/install-mcp.sh | bash
|
||||
```
|
||||
|
||||
- name: Bump Homebrew formula (uses local checksums)
|
||||
@@ -710,6 +710,8 @@ jobs:
|
||||
node-version: "25"
|
||||
registry-url: "https://registry.npmjs.org"
|
||||
|
||||
- uses: oven-sh/setup-bun@v2
|
||||
|
||||
- name: Determine version
|
||||
id: version
|
||||
run: lua scripts/determine-version.lua
|
||||
@@ -747,6 +749,8 @@ jobs:
|
||||
make set-npm-version PKG=packages/fff-bun VERSION="$VERSION"
|
||||
|
||||
cd packages/fff-bun
|
||||
bun install --frozen-lockfile
|
||||
bun run build
|
||||
npm publish --tag "$TAG" --access public --provenance
|
||||
|
||||
- name: Publish Node.js package
|
||||
|
||||
@@ -47,7 +47,8 @@ jobs:
|
||||
components: rustfmt, clippy
|
||||
|
||||
- name: Run tests
|
||||
run: cargo test --no-default-features --features zlob --workspace --exclude fff-nvim
|
||||
# fff-python requires full python o3 machinery which is very slow
|
||||
run: cargo test --no-default-features --features zlob --workspace --exclude fff-nvim --exclude fff-python
|
||||
|
||||
stress-test:
|
||||
name: Fuzz Tests
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
-- luacheck configuration for fff.nvim
|
||||
-- luacheck configuration for fff
|
||||
-- https://luacheck.readthedocs.io/en/stable/config.html
|
||||
|
||||
-- Neovim globals
|
||||
|
||||
Generated
+11
-9
@@ -633,7 +633,7 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
||||
|
||||
[[package]]
|
||||
name = "fff-c"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
dependencies = [
|
||||
"fff-query-parser",
|
||||
"fff-search",
|
||||
@@ -643,7 +643,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fff-grep"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
dependencies = [
|
||||
"bstr",
|
||||
"memchr",
|
||||
@@ -651,7 +651,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fff-mcp"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"fff-query-parser",
|
||||
@@ -662,8 +662,10 @@ dependencies = [
|
||||
"schemars",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"windows-sys 0.60.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -682,7 +684,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fff-nvim"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"chrono",
|
||||
@@ -703,7 +705,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fff-python"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
dependencies = [
|
||||
"fff-query-parser",
|
||||
"fff-search",
|
||||
@@ -713,7 +715,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fff-query-parser"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
dependencies = [
|
||||
"criterion",
|
||||
"zlob",
|
||||
@@ -721,7 +723,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "fff-search"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"aho-corasick",
|
||||
@@ -3235,9 +3237,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zlob"
|
||||
version = "1.6.2"
|
||||
version = "1.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57e7ca1588981ea66f5ac470915c4cb44a47ecfb5797576f65fca1bafacedf4e"
|
||||
checksum = "f0f010d9b10495cc0037cb47cedc143c39c7fa2d59f752dca19036fd0234a210"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"bitflags 2.11.0",
|
||||
|
||||
+3
-3
@@ -15,8 +15,8 @@ resolver = "2"
|
||||
module_inception = "allow"
|
||||
|
||||
[workspace.dependencies]
|
||||
fff-grep = { version = "0.10.3", path = "crates/fff-grep" }
|
||||
fff-query-parser = { version = "0.10.3", path = "crates/fff-query-parser", default-features = false }
|
||||
fff-grep = { version = "0.10.4", path = "crates/fff-grep" }
|
||||
fff-query-parser = { version = "0.10.4", path = "crates/fff-query-parser", default-features = false }
|
||||
|
||||
# Shared dependencies
|
||||
ahash = "0.8"
|
||||
@@ -36,7 +36,7 @@ ignore = "0.4.22"
|
||||
memmap2 = "0.9"
|
||||
mimalloc = "0.1.47"
|
||||
signal-hook-registry = "1.4"
|
||||
zlob = { version = "=1.6.2" }
|
||||
zlob = { version = "=1.6.3" }
|
||||
|
||||
mlua = { version = "0.11.1", features = ["module", "luajit"] }
|
||||
neo_frizbee = { version = "0.11.0", features = ["match_end_col"] }
|
||||
|
||||
+8
-8
@@ -2,34 +2,34 @@
|
||||
# Maintained in-repo; auto-bumped by .github/workflows/release.yaml on stable releases.
|
||||
class FffMcp < Formula
|
||||
desc "Fast file search toolkit for AI agents (MCP server)"
|
||||
homepage "https://github.com/dmtrKovalenko/fff.nvim"
|
||||
homepage "https://github.com/dmtrKovalenko/fff"
|
||||
license "MIT"
|
||||
version "0.10.3"
|
||||
version "0.10.4"
|
||||
|
||||
LIVECHECK_REPO = "dmtrKovalenko/fff.nvim".freeze
|
||||
RELEASE_BASE = "https://github.com/dmtrKovalenko/fff.nvim/releases/download".freeze
|
||||
LIVECHECK_REPO = "dmtrKovalenko/fff".freeze
|
||||
RELEASE_BASE = "https://github.com/dmtrKovalenko/fff/releases/download".freeze
|
||||
|
||||
on_macos do
|
||||
on_arm do
|
||||
url "#{RELEASE_BASE}/v#{version}/fff-mcp-aarch64-apple-darwin"
|
||||
sha256 "8c52acf1e95540f02cf55579126ebf580cf48af15c76e1c90301c2c8c5acbcf9"
|
||||
sha256 "f55ce2945cd30fd252a4b1e7d8674ff7ce41b104cc009a8d3d52d08bfccca2c0"
|
||||
end
|
||||
|
||||
on_intel do
|
||||
url "#{RELEASE_BASE}/v#{version}/fff-mcp-x86_64-apple-darwin"
|
||||
sha256 "f72c31c7f3355d37ec526ba56fd716341bd7186a15a399910cf3f2b46fef2099"
|
||||
sha256 "821aedd5873292841f32d7584eb68fea085b248e5c970ff5d4f6dca790e9b18c"
|
||||
end
|
||||
end
|
||||
|
||||
on_linux do
|
||||
on_arm do
|
||||
url "#{RELEASE_BASE}/v#{version}/fff-mcp-aarch64-unknown-linux-gnu"
|
||||
sha256 "ed2db5b7268c76619178594c31e400b0973668acfa42fe6b9a06a28ad459b667"
|
||||
sha256 "3f266c0eded51a106badf1d47448a7f963762ccf3a12c5a4f06ee2b7adaf82d1"
|
||||
end
|
||||
|
||||
on_intel do
|
||||
url "#{RELEASE_BASE}/v#{version}/fff-mcp-x86_64-unknown-linux-gnu"
|
||||
sha256 "2692bc567f8c5609a179795f5ee95555d783a678acdad9c9883e6730654a057e"
|
||||
sha256 "b5dd3182028c8a7bc34ee964cf2d30694f8121d2837a8516cf4a99bcfa822127"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -45,6 +45,11 @@ sync-js-api-check:
|
||||
build:
|
||||
cargo build --release --no-default-features --features zlob
|
||||
|
||||
# Only the crates the e2e suites load (nvim lua tests + C/bun/node FFI tests),
|
||||
# skipping fff-python (pyo3) and fff-mcp (tokio/rmcp) which e2e never touches.
|
||||
build-e2e:
|
||||
cargo build --release -p fff-nvim -p fff-c --no-default-features --features zlob
|
||||
|
||||
build-c-lib:
|
||||
cargo build --release -p fff-c --no-default-features --features zlob
|
||||
|
||||
@@ -90,7 +95,7 @@ test-setup:
|
||||
fi
|
||||
|
||||
test-rust:
|
||||
cargo test --workspace --no-default-features --features zlob --exclude fff-nvim
|
||||
cargo test --workspace --no-default-features --features zlob --exclude fff-nvim --exclude fff-python
|
||||
|
||||
# Watcher rescan harness: asserts that editing, build output, git activity and
|
||||
# preview reads all stay on the incremental path instead of re-walking the tree.
|
||||
@@ -305,7 +310,7 @@ lint: lint-rust lint-lua lint-ts
|
||||
|
||||
check: format lint
|
||||
|
||||
FFF_RELEASE_REPO ?= dmtrKovalenko/fff.nvim
|
||||
FFF_RELEASE_REPO ?= dmtrKovalenko/fff
|
||||
FFF_FORMULA_PATH ?= Formula/fff-mcp.rb
|
||||
FFF_INSTALL_SCRIPT_PATH ?= install-mcp.sh
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ curl -L https://dmtrkovalenko.dev/install-fff-mcp.sh | bash
|
||||
Windows (PowerShell):
|
||||
|
||||
```powershell
|
||||
irm https://raw.githubusercontent.com/dmtrKovalenko/fff.nvim/main/install-mcp.ps1 | iex
|
||||
irm https://raw.githubusercontent.com/dmtrKovalenko/fff/main/install-mcp.ps1 | iex
|
||||
```
|
||||
|
||||
The scripts live at [`install-mcp.sh`](./install-mcp.sh) and [`install-mcp.ps1`](./install-mcp.ps1) if you want to read them first. They print the exact wiring instructions for your client.
|
||||
@@ -49,7 +49,7 @@ brew install dmtrKovalenko/fff/fff-mcp
|
||||
brew upgrade fff-mcp # after new stable releases
|
||||
```
|
||||
|
||||
Formula lives in [`Formula/fff-mcp.rb`](./Formula/fff-mcp.rb) in this repo and is **auto-bumped on every stable release** (see `bump-homebrew-formula` in [`.github/workflows/release.yaml`](./.github/workflows/release.yaml)). Installs the prebuilt `fff-mcp` binary from [GitHub releases](https://github.com/dmtrKovalenko/fff.nvim/releases).
|
||||
Formula lives in [`Formula/fff-mcp.rb`](./Formula/fff-mcp.rb) in this repo and is **auto-bumped on every stable release** (see `bump-homebrew-formula` in [`.github/workflows/release.yaml`](./.github/workflows/release.yaml)). Installs the prebuilt `fff-mcp` binary from [GitHub releases](https://github.com/dmtrKovalenko/fff/releases).
|
||||
|
||||
### Codex setup
|
||||
|
||||
@@ -153,8 +153,9 @@ https://github.com/user-attachments/assets/5d0e1ce9-642c-4c44-aa88-01b05bb86abb
|
||||
#### lazy.nvim
|
||||
|
||||
```lua
|
||||
-- Package name changed from `fff.nvim` to `fff`. If you installed fff.nvim before, clean with `:Lazy clean`
|
||||
{
|
||||
'dmtrKovalenko/fff.nvim',
|
||||
'dmtrKovalenko/fff',
|
||||
build = function()
|
||||
-- downloads a prebuilt binary or falls back to cargo build
|
||||
require("fff.download").download_or_build_binary()
|
||||
@@ -187,13 +188,14 @@ https://github.com/user-attachments/assets/5d0e1ce9-642c-4c44-aa88-01b05bb86abb
|
||||
#### vim.pack
|
||||
|
||||
```lua
|
||||
vim.pack.add({ 'https://github.com/dmtrKovalenko/fff.nvim' })
|
||||
-- Package name changed from `fff.nvim` to `fff`. If you installed fff.nvim before, clean with `:packdel fff.nvim`
|
||||
vim.pack.add({ 'https://github.com/dmtrKovalenko/fff' })
|
||||
|
||||
vim.api.nvim_create_autocmd('PackChanged', {
|
||||
callback = function(ev)
|
||||
local name, kind = ev.data.spec.name, ev.data.kind
|
||||
if name == 'fff.nvim' and (kind == 'install' or kind == 'update') then
|
||||
if not ev.data.active then vim.cmd.packadd('fff.nvim') end
|
||||
if name == 'fff' and (kind == 'install' or kind == 'update') then
|
||||
if not ev.data.active then vim.cmd.packadd('fff') end
|
||||
require('fff.download').download_or_build_binary()
|
||||
end
|
||||
end,
|
||||
@@ -614,7 +616,7 @@ cargo build --release -p fff-c --features zlob
|
||||
|
||||
The output is a `cdylib` (`libfff_c.so` / `libfff_c.dylib` / `fff_c.dll`). The header lives at [`crates/fff-c/include/fff.h`](./crates/fff-c/include/fff.h).
|
||||
|
||||
Prebuilt binaries for every version, including every commit on main, are on the [releases page](https://github.com/dmtrKovalenko/fff.nvim/releases). The same binaries also ship inside the `@ff-labs/fff-bin-*` npm packages.
|
||||
Prebuilt binaries for every version, including every commit on main, are on the [releases page](https://github.com/dmtrKovalenko/fff/releases). The same binaries also ship inside the `@ff-labs/fff-bin-*` npm packages.
|
||||
|
||||
### Install
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "fff-c"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
edition = "2024"
|
||||
description = "Raw C api of FFF file finder"
|
||||
license = "MIT"
|
||||
@@ -19,6 +19,6 @@ zlob = ["fff/zlob", "fff-query-parser/zlob"]
|
||||
[dependencies]
|
||||
git2.workspace = true
|
||||
|
||||
fff = { package = "fff-search", path = "../fff-core", version = "0.10.3", default-features = false }
|
||||
fff-query-parser = { path = "../fff-query-parser", version = "0.10.3", default-features = false }
|
||||
fff = { package = "fff-search", path = "../fff-core", version = "0.10.4", default-features = false }
|
||||
fff-query-parser = { path = "../fff-query-parser", version = "0.10.4", default-features = false }
|
||||
serde_json = "1.0"
|
||||
|
||||
+3
-10
@@ -729,19 +729,12 @@ 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 = constraints_str.map(|c| {
|
||||
if is_ai {
|
||||
fff::QueryParser::new(fff_query_parser::AiGrepConfig).parse(c)
|
||||
} else {
|
||||
fff::grep::parse_grep_query(c)
|
||||
}
|
||||
});
|
||||
let parsed_constraints = constraints_str
|
||||
.map(|c| fff::QueryParser::new(fff_query_parser::AiGrepConfig).parse_constraints(c));
|
||||
|
||||
let constraint_refs: &[fff::Constraint<'_>] = match &parsed_constraints {
|
||||
Some(q) => &q.constraints,
|
||||
Some(constraints) => constraints,
|
||||
None => &[],
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "fff-search"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
authors = ["Dmitriy Kovalenko <dmtr.kovalenko@outlook.com>"]
|
||||
|
||||
@@ -0,0 +1,250 @@
|
||||
use heed::{Env, EnvOpenOptions};
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::ops::Deref;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, LazyLock, Mutex, MutexGuard, PoisonError, Weak};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use crate::lmdb::DbHealth;
|
||||
|
||||
pub(crate) struct EnvSpec {
|
||||
pub label: &'static str,
|
||||
pub map_size: usize,
|
||||
pub max_dbs: u32,
|
||||
pub size_cap_bytes: u64,
|
||||
}
|
||||
|
||||
pub(crate) struct PooledEnv {
|
||||
env: Env,
|
||||
key: PathBuf,
|
||||
/// lmdb's env spec label
|
||||
label: &'static str,
|
||||
map_size: usize,
|
||||
max_dbs: u32,
|
||||
health: DbHealth,
|
||||
gc_started: AtomicBool,
|
||||
dbi_lock: Mutex<()>,
|
||||
}
|
||||
|
||||
impl Drop for PooledEnv {
|
||||
fn drop(&mut self) {
|
||||
let mut pool = POOL.lock().unwrap_or_else(PoisonError::into_inner);
|
||||
// Only remove a dead entry: begin_exclusive_destroy may have removed ours.
|
||||
if pool.get(&self.key).is_some_and(|w| w.strong_count() == 0) {
|
||||
pool.remove(&self.key);
|
||||
}
|
||||
// heed closes the env right after this body; a concurrent reopen of the
|
||||
// same path rides out that gap via env_closing_event in get_or_open.
|
||||
}
|
||||
}
|
||||
|
||||
// Cloneable handle to a process-shared LMDB env, derefs to `heed::Env`.
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct SharedEnv(Arc<PooledEnv>);
|
||||
|
||||
impl Deref for SharedEnv {
|
||||
type Target = Env;
|
||||
fn deref(&self) -> &Env {
|
||||
&self.0.env
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for SharedEnv {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_tuple("SharedEnv").field(&self.0.env).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl SharedEnv {
|
||||
pub(crate) fn get_or_open(db_path: &Path, spec: &EnvSpec) -> Result<Self> {
|
||||
fs::create_dir_all(db_path).map_err(Error::CreateDir)?;
|
||||
let path = fs::canonicalize(db_path).map_err(|e| Error::EnvOpen {
|
||||
db: spec.label,
|
||||
source: heed::Error::Io(e),
|
||||
})?;
|
||||
|
||||
let mut close_waits = 0u32;
|
||||
let mut transient_retries = 0u32;
|
||||
|
||||
loop {
|
||||
let mut open_failed = false;
|
||||
|
||||
{
|
||||
let mut pool = POOL.lock().unwrap_or_else(PoisonError::into_inner);
|
||||
if let Some(existing) = pool.get(&path).and_then(Weak::upgrade) {
|
||||
drop(pool);
|
||||
if existing.label != spec.label
|
||||
|| existing.map_size != spec.map_size
|
||||
|| existing.max_dbs != spec.max_dbs
|
||||
{
|
||||
return Err(Error::EnvSpecMismatch {
|
||||
path,
|
||||
open_as: existing.label,
|
||||
requested_as: spec.label,
|
||||
});
|
||||
}
|
||||
return Ok(Self(existing));
|
||||
}
|
||||
|
||||
erase_if_oversized(&path, spec);
|
||||
let result = unsafe {
|
||||
let mut opts = EnvOpenOptions::new();
|
||||
opts.map_size(spec.map_size);
|
||||
if spec.max_dbs > 0 {
|
||||
opts.max_dbs(spec.max_dbs);
|
||||
}
|
||||
opts.open(&path)
|
||||
};
|
||||
|
||||
match result {
|
||||
Ok(env) => {
|
||||
let entry = Arc::new(PooledEnv {
|
||||
env,
|
||||
key: path.clone(),
|
||||
label: spec.label,
|
||||
map_size: spec.map_size,
|
||||
max_dbs: spec.max_dbs,
|
||||
health: DbHealth::new(),
|
||||
gc_started: AtomicBool::new(false),
|
||||
dbi_lock: Mutex::new(()),
|
||||
});
|
||||
pool.insert(path.clone(), Arc::downgrade(&entry));
|
||||
drop(pool);
|
||||
let shared = Self(entry);
|
||||
|
||||
match shared.clear_stale_readers() {
|
||||
Ok(cleared_count) if cleared_count > 0 => {
|
||||
tracing::info!(
|
||||
cleared_count,
|
||||
db = spec.label,
|
||||
"reclaimed stale LMDB reader slots at open"
|
||||
);
|
||||
}
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
tracing::debug!("clear_stale_readers at open failed: {e}")
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(shared);
|
||||
}
|
||||
Err(heed::Error::EnvAlreadyOpened) => open_failed = true,
|
||||
// special handling cause we know this happens randomly
|
||||
Err(e)
|
||||
if is_transient_env_open_error(&e)
|
||||
&& transient_retries < MAX_TRANSIENT_RETRIES =>
|
||||
{
|
||||
transient_retries += 1;
|
||||
tracing::debug!(
|
||||
path = %path.display(),
|
||||
transient_retries,
|
||||
error = ?e,
|
||||
"transient LMDB env open error, retrying"
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(Error::EnvOpen {
|
||||
db: spec.label,
|
||||
source: e,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if open_failed {
|
||||
close_waits += 1;
|
||||
if close_waits > MAX_CLOSE_WAITS {
|
||||
return Err(Error::EnvOpen {
|
||||
db: spec.label,
|
||||
source: heed::Error::EnvAlreadyOpened,
|
||||
});
|
||||
}
|
||||
|
||||
match heed::env_closing_event(&path) {
|
||||
Some(event) => {
|
||||
event.wait_timeout(CLOSE_WAIT);
|
||||
}
|
||||
None => thread::sleep(Duration::from_millis(2)),
|
||||
}
|
||||
} else {
|
||||
thread::sleep(TRANSIENT_RETRY_SLEEP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn health(&self) -> &DbHealth {
|
||||
&self.0.health
|
||||
}
|
||||
|
||||
// First caller wins: GC runs once per opened env, not once per tracker.
|
||||
pub(crate) fn try_start_gc(&self) -> bool {
|
||||
!self.0.gc_started.swap(true, Ordering::AcqRel)
|
||||
}
|
||||
|
||||
// LMDB forbids mdb_dbi_open from concurrent txns in the same process.
|
||||
pub(crate) fn lock_dbi_open(&self) -> MutexGuard<'_, ()> {
|
||||
self.0
|
||||
.dbi_lock
|
||||
.lock()
|
||||
.unwrap_or_else(PoisonError::into_inner)
|
||||
}
|
||||
|
||||
pub(crate) fn destroy(&self) -> Result<Option<heed::EnvClosingEvent>> {
|
||||
let mut pool = POOL.lock().unwrap_or_else(PoisonError::into_inner);
|
||||
let holders = Arc::strong_count(&self.0);
|
||||
|
||||
if holders > 1 {
|
||||
return Err(Error::DbInUse {
|
||||
db: self.0.label,
|
||||
path: self.0.key.clone(),
|
||||
holders: holders - 1,
|
||||
});
|
||||
}
|
||||
|
||||
pool.remove(&self.0.key);
|
||||
Ok(heed::env_closing_event(&self.0.key))
|
||||
}
|
||||
}
|
||||
|
||||
static POOL: LazyLock<Mutex<HashMap<PathBuf, Weak<PooledEnv>>>> = LazyLock::new(Mutex::default);
|
||||
|
||||
const CLOSE_WAIT: Duration = Duration::from_millis(100);
|
||||
const MAX_CLOSE_WAITS: u32 = 100;
|
||||
const TRANSIENT_RETRY_SLEEP: Duration = Duration::from_millis(50);
|
||||
const MAX_TRANSIENT_RETRIES: u32 = 8;
|
||||
|
||||
// Concurrent mdb_env_open calls on the same path can race on macOS
|
||||
// this is for some reason fixable by simple retry of the open
|
||||
fn is_transient_env_open_error(err: &heed::Error) -> bool {
|
||||
match err {
|
||||
heed::Error::Io(io) => matches!(
|
||||
io.kind(),
|
||||
std::io::ErrorKind::InvalidInput | std::io::ErrorKind::NotFound
|
||||
),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn erase_if_oversized(db_path: &Path, spec: &EnvSpec) {
|
||||
let data = db_path.join("data.mdb");
|
||||
let Ok(meta) = fs::metadata(&data) else {
|
||||
return;
|
||||
};
|
||||
|
||||
if meta.len() <= spec.size_cap_bytes {
|
||||
return;
|
||||
}
|
||||
|
||||
tracing::error!(
|
||||
path = %db_path.display(),
|
||||
size = meta.len(),
|
||||
cap = spec.size_cap_bytes,
|
||||
"LMDB db exceeds size cap, erasing"
|
||||
);
|
||||
let _ = fs::remove_file(&data);
|
||||
let _ = fs::remove_file(db_path.join("lock.mdb"));
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
use super::db_healthcheck::DbHealthChecker;
|
||||
use super::lmdb::{DbHealth, LmdbStore, is_map_full};
|
||||
use super::env_pool::SharedEnv;
|
||||
use crate::error::{Error, Result};
|
||||
use crate::file_picker::FFFMode;
|
||||
use crate::git::is_modified_status;
|
||||
use crate::lmdb::{DbHealth, LmdbStore, is_map_full};
|
||||
use heed::Database;
|
||||
use heed::types::{Bytes, SerdeBincode};
|
||||
use heed::{Database, Env};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use std::{collections::VecDeque, path::Path};
|
||||
|
||||
@@ -19,7 +20,7 @@ const AI_MAX_HISTORY_DAYS: f64 = 7.0; // Only consider accesses within 7 days
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FrecencyTracker {
|
||||
env: Env,
|
||||
env: SharedEnv,
|
||||
db: Database<Bytes, SerdeBincode<VecDeque<u64>>>,
|
||||
health: DbHealth,
|
||||
}
|
||||
@@ -77,7 +78,7 @@ impl LmdbStore for FrecencyTracker {
|
||||
// MAP_SIZE so we don't hit MDB_MAP_FULL before the open-time erase fires.
|
||||
const SIZE_CAP_BYTES: u64 = 12 * 1024 * 1024;
|
||||
|
||||
fn env(&self) -> &Env {
|
||||
fn shared_env(&self) -> &SharedEnv {
|
||||
&self.env
|
||||
}
|
||||
|
||||
@@ -85,7 +86,7 @@ impl LmdbStore for FrecencyTracker {
|
||||
&self.health
|
||||
}
|
||||
|
||||
fn purge_stale_data(env: &Env) -> Result<()> {
|
||||
fn purge_stale_data(env: &SharedEnv) -> Result<()> {
|
||||
let (deleted, pruned) = Self::purge_stale_entries(env)?;
|
||||
if deleted > 0 || pruned > 0 {
|
||||
tracing::info!(deleted, pruned, "Frecency GC purged entries");
|
||||
@@ -121,7 +122,7 @@ impl FrecencyTracker {
|
||||
/// Removes entries where all timestamps are older than MAX_HISTORY_DAYS,
|
||||
/// and prunes stale timestamps from entries that still have recent ones.
|
||||
/// Returns (deleted_count, pruned_count).
|
||||
fn purge_stale_entries(env: &Env) -> Result<(usize, usize)> {
|
||||
fn purge_stale_entries(env: &SharedEnv) -> Result<(usize, usize)> {
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
use heed::{Database, Env, EnvOpenOptions};
|
||||
use std::fs;
|
||||
use heed::{Database, Env};
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::sync::RwLock;
|
||||
use std::sync::atomic::{AtomicU8, Ordering};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use super::env_pool::{EnvSpec, SharedEnv};
|
||||
use crate::error::{Error, Result};
|
||||
|
||||
pub(crate) fn is_map_full(err: &heed::Error) -> bool {
|
||||
@@ -85,9 +84,13 @@ pub(crate) fn spawn_lmdb_gc<T: LmdbStore>(shared: Arc<RwLock<Option<T>>>) {
|
||||
let Some(ref tracker) = *guard else {
|
||||
return; // destroyed before we started
|
||||
};
|
||||
let env = tracker.env();
|
||||
// Trackers attaching to an already-pooled env must not repeat the
|
||||
// GC; the first opener's run flips the shared health flag.
|
||||
if !tracker.shared_env().try_start_gc() {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Err(e) = T::purge_stale_data(env) {
|
||||
if let Err(e) = T::purge_stale_data(tracker.shared_env()) {
|
||||
tracing::debug!("purge_stale_data failed: {e}");
|
||||
}
|
||||
|
||||
@@ -105,18 +108,6 @@ pub(crate) fn spawn_lmdb_gc<T: LmdbStore>(shared: Arc<RwLock<Option<T>>>) {
|
||||
}
|
||||
}
|
||||
|
||||
// Concurrent `mdb_env_open` calls on the same path can race on macOS
|
||||
// this is for some reason fixabtly by simple retry of the open
|
||||
fn is_transient_env_open_error(err: &heed::Error) -> bool {
|
||||
match err {
|
||||
heed::Error::Io(io) => matches!(
|
||||
io.kind(),
|
||||
std::io::ErrorKind::InvalidInput | std::io::ErrorKind::NotFound
|
||||
),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) trait LmdbStore: Sized + Send + Sync + 'static {
|
||||
/// Short label used to defferintiate different instances of this trait
|
||||
const LABEL: &'static str;
|
||||
@@ -127,85 +118,51 @@ pub(crate) trait LmdbStore: Sized + Send + Sync + 'static {
|
||||
/// Hard cap on `data.mdb` size.
|
||||
const SIZE_CAP_BYTES: u64;
|
||||
|
||||
/// Borrow the env in the read lock
|
||||
fn env(&self) -> &Env;
|
||||
/// Borrow the pooled env handle shared by every tracker of this path.
|
||||
fn shared_env(&self) -> &SharedEnv;
|
||||
/// Borrow the health flag from the tracker.
|
||||
fn health(&self) -> &DbHealth;
|
||||
|
||||
/// Borrow the raw heed env.
|
||||
fn env(&self) -> &Env {
|
||||
self.shared_env()
|
||||
}
|
||||
|
||||
/// Override to purge stale rows, compact, etc. Default no-op. Runs on
|
||||
/// the GC thread while a read lock is held against the shared handle,
|
||||
/// so destroy / re-init naturally wait for it.
|
||||
fn purge_stale_data(_env: &Env) -> Result<()> {
|
||||
fn purge_stale_data(_env: &SharedEnv) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Open the LMDB env. Returns env + a `DbHealth` starting in Pending;
|
||||
/// the GC thread spawned by `spawn_gc` flips it to Healthy. Write
|
||||
/// paths flip it to Degraded on MDB_MAP_FULL.
|
||||
/// Open (or join) the process-shared LMDB env for `db_path`. The health
|
||||
/// flag is per-env: the GC of the first opener flips it for everyone.
|
||||
#[tracing::instrument]
|
||||
fn open_env(db_path: &Path) -> Result<(Env, DbHealth)> {
|
||||
Self::erase_if_oversized(db_path);
|
||||
fs::create_dir_all(db_path).map_err(Error::CreateDir)?;
|
||||
let db = Self::LABEL;
|
||||
|
||||
const MAX_ATTEMPTS: u32 = 8;
|
||||
let mut attempt = 0u32;
|
||||
let env = loop {
|
||||
let result = unsafe {
|
||||
let mut opts = EnvOpenOptions::new();
|
||||
opts.map_size(Self::MAP_SIZE);
|
||||
if Self::MAX_DBS > 0 {
|
||||
opts.max_dbs(Self::MAX_DBS);
|
||||
}
|
||||
opts.open(db_path)
|
||||
};
|
||||
|
||||
match result {
|
||||
Ok(env) => break env,
|
||||
Err(e) if is_transient_env_open_error(&e) && attempt + 1 < MAX_ATTEMPTS => {
|
||||
attempt += 1;
|
||||
tracing::debug!(
|
||||
path = %db_path.display(),
|
||||
attempt,
|
||||
error = ?e,
|
||||
"transient LMDB env open error, retrying"
|
||||
);
|
||||
|
||||
thread::sleep(Duration::from_millis(50));
|
||||
}
|
||||
Err(e) => return Err(Error::EnvOpen { db, source: e }),
|
||||
}
|
||||
};
|
||||
|
||||
// Reclaim reader slots left behind by prior processes that died
|
||||
// without cleanup. Must run before we start any read txns (which
|
||||
// open_database_safe does) — otherwise we may hit MDB_READERS_FULL
|
||||
// on a fresh env just because lock.mdb still has stale entries
|
||||
// from a previous crash.
|
||||
//
|
||||
// This is the one LMDB maintenance call we run on the caller's
|
||||
// thread. If the lock file is genuinely wedged this will block
|
||||
// forever, but the alternative — never getting past init — is
|
||||
// worse and the bg-thread trick doesn't solve it anyway.
|
||||
match env.clear_stale_readers() {
|
||||
Ok(cleared) if cleared > 0 => {
|
||||
tracing::warn!(cleared, "reclaimed stale LMDB reader slots at open");
|
||||
}
|
||||
Ok(_) => {}
|
||||
Err(e) => tracing::debug!("clear_stale_readers at open failed: {e}"),
|
||||
}
|
||||
|
||||
Ok((env, DbHealth::new()))
|
||||
fn open_env(db_path: &Path) -> Result<(SharedEnv, DbHealth)> {
|
||||
let shared = SharedEnv::get_or_open(
|
||||
db_path,
|
||||
&EnvSpec {
|
||||
label: Self::LABEL,
|
||||
map_size: Self::MAP_SIZE,
|
||||
max_dbs: Self::MAX_DBS,
|
||||
size_cap_bytes: Self::SIZE_CAP_BYTES,
|
||||
},
|
||||
)?;
|
||||
let health = shared.health().clone();
|
||||
Ok((shared, health))
|
||||
}
|
||||
|
||||
/// Open or create a database without blocking on the LMDB writer mutex
|
||||
/// when the database already exists.
|
||||
fn open_database_safe<KC, DC>(env: &Env, name: Option<&str>) -> Result<Database<KC, DC>>
|
||||
fn open_database_safe<KC, DC>(env: &SharedEnv, name: Option<&str>) -> Result<Database<KC, DC>>
|
||||
where
|
||||
KC: 'static,
|
||||
DC: 'static,
|
||||
{
|
||||
let db = Self::LABEL;
|
||||
// mdb_dbi_open must not run from concurrent txns in this process.
|
||||
let _dbi_guard = env.lock_dbi_open();
|
||||
|
||||
let rtxn = env
|
||||
.read_txn()
|
||||
.map_err(|source| Error::DbStartReadTxn { db, source })?;
|
||||
@@ -237,23 +194,4 @@ pub(crate) trait LmdbStore: Sized + Send + Sync + 'static {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn erase_if_oversized(db_path: &Path) {
|
||||
let data = db_path.join("data.mdb");
|
||||
let Ok(meta) = fs::metadata(&data) else {
|
||||
return;
|
||||
};
|
||||
if meta.len() <= Self::SIZE_CAP_BYTES {
|
||||
return;
|
||||
}
|
||||
|
||||
tracing::error!(
|
||||
path = %db_path.display(),
|
||||
size = meta.len(),
|
||||
cap = Self::SIZE_CAP_BYTES,
|
||||
"LMDB db exceeds size cap, erasing"
|
||||
);
|
||||
let _ = fs::remove_file(&data);
|
||||
let _ = fs::remove_file(db_path.join("lock.mdb"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
pub(crate) mod env_pool;
|
||||
pub(crate) mod lmdb;
|
||||
|
||||
pub mod db_healthcheck;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use super::db_healthcheck::DbHealthChecker;
|
||||
use super::lmdb::{DbHealth, LmdbStore, is_map_full};
|
||||
use super::env_pool::SharedEnv;
|
||||
use crate::error::Error;
|
||||
use crate::lmdb::{DbHealth, LmdbStore, is_map_full};
|
||||
use heed::types::{Bytes, SerdeBincode};
|
||||
use heed::{Database, Env};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -27,7 +28,7 @@ struct HistoryEntry {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct QueryTracker {
|
||||
env: Env,
|
||||
env: SharedEnv,
|
||||
// Database for (project_path, query) -> QueryMatchEntry mappings
|
||||
query_file_db: Database<Bytes, SerdeBincode<QueryMatchEntry>>,
|
||||
// Database for project_path -> VecDeque<HistoryEntry> mappings (file picker)
|
||||
@@ -92,7 +93,7 @@ impl LmdbStore for QueryTracker {
|
||||
const MAX_DBS: u32 = 16;
|
||||
const SIZE_CAP_BYTES: u64 = 8 * 1024 * 1024;
|
||||
|
||||
fn env(&self) -> &Env {
|
||||
fn shared_env(&self) -> &SharedEnv {
|
||||
&self.env
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,22 @@ pub enum Error {
|
||||
#[source]
|
||||
source: heed::Error,
|
||||
},
|
||||
#[error(
|
||||
"LMDB env at {path} is already open as the '{open_as}' database with different options; requested by '{requested_as}'. Use a distinct path per database."
|
||||
)]
|
||||
EnvSpecMismatch {
|
||||
path: std::path::PathBuf,
|
||||
open_as: &'static str,
|
||||
requested_as: &'static str,
|
||||
},
|
||||
#[error(
|
||||
"The {db} database at {path} is still used by {holders} other tracker(s) in this process"
|
||||
)]
|
||||
DbInUse {
|
||||
db: &'static str,
|
||||
path: std::path::PathBuf,
|
||||
holders: usize,
|
||||
},
|
||||
#[error("Failed to create {db} database: {source}")]
|
||||
DbCreate {
|
||||
db: &'static str,
|
||||
|
||||
@@ -229,9 +229,19 @@ pub(crate) fn grep_search<'a>(
|
||||
return result;
|
||||
}
|
||||
|
||||
// Keep any explicit FilePath scope (AI mode `path/to/file.ext` prefix) so the
|
||||
// fallback can't leak matches outside the file the user pinned. Only the
|
||||
// swallowed operator/glob tokens are dropped. See issue #756.
|
||||
let scoped_constraints: fff_query_parser::ConstraintVec<'_> = query
|
||||
.constraints
|
||||
.iter()
|
||||
.filter(|c| matches!(c, fff_query_parser::Constraint::FilePath(_)))
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
let literal_query = FFFQuery {
|
||||
raw_query: query.raw_query,
|
||||
constraints: Vec::new(),
|
||||
constraints: scoped_constraints,
|
||||
fuzzy_query: fff_query_parser::FuzzyQuery::Text(raw),
|
||||
location: None,
|
||||
};
|
||||
|
||||
@@ -461,3 +461,58 @@ fn test_grep_no_duplicates_with_overflow_trailing_bits() {
|
||||
result.matches.len()
|
||||
);
|
||||
}
|
||||
|
||||
/// Issue #756: an AI-mode regex query with an inline FilePath scope and
|
||||
/// top-level alternation. The regex fragments are swallowed as bogus Glob
|
||||
/// constraints, the constrained search finds nothing, and the literal/regex
|
||||
/// fallback must NOT drop the FilePath scope — otherwise the `|` branch leaks
|
||||
/// matches into files outside the pinned path.
|
||||
#[test]
|
||||
fn regex_fallback_keeps_file_path_scope_issue_756() {
|
||||
use fff_query_parser::{AiGrepConfig, QueryParser};
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let base = crate::path_utils::canonicalize(dir.path()).unwrap();
|
||||
std::fs::create_dir(base.join("scope")).unwrap();
|
||||
std::fs::write(
|
||||
base.join("scope").join("target.css"),
|
||||
"/* ---------- target ---------- */\n",
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(
|
||||
base.join("outside.css"),
|
||||
"/* ---------- outside ---------- */\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut picker = FilePicker::new(FilePickerOptions {
|
||||
base_path: base.to_str().unwrap().into(),
|
||||
watch: false,
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap();
|
||||
picker.collect_files().unwrap();
|
||||
|
||||
let options = crate::GrepSearchOptions {
|
||||
mode: super::GrepMode::Regex,
|
||||
smart_case: true,
|
||||
max_matches_per_file: 80,
|
||||
page_limit: 100,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let raw = r"scope/target.css ^/\* |^\s*/\* ----------";
|
||||
let query = QueryParser::new(AiGrepConfig).parse(raw);
|
||||
let result = picker.grep(&query, &options);
|
||||
let mut paths: Vec<String> = result
|
||||
.files
|
||||
.iter()
|
||||
.map(|f| f.relative_path(&picker))
|
||||
.collect();
|
||||
paths.sort();
|
||||
|
||||
assert_eq!(
|
||||
paths,
|
||||
vec!["scope/target.css"],
|
||||
"regex fallback must not leak outside the FilePath scope"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::grep::{GrepContext, perform_grep};
|
||||
use super::prefilter::prefilter_with_filepath_retry;
|
||||
use super::prefilter::prefilter_files;
|
||||
use super::sink::{SinkState, debug_assert_newline_terminator};
|
||||
use super::types::{GrepResult, GrepSearchOptions};
|
||||
use crate::index::{BigramFilter, BigramOverlay, bigram_boundary, literal_candidates};
|
||||
@@ -121,7 +121,8 @@ pub(crate) fn multi_grep_search<'a>(
|
||||
let bigram_candidates = literal_candidates(bigram_index, bigram_overlay, patterns);
|
||||
let base_file_count = bigram_boundary(bigram_overlay, files.len());
|
||||
|
||||
let (files_to_search, filtered_file_count) = prefilter_with_filepath_retry(
|
||||
// Constraints are separate from patterns, so a miss must not broaden the search.
|
||||
let (files_to_search, filtered_file_count) = prefilter_files(
|
||||
files,
|
||||
constraints,
|
||||
bigram_candidates.as_deref(),
|
||||
|
||||
@@ -50,7 +50,7 @@ pub(super) fn prefilter_with_filepath_retry<'a>(
|
||||
/// Single pass prefilter that doesn't involve file reading
|
||||
/// allocates only amount of memory required for storing references of the FileItems have to be
|
||||
/// opened for grepping unaviodably, in the worst case allocates N * <word> memory if no prefilter needed
|
||||
fn prefilter_files<'a>(
|
||||
pub(crate) fn prefilter_files<'a>(
|
||||
files: &'a [FileItem],
|
||||
constraints: &[Constraint<'_>],
|
||||
bigram_candidates: Option<&[u64]>,
|
||||
|
||||
@@ -123,7 +123,7 @@ mod tests {
|
||||
// Source trees under $HOME stay searchable.
|
||||
for rel in [
|
||||
"dev/chromium/third_party/blink/renderer/core/dom/node.cc",
|
||||
"dev/fff.nvim/crates/fff-core/src/lib.rs",
|
||||
"dev/fff/crates/fff-core/src/lib.rs",
|
||||
"Documents/notes/todo.md",
|
||||
"dev/myproj/pkg/mod/thing.go",
|
||||
] {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! # FFF Search — High-performance file finder core
|
||||
//!
|
||||
//! This crate provides the core search engine for [FFF (Fast File Finder)](https://github.com/dmtrKovalenko/fff.nvim).
|
||||
//! This crate provides the core search engine for [FFF (Fast File Finder)](https://github.com/dmtrKovalenko/fff).
|
||||
//! It includes filesystem indexing with real-time watching, fuzzy matching powered
|
||||
//! by [frizbee](https://docs.rs/neo_frizbee), frecency scoring backed by LMDB,
|
||||
//! and multi-mode grep search.
|
||||
|
||||
@@ -491,20 +491,31 @@ impl<T: LmdbStore> SharedDb<T> {
|
||||
|
||||
/// Drop the in-memory tracker and delete the on-disk database directory.
|
||||
///
|
||||
/// Acquires the write lock, ensuring all readers (including any active mmap
|
||||
/// access) are finished before the LMDB environment is closed and the files
|
||||
/// are removed.
|
||||
///
|
||||
/// Returns `Ok(Some(path))` with the deleted path, or `Ok(None)` if no tracker was initialized.
|
||||
pub fn destroy(&self) -> Result<Option<PathBuf>, Error> {
|
||||
let mut guard = self.write()?;
|
||||
let Some(tracker) = guard.take() else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let closing_event = match tracker.shared_env().destroy() {
|
||||
Ok(closing) => closing,
|
||||
Err(e) => {
|
||||
*guard = Some(tracker);
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
|
||||
let db_path = tracker.env().path().to_path_buf();
|
||||
// Drop closes the LMDB env and unmaps the files
|
||||
drop(tracker);
|
||||
drop(guard);
|
||||
|
||||
// Deleting before mdb_env_close finishes would race the unmap.
|
||||
if let Some(event) = closing_event {
|
||||
event.wait_timeout(Duration::from_secs(5));
|
||||
}
|
||||
|
||||
std::fs::remove_dir_all(&db_path).map_err(|source| Error::RemoveDbDir {
|
||||
path: db_path.clone(),
|
||||
source,
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
//! One process must be able to hold many trackers over the same LMDB path
|
||||
//! (issues #700/#760): they share a single pooled env instead of failing
|
||||
//! with `EnvAlreadyOpened`.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use fff_search::frecency::FrecencyTracker;
|
||||
use fff_search::query_tracker::QueryTracker;
|
||||
use fff_search::shared::SharedFrecency;
|
||||
|
||||
fn unique_dir(name: &str) -> PathBuf {
|
||||
let dir = std::env::temp_dir().join(format!("fff-env-pool-{name}-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
dir
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn same_path_trackers_share_one_env() {
|
||||
let dir = unique_dir("share");
|
||||
let file = Path::new("/virtual/env-pool/shared.rs");
|
||||
|
||||
let a = FrecencyTracker::open(&dir).expect("first open");
|
||||
let b = FrecencyTracker::open(&dir).expect("second open in the same process (#700/#760)");
|
||||
|
||||
a.track_access(file).expect("write via a");
|
||||
assert_eq!(b.access_count(file).expect("read via b"), 1);
|
||||
|
||||
drop(a);
|
||||
b.track_access(file)
|
||||
.expect("b must stay usable after a drops");
|
||||
assert_eq!(b.access_count(file).unwrap(), 2);
|
||||
drop(b);
|
||||
|
||||
let c = FrecencyTracker::open(&dir).expect("reopen after all handles dropped");
|
||||
assert_eq!(
|
||||
c.access_count(file).unwrap(),
|
||||
2,
|
||||
"data persisted across reopen"
|
||||
);
|
||||
|
||||
drop(c);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concurrent_open_and_drop_never_collide() {
|
||||
let dir = unique_dir("hammer");
|
||||
let file = Path::new("/virtual/env-pool/hammer.rs");
|
||||
|
||||
let mut handles = Vec::new();
|
||||
for t in 0..8 {
|
||||
let dir = dir.clone();
|
||||
handles.push(std::thread::spawn(move || {
|
||||
for i in 0..100 {
|
||||
let tracker = FrecencyTracker::open(&dir)
|
||||
.unwrap_or_else(|e| panic!("thread {t} iteration {i}: {e}"));
|
||||
if i % 20 == 0 {
|
||||
tracker.track_access(file).expect("track access");
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
for handle in handles {
|
||||
handle.join().expect("no thread may panic");
|
||||
}
|
||||
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_store_on_same_path_is_rejected_with_clear_error() {
|
||||
let dir = unique_dir("mismatch");
|
||||
|
||||
let _frecency = FrecencyTracker::open(&dir).expect("frecency open");
|
||||
let err = QueryTracker::open(&dir).expect_err("env options differ, must be rejected");
|
||||
|
||||
let msg = err.to_string();
|
||||
assert!(
|
||||
msg.contains("frecency") && msg.contains("query"),
|
||||
"error must name both stores so the user can fix their config, got: {msg}"
|
||||
);
|
||||
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn destroy_refuses_while_shared_then_succeeds_when_sole() {
|
||||
let dir = unique_dir("destroy");
|
||||
let file = Path::new("/virtual/env-pool/destroy.rs");
|
||||
|
||||
let shared = SharedFrecency::default();
|
||||
shared
|
||||
.init(FrecencyTracker::open(&dir).expect("init open"))
|
||||
.expect("init");
|
||||
let other = FrecencyTracker::open(&dir).expect("second handle over the same db");
|
||||
|
||||
shared
|
||||
.destroy()
|
||||
.expect_err("destroy must refuse while another tracker uses the env");
|
||||
|
||||
// Refusal must keep both the files and the shared handle intact.
|
||||
assert!(
|
||||
dir.join("data.mdb").exists(),
|
||||
"db files survive a refused destroy"
|
||||
);
|
||||
shared
|
||||
.read()
|
||||
.expect("read lock")
|
||||
.as_ref()
|
||||
.expect("tracker restored after refused destroy")
|
||||
.track_access(file)
|
||||
.expect("shared handle still works");
|
||||
|
||||
drop(other);
|
||||
let removed = shared
|
||||
.destroy()
|
||||
.expect("sole-owner destroy succeeds")
|
||||
.expect("a path was removed");
|
||||
assert!(
|
||||
!removed.exists(),
|
||||
"db dir deleted once nobody shares the env"
|
||||
);
|
||||
}
|
||||
@@ -222,6 +222,17 @@ fn multi_grep_with_file_path_suffix_constraint() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_grep_with_missing_file_path_constraint_returns_no_matches() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let picker = create_picker(tmp.path(), &[("other.lua", "handleRequest\n")]);
|
||||
|
||||
let constraints = [Constraint::FilePath("missing.lua")];
|
||||
let result = picker.multi_grep(&["handleRequest"], &constraints, &plain_opts());
|
||||
|
||||
assert!(result.matches.is_empty());
|
||||
}
|
||||
|
||||
/// Glob constraints must match native Windows paths — the picker normalises
|
||||
/// separators when handing paths to the glob matcher.
|
||||
#[test]
|
||||
|
||||
@@ -3,7 +3,7 @@ name = "fff-grep"
|
||||
description = "File grepping logic for fff"
|
||||
license = "MIT"
|
||||
authors = ["Dmitriy Kovalenko <dmtr.kovalenko@outlok.com>"]
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
edition = "2024"
|
||||
|
||||
[lints]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "fff-mcp"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
edition = "2024"
|
||||
description = "MCP server for FFF file finder - drop-in replacement for AI code assistant search tools"
|
||||
license = "MIT"
|
||||
@@ -19,8 +19,8 @@ ripgrep = ["fff/ripgrep", "fff-query-parser/ripgrep"]
|
||||
zlob = ["fff/zlob", "fff-query-parser/zlob"]
|
||||
|
||||
[dependencies]
|
||||
fff = { package = "fff-search", path = "../fff-core", default-features = false , version = "0.10.3", features = ["definitions"] }
|
||||
fff-query-parser = { path = "../fff-query-parser", default-features = false , version = "0.10.3" }
|
||||
fff = { package = "fff-search", path = "../fff-core", default-features = false , version = "0.10.4", features = ["definitions"] }
|
||||
fff-query-parser = { path = "../fff-query-parser", default-features = false , version = "0.10.4" }
|
||||
mimalloc = { workspace = true }
|
||||
rmcp = { version = "1.7.0", features = ["server", "transport-io"] }
|
||||
schemars = "1.0"
|
||||
@@ -30,3 +30,13 @@ tokio = { version = "1", features = ["full"] }
|
||||
tracing = { workspace = true }
|
||||
git2 = { workspace = true }
|
||||
clap = { version = "4", features = ["derive", "env"] }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows-sys = { version = "0.60", features = [
|
||||
"Win32_Foundation",
|
||||
"Win32_System_Threading",
|
||||
"Win32_System_Diagnostics_ToolHelp",
|
||||
] }
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.8"
|
||||
|
||||
+59
-12
@@ -1,9 +1,12 @@
|
||||
mod cursor;
|
||||
mod healthcheck;
|
||||
mod output;
|
||||
mod parent;
|
||||
mod server;
|
||||
mod update_check;
|
||||
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use clap::Parser;
|
||||
use fff::file_picker::FilePicker;
|
||||
use fff::frecency::FrecencyTracker;
|
||||
@@ -92,7 +95,7 @@ pub const MCP_INSTRUCTIONS: &str = concat!(
|
||||
" !generated/ - exclude generated code",
|
||||
);
|
||||
|
||||
/// FFF MCP Server -- a high performance & accuracy file finder for AI code assistants.
|
||||
/// FFF MCP Server - a high performance & accuracy file finder for AI code assistants.
|
||||
#[derive(Parser)]
|
||||
#[command(name = "fff-mcp", version = concat!(env!("CARGO_PKG_VERSION"), " (", env!("FFF_GIT_HASH"), ")"))]
|
||||
pub(crate) struct Args {
|
||||
@@ -131,6 +134,7 @@ pub(crate) struct Args {
|
||||
|
||||
/// Disable the content index built after the initial scan.
|
||||
/// This makes grep calls slower but consumes less RAM (recommended to not turn off)
|
||||
#[arg(long = "no-content-indexing")]
|
||||
no_content_indexing: bool,
|
||||
|
||||
/// Explicitly enable content indexing even when `--no-warmup` is set.
|
||||
@@ -182,11 +186,12 @@ pub(crate) struct Args {
|
||||
#[arg(long = "healthcheck")]
|
||||
pub(crate) healthcheck: bool,
|
||||
|
||||
/// Exit after this many seconds of inactivity. 0 = never exit.
|
||||
/// Timeout of inactivity after which fff mcp will be exited. Even if the parent process
|
||||
/// is alive we don't want to occupy resources on index and file watches if fff is unused
|
||||
#[arg(
|
||||
long = "idle-timeout-secs",
|
||||
env = "FFF_MCP_IDLE_TIMEOUT_SECS",
|
||||
default_value_t = 900
|
||||
default_value_t = 60 * 60
|
||||
)]
|
||||
idle_timeout_secs: u64,
|
||||
}
|
||||
@@ -342,9 +347,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
};
|
||||
|
||||
if idle_timeout_secs > 0 {
|
||||
let parent_watcher = parent::ParentWatcher::new();
|
||||
match &parent_watcher {
|
||||
Some(watcher) => tracing::info!(
|
||||
"Watching parent process (pid {}); will exit when it dies",
|
||||
watcher.parent_pid()
|
||||
),
|
||||
None => tracing::warn!(
|
||||
"Parent process liveness detection unavailable; idle timeout will exit unconditionally"
|
||||
),
|
||||
}
|
||||
|
||||
if idle_timeout_secs > 0 || parent_watcher.is_some() {
|
||||
last_activity.store(
|
||||
std::time::SystemTime::now()
|
||||
SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map(|d| d.as_secs())
|
||||
.unwrap_or(0),
|
||||
@@ -353,9 +369,27 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let last_activity_for_watchdog = last_activity.clone();
|
||||
tokio::spawn(async move {
|
||||
let tick = std::time::Duration::from_secs(60);
|
||||
let tick = watchdog_interval();
|
||||
loop {
|
||||
tokio::time::sleep(tick).await;
|
||||
|
||||
if let Some(ref watcher) = parent_watcher {
|
||||
if !watcher.parent_alive() {
|
||||
tracing::info!(
|
||||
"Parent process (pid {}) exited, shutting down",
|
||||
watcher.parent_pid()
|
||||
);
|
||||
flush_logs_and_exit().await;
|
||||
}
|
||||
// Parent is alive: it owns our lifecycle, never exit on idle
|
||||
// Clients like Codex do not restart MCP servers @see #703
|
||||
continue;
|
||||
}
|
||||
|
||||
if idle_timeout_secs == 0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
let now = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map(|d| d.as_secs())
|
||||
@@ -363,12 +397,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let last = last_activity_for_watchdog.load(std::sync::atomic::Ordering::Relaxed);
|
||||
if now.saturating_sub(last) >= idle_timeout_secs {
|
||||
tracing::info!(
|
||||
"Exiting after {}s of inactivity (idle_timeout_secs={})",
|
||||
now.saturating_sub(last),
|
||||
idle_timeout_secs
|
||||
);
|
||||
std::process::exit(0);
|
||||
tracing::info!(?idle_timeout_secs, "Exiting due to inactivity",);
|
||||
flush_logs_and_exit().await;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -395,3 +425,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Tracing appender is non blocking, to get full log give it some time before hard exit
|
||||
async fn flush_logs_and_exit() -> ! {
|
||||
tokio::time::sleep(std::time::Duration::from_millis(250)).await;
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
fn watchdog_interval() -> Duration {
|
||||
if cfg!(debug_assertions)
|
||||
&& let Some(milliseconds) = std::env::var("FFF_MCP_TEST_WATCHDOG_INTERVAL_MS")
|
||||
.ok()
|
||||
.and_then(|value| value.parse().ok())
|
||||
{
|
||||
return Duration::from_millis(milliseconds);
|
||||
}
|
||||
Duration::from_secs(60)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
#[cfg(unix)]
|
||||
mod imp {
|
||||
pub struct ParentWatcher {
|
||||
ppid: u32,
|
||||
}
|
||||
|
||||
impl ParentWatcher {
|
||||
pub fn new() -> Option<Self> {
|
||||
let ppid = std::os::unix::process::parent_id();
|
||||
// ppid <= 1 means we were spawned by init and can't detect death
|
||||
(ppid > 1).then_some(Self { ppid })
|
||||
}
|
||||
|
||||
pub fn parent_pid(&self) -> u32 {
|
||||
self.ppid
|
||||
}
|
||||
|
||||
// When the parent dies the kernel reparents us, so getppid() changes.
|
||||
// Race-free and immune to PID reuse, unlike kill(ppid, 0).
|
||||
pub fn parent_alive(&self) -> bool {
|
||||
std::os::unix::process::parent_id() == self.ppid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
mod imp {
|
||||
use windows_sys::Win32::Foundation::{CloseHandle, HANDLE, INVALID_HANDLE_VALUE, WAIT_TIMEOUT};
|
||||
use windows_sys::Win32::System::Diagnostics::ToolHelp::{
|
||||
CreateToolhelp32Snapshot, PROCESSENTRY32, Process32First, Process32Next, TH32CS_SNAPPROCESS,
|
||||
};
|
||||
use windows_sys::Win32::System::Threading::{
|
||||
GetCurrentProcessId, OpenProcess, PROCESS_SYNCHRONIZE, WaitForSingleObject,
|
||||
};
|
||||
|
||||
pub struct ParentWatcher {
|
||||
handle: HANDLE,
|
||||
ppid: u32,
|
||||
}
|
||||
|
||||
// HANDLE is a raw pointer; it is only ever used via WaitForSingleObject
|
||||
// which is thread-safe, so moving/sharing the watcher across threads is fine.
|
||||
unsafe impl Send for ParentWatcher {}
|
||||
unsafe impl Sync for ParentWatcher {}
|
||||
|
||||
impl ParentWatcher {
|
||||
pub fn new() -> Option<Self> {
|
||||
let ppid = parent_pid_of_current()?;
|
||||
let handle = unsafe { OpenProcess(PROCESS_SYNCHRONIZE, 0, ppid) };
|
||||
if handle.is_null() {
|
||||
return None;
|
||||
}
|
||||
// Holding the handle pins the PID, preventing reuse for the process lifetime
|
||||
Some(Self { handle, ppid })
|
||||
}
|
||||
|
||||
pub fn parent_pid(&self) -> u32 {
|
||||
self.ppid
|
||||
}
|
||||
|
||||
pub fn parent_alive(&self) -> bool {
|
||||
unsafe { WaitForSingleObject(self.handle, 0) == WAIT_TIMEOUT }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ParentWatcher {
|
||||
fn drop(&mut self) {
|
||||
unsafe { CloseHandle(self.handle) };
|
||||
}
|
||||
}
|
||||
|
||||
fn parent_pid_of_current() -> Option<u32> {
|
||||
unsafe {
|
||||
let snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
if snapshot == INVALID_HANDLE_VALUE {
|
||||
return None;
|
||||
}
|
||||
let mut entry: PROCESSENTRY32 = std::mem::zeroed();
|
||||
entry.dwSize = std::mem::size_of::<PROCESSENTRY32>() as u32;
|
||||
let current = GetCurrentProcessId();
|
||||
let mut found = None;
|
||||
if Process32First(snapshot, &mut entry) != 0 {
|
||||
loop {
|
||||
if entry.th32ProcessID == current {
|
||||
found = Some(entry.th32ParentProcessID);
|
||||
break;
|
||||
}
|
||||
if Process32Next(snapshot, &mut entry) == 0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseHandle(snapshot);
|
||||
found
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub use imp::ParentWatcher;
|
||||
@@ -7,7 +7,6 @@ use fff_query_parser::AiGrepConfig;
|
||||
use rmcp::handler::server::wrapper::Parameters;
|
||||
use rmcp::model::*;
|
||||
use rmcp::{ServerHandler, schemars, tool, tool_handler, tool_router};
|
||||
use std::borrow::Cow;
|
||||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
@@ -421,7 +420,12 @@ impl FffServer {
|
||||
/// IMPORTANT: Keep queries SHORT — prefer 1-2 terms max.
|
||||
#[tool(
|
||||
name = "find_files",
|
||||
description = "Fuzzy file search by name. Searches FILE NAMES, not file contents. Use it when you need to find a file, not a definition. Use grep instead for searching code content (definitions, usage patterns). Supports fuzzy matching, path prefixes ('src/'), and glob constraints ('name **/src/*.{ts,tsx} !test/'). IMPORTANT: Keep queries SHORT — prefer 1-2 terms max. Multiple words are a waterfall (each narrows results), NOT OR. If unsure, start broad with 1 term and refine."
|
||||
description = "Fuzzy file search by name. Searches FILE NAMES, not file contents. Use it when you need to find a file, not a definition. Use grep instead for searching code content (definitions, usage patterns). Supports fuzzy matching, path prefixes ('src/'), and glob constraints ('name **/src/*.{ts,tsx} !test/'). IMPORTANT: Keep queries SHORT — prefer 1-2 terms max. Multiple words are a waterfall (each narrows results), NOT OR. If unsure, start broad with 1 term and refine.",
|
||||
annotations(
|
||||
read_only_hint = true,
|
||||
destructive_hint = false,
|
||||
open_world_hint = false
|
||||
)
|
||||
)]
|
||||
fn find_files(
|
||||
&self,
|
||||
@@ -536,7 +540,12 @@ impl FffServer {
|
||||
/// Prefer plain text over regex. Filter files with constraints.
|
||||
#[tool(
|
||||
name = "grep",
|
||||
description = "Search file contents. Search for bare identifiers (e.g. 'InProgressQuote', 'ActorAuth'), NOT code syntax or regex. Filter files with constraints (e.g. '*.rs query', 'src/ query'). Use filename, directory (ending with /) or glob expressions to prefilter. See server instructions for constraint syntax and core rules."
|
||||
description = "Search file contents. Search for bare identifiers (e.g. 'InProgressQuote', 'ActorAuth'), NOT code syntax or regex. Filter files with constraints (e.g. '*.rs query', 'src/ query'). Use filename, directory (ending with /) or glob expressions to prefilter. See server instructions for constraint syntax and core rules.",
|
||||
annotations(
|
||||
read_only_hint = true,
|
||||
destructive_hint = false,
|
||||
open_world_hint = false
|
||||
)
|
||||
)]
|
||||
fn grep(
|
||||
&self,
|
||||
@@ -573,7 +582,12 @@ impl FffServer {
|
||||
/// Patterns are literal text — NEVER escape special characters.
|
||||
#[tool(
|
||||
name = "multi_grep",
|
||||
description = "Search file contents for lines matching ANY of multiple patterns (OR logic). IMPORTANT: This returns files where ANY query matches, NOT all patterns. Patterns are literal text — NEVER escape special characters (no \\( \\) \\. etc). Faster than regex alternation for literal text. See server instructions for constraint syntax."
|
||||
description = "Search file contents for lines matching ANY of multiple patterns (OR logic). IMPORTANT: This returns files where ANY query matches, NOT all patterns. Patterns are literal text — NEVER escape special characters (no \\( \\) \\. etc). Faster than regex alternation for literal text. See server instructions for constraint syntax.",
|
||||
annotations(
|
||||
read_only_hint = true,
|
||||
destructive_hint = false,
|
||||
open_world_hint = false
|
||||
)
|
||||
)]
|
||||
fn multi_grep(
|
||||
&self,
|
||||
@@ -613,61 +627,12 @@ impl FffServer {
|
||||
.ok_or_else(|| ErrorData::internal_error("File picker not initialized", None))?;
|
||||
let patterns_refs: Vec<&str> = params.patterns.iter().map(|s| s.as_str()).collect();
|
||||
|
||||
let parser = fff_query_parser::QueryParser::new(fff_query_parser::AiGrepConfig);
|
||||
let parsed_constraints = parser.parse(constraint_query);
|
||||
let constraints = parsed_constraints.constraints.as_slice();
|
||||
let parser = QueryParser::new(AiGrepConfig);
|
||||
let constraints = parser.parse_constraints(constraint_query);
|
||||
|
||||
let result = picker.multi_grep(&patterns_refs, constraints, &options);
|
||||
let result = picker.multi_grep(&patterns_refs, &constraints, &options);
|
||||
let file_refs: Vec<&FileItem> = result.files.to_vec();
|
||||
|
||||
if result.matches.is_empty() && file_offset == 0 {
|
||||
// Fallback: try individual patterns with plain grep
|
||||
let (fallback_options, _) =
|
||||
make_grep_options(output_mode, GrepMode::PlainText, 0, context);
|
||||
|
||||
let fallback_options = GrepSearchOptions {
|
||||
time_budget_ms: 3000,
|
||||
before_context: 0,
|
||||
..fallback_options
|
||||
};
|
||||
|
||||
for pat in ¶ms.patterns {
|
||||
let full_query: Cow<str> = if !constraint_query.is_empty() {
|
||||
Cow::Owned(format!("{} {}", constraint_query, pat))
|
||||
} else {
|
||||
Cow::Borrowed(pat)
|
||||
};
|
||||
|
||||
let parsed = parser.parse(&full_query);
|
||||
let fb_result = picker.grep(&parsed, &fallback_options);
|
||||
|
||||
if !fb_result.matches.is_empty() {
|
||||
let fb_file_refs: Vec<&FileItem> = fb_result.files.to_vec();
|
||||
let mut cs = self.lock_cursors()?;
|
||||
let text = &GrepFormatter {
|
||||
matches: &fb_result.matches,
|
||||
files: &fb_file_refs,
|
||||
total_matched: fb_result.matches.len(),
|
||||
next_file_offset: fb_result.next_file_offset,
|
||||
output_mode,
|
||||
max_results,
|
||||
show_context: false,
|
||||
auto_expand_defs: auto_expand,
|
||||
picker,
|
||||
}
|
||||
.format(&mut cs);
|
||||
return Ok(CallToolResult::success(vec![Content::text(format!(
|
||||
"0 multi-pattern matches. Plain grep fallback for \"{}\":\n{}",
|
||||
pat, text
|
||||
))]));
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(CallToolResult::success(vec![Content::text(
|
||||
"0 matches.".to_string(),
|
||||
)]));
|
||||
}
|
||||
|
||||
if result.matches.is_empty() {
|
||||
return Ok(CallToolResult::success(vec![Content::text(
|
||||
"0 matches.".to_string(),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::sync::OnceLock;
|
||||
|
||||
const REPO: &str = "dmtrKovalenko/fff.nvim";
|
||||
const REPO: &str = "dmtrKovalenko/fff";
|
||||
const CURRENT_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
static UPDATE_NOTICE: OnceLock<String> = OnceLock::new();
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
use std::process::{Child, ChildStdin, Command, Stdio};
|
||||
use std::sync::mpsc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
const BIN: &str = env!("CARGO_BIN_EXE_fff-mcp");
|
||||
|
||||
#[test]
|
||||
fn stays_alive_while_parent_alive_despite_idle_timeout() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
std::fs::write(dir.path().join("a.txt"), "hello").unwrap();
|
||||
|
||||
let mut child = Command::new(BIN)
|
||||
.arg(dir.path())
|
||||
.args([
|
||||
"--no-update-check",
|
||||
"--no-warmup",
|
||||
"--no-watch",
|
||||
"--idle-timeout-secs",
|
||||
"1",
|
||||
])
|
||||
.arg("--log-file")
|
||||
.arg(dir.path().join("test.log"))
|
||||
.env("FFF_MCP_TEST_WATCHDOG_INTERVAL_MS", "100")
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::null())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
let mut stdin = child.stdin.take().unwrap();
|
||||
let stdout_lines = spawn_line_reader(child.stdout.take().unwrap());
|
||||
do_handshake(&mut stdin, &stdout_lines);
|
||||
|
||||
// Wait past the idle timeout and several watchdog ticks.
|
||||
std::thread::sleep(Duration::from_secs(2));
|
||||
assert!(
|
||||
child.try_wait().unwrap().is_none(),
|
||||
"fff-mcp exited on idle timeout even though its parent is alive"
|
||||
);
|
||||
|
||||
// Closing stdin ends the transport; the server must still shut down cleanly.
|
||||
drop(stdin);
|
||||
wait_for_exit(&mut child, Duration::from_secs(15));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn exits_when_parent_dies_even_without_idle_timeout() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
std::fs::write(dir.path().join("a.txt"), "hello").unwrap();
|
||||
let log_path = dir.path().join("test.log");
|
||||
let exit_signal = dir.path().join("exit-parent");
|
||||
|
||||
// Intermediary parent: sh backgrounds fff-mcp and waits until the handshake
|
||||
// completes before dying and orphaning it.
|
||||
let mut sh = Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(
|
||||
// Preserve stdin before POSIX shells assign /dev/null to background jobs.
|
||||
r#"exec 3<&0
|
||||
"$1" "$2" --no-update-check --no-warmup --no-watch \
|
||||
--idle-timeout-secs 0 --log-file "$3" <&3 &
|
||||
while [ ! -e "$4" ]; do sleep 0.1; done"#,
|
||||
)
|
||||
.arg("sh")
|
||||
.arg(BIN)
|
||||
.arg(dir.path())
|
||||
.arg(&log_path)
|
||||
.arg(&exit_signal)
|
||||
.env("FFF_MCP_TEST_WATCHDOG_INTERVAL_MS", "100")
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::null())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
let mut stdin = sh.stdin.take().unwrap();
|
||||
let stdout_lines = spawn_line_reader(sh.stdout.take().unwrap());
|
||||
do_handshake(&mut stdin, &stdout_lines);
|
||||
|
||||
std::fs::write(exit_signal, "").unwrap();
|
||||
sh.wait().unwrap();
|
||||
|
||||
// We still hold the stdin write end, so the only exit path is the parent
|
||||
// liveness check. EOF on stdout means fff-mcp closed it by exiting.
|
||||
let deadline = Instant::now() + Duration::from_secs(5);
|
||||
loop {
|
||||
match stdout_lines.recv_timeout(deadline.saturating_duration_since(Instant::now())) {
|
||||
Ok(_) => continue,
|
||||
Err(mpsc::RecvTimeoutError::Disconnected) => break,
|
||||
Err(mpsc::RecvTimeoutError::Timeout) => {
|
||||
panic!("fff-mcp did not exit within 5s of its parent dying")
|
||||
}
|
||||
}
|
||||
}
|
||||
drop(stdin);
|
||||
|
||||
let logs = read_session_logs(dir.path());
|
||||
assert!(
|
||||
logs.contains("Parent process") && logs.contains("exited, shutting down"),
|
||||
"expected parent-death exit reason in logs, got:\n{}",
|
||||
logs
|
||||
);
|
||||
}
|
||||
|
||||
fn do_handshake(stdin: &mut ChildStdin, stdout_lines: &mpsc::Receiver<String>) {
|
||||
let initialize = serde_json::json!({
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "initialize",
|
||||
"params": {
|
||||
"protocolVersion": "2024-11-05",
|
||||
"capabilities": {},
|
||||
"clientInfo": { "name": "parent-liveness-test", "version": "0.0.0" }
|
||||
}
|
||||
});
|
||||
writeln!(stdin, "{}", initialize).unwrap();
|
||||
stdin.flush().unwrap();
|
||||
|
||||
let response = stdout_lines
|
||||
.recv_timeout(Duration::from_secs(30))
|
||||
.expect("no initialize response within 30s");
|
||||
assert!(
|
||||
response.contains("\"serverInfo\""),
|
||||
"unexpected initialize response: {}",
|
||||
response
|
||||
);
|
||||
|
||||
writeln!(
|
||||
stdin,
|
||||
"{}",
|
||||
serde_json::json!({ "jsonrpc": "2.0", "method": "notifications/initialized" })
|
||||
)
|
||||
.unwrap();
|
||||
stdin.flush().unwrap();
|
||||
}
|
||||
|
||||
fn spawn_line_reader(stdout: std::process::ChildStdout) -> mpsc::Receiver<String> {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
std::thread::spawn(move || {
|
||||
for line in BufReader::new(stdout).lines() {
|
||||
match line {
|
||||
Ok(line) => {
|
||||
if tx.send(line).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
});
|
||||
rx
|
||||
}
|
||||
|
||||
fn wait_for_exit(child: &mut Child, timeout: Duration) {
|
||||
let deadline = Instant::now() + timeout;
|
||||
while Instant::now() < deadline {
|
||||
if child.try_wait().unwrap().is_some() {
|
||||
return;
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(100));
|
||||
}
|
||||
child.kill().ok();
|
||||
panic!(
|
||||
"fff-mcp did not exit within {:?} after stdin closed",
|
||||
timeout
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn read_session_logs(dir: &std::path::Path) -> String {
|
||||
let mut combined = String::new();
|
||||
for entry in std::fs::read_dir(dir).unwrap().flatten() {
|
||||
let name = entry.file_name().to_string_lossy().to_string();
|
||||
if name.starts_with("test") && name.ends_with(".log") {
|
||||
combined.push_str(&std::fs::read_to_string(entry.path()).unwrap_or_default());
|
||||
}
|
||||
}
|
||||
combined
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "fff-nvim"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
edition = "2024"
|
||||
|
||||
[lints]
|
||||
@@ -24,10 +24,10 @@ ahash = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
|
||||
# Local crates
|
||||
fff = { package = "fff-search", path = "../fff-core", version = "0.10.3", default-features = false, features = [
|
||||
fff = { package = "fff-search", path = "../fff-core", version = "0.10.4", default-features = false, features = [
|
||||
"mimalloc-collect",
|
||||
] }
|
||||
fff-query-parser = { path = "../fff-query-parser", version = "0.10.3", default-features = false }
|
||||
fff-query-parser = { path = "../fff-query-parser", version = "0.10.4", default-features = false }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
ctrlc = "3.4.2"
|
||||
git2 = { workspace = true }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "fff-python"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
edition = "2024"
|
||||
|
||||
[lints]
|
||||
@@ -17,7 +17,7 @@ ripgrep = ["fff/ripgrep", "fff-query-parser/ripgrep"]
|
||||
zlob = ["fff/zlob", "fff-query-parser/zlob"]
|
||||
|
||||
[dependencies]
|
||||
fff = { package = "fff-search", path = "../fff-core", version = "0.10.3", default-features = false }
|
||||
fff-query-parser = { path = "../fff-query-parser", version = "0.10.3", default-features = false }
|
||||
fff = { package = "fff-search", path = "../fff-core", version = "0.10.4", default-features = false }
|
||||
fff-query-parser = { path = "../fff-query-parser", version = "0.10.4", default-features = false }
|
||||
git2 = { workspace = true }
|
||||
pyo3 = { version = "0.24.0", features = ["extension-module", "abi3-py310"] }
|
||||
|
||||
@@ -693,15 +693,11 @@ impl FileFinder {
|
||||
}
|
||||
let pattern_refs: Vec<&str> = patterns.iter().map(|s| s.as_str()).collect();
|
||||
|
||||
let parsed_constraints = constraints.as_ref().map(|c| {
|
||||
if picker.mode().is_ai() {
|
||||
QueryParser::new(fff_query_parser::AiGrepConfig).parse(c)
|
||||
} else {
|
||||
fff::grep::parse_grep_query(c)
|
||||
}
|
||||
});
|
||||
let parsed_constraints = constraints
|
||||
.as_ref()
|
||||
.map(|c| QueryParser::new(fff_query_parser::AiGrepConfig).parse_constraints(c));
|
||||
let constraint_refs: &[fff::Constraint<'_>] = match &parsed_constraints {
|
||||
Some(q) => &q.constraints,
|
||||
Some(constraints) => constraints,
|
||||
None => &[],
|
||||
};
|
||||
let options = grep_options(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "fff-query-parser"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
edition = "2024"
|
||||
description = "Query parser for fff file finder - includes specific syntax for various constraints like globs, extensions, regex etc"
|
||||
license = "MIT"
|
||||
|
||||
@@ -49,6 +49,14 @@ impl<C: ParserConfig> QueryParser<C> {
|
||||
Self { config }
|
||||
}
|
||||
|
||||
/// Parse a field containing only constraints.
|
||||
pub fn parse_constraints<'a>(&self, query: &'a str) -> ConstraintVec<'a> {
|
||||
query
|
||||
.split_whitespace()
|
||||
.filter_map(|token| parse_token(token, &self.config))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn parse<'a>(&self, query: &'a str) -> FFFQuery<'a> {
|
||||
let raw_query = query;
|
||||
let config: &C = &self.config;
|
||||
@@ -498,7 +506,7 @@ fn parse_git_status(value: &str) -> Option<Constraint<'_>> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{FileSearchConfig, GrepConfig};
|
||||
use crate::{AiGrepConfig, FileSearchConfig, GrepConfig};
|
||||
|
||||
/// File-picker-like config with filename-constraint detection enabled,
|
||||
/// mirroring the Neovim layer's opt-in behavior.
|
||||
@@ -1019,6 +1027,42 @@ mod tests {
|
||||
assert_eq!(result.grep_text(), "pattern");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_standalone_constraints_preserve_directory() {
|
||||
let result = QueryParser::new(AiGrepConfig).parse_constraints("scope-a/");
|
||||
assert_eq!(result.as_slice(), &[Constraint::PathSegment("scope-a")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_plain_constraints_preserve_directory_only() {
|
||||
let directory = QueryParser::new(GrepConfig).parse_constraints("scope-a/");
|
||||
assert_eq!(directory.as_slice(), &[Constraint::PathSegment("scope-a")]);
|
||||
|
||||
let file = QueryParser::new(GrepConfig).parse_constraints("scope-a/one.txt");
|
||||
assert!(file.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_standalone_constraints_preserve_file() {
|
||||
let result = QueryParser::new(AiGrepConfig).parse_constraints("scope-a/one.txt");
|
||||
assert_eq!(
|
||||
result.as_slice(),
|
||||
&[Constraint::FilePath("scope-a/one.txt")]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_standalone_constraints_preserve_file_without_search_text() {
|
||||
let result = QueryParser::new(AiGrepConfig).parse_constraints("scope-a/ scope-a/one.txt");
|
||||
assert_eq!(
|
||||
result.as_slice(),
|
||||
&[
|
||||
Constraint::PathSegment("scope-a"),
|
||||
Constraint::FilePath("scope-a/one.txt")
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ai_grep_filename_with_pathsegment_only_promotes_to_text() {
|
||||
// When the ONLY non-text constraints are path-scoping (PathSegment,
|
||||
|
||||
+6
-4
@@ -24,8 +24,9 @@ INSTALLATION ~
|
||||
LAZY.NVIM
|
||||
|
||||
>lua
|
||||
-- Package name changed from `fff.nvim` to `fff`. If you installed fff.nvim before, clean with `:Lazy clean`
|
||||
{
|
||||
'dmtrKovalenko/fff.nvim',
|
||||
'dmtrKovalenko/fff',
|
||||
build = function()
|
||||
-- downloads a prebuilt binary or falls back to cargo build
|
||||
require("fff.download").download_or_build_binary()
|
||||
@@ -59,13 +60,14 @@ LAZY.NVIM
|
||||
VIM.PACK
|
||||
|
||||
>lua
|
||||
vim.pack.add({ 'https://github.com/dmtrKovalenko/fff.nvim' })
|
||||
-- Package name changed from `fff.nvim` to `fff`. If you installed fff.nvim before, clean with `:packdel fff.nvim`
|
||||
vim.pack.add({ 'https://github.com/dmtrKovalenko/fff' })
|
||||
|
||||
vim.api.nvim_create_autocmd('PackChanged', {
|
||||
callback = function(ev)
|
||||
local name, kind = ev.data.spec.name, ev.data.kind
|
||||
if name == 'fff.nvim' and (kind == 'install' or kind == 'update') then
|
||||
if not ev.data.active then vim.cmd.packadd('fff.nvim') end
|
||||
if name == 'fff' and (kind == 'install' or kind == 'update') then
|
||||
if not ev.data.active then vim.cmd.packadd('fff') end
|
||||
require('fff.download').download_or_build_binary()
|
||||
end
|
||||
end,
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
-- Single file Neovim config for testing fff.nvim locally
|
||||
-- Usage: nvim -u /Users/neogoose/dev/fff.nvim/init.lua
|
||||
-- Single file Neovim config for testing fff locally
|
||||
-- Usage: nvim -u /Users/neogoose/dev/fff/init.lua
|
||||
|
||||
-- Set up lazy.nvim plugin manager
|
||||
local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
|
||||
@@ -17,8 +17,8 @@ vim.opt.rtp:prepend(lazypath)
|
||||
|
||||
require('lazy').setup({
|
||||
{
|
||||
dir = '~/dev/fff.nvim',
|
||||
'https://github.com/dmtrKovalenko/fff.nvim',
|
||||
dir = '~/dev/fff',
|
||||
'https://github.com/dmtrKovalenko/fff',
|
||||
build = function()
|
||||
-- this will download prebuild binary or try to use existing rustup toolchain to build from source
|
||||
-- (if you are using lazy you can use gb for rebuilding a plugin if needed)
|
||||
@@ -34,7 +34,7 @@ require('lazy').setup({
|
||||
},
|
||||
config = function()
|
||||
require('fff').setup({
|
||||
-- Configure fff.nvim here
|
||||
-- Configure fff here
|
||||
ui = {
|
||||
width = 0.8,
|
||||
height = 0.8,
|
||||
@@ -59,4 +59,4 @@ vim.keymap.set('n', 'fg', function() require('fff').find_in_git_root() end, { de
|
||||
vim.keymap.set('n', 'fr', function() require('fff').scan_files() end, { desc = 'Rescan files' })
|
||||
vim.keymap.set('n', 'fs', function() require('fff').refresh_git_status() end, { desc = 'Refresh git status' })
|
||||
|
||||
vim.notify('FFF.nvim local config loaded! Press ff', vim.log.levels.INFO)
|
||||
vim.notify('FFF local config loaded! Press ff', vim.log.levels.INFO)
|
||||
|
||||
Generated
+12
-12
@@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"crane": {
|
||||
"locked": {
|
||||
"lastModified": 1773857772,
|
||||
"narHash": "sha256-5xsK26KRHf0WytBtsBnQYC/lTWDhQuT57HJ7SzuqZcM=",
|
||||
"lastModified": 1785782307,
|
||||
"narHash": "sha256-MPaRdVkf6zZP5fCPxYCi8Dr4pZzgmXzg8T9nVEbp3Mw=",
|
||||
"owner": "ipetkov",
|
||||
"repo": "crane",
|
||||
"rev": "b556d7bbae5ff86e378451511873dfd07e4504cd",
|
||||
"rev": "2c71e194474d13de031d729b729c968ddbe3507f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -51,11 +51,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1776329215,
|
||||
"narHash": "sha256-a8BYi3mzoJ/AcJP8UldOx8emoPRLeWqALZWu4ZvjPXw=",
|
||||
"lastModified": 1786593342,
|
||||
"narHash": "sha256-smTKQXMLLStzc8zJevMCckbk3My7SvbbLmPYZUJJKW4=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "b86751bc4085f48661017fa226dee99fab6c651b",
|
||||
"rev": "6b5e5b7a6631f065bf6908986990b37d845f847f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -81,11 +81,11 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1773803479,
|
||||
"narHash": "sha256-GD6i1F2vrSxbsmbS92+8+x3DbHOJ+yrS78Pm4xigW4M=",
|
||||
"lastModified": 1786762605,
|
||||
"narHash": "sha256-iQpYIhInh8gRx+cSnPtX+Yp2Gg9kr2h+MehETCqRgDo=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "f17186f52e82ec5cf40920b58eac63b78692ac7c",
|
||||
"rev": "ad8ebb59d84bcf3780c46f107e1d99eb4ca2fe7f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -134,11 +134,11 @@
|
||||
"systems": "systems_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1776789209,
|
||||
"narHash": "sha256-G6B7Q4TXn7MZ1mB+f9rymjsYF5PLWoSvmbxijb/99bw=",
|
||||
"lastModified": 1786753251,
|
||||
"narHash": "sha256-7UGNbG2MwgYCdsknKBL6wMXQQeiTmCiz+JS9zvcmqv4=",
|
||||
"owner": "mitchellh",
|
||||
"repo": "zig-overlay",
|
||||
"rev": "14fe971844e841297ddd2ce9783d6892b467af39",
|
||||
"rev": "a07cc99cee149044f27d95500717161fca2afdf6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
description = "fff.nvim";
|
||||
description = "fff";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@
|
||||
FFF MCP Server installer for Windows.
|
||||
.DESCRIPTION
|
||||
Pipe usage:
|
||||
irm https://raw.githubusercontent.com/dmtrKovalenko/fff.nvim/main/install-mcp.ps1 | iex
|
||||
irm https://raw.githubusercontent.com/dmtrKovalenko/fff/main/install-mcp.ps1 | iex
|
||||
Direct usage (supports params):
|
||||
iwr https://.../install-mcp.ps1 -OutFile install-mcp.ps1; .\install-mcp.ps1 -Version v0.1.2
|
||||
Env-var fallbacks (for the piped form):
|
||||
@@ -29,7 +29,7 @@ $ErrorActionPreference = 'Stop'
|
||||
# Force TLS 1.2 — PS 5.1 on older Win10 may default to SSL3/TLS1.0 which GitHub rejects.
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
|
||||
|
||||
$Repo = 'dmtrKovalenko/fff.nvim'
|
||||
$Repo = 'dmtrKovalenko/fff'
|
||||
$BinaryName = 'fff-mcp'
|
||||
if (-not $InstallDir) { $InstallDir = Join-Path $env:LOCALAPPDATA 'fff-mcp\bin' }
|
||||
|
||||
|
||||
+9
-9
@@ -2,20 +2,20 @@
|
||||
set -eo pipefail
|
||||
|
||||
# FFF MCP Server installer
|
||||
# Usage: curl -fsSL https://raw.githubusercontent.com/dmtrKovalenko/fff.nvim/main/install-mcp.sh | bash
|
||||
# Usage: curl -fsSL https://raw.githubusercontent.com/dmtrKovalenko/fff/main/install-mcp.sh | bash
|
||||
|
||||
REPO="dmtrKovalenko/fff.nvim"
|
||||
REPO="dmtrKovalenko/fff"
|
||||
BINARY_NAME="fff-mcp"
|
||||
INSTALL_DIR="${FFF_MCP_INSTALL_DIR:-$HOME/.local/bin}"
|
||||
|
||||
PINNED_RELEASE_TAG="v0.10.3"
|
||||
PINNED_RELEASE_TAG="v0.10.4"
|
||||
|
||||
SHA256_X86_64_UNKNOWN_LINUX_MUSL="8823476699977f3dbfe351862f083163810f66656522007cbb65be140c71994c"
|
||||
SHA256_AARCH64_UNKNOWN_LINUX_MUSL="f2092d02c26523476b19361c3fbe2e82033232efdd2e0bee9e7cdbbb31e9436a"
|
||||
SHA256_X86_64_APPLE_DARWIN="f72c31c7f3355d37ec526ba56fd716341bd7186a15a399910cf3f2b46fef2099"
|
||||
SHA256_AARCH64_APPLE_DARWIN="8c52acf1e95540f02cf55579126ebf580cf48af15c76e1c90301c2c8c5acbcf9"
|
||||
SHA256_X86_64_PC_WINDOWS_MSVC="7e4d5c007e65e70f7070b3fa39867cd48827873acebf981d933eef7b339759ce"
|
||||
SHA256_AARCH64_PC_WINDOWS_MSVC="ef677422bf5344b3e4c5952c6b5885f3e9b4d0e7608684de1f5fd56bcd3d22ad"
|
||||
SHA256_X86_64_UNKNOWN_LINUX_MUSL="68384121a9173b214190c594ea938cb5a1c52ca3069a3f3b1a0eecc28fd8ea82"
|
||||
SHA256_AARCH64_UNKNOWN_LINUX_MUSL="334ff6f28d5ee47b9652a6c590cf47b908541ff25cb1bd3c7c3303d5f5342c40"
|
||||
SHA256_X86_64_APPLE_DARWIN="821aedd5873292841f32d7584eb68fea085b248e5c970ff5d4f6dca790e9b18c"
|
||||
SHA256_AARCH64_APPLE_DARWIN="f55ce2945cd30fd252a4b1e7d8674ff7ce41b104cc009a8d3d52d08bfccca2c0"
|
||||
SHA256_X86_64_PC_WINDOWS_MSVC="2ff065dc7636c3d50d93a6ea55209760ed382bb6c096c01a3ba7357d6fa6b59e"
|
||||
SHA256_AARCH64_PC_WINDOWS_MSVC="42244ce562fec2ff13d97d819430e028f1f2e5a0d08418f9bd24f97d060741eb"
|
||||
|
||||
expected_sha_for() {
|
||||
case "$1" in
|
||||
|
||||
+50
-37
@@ -135,11 +135,17 @@ M.change_indexing_directory = function(new_path)
|
||||
return true
|
||||
end
|
||||
|
||||
M.ensure_initialized = function()
|
||||
if state.initialized then return fuzzy end
|
||||
--- Reset the file-picker flag so the next `ensure_initialized` recreates the
|
||||
--- Rust picker. Call after `cleanup_file_picker` drops it (`FFFClearCache`);
|
||||
--- otherwise the flag stays set and every later call operates on a dropped
|
||||
--- picker (see #772).
|
||||
M.mark_file_picker_uninitialized = function() state.file_picker_initialized = false end
|
||||
|
||||
M.ensure_initialized = function()
|
||||
local config = require('fff.conf').get()
|
||||
|
||||
-- Refusal gates both one-time setup and (re)creating the picker so we never
|
||||
-- index fs-root / home, even after a cache clear.
|
||||
-- Some folks are complaining that neovim instance is closing if ffi returns error on startup (via lazy=false)
|
||||
-- I can't repro so just precheck on lua side to prevent crashing neovim instance
|
||||
local refusal = fs_scanning_refusal(config)
|
||||
@@ -149,46 +155,53 @@ M.ensure_initialized = function()
|
||||
return fuzzy
|
||||
end
|
||||
|
||||
state.initialized = true
|
||||
if config.logging.enabled then
|
||||
local log_success, log_error =
|
||||
pcall(fuzzy.init_tracing, config.logging.log_file, config.logging.log_level, config.logging.retain_runs)
|
||||
if log_success then
|
||||
M.log_file_path = log_error
|
||||
else
|
||||
vim.notify('Failed to initialize logging: ' .. (tostring(log_error) or 'unknown error'), vim.log.levels.WARN)
|
||||
if not state.initialized then
|
||||
state.initialized = true
|
||||
if config.logging.enabled then
|
||||
local log_success, log_error =
|
||||
pcall(fuzzy.init_tracing, config.logging.log_file, config.logging.log_level, config.logging.retain_runs)
|
||||
if log_success then
|
||||
M.log_file_path = log_error
|
||||
else
|
||||
vim.notify('Failed to initialize logging: ' .. (tostring(log_error) or 'unknown error'), vim.log.levels.WARN)
|
||||
end
|
||||
end
|
||||
|
||||
local frecency_db_path = config.frecency.db_path or (vim.fn.stdpath('cache') .. '/fff_frecency')
|
||||
local history_db_path = config.history.db_path or (vim.fn.stdpath('data') .. '/fff_history')
|
||||
|
||||
local ok, result = pcall(fuzzy.init_db, frecency_db_path, history_db_path, true)
|
||||
if not ok then vim.notify('Failed to databases: ' .. tostring(result), vim.log.levels.WARN) end
|
||||
|
||||
setup_global_autocmds(config)
|
||||
|
||||
local highlights = require('fff.highlights')
|
||||
highlights.setup()
|
||||
|
||||
vim.api.nvim_create_autocmd('ColorScheme', {
|
||||
group = vim.api.nvim_create_augroup('fff_highlights', { clear = true }),
|
||||
callback = function() highlights.setup() end,
|
||||
desc = 'Re-apply FFF highlights on colorscheme change',
|
||||
})
|
||||
end
|
||||
|
||||
local frecency_db_path = config.frecency.db_path or (vim.fn.stdpath('cache') .. '/fff_frecency')
|
||||
local history_db_path = config.history.db_path or (vim.fn.stdpath('data') .. '/fff_history')
|
||||
|
||||
local ok, result = pcall(fuzzy.init_db, frecency_db_path, history_db_path, true)
|
||||
if not ok then vim.notify('Failed to databases: ' .. tostring(result), vim.log.levels.WARN) end
|
||||
|
||||
ok, result = pcall(fuzzy.init_file_picker, config.base_path, {
|
||||
follow_symlinks = config.follow_symlinks,
|
||||
enable_fs_root_scanning = config.enable_fs_root_scanning,
|
||||
enable_home_dir_scanning = config.enable_home_dir_scanning,
|
||||
enable_filename_constraint = config.grep and config.grep.enable_filename_constraint,
|
||||
})
|
||||
if not ok then
|
||||
vim.notify('Failed to initialize file picker: ' .. tostring(result), vim.log.levels.ERROR)
|
||||
return fuzzy
|
||||
-- Recreated whenever the picker was torn down (e.g. `FFFClearCache files`).
|
||||
-- Guarded separately from one-time setup so a cache clear rebuilds the
|
||||
-- picker instead of leaving a dropped one behind (#772).
|
||||
if not state.file_picker_initialized then
|
||||
local ok, result = pcall(fuzzy.init_file_picker, config.base_path, {
|
||||
follow_symlinks = config.follow_symlinks,
|
||||
enable_fs_root_scanning = config.enable_fs_root_scanning,
|
||||
enable_home_dir_scanning = config.enable_home_dir_scanning,
|
||||
enable_filename_constraint = config.grep and config.grep.enable_filename_constraint,
|
||||
})
|
||||
if not ok then
|
||||
vim.notify('Failed to initialize file picker: ' .. tostring(result), vim.log.levels.ERROR)
|
||||
return fuzzy
|
||||
end
|
||||
state.file_picker_initialized = true
|
||||
end
|
||||
|
||||
state.file_picker_initialized = true
|
||||
setup_global_autocmds(config)
|
||||
|
||||
local highlights = require('fff.highlights')
|
||||
highlights.setup()
|
||||
|
||||
vim.api.nvim_create_autocmd('ColorScheme', {
|
||||
group = vim.api.nvim_create_augroup('fff_highlights', { clear = true }),
|
||||
callback = function() highlights.setup() end,
|
||||
desc = 'Re-apply FFF highlights on colorscheme change',
|
||||
})
|
||||
|
||||
return fuzzy
|
||||
end
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ local system = require('fff.utils.system')
|
||||
local fs_utils = require('fff.utils.fs')
|
||||
local fff_version = require('fff.utils.version')
|
||||
|
||||
local GITHUB_REPO = 'dmtrKovalenko/fff.nvim'
|
||||
local GITHUB_REPO = 'dmtrKovalenko/fff'
|
||||
|
||||
local function get_binary_dir(plugin_dir) return plugin_dir .. '/../target/release' end
|
||||
|
||||
|
||||
+7
-1
@@ -101,7 +101,13 @@ function M.clear_cache(scope)
|
||||
|
||||
if scope == 'all' or scope == 'files' then
|
||||
local ok, err = pcall(fuzzy.cleanup_file_picker)
|
||||
if not ok then table.insert(errors, 'cleanup file picker: ' .. tostring(err)) end
|
||||
if not ok then
|
||||
table.insert(errors, 'cleanup file picker: ' .. tostring(err))
|
||||
else
|
||||
-- Rust picker is gone; clear the core flag so the next ensure_initialized
|
||||
-- rebuilds it instead of operating on a dropped picker (#772).
|
||||
require('fff.core').mark_file_picker_uninitialized()
|
||||
end
|
||||
end
|
||||
|
||||
if scope == 'all' or scope == 'frecency' then
|
||||
|
||||
@@ -174,8 +174,8 @@ If prebuilt binaries aren't available for your platform:
|
||||
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone https://github.com/dmtrKovalenko/fff.nvim
|
||||
cd fff.nvim
|
||||
git clone https://github.com/dmtrKovalenko/fff
|
||||
cd fff
|
||||
|
||||
# Build the C library
|
||||
cargo build --release -p fff-c
|
||||
|
||||
@@ -4,19 +4,24 @@
|
||||
"private": false,
|
||||
"description": "High-performance fuzzy file finder for Bun - perfect for LLM agent tools",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./src/index.ts",
|
||||
"types": "./src/index.ts"
|
||||
}
|
||||
"types": "./dist/index.d.ts",
|
||||
"bun": "./src/index.ts",
|
||||
"import": "./dist/index.js",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"src",
|
||||
"examples"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "bun build ./src/index.ts --format=esm --target=bun --sourcemap=external --outdir dist && tsc -p tsconfig.build.json",
|
||||
"test": "bun test test/",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"demo": "bun ./examples/search.ts"
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
import { afterEach, describe, expect, mock, test } from "bun:test";
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { FileFinder } from "../src/index";
|
||||
|
||||
// Real-native tests for #700/#760. Lives here, not in pi-fff/test: that suite
|
||||
// mocks @ff-labs/fff-bun process-globally and bun module mocks can't be undone.
|
||||
mock.module("@earendil-works/pi-tui", () => ({
|
||||
Text: class Text {
|
||||
text: string;
|
||||
constructor(text: string) {
|
||||
this.text = text;
|
||||
}
|
||||
setText(text: string) {
|
||||
this.text = text;
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
const schema = (type: string) => (options?: unknown) => ({ type, options });
|
||||
mock.module("@sinclair/typebox", () => ({
|
||||
Type: {
|
||||
Array: (items: unknown, options?: unknown) => ({ type: "array", items, options }),
|
||||
Boolean: schema("boolean"),
|
||||
Number: schema("number"),
|
||||
Object: (properties: unknown, options?: unknown) => ({
|
||||
type: "object",
|
||||
properties,
|
||||
options,
|
||||
}),
|
||||
Optional: (value: unknown) => ({ ...(value as object), optional: true }),
|
||||
String: schema("string"),
|
||||
Union: (items: unknown[], options?: unknown) => ({ type: "union", items, options }),
|
||||
},
|
||||
}));
|
||||
|
||||
const { default: fffExtension } = await import("../../pi-fff/src/index");
|
||||
|
||||
// Inject this package as the extension's SDK through the cache hook sdk.ts
|
||||
// already uses for reloads: CI has no node_modules to resolve "@ff-labs/fff-bun"
|
||||
// from pi-fff, and the finder stays the real native one either way.
|
||||
(globalThis as Record<string, unknown>).__fffSdkPromiseGlobal = Promise.resolve({
|
||||
FileFinder,
|
||||
});
|
||||
|
||||
const cleanups: Array<() => void> = [];
|
||||
|
||||
afterEach(() => {
|
||||
while (cleanups.length) cleanups.pop()?.();
|
||||
});
|
||||
|
||||
function makeWorkspace(name: string): string {
|
||||
const dir = mkdtempSync(join(tmpdir(), `pi-fff-native-${name}-`));
|
||||
cleanups.push(() => rmSync(dir, { recursive: true, force: true }));
|
||||
writeFileSync(join(dir, "alpha.ts"), "export const alpha = 1;\n");
|
||||
writeFileSync(join(dir, "beta.ts"), "export const beta = 2;\n");
|
||||
mkdirSync(join(dir, "src"));
|
||||
writeFileSync(join(dir, "src", "gamma.ts"), "export const gamma = 3;\n");
|
||||
return dir;
|
||||
}
|
||||
|
||||
function makeDbPaths() {
|
||||
const root = mkdtempSync(join(tmpdir(), "pi-fff-native-dbs-"));
|
||||
cleanups.push(() => rmSync(root, { recursive: true, force: true }));
|
||||
return { frecencyDbPath: join(root, "frecency"), historyDbPath: join(root, "history") };
|
||||
}
|
||||
|
||||
function createFinder(options: Parameters<typeof FileFinder.create>[0]) {
|
||||
const result = FileFinder.create(options);
|
||||
if (result.ok) {
|
||||
const finder = result.value;
|
||||
cleanups.push(() => {
|
||||
if (!finder.isDestroyed) finder.destroy();
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
type SearchOk = { ok: true; value: { items: Array<{ fileName: string }> } };
|
||||
type SearchResult = SearchOk | { ok: false; error: string };
|
||||
|
||||
function fileNames(
|
||||
finder: { fileSearch: (q: string, o: { pageSize: number }) => SearchResult },
|
||||
query: string,
|
||||
): string[] {
|
||||
const search = finder.fileSearch(query, { pageSize: 10 });
|
||||
expect(search.ok).toBe(true);
|
||||
return search.ok ? search.value.items.map((i) => i.fileName) : [];
|
||||
}
|
||||
|
||||
describe("fff-bun: many finders share one LMDB env per path (#700/#760)", () => {
|
||||
test("a second finder on the same db paths works and searches", async () => {
|
||||
const dbs = makeDbPaths();
|
||||
const main = createFinder({ basePath: makeWorkspace("main"), ...dbs });
|
||||
expect(main.ok).toBe(true);
|
||||
if (!main.ok) return;
|
||||
await main.value.waitForScan(15_000);
|
||||
expect(fileNames(main.value, "alpha")).toContain("alpha.ts");
|
||||
|
||||
// The createAgentSession scenario: same process, same db paths.
|
||||
const sub = createFinder({ basePath: makeWorkspace("subagent"), ...dbs });
|
||||
expect(sub.ok).toBe(true);
|
||||
if (!sub.ok) return;
|
||||
await sub.value.waitForScan(15_000);
|
||||
expect(fileNames(sub.value, "gamma")).toContain("gamma.ts");
|
||||
}, 30_000);
|
||||
|
||||
test("destroying one finder keeps the shared env alive for the other", async () => {
|
||||
const dbs = makeDbPaths();
|
||||
const first = createFinder({ basePath: makeWorkspace("first"), ...dbs });
|
||||
const second = createFinder({ basePath: makeWorkspace("second"), ...dbs });
|
||||
expect(first.ok).toBe(true);
|
||||
expect(second.ok).toBe(true);
|
||||
if (!first.ok || !second.ok) return;
|
||||
|
||||
first.value.destroy();
|
||||
await second.value.waitForScan(15_000);
|
||||
expect(fileNames(second.value, "alpha")).toContain("alpha.ts");
|
||||
|
||||
// And once the survivor is gone too, the paths are reusable.
|
||||
second.value.destroy();
|
||||
const third = createFinder({ basePath: makeWorkspace("third"), ...dbs });
|
||||
expect(third.ok).toBe(true);
|
||||
}, 30_000);
|
||||
|
||||
test("a db-less aux finder coexists with the main finder (#700)", async () => {
|
||||
const main = createFinder({ basePath: makeWorkspace("main"), ...makeDbPaths() });
|
||||
expect(main.ok).toBe(true);
|
||||
|
||||
const aux = createFinder({ basePath: makeWorkspace("aux") });
|
||||
expect(aux.ok).toBe(true);
|
||||
if (!aux.ok) return;
|
||||
await aux.value.waitForScan(15_000);
|
||||
expect(fileNames(aux.value, "gamma")).toContain("gamma.ts");
|
||||
}, 30_000);
|
||||
});
|
||||
|
||||
type EventHandler = (...args: unknown[]) => unknown;
|
||||
type RegisteredTool = {
|
||||
name: string;
|
||||
execute: (
|
||||
toolCallId: string,
|
||||
params: unknown,
|
||||
signal?: AbortSignal,
|
||||
) => Promise<unknown>;
|
||||
};
|
||||
|
||||
function startSession(
|
||||
cwd: string,
|
||||
dbs: { frecencyDbPath: string; historyDbPath: string },
|
||||
) {
|
||||
const events = new Map<string, EventHandler>();
|
||||
const tools = new Map<string, RegisteredTool>();
|
||||
const notifications: Array<{ message: string; level?: string }> = [];
|
||||
|
||||
const flags: Record<string, unknown> = {
|
||||
"fff-frecency-db": dbs.frecencyDbPath,
|
||||
"fff-history-db": dbs.historyDbPath,
|
||||
};
|
||||
|
||||
const pi = {
|
||||
getFlag: (name: string) => flags[name],
|
||||
on: (event: string, handler: EventHandler) => events.set(event, handler),
|
||||
registerCommand: () => undefined,
|
||||
registerFlag: () => undefined,
|
||||
registerTool: (tool: RegisteredTool) => tools.set(tool.name, tool),
|
||||
appendEntry: () => undefined,
|
||||
};
|
||||
|
||||
const ctx = {
|
||||
cwd,
|
||||
ui: {
|
||||
notify: (message: string, level?: string) => notifications.push({ message, level }),
|
||||
setStatus: () => undefined,
|
||||
},
|
||||
};
|
||||
|
||||
fffExtension(pi as never);
|
||||
cleanups.push(() => {
|
||||
void events.get("session_shutdown")?.({}, undefined);
|
||||
});
|
||||
|
||||
return {
|
||||
start: async () => events.get("session_start")?.({ reason: "startup" }, ctx),
|
||||
shutdown: async () => events.get("session_shutdown")?.({}, undefined),
|
||||
find: async (pattern: string, params?: Record<string, unknown>) =>
|
||||
JSON.stringify(
|
||||
await tools.get("fffind")?.execute("test-call", { pattern, ...params }),
|
||||
),
|
||||
errors: () => notifications.filter((n) => n.level === "error").map((n) => n.message),
|
||||
};
|
||||
}
|
||||
|
||||
describe("pi-fff: in-process double activation works (#760)", () => {
|
||||
test("two sessions in one process both search against the same dbs", async () => {
|
||||
const dbs = makeDbPaths();
|
||||
const first = startSession(makeWorkspace("session1"), dbs);
|
||||
await first.start();
|
||||
expect(first.errors()).toEqual([]);
|
||||
expect(await first.find("alpha")).toContain("alpha.ts");
|
||||
|
||||
// What createAgentSession does: activate the extension again in-process.
|
||||
const second = startSession(makeWorkspace("session2"), dbs);
|
||||
await second.start();
|
||||
expect(second.errors()).toEqual([]);
|
||||
expect(await second.find("gamma")).toContain("gamma.ts");
|
||||
|
||||
// And the first session keeps working alongside it.
|
||||
expect(await first.find("beta")).toContain("beta.ts");
|
||||
|
||||
await second.shutdown();
|
||||
await first.shutdown();
|
||||
}, 40_000);
|
||||
|
||||
test("aux finder over an external root shares the session dbs (#700)", async () => {
|
||||
const dbs = makeDbPaths();
|
||||
const session = startSession(makeWorkspace("aux-session"), dbs);
|
||||
await session.start();
|
||||
expect(session.errors()).toEqual([]);
|
||||
|
||||
// An absolute out-of-workspace path constraint routes to an aux finder,
|
||||
// which now opens the same frecency/history LMDB paths as the main finder.
|
||||
const external = makeWorkspace("aux-external");
|
||||
expect(await session.find("gamma", { path: external })).toContain("gamma.ts");
|
||||
expect(session.errors()).toEqual([]);
|
||||
|
||||
await session.shutdown();
|
||||
}, 40_000);
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"emitDeclarationOnly": true,
|
||||
"noEmit": false
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
@@ -152,8 +152,8 @@ If prebuilt binaries aren't available for your platform:
|
||||
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone https://github.com/dmtrKovalenko/fff.nvim
|
||||
cd fff.nvim
|
||||
git clone https://github.com/dmtrKovalenko/fff
|
||||
cd fff
|
||||
|
||||
# Build the C library
|
||||
cargo build --release -p fff-c
|
||||
|
||||
@@ -4,19 +4,26 @@
|
||||
"private": false,
|
||||
"description": "High-performance fuzzy file finder for Node.js - perfect for LLM agent tools",
|
||||
"type": "module",
|
||||
"main": "dist/src/index.js",
|
||||
"types": "dist/src/index.d.ts",
|
||||
"main": "dist/index.cjs",
|
||||
"module": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/src/index.js",
|
||||
"types": "./dist/src/index.d.ts"
|
||||
}
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"build": "npm run build:esm && npm run build:cjs && npm run build:types",
|
||||
"build:esm": "bun build ./src/index.ts --format=esm --target=node --external ffi-rs --sourcemap=external --outdir dist",
|
||||
"build:cjs": "bun build ./src/index.ts --format=cjs --target=node --external ffi-rs --sourcemap=external --outdir dist --entry-naming \"[name].cjs\"",
|
||||
"build:types": "tsc -p tsconfig.build.json",
|
||||
"test": "node test/e2e.mjs && node test/watch.mjs",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
|
||||
@@ -16,6 +16,9 @@ import { getLibFilename, getNpmPackageName } from "./platform.js";
|
||||
* Get the current file's directory
|
||||
*/
|
||||
function getCurrentDir(): string {
|
||||
// CJS build: import.meta.url is inlined at bundle time, __dirname is the truth
|
||||
if (typeof __dirname !== "undefined") return __dirname;
|
||||
|
||||
const url = import.meta.url;
|
||||
|
||||
if (url.startsWith("file://")) {
|
||||
@@ -30,7 +33,7 @@ function getCurrentDir(): string {
|
||||
function getPackageDir(): string {
|
||||
const currentDir = getCurrentDir();
|
||||
// In dev: src/ -> package root
|
||||
// In dist: dist/src/ -> package root
|
||||
// In dist: dist/ -> package root
|
||||
// We look for package.json to find the actual root
|
||||
let dir = currentDir;
|
||||
for (let i = 0; i < 5; i++) {
|
||||
|
||||
@@ -2,13 +2,13 @@ import { after, before, describe, it } from "node:test";
|
||||
import { strict as assert } from "node:assert";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { FileFinder } from "../dist/src/index.js";
|
||||
import { FileFinder } from "../dist/index.js";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const REPO_ROOT = resolve(__dirname, "..", "..", "..");
|
||||
const normalizePath = (p) => p.replace(/\\/g, "/");
|
||||
|
||||
/** @type {import("../dist/src/finder.js").FileFinder | null} */
|
||||
/** @type {import("../dist/finder.js").FileFinder | null} */
|
||||
let finder = null;
|
||||
|
||||
describe("fff-node", { concurrency: 1 }, () => {
|
||||
|
||||
@@ -13,7 +13,7 @@ import { existsSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import process from "node:process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { FileFinder } from "../dist/src/index.js";
|
||||
import { FileFinder } from "../dist/index.js";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const REPO_ROOT = resolve(__dirname, "..", "..", "..");
|
||||
|
||||
@@ -15,7 +15,7 @@ import { mkdtempSync, realpathSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, sep } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { FileFinder } from "../dist/src/index.js";
|
||||
import { FileFinder } from "../dist/index.js";
|
||||
|
||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
@@ -33,7 +33,7 @@ async function waitFor(cond, timeoutMs = 10_000) {
|
||||
/** All events delivered to a batch-callback mock, flattened across calls. */
|
||||
const deliveredEvents = (fn) => fn.mock.calls.flatMap((call) => call.arguments[0]);
|
||||
|
||||
/** @type {import("../dist/src/finder.js").FileFinder | null} */
|
||||
/** @type {import("../dist/finder.js").FileFinder | null} */
|
||||
let finder = null;
|
||||
/** @type {string} */
|
||||
let baseDir = "";
|
||||
@@ -237,7 +237,7 @@ describe("fff-node watch", { concurrency: 1 }, () => {
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { FileFinder } from ${JSON.stringify(new URL("../dist/src/index.js", import.meta.url).href)};
|
||||
import { FileFinder } from ${JSON.stringify(new URL("../dist/index.js", import.meta.url).href)};
|
||||
|
||||
const dir = mkdtempSync(join(tmpdir(), "fff-watch-exit-"));
|
||||
writeFileSync(join(dir, "seed.txt"), "seed");
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"emitDeclarationOnly": true,
|
||||
"noEmit": false
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
# fff-search
|
||||
|
||||
Python bindings for [FFF (Fast File Finder)](https://github.com/dmtrKovalenko/fff.nvim), built with [PyO3](https://pyo3.rs/) and [Maturin](https://www.maturin.rs/). Install with `pip install fff-search`; import as `fff`.
|
||||
Python bindings for [FFF (Fast File Finder)](https://github.com/dmtrKovalenko/fff), built with [PyO3](https://pyo3.rs/) and [Maturin](https://www.maturin.rs/). Install with `pip install fff-search`; import as `fff`.
|
||||
|
||||
## Requirements
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "fff-search"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
description = "Python bindings for FFF (Fast File Finder)"
|
||||
readme = "README.md"
|
||||
license = { text = "MIT" }
|
||||
@@ -15,8 +15,8 @@ dev = [
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
Repository = "https://github.com/dmtrKovalenko/fff.nvim"
|
||||
Issues = "https://github.com/dmtrKovalenko/fff.nvim/issues"
|
||||
Repository = "https://github.com/dmtrKovalenko/fff"
|
||||
Issues = "https://github.com/dmtrKovalenko/fff/issues"
|
||||
|
||||
[build-system]
|
||||
requires = ["maturin>=1.0,<2.0"]
|
||||
|
||||
@@ -50,7 +50,7 @@ class FileFinder(_FileFinder):
|
||||
return True
|
||||
|
||||
|
||||
__version__ = "0.10.3"
|
||||
__version__ = "0.10.4"
|
||||
|
||||
__all__ = [
|
||||
"FFFException",
|
||||
|
||||
Generated
+1
-1
@@ -34,7 +34,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "fff-search"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
source = { editable = "." }
|
||||
|
||||
[package.optional-dependencies]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# @ff-labs/pi-fff
|
||||
|
||||
A [pi](https://github.com/badlogic/pi-mono) extension that replaces the built-in `find` and `grep` tools with [FFF](https://github.com/dmtrKovalenko/fff.nvim) — a Rust-native, SIMD-accelerated file finder with built-in memory.
|
||||
A [pi](https://github.com/badlogic/pi-mono) extension that replaces the built-in `find` and `grep` tools with [FFF](https://github.com/dmtrKovalenko/fff) — a Rust-native, SIMD-accelerated file finder with built-in memory.
|
||||
|
||||
## What it does
|
||||
|
||||
@@ -44,20 +44,20 @@ pi install -l npm:@ff-labs/pi-fff
|
||||
**Via git:**
|
||||
|
||||
```bash
|
||||
pi install git:github.com/dmtrKovalenko/fff.nvim
|
||||
pi install git:github.com/dmtrKovalenko/fff
|
||||
```
|
||||
|
||||
Pin to a release:
|
||||
|
||||
```bash
|
||||
pi install git:github.com/dmtrKovalenko/fff.nvim@v0.3.0
|
||||
pi install git:github.com/dmtrKovalenko/fff@v0.3.0
|
||||
```
|
||||
|
||||
### Local development / manual install
|
||||
|
||||
```bash
|
||||
git clone https://github.com/dmtrKovalenko/fff.nvim.git
|
||||
cd fff.nvim/packages/pi-fff
|
||||
git clone https://github.com/dmtrKovalenko/fff.git
|
||||
cd fff/packages/pi-fff
|
||||
npm install
|
||||
```
|
||||
|
||||
@@ -65,14 +65,14 @@ Then add to your pi `settings.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"extensions": ["/path/to/fff.nvim/packages/pi-fff/src/index.ts"]
|
||||
"extensions": ["/path/to/fff/packages/pi-fff/src/index.ts"]
|
||||
}
|
||||
```
|
||||
|
||||
Or test directly:
|
||||
|
||||
```bash
|
||||
pi -e /path/to/fff.nvim/packages/pi-fff/src/index.ts
|
||||
pi -e /path/to/fff/packages/pi-fff/src/index.ts
|
||||
```
|
||||
|
||||
This extension registers FFF-powered tools (`fffind`, `ffgrep`, `fff-multi-grep`) alongside pi's built-in tools.
|
||||
|
||||
@@ -18,6 +18,8 @@ export interface AuxOpts {
|
||||
enableHomeDirScanning?: boolean;
|
||||
// Called before a newly spawned aux picker starts a scan that covers $HOME.
|
||||
onHomeDirScan?: (root: string) => void;
|
||||
frecencyDbPath?: string;
|
||||
historyDbPath?: string;
|
||||
}
|
||||
|
||||
export class AuxFinderPool {
|
||||
@@ -100,17 +102,18 @@ export class AuxFinderPool {
|
||||
}
|
||||
|
||||
const { FileFinder } = await loadSdk();
|
||||
// LMDB env can only be opened once per process; the main finder already
|
||||
// owns the frecency/history DBs. Aux finders are transient and run without
|
||||
// persistent scoring — see issue #700.
|
||||
const result = FileFinder.create({
|
||||
basePath: root,
|
||||
frecencyDbPath: this.opts.frecencyDbPath,
|
||||
historyDbPath: this.opts.historyDbPath,
|
||||
aiMode: true,
|
||||
enableHomeDirScanning,
|
||||
enableFsRootScanning: this.opts.enableFsRootScanning,
|
||||
});
|
||||
if (!result.ok)
|
||||
|
||||
if (!result.ok) {
|
||||
throw new Error(`Failed to create aux file finder for ${root}: ${result.error}`);
|
||||
}
|
||||
|
||||
await result.value.waitForScan(SCAN_TIMEOUT_MS);
|
||||
const entry: AuxPicker = {
|
||||
|
||||
@@ -34,6 +34,8 @@ export { SCAN_TIMEOUT_MS } from "./sdk";
|
||||
|
||||
const DEFAULT_GREP_LIMIT = 20;
|
||||
const DEFAULT_FIND_LIMIT = 30;
|
||||
const GREP_PAGE_SIZE_MAX = 50;
|
||||
const GREP_CONTEXT_MAX = 20;
|
||||
const GREP_MAX_LINE_LENGTH = 500;
|
||||
const MENTION_MAX_RESULTS = 20;
|
||||
|
||||
@@ -128,6 +130,13 @@ function truncateLine(line: string, max = GREP_MAX_LINE_LENGTH): string {
|
||||
return trimmed.length <= max ? trimmed : `${trimmed.slice(0, max)}...`;
|
||||
}
|
||||
|
||||
// Clamp caller-supplied context to a non-negative bounded integer so a large
|
||||
// value cannot multiply output size past the model window.
|
||||
function clampContext(context: number | undefined): number {
|
||||
if (!context || context < 0) return 0;
|
||||
return Math.min(Math.floor(context), GREP_CONTEXT_MAX);
|
||||
}
|
||||
|
||||
const HOT_FRECENCY = 25;
|
||||
const WARM_FRECENCY = 20;
|
||||
|
||||
@@ -309,7 +318,7 @@ export default function fffExtension(pi: ExtensionAPI) {
|
||||
|
||||
const toolNames = resolveToolNames(currentMode);
|
||||
|
||||
// DB path resolution: flag > env > undefined (use fff-node defaults)
|
||||
// DB path resolution: flag > env > undefined (no persistent DBs)
|
||||
const frecencyDbPath =
|
||||
(pi.getFlag("fff-frecency-db") as string | undefined) ??
|
||||
process.env.FFF_FRECENCY_DB ??
|
||||
@@ -320,11 +329,7 @@ export default function fffExtension(pi: ExtensionAPI) {
|
||||
undefined;
|
||||
|
||||
// flag (boolean) > env ("1"/"true", or "0"/"false") > default.
|
||||
function resolveBoolOpt(
|
||||
flagName: string,
|
||||
envName: string,
|
||||
fallback = false,
|
||||
): boolean {
|
||||
function resolveBoolOpt(flagName: string, envName: string, fallback = false): boolean {
|
||||
const flag = pi.getFlag(flagName);
|
||||
if (typeof flag === "boolean") return flag;
|
||||
if (typeof flag === "string") return flag === "true" || flag === "1";
|
||||
@@ -375,10 +380,12 @@ export default function fffExtension(pi: ExtensionAPI) {
|
||||
);
|
||||
}
|
||||
|
||||
let auxPool = new AuxFinderPool({
|
||||
const auxPool = new AuxFinderPool({
|
||||
enableFsRootScanning,
|
||||
enableHomeDirScanning,
|
||||
onHomeDirScan: warnHomeDirScan,
|
||||
frecencyDbPath,
|
||||
historyDbPath,
|
||||
});
|
||||
|
||||
// in case cwd changes we need to figure this out
|
||||
@@ -691,7 +698,9 @@ export default function fffExtension(pi: ExtensionAPI) {
|
||||
}),
|
||||
),
|
||||
context: Type.Optional(
|
||||
Type.Number({ description: "Context lines before+after each match" }),
|
||||
Type.Number({
|
||||
description: `Context lines before+after each match (0-${GREP_CONTEXT_MAX})`,
|
||||
}),
|
||||
),
|
||||
limit: Type.Optional(
|
||||
Type.Number({
|
||||
@@ -724,6 +733,10 @@ export default function fffExtension(pi: ExtensionAPI) {
|
||||
|
||||
const picker = aux ? aux.finder : await ensureFinder(activeCwd);
|
||||
const effectiveLimit = Math.max(1, params.limit ?? DEFAULT_GREP_LIMIT);
|
||||
// pageSize caps TOTAL matches across all files; maxMatchesPerFile alone
|
||||
// only caps per-file, so limit=5 could still return a full SDK page.
|
||||
const pageSize = Math.min(effectiveLimit, GREP_PAGE_SIZE_MAX);
|
||||
const context = clampContext(params.context);
|
||||
const query = aux
|
||||
? aux.query
|
||||
: buildQuery(params.path, pattern, params.exclude, activeCwd);
|
||||
@@ -771,10 +784,11 @@ export default function fffExtension(pi: ExtensionAPI) {
|
||||
const grepResult = picker.grep(query, {
|
||||
mode,
|
||||
smartCase,
|
||||
maxMatchesPerFile: Math.min(effectiveLimit, 50),
|
||||
maxMatchesPerFile: pageSize,
|
||||
pageSize,
|
||||
cursor: (params.cursor ? getCursor(params.cursor) : null) ?? null,
|
||||
beforeContext: params.context ?? 0,
|
||||
afterContext: params.context ?? 0,
|
||||
beforeContext: context,
|
||||
afterContext: context,
|
||||
classifyDefinitions: true,
|
||||
timeBudgetMs: GREP_TIME_BUDGET_MS,
|
||||
});
|
||||
@@ -803,7 +817,8 @@ export default function fffExtension(pi: ExtensionAPI) {
|
||||
const fuzzy = picker.grep(fuzzyQuery, {
|
||||
mode: "fuzzy",
|
||||
smartCase,
|
||||
maxMatchesPerFile: Math.min(effectiveLimit, 50),
|
||||
maxMatchesPerFile: pageSize,
|
||||
pageSize,
|
||||
cursor: null,
|
||||
beforeContext: 0,
|
||||
afterContext: 0,
|
||||
@@ -1015,7 +1030,11 @@ export default function fffExtension(pi: ExtensionAPI) {
|
||||
constraints: Type.Optional(
|
||||
Type.String({ description: "File filter, e.g. '*.{ts,tsx} !test/'" }),
|
||||
),
|
||||
context: Type.Optional(Type.Number({ description: "Context lines before+after" })),
|
||||
context: Type.Optional(
|
||||
Type.Number({
|
||||
description: `Context lines before+after (0-${GREP_CONTEXT_MAX})`,
|
||||
}),
|
||||
),
|
||||
limit: Type.Optional(
|
||||
Type.Number({
|
||||
description: `Max matches (default ${DEFAULT_GREP_LIMIT})`,
|
||||
@@ -1044,15 +1063,18 @@ export default function fffExtension(pi: ExtensionAPI) {
|
||||
|
||||
const f = await ensureFinder(activeCwd);
|
||||
const effectiveLimit = Math.max(1, params.limit ?? DEFAULT_GREP_LIMIT);
|
||||
const pageSize = Math.min(effectiveLimit, GREP_PAGE_SIZE_MAX);
|
||||
const context = clampContext(params.context);
|
||||
|
||||
const grepResult = f.multiGrep({
|
||||
patterns: params.patterns,
|
||||
constraints: params.constraints,
|
||||
maxMatchesPerFile: Math.min(effectiveLimit, 50),
|
||||
maxMatchesPerFile: pageSize,
|
||||
pageSize,
|
||||
smartCase: true,
|
||||
cursor: (params.cursor ? getCursor(params.cursor) : null) ?? null,
|
||||
beforeContext: params.context ?? 0,
|
||||
afterContext: params.context ?? 0,
|
||||
beforeContext: context,
|
||||
afterContext: context,
|
||||
});
|
||||
|
||||
if (!grepResult.ok) throw new Error(grepResult.error);
|
||||
|
||||
@@ -22,8 +22,21 @@ function detectRuntime(): "bun" | "node" {
|
||||
export function loadSdk(): Promise<{ FileFinder: FileFinderStatic }> {
|
||||
if (sdkPromise) return sdkPromise;
|
||||
|
||||
// Pi reloads extension modules with jiti moduleCache:false, so this module
|
||||
// is re-executed on every /reload. Re-importing the fff-bun module graph
|
||||
// (which top-level awaits a `type: "file"` import of the native .so) hangs
|
||||
// forever inside the Bun-compiled pi binary. Cache the first import on
|
||||
// globalThis so reloads reuse the resolved module instead of re-importing.
|
||||
const g = globalThis as Record<string, unknown>;
|
||||
if (g.__fffSdkPromiseGlobal) {
|
||||
sdkPromise = g.__fffSdkPromiseGlobal as Promise<{ FileFinder: FileFinderStatic }>;
|
||||
return sdkPromise;
|
||||
}
|
||||
|
||||
// default to node as it seems like default option
|
||||
const pkg = detectRuntime() === "bun" ? "@ff-labs/fff-bun" : "@ff-labs/fff-node";
|
||||
sdkPromise = import(pkg) as Promise<{ FileFinder: FileFinderStatic }>;
|
||||
return sdkPromise;
|
||||
const p = import(pkg) as Promise<{ FileFinder: FileFinderStatic }>;
|
||||
sdkPromise = p;
|
||||
(globalThis as Record<string, unknown>).__fffSdkPromiseGlobal = p;
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -119,16 +119,26 @@ describe("AuxFinderPool covering reuse", () => {
|
||||
expect(createOptions[0].enableHomeDirScanning).toBe(false);
|
||||
});
|
||||
|
||||
// Regression for #700: aux finders must not reopen the main frecency/history
|
||||
// LMDB envs, or heed fails with "environment already open in this program".
|
||||
test("aux finders are created without frecency/history db paths", async () => {
|
||||
const pool = makePool();
|
||||
// #700 is fixed by the process-wide LMDB env pool: same-path opens share one
|
||||
// env, so aux finders now reuse the session's frecency/history DBs.
|
||||
test("aux finders receive the pool's frecency/history db paths", async () => {
|
||||
const pool = makePool({
|
||||
frecencyDbPath: "/dbs/frecency",
|
||||
historyDbPath: "/dbs/history",
|
||||
});
|
||||
await pool.acquire("/a/b/c");
|
||||
await pool.acquire("/x/y");
|
||||
expect(createOptions.length).toBe(2);
|
||||
for (const opts of createOptions) {
|
||||
expect(opts.frecencyDbPath).toBeUndefined();
|
||||
expect(opts.historyDbPath).toBeUndefined();
|
||||
expect(opts.frecencyDbPath).toBe("/dbs/frecency");
|
||||
expect(opts.historyDbPath).toBe("/dbs/history");
|
||||
}
|
||||
});
|
||||
|
||||
test("aux finders stay db-less when the session has no db paths", async () => {
|
||||
const pool = makePool();
|
||||
await pool.acquire("/a/b/c");
|
||||
expect(createOptions[0].frecencyDbPath).toBeUndefined();
|
||||
expect(createOptions[0].historyDbPath).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
+1
-1
@@ -77,4 +77,4 @@ git push origin "$TAG"
|
||||
|
||||
echo ""
|
||||
echo "Release $VERSION created and pushed."
|
||||
echo "CI will build and publish: https://github.com/dmtrKovalenko/fff.nvim/actions"
|
||||
echo "CI will build and publish: https://github.com/dmtrKovalenko/fff/actions"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---@diagnostic disable: undefined-field, missing-fields
|
||||
-- Regression test for https://github.com/dmtrKovalenko/fff.nvim/issues/389
|
||||
-- Regression test for https://github.com/dmtrKovalenko/fff/issues/389
|
||||
-- When find_files_in_dir(dir) runs with dir != neovim's cwd, the Rust indexer
|
||||
-- reports paths relative to `dir`, but the Lua side used to resolve them
|
||||
-- against neovim's cwd when calling :edit / preview / quickfix — so files
|
||||
|
||||
@@ -31,7 +31,7 @@ local function find_result_by_name(items, name)
|
||||
end
|
||||
|
||||
describe('programmatic search APIs', function()
|
||||
describe('against the actual fff.nvim repo', function()
|
||||
describe('against the actual fff repo', function()
|
||||
before_each(function()
|
||||
pcall(vim.api.nvim_del_augroup_by_name, 'fff_file_tracking')
|
||||
vim.g.fff = {}
|
||||
@@ -181,9 +181,9 @@ describe('programmatic search APIs', function()
|
||||
fd:write('-- only lives in the other sandbox\n')
|
||||
fd:close()
|
||||
|
||||
-- Sanity: the file does not exist in the primary (fff.nvim) index.
|
||||
-- Sanity: the file does not exist in the primary (fff) index.
|
||||
local before = fff.file_search(other_filename)
|
||||
assert.are.equal(0, #before.items, 'sandbox file leaked into primary fff.nvim index')
|
||||
assert.are.equal(0, #before.items, 'sandbox file leaked into primary fff index')
|
||||
|
||||
local result = fff.file_search(other_filename, { cwd = sandbox_root })
|
||||
assert.is_true(#result.items > 0, 'cwd switch did not surface file from the new root')
|
||||
@@ -202,7 +202,7 @@ describe('programmatic search APIs', function()
|
||||
sandbox_root = vim.fn.tempname() .. '_other_grep'
|
||||
vim.fn.mkdir(sandbox_root, 'p')
|
||||
-- Build the marker by concatenation so the literal string doesn't
|
||||
-- appear anywhere in the fff.nvim tree (otherwise the "before" grep
|
||||
-- appear anywhere in the fff tree (otherwise the "before" grep
|
||||
-- would find this very test file via its own marker constant).
|
||||
local marker = 'isolated_grep' .. '_marker_xyzzy'
|
||||
local fd = assert(io.open(sandbox_root .. '/grep_target.lua', 'w'))
|
||||
@@ -214,9 +214,9 @@ describe('programmatic search APIs', function()
|
||||
-- this is fine in practice cause this is not a real use case for fff to search RIGHT AFTER mkdir
|
||||
if vim.fn.has('win32') == 1 then vim.wait(250, function() return false end) end
|
||||
|
||||
-- Marker must not exist anywhere in the primary fff.nvim tree.
|
||||
-- Marker must not exist anywhere in the primary fff tree.
|
||||
local before = fff.content_search(marker)
|
||||
assert.are.equal(0, #before.items, 'marker leaked into primary fff.nvim tree')
|
||||
assert.are.equal(0, #before.items, 'marker leaked into primary fff tree')
|
||||
|
||||
local result = fff.content_search(marker, { cwd = sandbox_root })
|
||||
assert.is_true(#result.items > 0, 'cwd switch did not surface match from the new root')
|
||||
|
||||
Reference in New Issue
Block a user