Commit Graph

43 Commits

Author SHA1 Message Date
Julian Descottes
03cdcd7b0a Bug 1593921 - Use eslint-disable-next-line to disable complexity checks in DevTools r=pbro
Using next-line is less error prone for refactorings than wrapping methods with enable/disable blocks.

Differential Revision: https://phabricator.services.mozilla.com/D51782
2019-11-05 14:29:04 +00:00
Nicolas Chevobbe
896b4d42c1 Bug 1580181 - Reorganize js-property-provider. r=ochameau.
Move analyzeInputString function below JSPropertyProvider, so
the exported function appears first in the file.

Differential Revision: https://phabricator.services.mozilla.com/D49107
2019-10-15 14:24:48 +00:00
Nicolas Chevobbe
290ba5cb21 Bug 1568779 - Remove editors settings comments in devtools files. r=pbro.
Differential Revision: https://phabricator.services.mozilla.com/D42300
2019-08-19 12:48:16 +00:00
Julian Descottes
0c7f6dc0d0 Bug 1568823 - Simplify parser.js and rename to parser-helper r=nchevobbe
Depends on D39335
Looking in details at get(), the implementation can also be simplified

Differential Revision: https://phabricator.services.mozilla.com/D39338
2019-07-25 13:21:03 +00:00
Julian Descottes
834b25fba4 Bug 1568823 - Move Parser.jsm to a regular module in devtools/shared/webconsole r=nchevobbe
Depends on D39333

Differential Revision: https://phabricator.services.mozilla.com/D39335
2019-07-25 13:17:11 +00:00
Nicolas Chevobbe
fcaf6fefa1 Bug 1563761 - Handle comments in analyzeInput. r=ochameau.
We weren't handling comments at all, which means that having
any in the console would probably make the autocomplete not
working.
This patch handles both inline and multiline javascript comments,
and adds test cases to ensure we don't regress.

Depends on D36573

Differential Revision: https://phabricator.services.mozilla.com/D37196
2019-07-10 08:00:32 +00:00
Nicolas Chevobbe
4ced960d1c Bug 1557305 - Speed up JsPropertyProvider analyzeInput function. r=ochameau.
We were using Array.from to get an array of all the characters, and
be able to slice parts of the strings to run some checks.
This had the disadvantage of being quite slow on very large strings,
at a point where we introduced a bail out mechanism into the function
to not block the content page.
This patch switches to `String.prototype[Symbol.iterator]` to loop
over all the character, and removes lots of array and string manipulations.
On the same, super-large, string, the function cost went from 6700ms to
less than 200ms.

Differential Revision: https://phabricator.services.mozilla.com/D36572
2019-07-08 06:24:38 +00:00
Victor Porof
435f7b056d Bug 1561435 - Format remaining devtools/, a=automatic-formatting, CLOSED TREE
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D35894
2019-07-05 11:29:32 +02:00
Nicolas Chevobbe
f283503d3a Bug 1556068 - Track JsPropertyProvider's analyzeInput string and bail if it's taking too long. r=Honza.
It can happen that the string we receive is quite large
and as a result takes a long time to analyze, freezing
the process.
This patch simply tracks for how long the for loop is running,
and bail out if it's greater than a given time (set to 2500 ms
for now).
This is mostly a safeguard, a future patch should try to improve
the performance of the function itself.

Differential Revision: https://phabricator.services.mozilla.com/D33791
2019-06-06 13:08:21 +00:00
Patrick Brosset
d93842478f Bug 1553451 - Lower the eslint complexity level to 20 for devtools and exlude more complex functions; r=jdescottes
We want to go back to ESLint's default complexity level so that newly introduced code is checked for complexity.
At the same time, to make that work, we're excluding all of the more complex functions for now.
We should fix them: make them less complex, and remove the eslint-disable comment.
See bug 1553449 for more information about this.

