drive workspace ignore from ignore_files:, add files.walk

Replace the hardcoded .gitignore + .clideignore read with the ordered
ignore_files: chain from .pql/config.yaml (D-4) — the single ignore
knob clide owns (D-3). readIgnoreFiles defaults to .gitignore (plus
.clideignore when present) when the config is absent or malformed, and
honours an explicit [] as "no file-based exclusions".

Add walkFiles + the files.walk command: a recursive, ignore-pruned,
capped flat file listing reused by quick-open (T-51) and the search
engine (T-52). Closes the never-filed ignore-layering placeholder in
files_commands.dart.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-31 20:08:34 +02:00
co-authored by Claude Opus 4.8
parent 7e76455775
commit d7be5535d5
7 changed files with 267 additions and 7 deletions
+11
View File
@@ -73,6 +73,17 @@ void main() {
expect(names, ['main.dart']);
});
test('files.walk returns a flat, recursive file list (no dirs, no ignored)', () async {
final r = await call('files.walk', const {});
expect(r.ok, isTrue);
final paths = (r.data['files'] as List).cast<String>();
expect(paths, containsAll(['README.md', 'pubspec.yaml', 'lib/main.dart']));
// Directories themselves are never emitted, and .dart_tool is pruned.
expect(paths, isNot(contains('lib')));
expect(paths.any((p) => p.startsWith('.dart_tool')), isFalse);
expect(r.data['truncated'], isFalse);
});
test('files.watch acks subscription', () async {
final r = await call('files.watch', const {});
expect(r.ok, isTrue);
+63
View File
@@ -0,0 +1,63 @@
/// Tests for `readIgnoreFiles` — resolving the clide-owned
/// `ignore_files:` key from `.pql/config.yaml` (D-3 / D-4).
library;
import 'dart:io';
import 'package:clide/src/files/pql_config.dart';
import 'package:test/test.dart';
void main() {
late Directory root;
setUp(() async {
root = await Directory.systemTemp.createTemp('clide-pqlconfig-');
});
tearDown(() async {
if (root.existsSync()) root.deleteSync(recursive: true);
});
void writeConfig(String body) {
Directory('${root.path}/.pql').createSync();
File('${root.path}/.pql/config.yaml').writeAsStringSync(body);
}
test('no config → defaults to [.gitignore]', () {
expect(readIgnoreFiles(root), ['.gitignore']);
});
test('no config but .clideignore present → adds it after .gitignore', () {
File('${root.path}/.clideignore').writeAsStringSync('build/\n');
expect(readIgnoreFiles(root), ['.gitignore', '.clideignore']);
});
test('explicit ignore_files list is honoured verbatim and in order', () {
writeConfig('ignore_files: [.gitignore, .pqlignore]\n');
expect(readIgnoreFiles(root), ['.gitignore', '.pqlignore']);
});
test('explicit empty list disables file-based exclusions', () {
writeConfig('ignore_files: []\n');
expect(readIgnoreFiles(root), isEmpty);
});
test('config present but key absent → default (ignores .clideignore rule only via default)', () {
writeConfig('frontmatter: yaml\n');
expect(readIgnoreFiles(root), ['.gitignore']);
});
test('non-string entries are dropped from the list', () {
writeConfig('ignore_files: [.gitignore, 42, .pqlignore]\n');
expect(readIgnoreFiles(root), ['.gitignore', '.pqlignore']);
});
test('malformed YAML falls back to the default (never throws)', () {
writeConfig('ignore_files: [unterminated\n:::bad');
expect(readIgnoreFiles(root), ['.gitignore']);
});
test('ignore_files set to a scalar (not a list) falls back to default', () {
writeConfig('ignore_files: .gitignore\n');
expect(readIgnoreFiles(root), ['.gitignore']);
});
}
+65
View File
@@ -0,0 +1,65 @@
/// Tests for `walkFiles` — the recursive, ignore-pruned, capped
/// workspace file walk behind `files.walk` and the search engine.
library;
import 'dart:io';
import 'package:clide/src/files/ignore.dart';
import 'package:clide/src/files/listing.dart';
import 'package:test/test.dart';
void main() {
late Directory root;
setUp(() async {
root = await Directory.systemTemp.createTemp('clide-walk-');
File('${root.path}/README.md').writeAsStringSync('a');
File('${root.path}/pubspec.yaml').writeAsStringSync('b');
Directory('${root.path}/lib/src').createSync(recursive: true);
File('${root.path}/lib/main.dart').writeAsStringSync('c');
File('${root.path}/lib/src/util.dart').writeAsStringSync('d');
Directory('${root.path}/build').createSync();
File('${root.path}/build/output.bin').writeAsStringSync('e');
});
tearDown(() async {
if (root.existsSync()) root.deleteSync(recursive: true);
});
test('walks recursively, returns files sorted by path', () async {
final r = await walkFiles(root: root, ignore: IgnoreSet([]));
expect(r.truncated, isFalse);
expect(r.files.map((e) => e.path).toList(), [
'README.md',
'build/output.bin',
'lib/main.dart',
'lib/src/util.dart',
'pubspec.yaml',
]);
});
test('prunes ignored directories (build/ via builtin ignore)', () async {
final r = await walkFiles(root: root, ignore: IgnoreSet.builtin());
final paths = r.files.map((e) => e.path).toList();
expect(paths, isNot(contains('build/output.bin')));
expect(paths, containsAll(['README.md', 'lib/main.dart', 'lib/src/util.dart']));
});
test('emits only files, never directory entries', () async {
final r = await walkFiles(root: root, ignore: IgnoreSet([]));
expect(r.files.every((e) => !e.isDirectory), isTrue);
});
test('respects the maxFiles cap and flags truncation', () async {
final r = await walkFiles(root: root, ignore: IgnoreSet([]), maxFiles: 2);
expect(r.truncated, isTrue);
expect(r.files, hasLength(2));
});
test('an empty workspace yields no files and is not truncated', () async {
final empty = await Directory.systemTemp.createTemp('clide-walk-empty-');
addTearDown(() => empty.deleteSync(recursive: true));
final r = await walkFiles(root: empty, ignore: IgnoreSet([]));
expect(r.files, isEmpty);
expect(r.truncated, isFalse);
});
}