Home Download Buy Blog Forum Support

Command argument type limitation ?

Command argument type limitation ?

Postby bizoo on Tue Jun 28, 2011 12:01 pm

Sorry, lot of questions today :?:

I try this plugin:
Code: Select all
class TestOracleCommand(sublime_plugin.TextCommand):
    def run(self, edit, myparam):
        print myparam

And call it with:
Code: Select all
>>> view.run_command("test_oracle", {"myparam":[1,2]})
[1.0, 2.0]
>>> view.run_command("test_oracle", {"myparam":(1,2)})
None
>>> view.run_command("test_oracle", {"myparam":sublime.Region(0)})
None

As we can see, some type of parameter doesn't pass to the command.
Is it a bug or a limitation ?
bizoo
 
Posts: 886
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Command argument type limitation ?

Postby jps on Tue Jun 28, 2011 12:11 pm

Only types that have a direct JSON representation can be passed: lists, dictionaries (with string keys), numbers, bools, and strings.
jps
Site Admin
 
Posts: 3071
Joined: Wed Mar 19, 2008 12:33 pm

Re: Command argument type limitation ?

Postby bizoo on Tue Jun 28, 2011 12:27 pm

OK, thanks for the quick answer.

Could I replace:
Code: Select all
self.window.run_command("oracle_exec", {"dsn": dsn, "entities": entities})

with:
Code: Select all
oracle_exec.OracleExecCommand(self.window).run(dsn=dsn, entities=entities)

It look like it work but do you see any issue with this ?

My other option is to convert the unsupported type in my argument to something supported and convert it back later.
bizoo
 
Posts: 886
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Command argument type limitation ?

Postby jps on Tue Jun 28, 2011 1:21 pm

I'd recommend converting the arguments.

Where possible, commands should purely depend on their arguments, and not data passed in other ways: this allows them to work properly in key bindings, menus, macros, and be repeated. Because this isn't a TextCommand, macros aren't an argument, but you may want to bind a key to the command in the future.
jps
Site Admin
 
Posts: 3071
Joined: Wed Mar 19, 2008 12:33 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 29 guests