Skip to content

Commit 6d9d946

Browse files
committed
fix: filtering, revamp logic
- Remove the query language stuff that was a pain to use (long term should be replaced with a notebook) - Uses a simple 'language' similar to the VS Code marketplace search syntax. - Build that and fix filtering to work in the flame graph Fixes #5
1 parent d1fa975 commit 6d9d946

28 files changed

+654
-1254
lines changed

.vscode/settings.json

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// Place your settings in this file to overwrite default and user settings.
22
{
3-
"files.exclude": {
4-
"**/out": false // set this to true to hide the "out" folder with the compiled JS files
5-
},
6-
"search.exclude": {
7-
"**/out": true // set this to false to include "out" folder in search results
8-
},
9-
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10-
"typescript.tsc.autoDetect": "off",
11-
"eslint.enable": true
3+
"files.exclude": {
4+
"**/out": false // set this to true to hide the "out" folder with the compiled JS files
5+
},
6+
"search.exclude": {
7+
"**/out": true // set this to false to include "out" folder in search results
8+
},
9+
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10+
"typescript.tsc.autoDetect": "off",
11+
"eslint.enable": true,
12+
"editor.formatOnSave": true,
13+
"editor.codeActionsOnSave": {
14+
"source.organizeImports": true
15+
}
1216
}

packages/vscode-js-profile-core/src/client/rich-filter.tsx

+11-17
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
* Copyright (C) Microsoft Corporation. All rights reserved.
33
*--------------------------------------------------------*/
44

5-
import { h, FunctionComponent, Fragment, ComponentChild } from 'preact';
6-
import { useState, useEffect, useContext } from 'preact/hooks';
7-
import { Filter } from './filter';
8-
import { ToggleButton } from './toggle-button';
5+
import { ComponentChild, Fragment, FunctionComponent, h } from 'preact';
6+
import { useContext, useEffect, useState } from 'preact/hooks';
97
import * as CaseSensitive from 'vscode-codicons/src/icons/case-sensitive.svg';
108
import * as Regex from 'vscode-codicons/src/icons/regex.svg';
9+
import { evaluate, IDataSource, IQueryResults } from '../ql';
10+
import { Filter } from './filter';
1111
import styles from './rich-filter.css';
12-
import { evaluate, IDataSource } from '../ql';
13-
import { VsCodeApi, IVscodeApi } from './vscodeApi';
12+
import { ToggleButton } from './toggle-button';
1413
import { useLazyEffect } from './useLazyEffect';
14+
import { IVscodeApi, VsCodeApi } from './vscodeApi';
1515

1616
/**
1717
* Filter that the RichFilter returns,
@@ -42,15 +42,13 @@ export const compileFilter = (fn: IRichFilter): ((input: string) => boolean) =>
4242
export type RichFilterComponent<T> = FunctionComponent<{
4343
data: IDataSource<T>;
4444
placeholder: string;
45-
getDefaultFilterText: (value: T) => ReadonlyArray<string>;
46-
onChange: (data: ReadonlyArray<T>) => void;
45+
onChange: (data: IQueryResults<T>) => void;
4746
foot?: ComponentChild;
4847
}>;
4948

5049
export const richFilter = <T extends {}>(): RichFilterComponent<T> => ({
5150
placeholder,
5251
data,
53-
getDefaultFilterText,
5452
onChange,
5553
foot,
5654
}) => {
@@ -65,17 +63,13 @@ export const richFilter = <T extends {}>(): RichFilterComponent<T> => ({
6563
}, [text]);
6664

6765
useEffect(() => {
68-
if (!text.includes('query()')) {
69-
const filter = compileFilter({ text, caseSensitive, regex });
70-
onChange(data.data.filter(d => getDefaultFilterText(d).some(filter)));
71-
return;
72-
}
73-
7466
try {
7567
onChange(
7668
evaluate({
77-
expression: text,
78-
dataSources: { query: data },
69+
input: text,
70+
regex,
71+
caseSensitive,
72+
datasource: data,
7973
}),
8074
);
8175
setError(undefined);

packages/vscode-js-profile-core/src/cpu/layout.tsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import { h, FunctionComponent, Fragment, ComponentType } from 'preact';
55
import { useState, useMemo } from 'preact/hooks';
66
import { richFilter, RichFilterComponent } from '../client/rich-filter';
77
import styles from './layout.css';
8-
import { IDataSource } from '../ql';
8+
import { IDataSource, IQueryResults } from '../ql';
99

1010
export interface IBodyProps<T> {
11-
data: ReadonlyArray<T>;
11+
data: IQueryResults<T>;
1212
}
1313

1414
type CpuProfileLayoutComponent<T> = FunctionComponent<{
1515
data: IDataSource<T>;
16-
getDefaultFilterText: (value: T) => ReadonlyArray<string>;
1716
body: ComponentType<IBodyProps<T>>;
1817
filterFooter?: ComponentType<{}>;
1918
}>;
@@ -23,20 +22,18 @@ type CpuProfileLayoutComponent<T> = FunctionComponent<{
2322
*/
2423
export const cpuProfileLayoutFactory = <T extends {}>(): CpuProfileLayoutComponent<T> => ({
2524
data,
26-
getDefaultFilterText,
2725
body: RowBody,
2826
filterFooter: FilterFooter,
2927
}) => {
3028
const RichFilter = useMemo<RichFilterComponent<T>>(richFilter, []);
31-
const [filteredData, setFilteredData] = useState<ReadonlyArray<T> | undefined>(undefined);
29+
const [filteredData, setFilteredData] = useState<IQueryResults<T> | undefined>(undefined);
3230
const footer = useMemo(() => (FilterFooter ? <FilterFooter /> : undefined), [FilterFooter]);
3331

3432
return (
3533
<Fragment>
3634
<div className={styles.filter}>
3735
<RichFilter
3836
data={data}
39-
getDefaultFilterText={getDefaultFilterText}
4037
onChange={setFilteredData}
4138
placeholder="Filter functions or files, or start a query()"
4239
foot={footer}

packages/vscode-js-profile-core/src/cpu/model.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const enum Category {
1414
System,
1515
User,
1616
Module,
17+
Deemphasized,
1718
}
1819

1920
/**

packages/vscode-js-profile-core/src/ql/column.ts

-56
This file was deleted.

packages/vscode-js-profile-core/src/ql/emitter.ts

-41
This file was deleted.

0 commit comments

Comments
 (0)