Differential Revision: https://phabricator.services.mozilla.com/D32139
2019-05-23 09:06:16 +00:00
Mihai Alexandru Michis
c358baf0c3 Backed out changeset 0f9626b48a66 (bug 1553451) for linting failures. CLOSED TREE 2019-05-23 10:58:22 +03:00
Patrick Brosset
18bd75fb8c Bug 1553451 - Lower the eslint complexity level to 20 for devtools and exlude more complex functions; r=jdescottes
We want to go back to ESLint's default complexity level so that newly introduced code is checked for complexity.
At the same time, to make that work, we're excluding all of the more complex functions for now.
We should fix them: make them less complex, and remove the eslint-disable comment.
See bug 1553449 for more information about this.

Differential Revision: https://phabricator.services.mozilla.com/D32139
2019-05-23 07:07:49 +00:00
Patrick Brosset
dc09b99342 Bug 1544223 - Disable a few high complexity functions and lower the limit to prevent more complexity; r=jdescottes
Depends on D31973

Differential Revision: https://phabricator.services.mozilla.com/D32120
2019-05-22 12:08:59 +00:00
Oriol Brufau
e77c20b90f Bug 1541422 - Escape special characters in autocomplete. r=nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D26617
2019-04-09 16:46:34 +00:00
Nicolas Chevobbe
9ffa4a8b95 Bug 1527238 - Speed up webconsole server's autocomplete function; r=Honza.
There are 2 changes in this patch.

In js-property-provider, we iterate over a Set
and delete item we don't want into instead of
turning the Set into an array, filter on it, and
convert it back to a new Set.

In the autocomplete function, we don't use regexp
anymore in the sort callback as we already have
a way to tell if we're performing an element access.

Differential Revision: https://phabricator.services.mozilla.com/D19471
2019-02-15 15:02:51 +00:00
Nicolas Chevobbe
80f6a5467b Bug 1499289 - Change how we deal with getter evaluation in JsPropertyProvider; r=bgrins.
While trying to implement the invoke getter from
autocomplete popup, it became clear to me that the
initial implementation in js-property-provider wasn't
good enough, as we need to keep track of all the
authorizations the user gave when working on a given
expression.

In order to handle this, JsPropertyProvider now
returns an array of strings representing the path
to the unsafe getter when no matching authorizations
are provided.

If authorizations are provided, we can check for each
properties that the user authorized the execution.
This way, we can handle deep object access after a getter
(e.g. `x.myGetter.foo.bar.baz.entries`) without asking
the user if they want to invoke `myGetter` on each
step of the completion.

This makes handling intermediary getters (e.g.
`x.myGetter.foo.myOtherGetter.bar`) way easier as well.
In the UI, the user will be prompted to invoke the getter one
after the other (if for example they try to complete a pasted
expression which contains multiple getters, they will have
prompts for `myGetter`, and then for `myOtherGetter`).

We wire-up the webconsole client and the webconsole actor for
the autocomplete function, to make them ready for frontend
use.

The existing JsPropertyProvider getters test are updated to
match the change of parameter (invokeGetter -> authorizedEvaluations),
and some tests are added to make sure everything work as intended.

Differential Revision: https://phabricator.services.mozilla.com/D12940
2019-01-07 09:49:10 +00:00
Nicolas Chevobbe
99a316cbad Bug 1231489 - Use content prototype for autocompletion of String, Number and Array literals; r=bgrins.
When provided a string, number or array literals, we use to
simply return the properties from String.prototype, Number.prototype
and Array.prototype.
This is working fine unless the content prototypes are modified.
In order to make it work properly, we retrieve the actual content
prototype.
The js-property-provider unit test is modified to ensure this is
working as expected.

