Sublime Forum

How does the new context-aware auto complete work?

#1

I quote from https://www.sublimetext.com/

The auto complete engine has been rewritten to provide smart completions based on existing code in a project. Suggestions are also augmented with info about their kind, and provide links to definitions.

How exactly does it work? Does it look for clear, exact patterns? Does it use machine learning? I have no idea, and I’m really curious. I can’t find anything about it on the website.

0 Likes

#2

I don’t think it’s been expressed anywhere exactly how this is accomplished behind the scenes. It does seem to be looking for patterns and context clues though. I’m not sure that I’d call it machine learning per se, but I’m no expert in that. :slight_smile:

I demonstrate this lightly in the video linked below (the link jumps directly to the demo), but for example it will append () after a function call if it thinks it’s needed, but the clue for that comes from having seen you do it previously in the file. Similarly it notices a pattern of there being text inside of call parenthesis or not and puts the cursor inside.

Perhaps the most learning-adjacent thing here is the aspect of noticing what sorts of values you’re assigning to things and added them to the AC list and prioritizing their positions for you. Though that could still be explained by pattern recognition, I would think.

From my experimentation it only takes a single clue in any of the cases I tried for it to decide it’s something that should happen, and in “real world” code examples it has always gotten it correct as well.

1 Like

#3

That’s really interesting. I’ll play around with it some more and see if I can find more interesting behavior. Whatever it’s doing, it seems to work pretty well. It’s definitely one of my favorite new features.

1 Like