Sublime Forum

Get a list of all methods/functions of a file

#1

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

0 Likes

#2

view.symbols() should be what you are looking for : http://www.sublimetext.com/docs/3/api_reference.html

0 Likes

#3

Hi Clams, thanks for the answer. Unfortunately, view.symbols gives me an empty array.

0 Likes

#4

You could also use

view.find_by_selector("entity.name.function")

which returns a list of sublime.Region objects.

0 Likes

#5

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

0 Likes

#6

What syntax file are you using for LLVM IR? (this is displayed in the lower right corner of SublimeText).

0 Likes

#7

This one
https://packagecontrol.io/packages/LLVM

0 Likes

#8

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.

0 Likes

#9

Thanks! That worked for me. I will take a look into updating the LLVM IR syntax file.

0 Likes