Home Download Buy Blog Forum Support

Retrieve a file's symbols

Retrieve a file's symbols

Postby C0D312 on Thu Nov 17, 2011 2:36 am

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.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Retrieve a file's symbols

Postby facelessuser on Thu Nov 17, 2011 2:56 am

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.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: Retrieve a file's symbols

Postby C0D312 on Thu Nov 17, 2011 3:07 am

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...
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Retrieve a file's symbols

Postby facelessuser on Thu Nov 17, 2011 3:24 am

If you just need to read a file.

Code: Select all
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.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: Retrieve a file's symbols

Postby C0D312 on Thu Nov 17, 2011 11:59 am

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.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Retrieve a file's symbols

Postby facelessuser on Thu Nov 17, 2011 4:33 pm

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.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: Retrieve a file's symbols

Postby C0D312 on Thu Nov 17, 2011 9:31 pm

@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.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 14 guests