Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Merged
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 assets/panel/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ DevToolsModules(
'panel.js',
'parser-worker.js',
'pretty-print-worker.js',
'search-worker.js',
)
1 change: 1 addition & 0 deletions bin/run-mochitests-docker
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ docker run -it \
-v `pwd`/assets/build/debugger.js:/gecko/devtools/client/debugger/new/debugger.js \
-v `pwd`/assets/build/pretty-print-worker.js:/gecko/devtools/client/debugger/new/pretty-print-worker.js \
-v `pwd`/assets/build/parser-worker.js:/gecko/devtools/client/debugger/new/parser-worker.js \
-v `pwd`/assets/build/search-worker.js:/gecko/devtools/client/debugger/new/search-worker.js \
-v `pwd`/assets/build/integration-tests.js:/gecko/devtools/client/debugger/new/integration-tests.js \
-v `pwd`/assets/build/debugger.css:/gecko/devtools/client/debugger/new/debugger.css \
-v `pwd`/assets/build/panel/debugger.properties:/gecko/devtools/client/locales/en-US/debugger.properties \
Expand Down
3 changes: 2 additions & 1 deletion configs/development.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"workers": {
"parserURL": "http://localhost:8000/assets/build/parser-worker.js",
"sourceMapURL": "http://localhost:8000/assets/build/source-map-worker.js",
"prettyPrintURL": "http://localhost:8000/assets/build/pretty-print-worker.js"
"prettyPrintURL": "http://localhost:8000/assets/build/pretty-print-worker.js",
"searchURL": "http://localhost:8000/assets/build/search-worker.js"
},
"features": {
"blackbox": {
Expand Down
3 changes: 2 additions & 1 deletion configs/firefox-panel.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
},
"workers": {
"parserURL": "resource://devtools/client/debugger/new/parser-worker.js",
"prettyPrintURL": "resource://devtools/client/debugger/new/pretty-print-worker.js"
"prettyPrintURL": "resource://devtools/client/debugger/new/pretty-print-worker.js",
"searchURL": "resource://devtools/client/debugger/new/search-worker.js"
},
"features": {
"blackbox": { "enabled": true },
Expand Down
2 changes: 1 addition & 1 deletion src/actions/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "../selectors";

import { PROMISE } from "../utils/redux/middleware/promise";
import parser from "../utils/parser";
import * as parser from "../utils/parser";

import type { Source } from "debugger-html";
import type { ThunkArgs } from "./types";
Expand Down
7 changes: 4 additions & 3 deletions src/components/Editor/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import {
findNext,
findPrev,
removeOverlay,
countMatches,
clearIndex
} from "../../utils/editor";

import { countMatches } from "../../utils/search";

import { scrollList } from "../../utils/result-list";
import classnames from "classnames";
import debounce from "lodash/debounce";
Expand Down Expand Up @@ -394,7 +395,7 @@ class SearchBar extends Component {
}
}

searchContents(query: string) {
async searchContents(query: string) {
const {
selectedSource,
modifiers,
Expand All @@ -408,7 +409,7 @@ class SearchBar extends Component {

const ctx = { ed, cm: ed.codeMirror };

const newCount = countMatches(
const newCount = await countMatches(
query,
selectedSource.get("text"),
modifiers.toJS()
Expand Down
4 changes: 4 additions & 0 deletions src/utils/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import ReactDOM from "react-dom";
import { getValue, isFirefoxPanel } from "devtools-config";
import { renderRoot } from "devtools-launchpad";
import { startSourceMapWorker, stopSourceMapWorker } from "devtools-source-map";
import { startSearchWorker, stopSearchWorker } from "../utils/search";

import {
startPrettyPrintWorker,
stopPrettyPrintWorker
Expand Down Expand Up @@ -52,6 +54,7 @@ export function bootstrapWorkers() {
}
startPrettyPrintWorker(getValue("workers.prettyPrintURL"));
startParserWorker(getValue("workers.parserURL"));
startSearchWorker(getValue("workers.searchURL"));
}

export function teardownWorkers() {
Expand All @@ -61,4 +64,5 @@ export function teardownWorkers() {
}
stopPrettyPrintWorker();
stopParserWorker();
stopSearchWorker();
}
2 changes: 0 additions & 2 deletions src/utils/editor/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { isEnabled } from "devtools-config";
import { isPretty, isJavaScript } from "../source";
import { isOriginalId } from "devtools-source-map";
import buildQuery from "./build-query";
import * as sourceDocumentUtils from "./source-documents";
const { getDocument } = sourceDocumentUtils;

Expand Down Expand Up @@ -119,7 +118,6 @@ module.exports = Object.assign(
createEditor,
shouldShowPrettyPrint,
shouldShowFooter,
buildQuery,
isTextForSource,
breakpointAtLocation,
traverseResults,
Expand Down
15 changes: 1 addition & 14 deletions src/utils/editor/source-search.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

import buildQuery from "./build-query";
import buildQuery from "../search/utils/build-query";

import type { SearchModifiers } from "../../types";

Expand Down Expand Up @@ -296,22 +296,9 @@ function clearIndex(ctx: any, query: string, modifiers: SearchModifiers) {
state.matchIndex = -1;
}

function countMatches(
query: string,
text: string,
modifiers: SearchModifiers
): number {
const regexQuery = buildQuery(query, modifiers, {
isGlobal: true
});
const match = text.match(regexQuery);
return match ? match.length : 0;
}

export {
buildQuery,
clearIndex,
countMatches,
find,
findNext,
findPrev,
Expand Down
19 changes: 6 additions & 13 deletions src/utils/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@ import { workerUtils } from "devtools-utils";
const { WorkerDispatcher } = workerUtils;

const dispatcher = new WorkerDispatcher();
export const startParserWorker = dispatcher.start.bind(dispatcher);
export const stopParserWorker = dispatcher.stop.bind(dispatcher);

const getClosestExpression = dispatcher.task("getClosestExpression");
const getSymbols = dispatcher.task("getSymbols");
const getVariablesInScope = dispatcher.task("getVariablesInScope");
const getOutOfScopeLocations = dispatcher.task("getOutOfScopeLocations");
export const getClosestExpression = dispatcher.task("getClosestExpression");
export const getSymbols = dispatcher.task("getSymbols");
export const getVariablesInScope = dispatcher.task("getVariablesInScope");
export const getOutOfScopeLocations = dispatcher.task("getOutOfScopeLocations");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh, we an use export directly and avoid the module.exports... yay


export type { SymbolDeclaration, SymbolDeclarations } from "./getSymbols";
export type { AstLocation } from "./types";

module.exports = {
getSymbols,
getVariablesInScope,
getOutOfScopeLocations,
getClosestExpression,
startParserWorker: dispatcher.start.bind(dispatcher),
stopParserWorker: dispatcher.stop.bind(dispatcher)
};
14 changes: 7 additions & 7 deletions src/utils/pretty-print/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import assert from "../assert";
import type { Source, SourceText } from "../../types";

const dispatcher = new WorkerDispatcher();
export const startPrettyPrintWorker = dispatcher.start.bind(dispatcher);
export const stopPrettyPrintWorker = dispatcher.stop.bind(dispatcher);
const _prettyPrint = dispatcher.task("prettyPrint");

type PrettyPrintOpts = {
Expand All @@ -16,7 +18,11 @@ type PrettyPrintOpts = {
url: string
};

async function prettyPrint({ source, sourceText, url }: PrettyPrintOpts) {
export async function prettyPrint({
source,
sourceText,
url
}: PrettyPrintOpts) {
const contentType = sourceText ? sourceText.contentType : "";
const indent = 2;

Expand All @@ -31,9 +37,3 @@ async function prettyPrint({ source, sourceText, url }: PrettyPrintOpts) {
source: sourceText ? sourceText.text : undefined
});
}

module.exports = {
prettyPrint,
startPrettyPrintWorker: dispatcher.start.bind(dispatcher),
stopPrettyPrintWorker: dispatcher.stop.bind(dispatcher)
};
42 changes: 12 additions & 30 deletions src/utils/pretty-print/worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// @flow

import prettyFast from "pretty-fast";
import assert from "../assert";

import { workerUtils } from "devtools-utils";
const { workerHandler } = workerUtils;

type Mappings = {
_array: Mapping[]
Expand All @@ -24,19 +26,15 @@ type InvertedMapping = {
};

function prettyPrint({ url, indent, source }) {
try {
const prettified = prettyFast(source, {
url: url,
indent: " ".repeat(indent)
});
const prettified = prettyFast(source, {
url: url,
indent: " ".repeat(indent)
});

return {
code: prettified.code,
mappings: prettified.map._mappings
};
} catch (e) {
throw new Error(`${e.message}\n${e.stack}`);
}
return {
code: prettified.code,
mappings: invertMappings(prettified.map._mappings)
};
}

function invertMappings(mappings: Mappings) {
Expand All @@ -59,20 +57,4 @@ function invertMappings(mappings: Mappings) {
});
}

self.onmessage = function(msg) {
const { id, args } = msg.data;
assert(msg.data.method === "prettyPrint", "Method must be `prettyPrint`");

try {
let { code, mappings } = prettyPrint(args[0]);
self.postMessage({
id,
response: {
code,
mappings: invertMappings(mappings)
}
});
} catch (e) {
self.postMessage({ id, error: e });
}
};
self.onmessage = workerHandler({ prettyPrint });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did a bit of clean up while i was in the worker code

8 changes: 8 additions & 0 deletions src/utils/search/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { workerUtils } from "devtools-utils";
const { WorkerDispatcher } = workerUtils;

const dispatcher = new WorkerDispatcher();
export const startSearchWorker = dispatcher.start.bind(dispatcher);
export const stopSearchWorker = dispatcher.stop.bind(dispatcher);

export const countMatches = dispatcher.task("countMatches");
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import escapeRegExp from "lodash/escapeRegExp";
import { buildQuery } from "../editor";
import buildQuery from "../utils/build-query";

describe("build-query", () => {
it("case-sensitive, whole-word, regex search", () => {
Expand Down
49 changes: 49 additions & 0 deletions src/utils/search/tests/countMatches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { countMatches } from "../worker";

describe("search", () => {
describe("countMatches", () => {
it("counts basic string match", () => {
const text = "the test string with test in it multiple times test.";
const query = "test";
const count = countMatches(query, text, {
caseSensitive: true,
wholeWord: false,
regexMatch: false
});
expect(count).toBe(3);
});

it("counts basic string match case-sensitive", () => {
const text = "the Test string with test in it multiple times test.";
const query = "Test";
const count = countMatches(query, text, {
caseSensitive: true,
wholeWord: false,
regexMatch: false
});
expect(count).toBe(1);
});

it("counts whole word string match", () => {
const text = "the test string test in it multiple times whoatestthe.";
const query = "test";
const count = countMatches(query, text, {
caseSensitive: true,
wholeWord: true,
regexMatch: false
});
expect(count).toBe(2);
});

it("counts regex match", () => {
const text = "the test string test in it multiple times whoatestthe.";
const query = "(\\w+)\\s+(\\w+)";
const count = countMatches(query, text, {
caseSensitive: true,
wholeWord: false,
regexMatch: true
});
expect(count).toBe(4);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import escapeRegExp from "lodash/escapeRegExp";

import type { SearchModifiers } from "../../types";
import type { SearchModifiers } from "../../../types";

type QueryOptions = {
isGlobal?: boolean,
Expand Down
17 changes: 17 additions & 0 deletions src/utils/search/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import buildQuery from "./utils/build-query";
import { workerUtils } from "devtools-utils";
const { workerHandler } = workerUtils;

export function countMatches(
query: string,
text: string,
modifiers: SearchModifiers
): number {
const regexQuery = buildQuery(query, modifiers, {
isGlobal: true
});
const match = text.match(regexQuery);
return match ? match.length : 0;
}

self.onmessage = workerHandler({ countMatches });
Loading