Hi all, my question is concerned of how can I get a list of all methods/functions defined in a file. Something really close to what Cmd + R does. Is there an API for that? This is language specific syntax thing?
Regards
Hi all, my question is concerned of how can I get a list of all methods/functions defined in a file. Something really close to what Cmd + R does. Is there an API for that? This is language specific syntax thing?
Regards
view.symbols() should be what you are looking for : http://www.sublimetext.com/docs/3/api_reference.html
Hi Clams, thanks for the answer. Unfortunately, view.symbols
gives me an empty array.
You could also use
view.find_by_selector("entity.name.function")
which returns a list of sublime.Region objects.
The same thing, an empty list. If it helps, the file I am applying those commands is a LLVM IR file:
https://pastebin.com/XPA9Z2WJ
What syntax file are you using for LLVM IR? (this is displayed in the lower right corner of SublimeText).
That syntax is somewhat dated, unfortunately. It is not set up in a way in which we can leverage view.symbols
or view.find_by_selector
. I am not very familiar with LLVM IR, but I am guessing you’re trying to find the lines that start with define
? In that case, you could try a purely text-based approach:
view.find_all(r'^define .*$')
although that will only fetch the first line where the define
keyword starts. I am uncertain wether this construct can span multiple lines.
Someone should give that LLVM IR syntax an update.
Thanks! That worked for me. I will take a look into updating the LLVM IR syntax file.