@@ -20,6 +20,7 @@ import type {
2020 ProjectSearchEntriesResult ,
2121} from "@t3tools/contracts" ;
2222import { isWorkspaceImagePreviewPath } from "@t3tools/shared/filePreview" ;
23+ import { HostProcessPlatform } from "@t3tools/shared/hostProcess" ;
2324
2425import * as WorkspaceSearchIndexService from "./WorkspaceSearchIndexService.ts" ;
2526
@@ -35,8 +36,8 @@ const CONTENT_SEARCH_TIME_BUDGET_MS = 250;
3536const CONTENT_SEARCH_MAX_MATCHES_PER_FILE = 100 ;
3637const CONTENT_SEARCH_MAX_CANDIDATES = 25_000 ;
3738
38- function toPosixPath ( input : string ) : string {
39- return input . replaceAll ( "\\" , "/" ) ;
39+ function toPosixPath ( input : string , platform : NodeJS . Platform ) : string {
40+ return platform === "win32" ? input . replaceAll ( "\\" , "/" ) : input ;
4041}
4142
4243function trimDirectorySeparator ( input : string ) : string {
@@ -48,8 +49,8 @@ function parentPathOf(input: string): string | undefined {
4849 return separatorIndex === - 1 ? undefined : input . slice ( 0 , separatorIndex ) ;
4950}
5051
51- function toProjectEntry ( item : MixedItem ) : ProjectEntry | null {
52- const normalizedPath = trimDirectorySeparator ( toPosixPath ( item . item . relativePath ) ) ;
52+ function toProjectEntry ( item : MixedItem , platform : NodeJS . Platform ) : ProjectEntry | null {
53+ const normalizedPath = trimDirectorySeparator ( toPosixPath ( item . item . relativePath , platform ) ) ;
5354 if ( ! normalizedPath ) {
5455 return null ;
5556 }
@@ -60,23 +61,24 @@ function toProjectEntry(item: MixedItem): ProjectEntry | null {
6061 } ;
6162}
6263
63- function toFileEntry ( item : FileItem ) : ProjectEntry | null {
64- const normalizedPath = trimDirectorySeparator ( toPosixPath ( item . relativePath ) ) ;
64+ function toFileEntry ( item : FileItem , platform : NodeJS . Platform ) : ProjectEntry | null {
65+ const normalizedPath = trimDirectorySeparator ( toPosixPath ( item . relativePath , platform ) ) ;
6566 return normalizedPath ? { path : normalizedPath , kind : "file" } : null ;
6667}
6768
68- function toDirectoryEntry ( item : DirItem ) : ProjectEntry | null {
69- const normalizedPath = trimDirectorySeparator ( toPosixPath ( item . relativePath ) ) ;
69+ function toDirectoryEntry ( item : DirItem , platform : NodeJS . Platform ) : ProjectEntry | null {
70+ const normalizedPath = trimDirectorySeparator ( toPosixPath ( item . relativePath , platform ) ) ;
7071 return normalizedPath ? { path : normalizedPath , kind : "directory" } : null ;
7172}
7273
7374function mapFileSearchResult (
7475 result : SearchResult ,
7576 limit : number ,
77+ platform : NodeJS . Platform ,
7678 imageOnly = false ,
7779) : ProjectSearchEntriesResult {
7880 const entries = result . items . flatMap ( ( item ) => {
79- const entry = toFileEntry ( item ) ;
81+ const entry = toFileEntry ( item , platform ) ;
8082 return entry && ( ! imageOnly || isWorkspaceImagePreviewPath ( entry . path ) ) ? [ entry ] : [ ] ;
8183 } ) ;
8284 return {
@@ -88,9 +90,10 @@ function mapFileSearchResult(
8890function mapDirectorySearchResult (
8991 result : DirSearchResult ,
9092 limit : number ,
93+ platform : NodeJS . Platform ,
9194) : ProjectSearchEntriesResult {
9295 const entries = result . items . flatMap ( ( item ) => {
93- const entry = toDirectoryEntry ( item ) ;
96+ const entry = toDirectoryEntry ( item , platform ) ;
9497 return entry ? [ entry ] : [ ] ;
9598 } ) ;
9699 const rootDirectoryCount = result . items . some ( ( item ) => item . relativePath . length === 0 ) ? 1 : 0 ;
@@ -103,10 +106,11 @@ function mapDirectorySearchResult(
103106function mapMixedSearchResult (
104107 result : MixedSearchResult ,
105108 limit : number ,
109+ platform : NodeJS . Platform ,
106110) : { readonly entries : ProjectEntry [ ] ; readonly truncated : boolean } {
107111 const entries : ProjectEntry [ ] = [ ] ;
108112 for ( const item of result . items ) {
109- const entry = toProjectEntry ( item ) ;
113+ const entry = toProjectEntry ( item , platform ) ;
110114 if ( entry ) {
111115 entries . push ( entry ) ;
112116 }
@@ -267,6 +271,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
267271 cwd : string ,
268272 variant : WorkspaceSearchIndexService . WorkspaceSearchIndexVariant = "paths" ,
269273) {
274+ const platform = yield * HostProcessPlatform ;
270275 const finder = yield * Effect . acquireRelease ( createFinder ( cwd , variant ) , ( finder ) =>
271276 Effect . try ( {
272277 try : ( ) => finder . destroy ( ) ,
@@ -356,6 +361,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
356361 const mapped = mapMixedSearchResult (
357362 result ,
358363 WorkspaceSearchIndexService . WORKSPACE_INDEX_MAX_ENTRIES ,
364+ platform ,
359365 ) ;
360366 const sortedEntries = withDirectoryAncestors ( mapped . entries ) . toSorted ( ( left , right ) =>
361367 left . path . localeCompare ( right . path ) ,
@@ -377,18 +383,18 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
377383 const result = yield * runSearch ( query , pageSize , "fileSearch" , ( ) =>
378384 finder . fileSearch ( query , { pageSize } ) ,
379385 ) ;
380- return mapFileSearchResult ( result , limit , imageOnly ) ;
386+ return mapFileSearchResult ( result , limit , platform , imageOnly ) ;
381387 }
382388 if ( kind === "directory" ) {
383389 const result = yield * runSearch ( query , pageSize , "directorySearch" , ( ) =>
384390 finder . directorySearch ( query , { pageSize } ) ,
385391 ) ;
386- return mapDirectorySearchResult ( result , limit ) ;
392+ return mapDirectorySearchResult ( result , limit , platform ) ;
387393 }
388394 const result = yield * runSearch ( query , pageSize , "mixedSearch" , ( ) =>
389395 finder . mixedSearch ( query , { pageSize } ) ,
390396 ) ;
391- return mapMixedSearchResult ( result , limit ) ;
397+ return mapMixedSearchResult ( result , limit , platform ) ;
392398 } ) ;
393399
394400 const searchContents : WorkspaceSearchIndexService . WorkspaceSearchIndex [ "Service" ] [ "searchContents" ] =
@@ -429,7 +435,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
429435 ) ;
430436 if ( matchRanges . length === 0 ) continue ;
431437 pageMatches . push ( {
432- path : toPosixPath ( match . relativePath ) ,
438+ path : toPosixPath ( match . relativePath , platform ) ,
433439 lineNumber : match . lineNumber ,
434440 lineContent : match . lineContent ,
435441 matchRanges,
0 commit comments