Repository navigation
devtools: Add an initial basic autocomplete implementation - #46382
Conversation
|
(Going to test this some more before submitting it for review) |
30b7f92 to
771ceda
Compare
eerii
left a comment
There was a problem hiding this comment.
Thank you for this! It is looking great. I tested it locally and the basic features work and tests are passing. I left some comments.
| .binding_variables | ||
| .iter() | ||
| .map(|bind| &bind.name) | ||
| .filter(|name| name.starts_with(prefix)) |
There was a problem hiding this comment.
We are already doing filtering in ConsoleActor::handle_message, and it is case insensitive there. Since we are also filtering here beforehand, and it is case sensitive, we are dropping some valid suggestions.
For example, if you write weak, Firefox shows WeakMap as a suggestion but Servo is not showing anything.
| props | ||
| .iter() | ||
| .map(|p| &p.name) | ||
| .filter(|name| name.starts_with(prefix)) |
| let environment_name = rx.recv().map_err(|_| ActorError::Internal)?; | ||
| let environment_actor = registry.find::<EnvironmentActor>(&environment_name); | ||
|
|
||
| let prompt = msg |
There was a problem hiding this comment.
One thing I noticed is that autocomplete only works when starting to write. When there are already some characters it doesn't show. For example:
Wi // shows Window
a = Wi // nothing
console.log(Wi) // nothing
// similarly
con // completes to console
console.l // doesn't show autocomplete anymoreI think this comes from us using the full msg text as the prefix directly. Firefox does some processing to find the interesting part for completion. However, this seems quite some complex logic, so we could leave it as a TODO.
There is also a cursor field for when the completion is not at the end, but again we can leave that as a followup.
| from: self.name().into(), | ||
| matches: vec![], | ||
| match_prop: "".to_owned(), | ||
| is_element_access: false, |
There was a problem hiding this comment.
If we end up implementing proper completion we would need to change the hardcoded false is_element_access to distinguish between property access and bracket access.
| # assert "continue" in result["matches"] | ||
|
|
||
| assert "console_test_value" in result["matches"] | ||
| assert result["matchProp"] == prompt |
There was a problem hiding this comment.
It would be nice to have a test for the case senstive things.
For example, if we do TestValue = 1, typing test and Test should both autocomplete, but typing TEST should not (at least according to Firefox's behaviour).
|
Good points about case-(in)sensitivity! I'll make sure that those are covered by tests and fixed. With this initial PR I am limiting the scope to autocompleting identifiers without any indexing. I'm planning to expand the autocomplete functionality over a series of PRs. In fact, I already rewrote most of Other things that Firefox does is string, array, and number prototypes from literals, and eager execution of functions (not that we support eager currently). Greetings from the great outdoors and/or Bornhack! 🌳⛺ |
|
That sounds great! We can do the case sensitive fixes here, and I agree that it's best to leave the rest for other PRs :) Don't hesitate to ping me for review when they are ready. PS: I didn't know what Bornhack was, but I looked it up and it sounds so cool!!! Hope you have a great time ^^ |
771ceda to
1a24e64
Compare
Signed-off-by: Freya Arbjerg <[email protected]>
1a24e64 to
9d2a255
Compare
|
@eerii Yeah it's been great ^w^ Anyways, that should do it for case-sensitivity. It didn't occur to me until now that Firefox uses a different rule than I expected |
eerii
left a comment
There was a problem hiding this comment.
Thank you, it looks great! :)
The rule that Firefox uses is quite interesting! It is also different than the one I expected. I thought it was going to be "if lowercase, match all, but as soon as any character is uppercase, do case sensitive match", but it's only if the first character is uppercase. Thank you for adding the test cases, it's much more clear now.
This PR adds autocomplete for the console tab in devtools. Currently this is a simple match against environment identifiers without any parsing or indexing.
Both frame environments and the global environment is supported.
Testing: Added a test each against frame and global scopes, as well as one test for case-sensitivity
Fixes: Part of #39858