Skip to content

Commit 85060bb

Browse files
committed
fix: Pass absolute path when loading file content
1 parent ac00047 commit 85060bb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/search/src/build-snippet-index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isAbsolute, join } from 'path';
12
import { Tokenizer } from './build-file-index';
23
import { ContentReader } from './ioutil';
34
import SnippetIndex from './snippet-index';
@@ -16,14 +17,16 @@ type Context = {
1617
};
1718

1819
async function indexFile(context: Context, file: File) {
19-
const fileContent = await context.contentReader(file.filePath);
20+
const filePath = isAbsolute(file.filePath) ? file.filePath : join(file.directory, file.filePath);
21+
22+
const fileContent = await context.contentReader(filePath);
2023
if (!fileContent) return;
2124

2225
const extension = file.filePath.split('.').pop() || '';
2326
const chunks = await context.splitter(fileContent, extension);
2427

2528
chunks.forEach((chunk, index) => {
26-
const snippetId = `${file.filePath}:${index}`;
29+
const snippetId = `${filePath}:${index}`;
2730
const { content, startLine, endLine } = chunk;
2831
context.snippetIndex.indexSnippet(
2932
snippetId,

0 commit comments

Comments
 (0)