Sublime Forum

How to extract Symbols from a file on disk and add them to current AutoComplete?


In my toy programming language you can import additional dependencies as follows (assume main.jbb):

import "absolute/path/to/my_functions.jbb"
// some code
print "hello world from main"

my_functions.jbb contains:

func add_numbers(a, b) {
    a + b

func helloworld(a, b) {
   print "hello world from my_functions.jbb"

Suppose main.jbb is the only file open in Sublime, no projects or anything, just the file by itself. I want to make an extension that would parse all import statements in the currently opened file, parse the files that are being imported, extract any symbols they might define and add those symbols to the currently opened file’s auto-complete list. In this case, add_numbers and helloworld would be added to main.jbb's auto-complete.

How do I go about creating such an extension? I need a high level overview (what APIs, functions, modules, etc).



An on_query_completions event handler in an EventListener or a ViewEventListener would be how you go about adding dynamic completions to auto completion popup. Sublime triggers that event when it’s about to display completions.

That event wants you to return back a list of potential completions, so likely you want to do something like pre-parse the file to have the completions ready to draw from when the event happens. For something like that you can use on_load to detect when a file is loaded and on_modified to determine when a file is changed (e.g. so that you can check to see if there are new imports or not).

The API Documentation has more information on the API that’s available to plugins.