Differential Revision: https://phabricator.services.mozilla.com/D15843
2019-01-08 07:59:24 +00:00
Nicolas Chevobbe
1882b66b88 Bug 1510422 - Fix autocomplete cache handling; r=Honza.
In Bug 1462394, we moved the autocomplete data handling
out of the JsTerm to the Redux store. In the process, we
regress some cases like `await n`, which should display
`navigator`, but isn't anymore when the user types the
whole sequence. Ctrl+Space would still show the popup,
which indicates that the issue is not on the server-side.

This issue is caused because our new code decides that
we should hit the cache when typing the `n`, and there's
nothing in the cache.

Previously, we were clearing the cache as soon as the input
last string wasn't alphanumeric, which we don't anymore.
To fix that, instead of relying on the last string of the
input (which could be wrong in cases like `x.["hello `), we
clear the cache when the autocomplete service returns a null
`matches` property.

In the JsPropertyProvider, we use to return null whenever
there isn't any search done (incorrect input, empty match prop, …).
So it seems like a good idea to bust the cache when the
server returns null.

This requires some changes to the autocomplete service, as well
as some in jsPropertyProvider (e.g. to handle `await `).

Tests are added both on the client and the frontend to make sure
we don't regress this (those tests fail without the actual fix).

Differential Revision: https://phabricator.services.mozilla.com/D13231
2018-11-29 13:58:57 +00:00
Nicolas Chevobbe
e013d59ca9 Bug 1473841 - Don't return dot-notation invalid properties; r=Honza.
In JsPropertyProvider, if doing a property access (with a dot),
check that the results are suited for a dot notation (e.g. `data`
is, while `data-test` is not).
In case, of an element access, we can return everything.

This implies making some changes to some tests which were using
invalid dot notation access in some case, which revealed a
bug with bracket autocomplete and spaces.

So the bracket autocomplete with spaces is now also fixed, and
a test case was added for that as well.

Differential Revision: https://phabricator.services.mozilla.com/D12726
2018-11-27 13:46:46 +00:00
Nicolas Chevobbe
fc095e66e0 Bug 1506867 - Use AST to get the properties-access chain; r=bgrins.
Differential Revision: https://phabricator.services.mozilla.com/D11893
2018-11-20 06:43:03 +00:00
Nicolas Chevobbe
79147a9c34 Bug 1216632 - Make autocompletion work on $_ and $0; r=bgrins.
To make $0 autocompletion work, we need to pass the current
selectedNode actor from the frontend, so we can retrieve the
object reference later.
For $_, we need the webconsole actor reference to be able
to retrieve the last input result.
Since the list of parameters of JsPropertyProviders was
getting a bit long, we transform them in an object so it's
more legible on the consumer side.
Mochitests are added for both helpers to ensure this work
as expected.

Differential Revision: https://phabricator.services.mozilla.com/D11866
2018-11-15 09:49:14 +00:00
Nicolas Chevobbe
549a619b21 Bug 1479366 - Handle Number literals in JsPropertyProvider; r=bgrins.
When provided a number literal, JsPropertyProvider would
not return anything.
This patch solves this issue by adding an if case for those
objects.
Numerous test cases are added in test_js_property_provider to
make sure we handle this as expected and that we don't have
false positives.

Differential Revision: https://phabricator.services.mozilla.com/D11483
2018-11-12 07:39:38 +00:00
Nicolas Chevobbe
ccc695e796 Bug 1505393 - Add better handling of unsafe getters in JsPropertyProvider; r=bgrins.
This patch adds two things to JsPropertyProvider:
- when provided an input which try to access an unsafe
getter properties, the function will indicate that an
unsafe getter should be invoked, with its name.
- a new boolean argument that when set to true would
invoke any unsafe getter that might be in the expression
to be completed.

For simplicity sake, the function only warns the user
of the presence of an unsafe getter when it's the last
property of the expression:

`object.myGetter.` will return that `myGetter` should be invoked
`object.myGetter.a.b.` will not (because then, a and b could
also be getters, and it's getting complex to handle both in
the function itself as in the UI).

Tests are added to ensure this works as expected.

