Search (PQL DSL query) is now the default left tab; Markdown (filtered to .md files) on the right. Clicking a markdown file publishes on the message bus; the markdown extension activates the context panel viewer and re-publishes on a load channel after the frame so the viewer is guaranteed to be mounted. Viewer subscribes to load channel and editor buffer events, publishes focus for sidebar highlighting. Co-Authored-By: Claude <noreply@anthropic.com>
109 lines
2.4 KiB
Dart
109 lines
2.4 KiB
Dart
/// State model for the pql sidebar panel.
|
|
///
|
|
/// Manages schema cache, query execution, file listing, and
|
|
/// decision/ticket views. All data comes through pql.* IPC verbs.
|
|
library;
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:clide/kernel/kernel.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
enum PqlView { query, markdown }
|
|
|
|
class PqlController extends ChangeNotifier {
|
|
PqlController({required this.ipc});
|
|
|
|
final DaemonClient ipc;
|
|
|
|
PqlView _view = PqlView.query;
|
|
PqlView get view => _view;
|
|
|
|
String? _error;
|
|
String? get error => _error;
|
|
|
|
bool _loading = false;
|
|
bool get loading => _loading;
|
|
|
|
List<Map<String, Object?>> _results = const [];
|
|
List<Map<String, Object?>> get results => _results;
|
|
|
|
Map<String, Object?> _planStatus = const {};
|
|
Map<String, Object?> get planStatus => _planStatus;
|
|
|
|
void switchView(PqlView v) {
|
|
if (_view == v) return;
|
|
_view = v;
|
|
_results = const [];
|
|
_error = null;
|
|
notifyListeners();
|
|
switch (v) {
|
|
case PqlView.markdown:
|
|
unawaited(loadMarkdownFiles());
|
|
case PqlView.query:
|
|
break;
|
|
}
|
|
}
|
|
|
|
Future<void> loadMarkdownFiles({String? glob}) async {
|
|
_loading = true;
|
|
notifyListeners();
|
|
|
|
final r = await ipc.request('pql.files', args: {
|
|
'glob': glob ?? '**/*.md',
|
|
'limit': 200,
|
|
});
|
|
|
|
_loading = false;
|
|
if (!r.ok) {
|
|
_error = r.error?.message;
|
|
notifyListeners();
|
|
return;
|
|
}
|
|
_error = null;
|
|
_results = _castList(r.data['files']);
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> runQuery(String dsl) async {
|
|
if (dsl.trim().isEmpty) return;
|
|
_loading = true;
|
|
_error = null;
|
|
notifyListeners();
|
|
|
|
final r = await ipc.request('pql.query', args: {
|
|
'query': dsl,
|
|
'limit': 200,
|
|
});
|
|
|
|
_loading = false;
|
|
if (!r.ok) {
|
|
_error = r.error?.message;
|
|
_results = const [];
|
|
notifyListeners();
|
|
return;
|
|
}
|
|
_results = _castList(r.data['results']);
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> loadPlanStatus() async {
|
|
final r = await ipc.request('pql.plan.status');
|
|
if (r.ok) {
|
|
_planStatus = r.data;
|
|
notifyListeners();
|
|
}
|
|
}
|
|
|
|
void clearError() {
|
|
if (_error == null) return;
|
|
_error = null;
|
|
notifyListeners();
|
|
}
|
|
|
|
static List<Map<String, Object?>> _castList(Object? raw) {
|
|
if (raw is! List) return const [];
|
|
return [for (final e in raw) (e as Map).cast<String, Object?>()];
|
|
}
|
|
}
|