Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions packages/cli/src/fulltext/FileIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ import listGitProjectFiles from './listGitProjectFIles';
import querySymbols from './querySymbols';
import { fileNameMatchesFilterPatterns } from './fileNameMatchesFilterPatterns';

makeDebug.formatters.a = (v) => {
return v.join(' ');
};

const debug = makeDebug('appmap:file-index');

// enable to see all indexing terms for each file
const debugTerms = makeDebug('appmap:file-index:terms');

export type FileIndexMatch = {
directory: string;
fileName: string;
Expand Down Expand Up @@ -49,7 +56,7 @@ export class FileIndex {
const rows = this.database.prepare(query).all(searchExpr, limit);
if (debug.enabled)
for (const row of rows) {
debug(`Found row ${(row as { file_name: string }).file_name}`);
debug('Found row %s', (row as { file_name: string }).file_name);
}
return rows.map((row: any) => ({
directory: row.directory,
Expand Down Expand Up @@ -88,7 +95,8 @@ export class FileIndex {
if (options.allowSymbols) {
debug('Symbol parsing is enabled.');
debug(
`Generic symbol parsing is ${options.allowGenericParsing ? 'enabled.' : 'disabled.'}`
'Generic symbol parsing is %s',
options.allowGenericParsing ? 'enabled.' : 'disabled.'
);
} else {
debug('Symbol parsing is disabled.');
Expand Down Expand Up @@ -135,16 +143,17 @@ export class FileIndex {
const fileNameTokens = filePath.split(path.sep);

try {
let terms = queryKeywords(fileNameTokens).join(' ');
let terms = queryKeywords(fileNameTokens);

if (allowSymbols) {
const symbols = querySymbols(path.join(directory, filePath), allowGenericParsing);
terms += ` ${queryKeywords(symbols).sort().join(' ')}`;
terms = terms.concat(queryKeywords(symbols).sort());
}

debug(`Indexing file path ${filePath} with terms ${terms}`);
debug('Indexing file path %s with %d terms', filePath, terms.length);
debugTerms('Terms for path %s: %a', filePath, terms);

this.#insert.run(directory, filePath, terms);
this.#insert.run(directory, filePath, terms.join(' '));
} catch (error) {
console.warn(`Error indexing document ${filePath}`);
console.warn(error);
Expand Down Expand Up @@ -194,6 +203,7 @@ const BINARY_FILE_EXTENSIONS: string[] = [
'jar',
'jpeg',
'jpg',
'js.map',
'min.js',
'min.css',
'mkv',
Expand Down Expand Up @@ -229,6 +239,7 @@ const BINARY_FILE_EXTENSIONS: string[] = [
'xls',
'xlsx',
'xz',
'yarn.lock',
'zip',
].map((ext) => '.' + ext);

Expand Down Expand Up @@ -271,10 +282,10 @@ export async function filterFiles(
appendFile = true;
if (stats.size > 50_000) {
if (isDataFile(fileName)) {
debug(`Skipping large data file ${fileName} with size ${stats.size}`);
debug('Skipping large data file %s with size %d', fileName, stats.size);
appendFile = false;
} else {
debug(`WARNING Large file ${fileName} with size ${stats.size}`);
debug('WARNING Large file %s with size %d', fileName, stats.size);
}
}
}
Expand Down
Loading