Differential Revision: https://phabricator.services.mozilla.com/D11170
2018-11-08 15:47:53 +00:00
Mark Banner
3d6aaad3f5 Bug 1486741 - Enable ESLint rule comma-dangle for all of mozilla-central (automatic fixes). r=mossop
Differential Revision: https://phabricator.services.mozilla.com/D8389
2018-10-19 12:55:39 +00:00
Nicolas Chevobbe
37e518383b Bug 1498598 - Make js-property-provider better; r=bgrins.
This patches solves 2 issues:
- it doesn't return any result when the user is trying to
perform a variable, function or class declaration (e.g.
var d).
- js-property-provider used to compute the last statement
by only looking for space or ; chars. But there are a lot
of cases (basically each time using an operator), where we
should return results and we weren't.
Test cases are added to cover those fixes.

Differential Revision: https://phabricator.services.mozilla.com/D8968
2018-10-17 15:02:41 +00:00
Nicolas Chevobbe
83a7159e33 Bug 1476656 - Trigger autocomplete on bracket; r=Honza.
This patch adds the ability to open the autocomplete popup when
typing an opening bracket (i.e. `[`]) in the console input.
This impacts a significant amount of function where we assumed
that the only way to get a completion was to use a dot.
We uses the rename `anylyzeInputString` function to get the
completion part from an input, as well as if the user is performing
an element access (i.e., using the bracket).
We then send that information to the webconsole actor, which send
it to the client.
This allows us to rely on a single parse of the input and gives us
access to this information everywhere we need to, be it on the client
or on the server.

We allow the user to type property name without quotes, and we add
them when the user accept an autocompletion.
We also automatically add a closing bracket (i.e. `]`), when it's needed.

Some test are added. On the server side to make sure the actor's autocomplete
function returns what's expected.
We take that as an opportunity to add test for commands.
On the client side, tests are added to ensure the different behavior works
as expected (check the completion text and the input  after accepting
the completion when the user entered some letters, or not, with or without
quotes, with different quotes, hitting the autocomplete cache, …).

A test which accesses the autocomplete cache was modified since the shape
of the cache changed to include the last matchProp as well as the
isElementAccess boolean.

Differential Revision: https://phabricator.services.mozilla.com/D6128
2018-09-26 13:54:35 +00:00
Nicolas Chevobbe
334b7e5e5b Bug 1217198 - Better autocompletion for template literals; r=Honza.
Add a new template literal state to findCompletionBeginning so we can
better handle the autocompletion for them.

Differential Revision: https://phabricator.services.mozilla.com/D4853
2018-09-05 11:37:33 +00:00
Nicolas Chevobbe
8d0154a21f Bug 672733 - Make autocomplete search case insensitive; r=Honza.
This patch adds a smarter heuristic for autocompletion results:
if the input first letter is lowercased, then we'll filter
matching properties case insensitively. But if the user starts
with an uppercase, we assume they know the property they want
and thus respect the casing.
For example: `win` will return both `window` and `Window`, but
`Win` will return `Window` only.
Due to this behavior, we change the order of the autocomplete
results so lowercased property are displayed before the uppercased
one.
If we take are example again, it's likely that if a user type `win`,
they want `window`, but the alphabetical order would return `Window`
first which would annoy user.

Now, since we return results that does not match exactly the user
input, we need to modify the frontend.

Usually, we only show the autocompletion popup if there are
at least 2 matching items, since 1 matching item will still
be displayed using the autocompletion text. But now, since the
input might not match, we want to still display the popup if
there is one matching item, but starts differentely than what
the user entered.
For example, the user typed `window.addeve`, which matches
`addEventListener`. The completion text will make it looks like
it will be completed to `window.addeventListener`, which would
be undefined. So showing the popup with the actual matching
property might avoid some confusion for the user.

