refactor: search-utils to use IVaultAdapter
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { App, TFile } from 'obsidian';
|
import { TFile } from 'obsidian';
|
||||||
import { SearchMatch } from '../types/mcp-types';
|
import { SearchMatch } from '../types/mcp-types';
|
||||||
import { GlobUtils } from './glob-utils';
|
import { GlobUtils } from './glob-utils';
|
||||||
|
import { IVaultAdapter } from '../adapters/interfaces';
|
||||||
|
|
||||||
export interface SearchOptions {
|
export interface SearchOptions {
|
||||||
query: string;
|
query: string;
|
||||||
@@ -25,7 +26,7 @@ export class SearchUtils {
|
|||||||
* Search vault files with advanced filtering and regex support
|
* Search vault files with advanced filtering and regex support
|
||||||
*/
|
*/
|
||||||
static async search(
|
static async search(
|
||||||
app: App,
|
vault: IVaultAdapter,
|
||||||
options: SearchOptions
|
options: SearchOptions
|
||||||
): Promise<{ matches: SearchMatch[]; stats: SearchStatistics }> {
|
): Promise<{ matches: SearchMatch[]; stats: SearchStatistics }> {
|
||||||
const {
|
const {
|
||||||
@@ -61,7 +62,7 @@ export class SearchUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get files to search
|
// Get files to search
|
||||||
let files = app.vault.getMarkdownFiles();
|
let files = vault.getMarkdownFiles();
|
||||||
|
|
||||||
// Filter by folder if specified
|
// Filter by folder if specified
|
||||||
if (folder) {
|
if (folder) {
|
||||||
@@ -87,7 +88,7 @@ export class SearchUtils {
|
|||||||
filesSearched++;
|
filesSearched++;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const content = await app.vault.read(file);
|
const content = await vault.read(file);
|
||||||
const fileMatches = this.searchInFile(
|
const fileMatches = this.searchInFile(
|
||||||
file,
|
file,
|
||||||
content,
|
content,
|
||||||
@@ -246,7 +247,7 @@ export class SearchUtils {
|
|||||||
* Search for Waypoint markers in vault
|
* Search for Waypoint markers in vault
|
||||||
*/
|
*/
|
||||||
static async searchWaypoints(
|
static async searchWaypoints(
|
||||||
app: App,
|
vault: IVaultAdapter,
|
||||||
folder?: string
|
folder?: string
|
||||||
): Promise<Array<{
|
): Promise<Array<{
|
||||||
path: string;
|
path: string;
|
||||||
@@ -264,7 +265,7 @@ export class SearchUtils {
|
|||||||
}> = [];
|
}> = [];
|
||||||
|
|
||||||
// Get files to search
|
// Get files to search
|
||||||
let files = app.vault.getMarkdownFiles();
|
let files = vault.getMarkdownFiles();
|
||||||
|
|
||||||
// Filter by folder if specified
|
// Filter by folder if specified
|
||||||
if (folder) {
|
if (folder) {
|
||||||
@@ -281,7 +282,7 @@ export class SearchUtils {
|
|||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
try {
|
try {
|
||||||
const content = await app.vault.read(file);
|
const content = await vault.read(file);
|
||||||
const lines = content.split('\n');
|
const lines = content.split('\n');
|
||||||
|
|
||||||
let inWaypoint = false;
|
let inWaypoint = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user