Skip to content

Commit

Permalink
fix: filtering, revamp logic
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
connor4312 committed Jul 19, 2020
1 parent d1fa975 commit 6d9d946
Show file tree
Hide file tree
Showing 28 changed files with 654 additions and 1,254 deletions.
22 changes: 13 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"**/out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"**/out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"eslint.enable": true
"files.exclude": {
"**/out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"**/out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"eslint.enable": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}
28 changes: 11 additions & 17 deletions packages/vscode-js-profile-core/src/client/rich-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import { h, FunctionComponent, Fragment, ComponentChild } from 'preact';
import { useState, useEffect, useContext } from 'preact/hooks';
import { Filter } from './filter';
import { ToggleButton } from './toggle-button';
import { ComponentChild, Fragment, FunctionComponent, h } from 'preact';
import { useContext, useEffect, useState } from 'preact/hooks';
import * as CaseSensitive from 'vscode-codicons/src/icons/case-sensitive.svg';
import * as Regex from 'vscode-codicons/src/icons/regex.svg';
import { evaluate, IDataSource, IQueryResults } from '../ql';
import { Filter } from './filter';
import styles from './rich-filter.css';
import { evaluate, IDataSource } from '../ql';
import { VsCodeApi, IVscodeApi } from './vscodeApi';
import { ToggleButton } from './toggle-button';
import { useLazyEffect } from './useLazyEffect';
import { IVscodeApi, VsCodeApi } from './vscodeApi';

/**
* Filter that the RichFilter returns,
Expand Down Expand Up @@ -42,15 +42,13 @@ export const compileFilter = (fn: IRichFilter): ((input: string) => boolean) =>
export type RichFilterComponent<T> = FunctionComponent<{
data: IDataSource<T>;
placeholder: string;
getDefaultFilterText: (value: T) => ReadonlyArray<string>;
onChange: (data: ReadonlyArray<T>) => void;
onChange: (data: IQueryResults<T>) => void;
foot?: ComponentChild;
}>;

export const richFilter = <T extends {}>(): RichFilterComponent<T> => ({
placeholder,
data,
getDefaultFilterText,
onChange,
foot,
}) => {
Expand All @@ -65,17 +63,13 @@ export const richFilter = <T extends {}>(): RichFilterComponent<T> => ({
}, [text]);

useEffect(() => {
if (!text.includes('query()')) {
const filter = compileFilter({ text, caseSensitive, regex });
onChange(data.data.filter(d => getDefaultFilterText(d).some(filter)));
return;
}

try {
onChange(
evaluate({
expression: text,
dataSources: { query: data },
input: text,
regex,
caseSensitive,
datasource: data,
}),
);
setError(undefined);
Expand Down
9 changes: 3 additions & 6 deletions packages/vscode-js-profile-core/src/cpu/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import { h, FunctionComponent, Fragment, ComponentType } from 'preact';
import { useState, useMemo } from 'preact/hooks';
import { richFilter, RichFilterComponent } from '../client/rich-filter';
import styles from './layout.css';
import { IDataSource } from '../ql';
import { IDataSource, IQueryResults } from '../ql';

export interface IBodyProps<T> {
data: ReadonlyArray<T>;
data: IQueryResults<T>;
}

type CpuProfileLayoutComponent<T> = FunctionComponent<{
data: IDataSource<T>;
getDefaultFilterText: (value: T) => ReadonlyArray<string>;
body: ComponentType<IBodyProps<T>>;
filterFooter?: ComponentType<{}>;
}>;
Expand All @@ -23,20 +22,18 @@ type CpuProfileLayoutComponent<T> = FunctionComponent<{
*/
export const cpuProfileLayoutFactory = <T extends {}>(): CpuProfileLayoutComponent<T> => ({
data,
getDefaultFilterText,
body: RowBody,
filterFooter: FilterFooter,
}) => {
const RichFilter = useMemo<RichFilterComponent<T>>(richFilter, []);
const [filteredData, setFilteredData] = useState<ReadonlyArray<T> | undefined>(undefined);
const [filteredData, setFilteredData] = useState<IQueryResults<T> | undefined>(undefined);
const footer = useMemo(() => (FilterFooter ? <FilterFooter /> : undefined), [FilterFooter]);

return (
<Fragment>
<div className={styles.filter}>
<RichFilter
data={data}
getDefaultFilterText={getDefaultFilterText}
onChange={setFilteredData}
placeholder="Filter functions or files, or start a query()"
foot={footer}
Expand Down
1 change: 1 addition & 0 deletions packages/vscode-js-profile-core/src/cpu/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const enum Category {
System,
User,
Module,
Deemphasized,
}

/**
Expand Down
56 changes: 0 additions & 56 deletions packages/vscode-js-profile-core/src/ql/column.ts

This file was deleted.

41 changes: 0 additions & 41 deletions packages/vscode-js-profile-core/src/ql/emitter.ts

This file was deleted.

0 comments on commit 6d9d946

Please sign in to comment.