Sublime Forum

Why doesn't this minimal ListInputHandler work?

#1

I’m stumped why the following isn’t working. I’ve reduced it to minimal code that’s the same as other *InputHandlers I use successfully. What am I missing?

import sublime_plugin


class ReplFlavourInputHandler(sublime_plugin.ListInputHandler):
    def placeholder(self):
        return "Select a REPL flavour"

    def list_items(self):
        return ["JVM", "Browser", "Node"]


class OpenClojureRepl(sublime_plugin.TextCommand):
    def run(self, edit, repl_flavour):
        pass

    def input(self, args):
        return ReplFlavourInputHandler()

That open_clojure_repl command is bound to a key. The problem seems to be that its input method is never consulted by Sublime and so its run method fails with:

TypeError: run() missing 1 required positional argument: 'repl_flavour'

REF:
https://www.sublimetext.com/docs/3/api_reference.html#sublime_plugin.TextCommand
https://www.sublimetext.com/docs/3/api_reference.html#sublime_plugin.ListInputHandler

0 Likes

Raising a Text Input Handler with a Key binding
#2

I think maybe the input handlers only work when the command is invoked from the Command Palette, no?

1 Like

#3

I think the error message says you did not specify the repl_flavour in args in your keybinding settings since it’s defined as a required arg in your run().

0 Likes

#4

The input() method of a command is invoked when you try to execute a command and it’s missing arguments, but only when that command is in the command palette (i.e. there is an entry in a sublime-commands file for it). It looks like you may have missed that step.

2 Likes

#5

As a side note, although input handlers will be invoked for commands invoked via means other than the command palette (such as a key binding), there is a hard to trace bug in which occasionally Sublime will select and execute the wrong command when you press the key.

I don’t think this is officially reported though, as it doesn’t happen very often and it doesn’t seem to have any known steps to replicate it.

0 Likes

#6

The feature is that the argument is supposed to be automagically plumbed in, with a name derived from the class name of the InputHandler.

Damn. That’s it.

Ah, nice! So it doesn’t actually have to be invoked from the Command Palette, it just needs a presence there, and then it can be invoked directly from a keybinding.

1 Like

#7

I can reproduce this bug 100% of the time. Here’s a video:

And a bug report: https://github.com/SublimeTextIssues/Core/issues/2926

2 Likes