Skip to content

devtools: Add an initial basic autocomplete implementation - #46382

Merged
eerii merged 1 commit into
servo:mainfrom
freyacodes:console-autocomplete
Jul 27, 2026
Merged

eerii merged 1 commit into
servo:mainfrom
freyacodes:console-autocomplete

Conversation

@freyacodes

@freyacodes freyacodes commented Jul 8, 2026 •

Copy link
Copy Markdown
Member

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

@freyacodes

Copy link
Copy Markdown
Member Author

(Going to test this some more before submitting it for review)

@freyacodes
freyacodes force-pushed the console-autocomplete branch 2 times, most recently from 30b7f92 to 771ceda Compare July 18, 2026 18:03
@freyacodes
freyacodes marked this pull request as ready for review July 18, 2026 18:54
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jul 18, 2026

@eerii eerii left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same for this one

let environment_name = rx.recv().map_err(|_| ActorError::Internal)?;
let environment_actor = registry.find::<EnvironmentActor>(&environment_name);

let prompt = msg

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 anymore

I 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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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).

@freyacodes

Copy link
Copy Markdown
Member Author

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 analyze-input-string.js for Servo last night for a followup pr (I just opened an early draft in #46660). There's also js-property-provider.js to eventually consider.

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! 🌳⛺

@eerii

eerii commented Jul 20, 2026

Copy link
Copy Markdown
Member

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 ^^

@freyacodes
freyacodes force-pushed the console-autocomplete branch from 771ceda to 1a24e64 Compare July 20, 2026 20:02
@freyacodes
freyacodes force-pushed the console-autocomplete branch from 1a24e64 to 9d2a255 Compare July 20, 2026 20:08
@freyacodes

Copy link
Copy Markdown
Member Author

@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 eerii left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Jul 27, 2026
@eerii
eerii added this pull request to the merge queue Jul 27, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 27, 2026
Merged via the queue into servo:main with commit 6954c43 Jul 27, 2026
31 checks passed
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants