Sublime Forum

Retrieve a file's symbols

#1

I’m creating a plugin that retrieves all of a object’s functions and adds them into the autocomplete. (Found on Github: https://github.com/BoundInCode/Function-Copier) The only piece I’m missing is how to load another file into the plugin. Once I load the file, I can use find all the symbols that have the scope “entity.name.function.”

Does anyone know how I could do this?

Thanks.

0 Likes

#2

Can you be a little more specific? In what context are you loading another file into the plugin. An example would be nice so I can better understand how to help.

0 Likes

#3

I’ll do my best to explain.

My plugin, at the moment, has a filename (that corresponds to a file that’s located in my project). I would like the plugin to parse through the file (not the current file, but a file in my project) and retrieve all of the file’s function names. It would work comparably to when you press ctrl+R (super+R on mac) and it lists the symbol definitions for the current file.

I would store the method names in a list that I will load into the autocomplete.

I hope that’s a little more clarifying…

0 Likes

#4

If you just need to read a file.

with open('/path_to_file/file', 'r') as f: read_data = f.read()

And then parse read_data. I hope this is what you are looking for. If it is a large file, you may want to chunk the data.

0 Likes

#5

Thanks a lot. I’m just teaching myself Python as I go so I wasn’t sure if there was a module I had to load or something. That helps.

0 Likes

#6

No problem. I am teaching myself Python as well. I know a bunch of other languages, but still, there is always a learning curve when teaching yourself a new language.

0 Likes

#7

@Facelessuser,

Thanks again for all your help. I was able to finish my plugin with your help. While there is still room for improvement, it’s exciting.

0 Likes