зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1874363 - [devtools] Remove build-debugger source-editor mapping. r=devtools-reviewers,ochameau.
Also remove devtools/client/debugger/src/utils/editor/source-editor.js which wasn't used an look like a relic of ancient times. Differential Revision: https://phabricator.services.mozilla.com/D198409
This commit is contained in:
Родитель
88903cc4ad
Коммит
8be3e22ff3
|
@ -23,7 +23,6 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"acorn": "~8.8.2",
|
||||
"codemirror": "^5.28.0",
|
||||
"react": "16.8.6",
|
||||
"react-dom": "16.8.6",
|
||||
"react-redux": "^5.0.7",
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
import SourceEditor from "./source-editor";
|
||||
import SourceEditor from "devtools/client/shared/sourceeditor/editor";
|
||||
import { features, prefs } from "../prefs";
|
||||
|
||||
export function createEditor() {
|
||||
|
|
|
@ -10,7 +10,6 @@ CompiledModules(
|
|||
"get-expression.js",
|
||||
"index.js",
|
||||
"source-documents.js",
|
||||
"source-editor.js",
|
||||
"source-search.js",
|
||||
"tokens.js",
|
||||
)
|
||||
|
|
|
@ -1,145 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
/**
|
||||
* CodeMirror source editor utils
|
||||
* @module utils/source-editor
|
||||
*/
|
||||
|
||||
const CodeMirror = require("codemirror");
|
||||
|
||||
require("raw!chrome://devtools/content/shared/sourceeditor/codemirror/lib/codemirror.css");
|
||||
require("codemirror/mode/javascript/javascript");
|
||||
require("codemirror/mode/htmlmixed/htmlmixed");
|
||||
require("codemirror/mode/coffeescript/coffeescript");
|
||||
require("codemirror/mode/jsx/jsx");
|
||||
require("codemirror/mode/elm/elm");
|
||||
require("codemirror/mode/clojure/clojure");
|
||||
require("codemirror/mode/haxe/haxe");
|
||||
require("codemirror/addon/search/searchcursor");
|
||||
require("codemirror/addon/fold/foldcode");
|
||||
require("codemirror/addon/fold/brace-fold");
|
||||
require("codemirror/addon/fold/indent-fold");
|
||||
require("codemirror/addon/fold/foldgutter");
|
||||
require("codemirror/addon/runmode/runmode");
|
||||
require("codemirror/addon/selection/active-line");
|
||||
require("codemirror/addon/edit/matchbrackets");
|
||||
require("codemirror/addon/display/placeholder");
|
||||
require("codemirror/mode/clike/clike");
|
||||
require("codemirror/mode/rust/rust");
|
||||
|
||||
require("raw!chrome://devtools/content/debugger/src/utils/editor/source-editor.css");
|
||||
|
||||
// NOTE: we should eventually use debugger-html context type mode
|
||||
|
||||
// Maximum allowed margin (in number of lines) from top or bottom of the editor
|
||||
// while shifting to a line which was initially out of view.
|
||||
const MAX_VERTICAL_OFFSET = 3;
|
||||
|
||||
export default class SourceEditor {
|
||||
opts;
|
||||
editor;
|
||||
|
||||
constructor(opts) {
|
||||
this.opts = opts;
|
||||
}
|
||||
|
||||
appendToLocalElement(node) {
|
||||
this.editor = CodeMirror(node, this.opts);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
// Unlink the current document.
|
||||
if (this.editor.doc) {
|
||||
this.editor.doc.cm = null;
|
||||
}
|
||||
}
|
||||
|
||||
get codeMirror() {
|
||||
return this.editor;
|
||||
}
|
||||
|
||||
get CodeMirror() {
|
||||
return CodeMirror;
|
||||
}
|
||||
|
||||
setText(str) {
|
||||
this.editor.setValue(str);
|
||||
}
|
||||
|
||||
getText() {
|
||||
return this.editor.getValue();
|
||||
}
|
||||
|
||||
setMode(value) {
|
||||
this.editor.setOption("mode", value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the current document with a new source document
|
||||
* @memberof utils/source-editor
|
||||
*/
|
||||
replaceDocument(doc) {
|
||||
this.editor.swapDoc(doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a CodeMirror Document
|
||||
* @returns CodeMirror.Doc
|
||||
* @memberof utils/source-editor
|
||||
*/
|
||||
createDocument() {
|
||||
return new CodeMirror.Doc("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Aligns the provided line to either "top", "center" or "bottom" of the
|
||||
* editor view with a maximum margin of MAX_VERTICAL_OFFSET lines from top or
|
||||
* bottom.
|
||||
* @memberof utils/source-editor
|
||||
*/
|
||||
alignLine(line, align = "top") {
|
||||
const cm = this.editor;
|
||||
const editorClientRect = cm.getWrapperElement().getBoundingClientRect();
|
||||
|
||||
const from = cm.lineAtHeight(editorClientRect.top, "page");
|
||||
const to = cm.lineAtHeight(
|
||||
editorClientRect.height + editorClientRect.top,
|
||||
"page"
|
||||
);
|
||||
|
||||
const linesVisible = to - from;
|
||||
const halfVisible = Math.round(linesVisible / 2);
|
||||
|
||||
// If the target line is in view, skip the vertical alignment part.
|
||||
if (line <= to && line >= from) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Setting the offset so that the line always falls in the upper half
|
||||
// of visible lines (lower half for bottom aligned).
|
||||
// MAX_VERTICAL_OFFSET is the maximum allowed value.
|
||||
const offset = Math.min(halfVisible, MAX_VERTICAL_OFFSET);
|
||||
|
||||
let topLine =
|
||||
{
|
||||
center: Math.max(line - halfVisible, 0),
|
||||
bottom: Math.max(line - linesVisible + offset, 0),
|
||||
top: Math.max(line - offset, 0),
|
||||
}[align || "top"] || offset;
|
||||
|
||||
// Bringing down the topLine to total lines in the editor if exceeding.
|
||||
topLine = Math.min(topLine, cm.lineCount());
|
||||
this.setFirstVisibleLine(topLine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls the view such that the given line number is the first visible line.
|
||||
* @memberof utils/source-editor
|
||||
*/
|
||||
setFirstVisibleLine(line) {
|
||||
const { top } = this.editor.charCoords({ line, ch: 0 }, "local");
|
||||
this.editor.scrollTo(0, top);
|
||||
}
|
||||
}
|
Двоичный файл не отображается.
|
@ -3,23 +3,20 @@
|
|||
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
import { createEditor } from "../create-editor";
|
||||
import SourceEditor from "../source-editor";
|
||||
|
||||
import { features } from "../../prefs";
|
||||
|
||||
describe("createEditor", () => {
|
||||
test("Returns a SourceEditor", () => {
|
||||
test("SourceEditor default config", () => {
|
||||
const editor = createEditor();
|
||||
expect(editor).toBeInstanceOf(SourceEditor);
|
||||
expect(editor.opts).toMatchSnapshot();
|
||||
expect(editor.opts.gutters).not.toContain("CodeMirror-foldgutter");
|
||||
expect(editor.config).toMatchSnapshot();
|
||||
expect(editor.config.gutters).not.toContain("CodeMirror-foldgutter");
|
||||
});
|
||||
|
||||
test("Adds codeFolding", () => {
|
||||
features.codeFolding = true;
|
||||
const editor = createEditor();
|
||||
expect(editor).toBeInstanceOf(SourceEditor);
|
||||
expect(editor.opts).toMatchSnapshot();
|
||||
expect(editor.opts.gutters).toContain("CodeMirror-foldgutter");
|
||||
expect(editor.config).toMatchSnapshot();
|
||||
expect(editor.config.gutters).toContain("CodeMirror-foldgutter");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,160 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
import CodeMirror from "codemirror";
|
||||
import { getExpressionFromCoords } from "../get-expression";
|
||||
|
||||
describe("get-expression", () => {
|
||||
let isCreateTextRangeDefined;
|
||||
|
||||
beforeAll(() => {
|
||||
if (document.body.createTextRange) {
|
||||
isCreateTextRangeDefined = true;
|
||||
} else {
|
||||
isCreateTextRangeDefined = false;
|
||||
// CodeMirror needs createTextRange
|
||||
// https://discuss.codemirror.net/t/working-in-jsdom-or-node-js-natively/138/5
|
||||
document.body.createTextRange = () => ({
|
||||
getBoundingClientRect: jest.fn(),
|
||||
getClientRects: () => ({}),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
if (!isCreateTextRangeDefined) {
|
||||
delete document.body.createTextRange;
|
||||
}
|
||||
});
|
||||
|
||||
describe("getExpressionFromCoords", () => {
|
||||
it("returns null when location.line is greater than the lineCount", () => {
|
||||
const cm = CodeMirror(document.body, {
|
||||
value: "let Line1;\n" + "let Line2;\n",
|
||||
mode: "javascript",
|
||||
});
|
||||
|
||||
const result = getExpressionFromCoords(cm, {
|
||||
line: 3,
|
||||
column: 1,
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("gets the expression using CodeMirror.getTokenAt", () => {
|
||||
const codemirrorMock = {
|
||||
lineCount: () => 100,
|
||||
getTokenAt: jest.fn(() => ({ start: 0, end: 0 })),
|
||||
doc: {
|
||||
getLine: () => "",
|
||||
},
|
||||
};
|
||||
getExpressionFromCoords(codemirrorMock, { line: 1, column: 1 });
|
||||
expect(codemirrorMock.getTokenAt).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("requests the correct line and column from codeMirror", () => {
|
||||
const codemirrorMock = {
|
||||
lineCount: () => 100,
|
||||
getTokenAt: jest.fn(() => ({ start: 0, end: 1 })),
|
||||
doc: {
|
||||
getLine: jest.fn(() => ""),
|
||||
},
|
||||
};
|
||||
getExpressionFromCoords(codemirrorMock, { line: 20, column: 5 });
|
||||
// getExpressionsFromCoords uses one based line indexing
|
||||
// CodeMirror uses zero based line indexing
|
||||
expect(codemirrorMock.getTokenAt).toHaveBeenCalledWith({
|
||||
line: 19,
|
||||
ch: 5,
|
||||
});
|
||||
expect(codemirrorMock.doc.getLine).toHaveBeenCalledWith(19);
|
||||
});
|
||||
|
||||
it("when called with column 0 returns null", () => {
|
||||
const cm = CodeMirror(document.body, {
|
||||
value: "foo bar;\n",
|
||||
mode: "javascript",
|
||||
});
|
||||
|
||||
const result = getExpressionFromCoords(cm, {
|
||||
line: 1,
|
||||
column: 0,
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("gets the expression when first token on the line", () => {
|
||||
const cm = CodeMirror(document.body, {
|
||||
value: "foo bar;\n",
|
||||
mode: "javascript",
|
||||
});
|
||||
|
||||
const result = getExpressionFromCoords(cm, {
|
||||
line: 1,
|
||||
column: 1,
|
||||
});
|
||||
if (!result) {
|
||||
throw new Error("no result");
|
||||
}
|
||||
expect(result.expression).toEqual("foo");
|
||||
expect(result.location.start).toEqual({ line: 1, column: 0 });
|
||||
expect(result.location.end).toEqual({ line: 1, column: 3 });
|
||||
});
|
||||
|
||||
it("includes previous tokens in the expression", () => {
|
||||
const cm = CodeMirror(document.body, {
|
||||
value: "foo.bar;\n",
|
||||
mode: "javascript",
|
||||
});
|
||||
|
||||
const result = getExpressionFromCoords(cm, {
|
||||
line: 1,
|
||||
column: 5,
|
||||
});
|
||||
if (!result) {
|
||||
throw new Error("no result");
|
||||
}
|
||||
expect(result.expression).toEqual("foo.bar");
|
||||
expect(result.location.start).toEqual({ line: 1, column: 0 });
|
||||
expect(result.location.end).toEqual({ line: 1, column: 7 });
|
||||
});
|
||||
|
||||
it("includes multiple previous tokens in the expression", () => {
|
||||
const cm = CodeMirror(document.body, {
|
||||
value: "foo.bar.baz;\n",
|
||||
mode: "javascript",
|
||||
});
|
||||
|
||||
const result = getExpressionFromCoords(cm, {
|
||||
line: 1,
|
||||
column: 10,
|
||||
});
|
||||
if (!result) {
|
||||
throw new Error("no result");
|
||||
}
|
||||
expect(result.expression).toEqual("foo.bar.baz");
|
||||
expect(result.location.start).toEqual({ line: 1, column: 0 });
|
||||
expect(result.location.end).toEqual({ line: 1, column: 11 });
|
||||
});
|
||||
|
||||
it("does not include tokens not part of the expression", () => {
|
||||
const cm = CodeMirror(document.body, {
|
||||
value: "foo bar.baz;\n",
|
||||
mode: "javascript",
|
||||
});
|
||||
|
||||
const result = getExpressionFromCoords(cm, {
|
||||
line: 1,
|
||||
column: 10,
|
||||
});
|
||||
if (!result) {
|
||||
throw new Error("no result");
|
||||
}
|
||||
expect(result.expression).toEqual("bar.baz");
|
||||
expect(result.location.start).toEqual({ line: 1, column: 4 });
|
||||
expect(result.location.end).toEqual({ line: 1, column: 11 });
|
||||
});
|
||||
});
|
||||
});
|
|
@ -58,6 +58,8 @@ if (isNode()) {
|
|||
pref("devtools.debugger.features.inline-preview", true);
|
||||
pref("devtools.debugger.features.javascript-tracing", false);
|
||||
pref("devtools.editor.tabsize", 2);
|
||||
pref("devtools.editor.expandtab", false);
|
||||
pref("devtools.editor.autoclosebrackets", false);
|
||||
}
|
||||
|
||||
export const prefs = new PrefsHelper("devtools", {
|
||||
|
|
|
@ -68,6 +68,13 @@ add_task(async function () {
|
|||
{ line: 51, column: 39, expression: "#privateVar", result: 2 },
|
||||
]);
|
||||
|
||||
await testPreviews(dbg, "multipleTokens", [
|
||||
{ line: 81, column: 4, expression: "foo", result: "Object" },
|
||||
{ line: 81, column: 11, expression: "blip", result: "Object" },
|
||||
{ line: 82, column: 8, expression: "bar", result: "Object" },
|
||||
{ line: 84, column: 16, expression: "boom", result: `0` },
|
||||
]);
|
||||
|
||||
await testHoveringInvalidTargetTokens(dbg);
|
||||
|
||||
info(
|
||||
|
|
|
@ -74,4 +74,13 @@ function invalidTargets() {
|
|||
const myVar = "foo";
|
||||
debugger;
|
||||
return myVar;
|
||||
}
|
||||
|
||||
function multipleTokens() {
|
||||
var foo = {bar: { baz: "bloop"}}, blip = {boom: 0};
|
||||
foo || blip
|
||||
foo.bar;
|
||||
foo.bar.baz;
|
||||
foo || blip.boom;
|
||||
debugger;
|
||||
}
|
|
@ -2135,11 +2135,6 @@ co@^4.6.0:
|
|||
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
|
||||
integrity sha512-QVb0dM5HvG+uaxitm8wONl7jltx8dqhfU33DcqtOZcLSVIKSDDLDi7+0LbAKiyI8hD9u42m2YxXSkMGWThaecQ==
|
||||
|
||||
codemirror@^5.28.0:
|
||||
version "5.65.15"
|
||||
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.65.15.tgz#66899278f44a7acde0eb641388cd563fe6dfbe19"
|
||||
integrity sha512-YC4EHbbwQeubZzxLl5G4nlbLc1T21QTrKGaOal/Pkm9dVDMZXMH7+ieSPEOZCtO9I68i8/oteJKOxzHC2zR+0g==
|
||||
|
||||
collect-v8-coverage@^1.0.0:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/collect-v8-coverage/-/collect-v8-coverage-1.0.2.tgz#c0b29bcd33bcd0779a1344c2136051e6afd3d9e9"
|
||||
|
|
|
@ -9,7 +9,6 @@ const fs = require("fs");
|
|||
const _path = require("path");
|
||||
|
||||
const mappings = {
|
||||
"./source-editor": "devtools/client/shared/sourceeditor/editor",
|
||||
react: "devtools/client/shared/vendor/react",
|
||||
"react-dom": "devtools/client/shared/vendor/react-dom",
|
||||
"react-dom-factories": "devtools/client/shared/vendor/react-dom-factories",
|
||||
|
|
Загрузка…
Ссылка в новой задаче