Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ tmp/appmap
packages/*/tmp/
*.appmap.json
.navie
.run-stats

3 changes: 3 additions & 0 deletions appmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ packages:
- .yarn
- path: packages/search
exclude:
- search/built/tokenize
- search/built/query-keywords
- search/built/split-camelized
- node_modules
- .yarn
- path: packages/client
Expand Down
44 changes: 34 additions & 10 deletions packages/cli/src/cmds/search/search.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import yargs from 'yargs';

import sqlite3 from 'better-sqlite3';
import assert from 'assert';
import { readFileSync } from 'fs';
import { writeFile } from 'fs/promises';
import { AppMap, AppMapFilter, buildAppMap, deserializeFilter } from '@appland/models';
import { FileIndex } from '@appland/search';

import { handleWorkingDirectory } from '../../lib/handleWorkingDirectory';
import { verbose } from '../../utils';
import searchSingleAppMap, { SearchOptions as SingleSearchOptions } from './searchSingleAppMap';
import AppMapIndex, {
SearchResponse as DiagramsSearchResponse,
SearchOptions,
} from '../../fulltext/AppMapIndex';
import { SearchResponse as DiagramsSearchResponse } from '../../rpc/explain/index/appmap-match';
import {
SearchResult as EventSearchResult,
SearchResponse as EventSearchResponse,
} from '../../fulltext/FindEvents';
import { openInBrowser } from '../open/openers';
import { buildAppMapIndex, search } from '../../rpc/explain/index/appmap-index';
import buildIndexInTempDir from '../../rpc/explain/index/build-index-in-temp-dir';

export const command = 'search <query>';
export const describe =
Expand Down Expand Up @@ -83,7 +83,21 @@ export const builder = (args: yargs.Argv) => {
return args.strict();
};

export const handler = async (argv: any) => {
type ArgumentTypes = {
directory: string;
query: string;
appmap: string;
contextDepth: number;
maxSize: string;
filter: string;
show: boolean;
maxResults: number;
findEvents: boolean;
format: 'json' | 'appmap';
verbose: boolean;
};

export const handler = async (argv: ArgumentTypes) => {
verbose(argv.verbose);

const { directory, query, appmap, contextDepth, show, maxResults, findEvents, format } = argv;
Expand Down Expand Up @@ -160,19 +174,29 @@ export const handler = async (argv: any) => {
maxResults,
};
const { maxSize, filter: filterStr } = argv;
if (maxSize) options.maxSize = maxSize;
if (maxSize) options.maxSize = parseInt(maxSize);
if (filterStr) options.filter = deserializeFilter(filterStr);
const response = await searchSingleAppMap(appmap, query, options);
await presentResults(response);
} else {
const options: SearchOptions = {
const options = {
maxResults,
};
const response = await AppMapIndex.search([process.cwd()], query, options);

const index = await buildIndexInTempDir('appmaps', async (indexFile) => {
const db = new sqlite3(indexFile);
const fileIndex = new FileIndex(db);
await buildAppMapIndex(fileIndex, [process.cwd()]);
return fileIndex;
});

const response = await search(index.index, query.split(/\s+/).join(' OR '), maxResults);
index.close();

if (findEvents) {
const eventOptions: SingleSearchOptions = { maxResults };
const { maxSize, filter: filterStr } = argv;
if (maxSize) eventOptions.maxSize = maxSize;
if (maxSize) eventOptions.maxSize = parseInt(maxSize, 10);
if (filterStr) eventOptions.filter = deserializeFilter(filterStr);

const { results } = response;
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/cmds/search/searchSingleAppMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default async function searchSingleAppMap(
query: string,
options: SearchOptions = {}
): Promise<SearchResponse> {
// eslint-disable-next-line no-param-reassign
if (appmap.endsWith('.appmap.json')) appmap = appmap.slice(0, -'.appmap.json'.length);

const findEvents = new FindEvents(appmap);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/unbound-method */
/* eslint-disable class-methods-use-this */
const { CodeObject } = require('@appland/models');
const { CodeObjectType } = require('@appland/models');
const Unique = require('./unique');

function packageOf(codeObject) {
Expand All @@ -9,7 +9,7 @@ function packageOf(codeObject) {
}

const ancestors = [codeObject, ...codeObject.ancestors()];
let packageObject = ancestors.find((a) => a.type === CodeObject.PACKAGE);
let packageObject = ancestors.find((a) => a.type === CodeObjectType.PACKAGE);
if (!packageObject && ancestors.length >= 1) {
packageObject = ancestors[ancestors.length - 1];
}
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/src/fingerprint/fingerprintQueue.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { queue, QueueObject } from 'async';
import FileTooLargeError from './fileTooLargeError';
import Fingerprinter from './fingerprinter';

function isNodeError(error: unknown, code?: string): error is NodeJS.ErrnoException {
return error instanceof Error && (!code || (error as NodeJS.ErrnoException).code === code);
}
import { isNodeError } from '../utils';

export default class FingerprintQueue {
public handler: Fingerprinter;
Expand Down
Loading
Loading