Sublime Forum

Paste Method

#1

One of the things I missed about using an IDE is that I can easily see all the available functions to an Object. Then I discovered how powerful Goto Anything is… So I built my very first plugin which opens goto anything, filled with the class of whatever object you have selected. (Only works with Java at the moment)

example: MyClass obj; obj|
press ctrl+r (super+r on OSX), goto anything opens with:

MyClass@

This way, all my class methods are displayed…
So here’s the question. Is there anyway to make a plugin that when I press enter, it copies the function name, escapes the overlap panel, and pastes function name in the window?

Thanks for any help.

0 Likes

#2

Probably, what do you mean overlap panel? Do you have a clip of code where you invoke said overlap panel? I am not exactly sure what you mean. If you mean quick panel, then yes, you can give it a callback, and it will return the index of the item selected, since you populate it, you should also know the index.

I would really need more info, or see the code to be more help.

0 Likes

#3

By overlap panel, I meant the Goto anything panel.

I was a bit reluctant to show my code because its my first plugin and its a pretty shitty attempt at python. BTW, I really suck at regex, so any help there is really appreciated. Thanks for your help.

Here’s the plugin: https://github.com/BoundInCode/Function-Copier

0 Likes

#4

I’ve added some comments on your initial commit, I hope they’re helpful!

0 Likes

#5

Thanks. I made those corrections.

0 Likes

#6

Don’t feel bad. If I withheld my code every time I thought it was crappy, I would never let it out of my hands. :smile:

One suggestion, run SublimeLinter on your code.

Now, your question: The problem is, I don’t think the “goto” panel has callbacks or any real way to access what it selects. It is designed with the purpose of “going to” ; I don’t think it was designed to be used out of context.

I would personally ask jps if he could provide a method to retrieve goto anything results via the api without calling a goto panel, or ask if this already exists hidden somewhere. I just don’t have enough experience with the api to tell you if it already exists, but I suspect it doesn’t.

0 Likes

#7

So a decided that it might be more straightforward if I use the auto_complete api instead of the Goto anything.

So the plugin should:

  1. find the object type (done)
  2. Find all methods of that class (check for: entity.name.function)
  3. Populate the auto_complete with all the methods. (???)
  4. Open auto_complete (view.run_command(‘auto_complete’, {‘disable_auto_insert’: True}))

Before I embark, I have a question. How do I populate the auto_complete list? I’ve been scanning the codeintel plugin for clues but it’s just a big puzzle…

0 Likes

#8

[quote=“C0D312”]…
How do I populate the auto_complete list? …[/quote]

I believe, you can do it like this:
sublime_plugin.EventListener -> on_query_completions -> return (x, x) for x in your_list]

0 Likes

#9

Yeah, I think ask is on the right path. I haven’t tried to do this specifically yet with the api, so my knowledge is limited on this topic, but I think this is the way you need to go from looking at CodeIntel.

0 Likes