A test was added to make sure the frontend works as expected.
Some test cases were added in the server test to make sure
the actor returns expected results. Other tests needed some
adjustement because of the insensitive case matches and the
new order of results.

Differential Revision: https://phabricator.services.mozilla.com/D4061
2018-08-27 16:08:56 +00:00
Nicolas Chevobbe
d84d66306b Bug 1472117 - Fix autocompletion with "." surrounded by spaces; r=bgrins.
Expressions like `window . addEventListener` are perfectly valid in JS,
but our autocompletion provider wasn't working well in such case.
We modify the JSPropertyProvider to make sure to handle this kind of
syntax and add test cases to make sure it works as intended.`

Differential Revision: https://phabricator.services.mozilla.com/D2988
2018-08-14 13:40:08 +00:00
Julian Descottes
82711b9a8f Bug 1454696 - Run eslint --fix for prefer-const;r=yulia
MozReview-Commit-ID: F6xUXCgdRE4
2018-06-01 12:36:09 +02:00
Oriol Brufau
d55e29ac45 Bug 1457711 - Catch errors thrown by console's property previewer; r=nchevobbe
MozReview-Commit-ID: LKsYn5gSn58
2018-04-28 22:29:43 +02:00
J. Ryan Stinnett
8d1c817851 Bug 1443081 - Apply spacing via eslint --fix for DevTools. r=jdescottes
MozReview-Commit-ID: 2RVNt140Zte
2018-03-12 13:44:41 -05:00
Florian Quèze
c5f15a4700 Bug 1339461 - script-generated patch to convert foo.indexOf(...) == -1 to foo.includes(), r=Mossop. 2018-02-01 20:45:22 +01:00
Mark Banner
ac3e440190 Bug 1371293 - Fix various devtools warnings after upgrading to ESLint 4. r=miker
ESLint 4 will turn on all rules after an eslint-enable with no arguments. Therefore be more specific about which rules are being disabled.

MozReview-Commit-ID: IoPBG72zySm
2017-11-06 14:01:33 +00:00
Sebastian Hengst
c6d9ef3e98 Backed out changeset 6bc38f188ef2 (bug 1330099) for devtools failures. r=backout 2017-01-11 23:21:56 +01:00
Tim Nguyen
548b6bdbef Bug 1330099 - Enable object-shorthand eslint rule. r=jryans
MozReview-Commit-ID: 3wA25rfznBv
2017-01-11 21:22:15 +00:00
J. Ryan Stinnett
8aa03a5d4d Bug 1263258 - Require space before paren for anonymous functions. r=pbro
MozReview-Commit-ID: 2F0j45Vxn2I
2016-04-27 09:06:15 -05:00
Dave Townsend
4ac1a46d5e Bug 1257246: Update devtools for eslint 2. r=pbro
ESLint 2 now flags anonymous generator functions according to
generator-star-spacing. Most of the changes here are correcting that.

MozReview-Commit-ID: 9xg2Gmlaz94
2016-04-05 11:31:19 -07:00
Tom Tromey
c0dd7eb1a4 Bug 1255799 - make devtools/client/webconsole eslint-clean; r=odvarko
MozReview-Commit-ID: AnaXFFHlNLM
2016-03-16 08:16:00 +01:00
Lin Clark
486652076f Bug 1241956 - Use standard license boilerplate in webconsole js files. r=bgrins 2016-01-25 11:19:58 -08:00
Brian Grinstead
026f3b0504 Bug 1207868 - Fix lexical scope autocomplete for global 'let' and 'const';r=past 2015-12-03 11:35:33 -08:00
Brian Grinstead
2e5b12676f Bug 1218455 - Special case 'this' to include in console autocompletion;r=fitzgen 2015-12-02 09:24:16 -08:00
Brian Grinstead
c7d30d98d0 Bug 1217591 - Make JS autocompletion in the console work inside of a worker toolbox;r=fitzgen 2015-10-26 11:55:40 -07:00