Sublime Forum

Command argument type limitation?

#1

Sorry, lot of questions today :question:

I try this plugin:

class TestOracleCommand(sublime_plugin.TextCommand): def run(self, edit, myparam): print myparam
And call it with:

[code]>>> 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[/code]
As we can see, some type of parameter doesn’t pass to the command.
Is it a bug or a limitation ?

0 Likes

#2

Only types that have a direct JSON representation can be passed: lists, dictionaries (with string keys), numbers, bools, and strings.

0 Likes

#3

OK, thanks for the quick answer.

Could I replace:

self.window.run_command("oracle_exec", {"dsn": dsn, "entities": entities})

with:

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.

0 Likes

#4

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.

0 Likes