Refactor: Rename file search functions for clarity

This commit is contained in:
travertexg 2025-06-09 16:52:36 +00:00
parent c2dfb48e22
commit 250a0e1bde
5 changed files with 14 additions and 14 deletions

View File

@ -29,10 +29,10 @@ import {
LLMBaseUrlNotSetException, LLMBaseUrlNotSetException,
LLMModelNotSetException, LLMModelNotSetException,
} from '../../core/llm/exception' } from '../../core/llm/exception'
import { searchFilesWithCorePlugin } from '../../core/search/match/coreplugin-match' import { matchSearchUsingCorePlugin } from '../../core/search/match/coreplugin-match'
import { searchFilesWithOmnisearch } from '../../core/search/match/omnisearch-match' import { matchSearchUsingOmnisearch } from '../../core/search/match/omnisearch-match'
import { regexSearchFilesWithRipgrep } from '../../core/search/regex/ripgrep-regex' import { regexSearchUsingRipgrep } from '../../core/search/regex/ripgrep-regex'
import { regexSearchFilesWithCorePlugin } from '../../core/search/regex/coreplugin-regex' import { regexSearchUsingCorePlugin } from '../../core/search/regex/coreplugin-regex'
import { useChatHistory } from '../../hooks/use-chat-history' import { useChatHistory } from '../../hooks/use-chat-history'
import { useCustomModes } from '../../hooks/use-custom-mode' import { useCustomModes } from '../../hooks/use-custom-mode'
import { t } from '../../lang/helpers' import { t } from '../../lang/helpers'
@ -614,9 +614,9 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
const searchBackend = settings.matchSearchBackend const searchBackend = settings.matchSearchBackend
let results: string; let results: string;
if (searchBackend === 'omnisearch') { if (searchBackend === 'omnisearch') {
results = await searchFilesWithOmnisearch(toolArgs.query, app) results = await matchSearchUsingOmnisearch(toolArgs.query, app)
} else { } else {
results = await searchFilesWithCorePlugin(toolArgs.query, app) results = await matchSearchUsingCorePlugin(toolArgs.query, app)
} }
const formattedContent = `[match_search_files for '${toolArgs.filepath}'] Result:\n${results}\n`; const formattedContent = `[match_search_files for '${toolArgs.filepath}'] Result:\n${results}\n`;
return { return {
@ -636,13 +636,13 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
const searchBackend = settings.regexSearchBackend const searchBackend = settings.regexSearchBackend
let results: string; let results: string;
if (searchBackend === 'coreplugin') { if (searchBackend === 'coreplugin') {
results = await regexSearchFilesWithCorePlugin(toolArgs.regex, app) results = await regexSearchUsingCorePlugin(toolArgs.regex, app)
} else { } else {
// @ts-expect-error Obsidian API type mismatch // @ts-expect-error Obsidian API type mismatch
const baseVaultPath = String(app.vault.adapter.getBasePath()) const baseVaultPath = String(app.vault.adapter.getBasePath())
const absolutePath = path.join(baseVaultPath, toolArgs.filepath) const absolutePath = path.join(baseVaultPath, toolArgs.filepath)
const ripgrepPath = settings.ripgrepPath const ripgrepPath = settings.ripgrepPath
results = await regexSearchFilesWithRipgrep(absolutePath, toolArgs.regex, ripgrepPath) results = await regexSearchUsingRipgrep(absolutePath, toolArgs.regex, ripgrepPath)
} }
const formattedContent = `[regex_search_files for '${toolArgs.filepath}'] Result:\n${results}\n`; const formattedContent = `[regex_search_files for '${toolArgs.filepath}'] Result:\n${results}\n`;
return { return {

View File

@ -14,7 +14,7 @@ import {
* @param query The query to search for. * @param query The query to search for.
* @returns A promise that resolves to a formatted string of search results. * @returns A promise that resolves to a formatted string of search results.
*/ */
export async function searchFilesWithCorePlugin( export async function matchSearchUsingCorePlugin(
query: string, query: string,
app: App, app: App,
): Promise<string> { ): Promise<string> {

View File

@ -47,7 +47,7 @@ function isOmnisearchAvailable(): boolean {
* @param app The Obsidian App instance. * @param app The Obsidian App instance.
* @returns A formatted string of search results. * @returns A formatted string of search results.
*/ */
export async function searchFilesWithOmnisearch( export async function matchSearchUsingOmnisearch(
query: string, query: string,
app: App, app: App,
): Promise<string> { ): Promise<string> {

View File

@ -1,5 +1,5 @@
import { App } from "obsidian"; import { App } from "obsidian";
import { searchFilesWithCorePlugin } from '../match/coreplugin-match' import { matchSearchUsingCorePlugin } from '../match/coreplugin-match'
/** /**
* Performs a regular expression search using Obsidian's core search plugin. * Performs a regular expression search using Obsidian's core search plugin.
@ -8,10 +8,10 @@ import { searchFilesWithCorePlugin } from '../match/coreplugin-match'
* @param regex The regular expression to search for. * @param regex The regular expression to search for.
* @returns A promise that resolves to a formatted string of search results. * @returns A promise that resolves to a formatted string of search results.
*/ */
export async function regexSearchFilesWithCorePlugin( export async function regexSearchUsingCorePlugin(
regex: string, regex: string,
app: App, app: App,
): Promise<string> { ): Promise<string> {
const regexQuery = `/${regex}/`; const regexQuery = `/${regex}/`;
return searchFilesWithCorePlugin(regexQuery, app); return matchSearchUsingCorePlugin(regexQuery, app);
} }

View File

@ -66,7 +66,7 @@ async function execRipgrep(bin: string, args: string[]): Promise<string> {
}) })
} }
export async function regexSearchFilesWithRipgrep( export async function regexSearchUsingRipgrep(
directoryPath: string, directoryPath: string,
regex: string, regex: string,
ripgrepPath: string, ripgrepPath: string,