dapetcu21 / atom-autocomplete-lua

Extensible autocomplete+ provider for Lua
35 stars 6 forks source link

Allow optional function arguments complete #2

Closed ThaisRobba closed 7 years ago

ThaisRobba commented 7 years ago

Sometimes we want to pass a reference to a function, sometimes we want to call it. We should have a key combination for completing function arguments, instead of a toggle setting.

Maybe Shift+Enter to autocomplete with arguments snippets and plain Enter to autocomplete just the function name.

dapetcu21 commented 7 years ago

Hmm... That's a fair point. Unfortunately, autocomplete+ doesn't let me change suggestions between them being displayed and them being entered. Maybe I could have the option of having both completion variants in the list: one with arguments and one without?

ThaisRobba commented 7 years ago

I'm not a fan of the duplication but that could work. Perhaps the reference could be shown as a value and the function call as a function? Not sure what is best.


Is it possible to have modifiers keys that change what is shown in the autocomplete? For instance:

-Is suggesting onStart -Hold alt -Is suggesting onStart(content, options)

Not sure if that is possible (or desirable). Might affect too much the regular bindings.

dapetcu21 commented 7 years ago

That would be great, but it's not possible. Autocomplete+ manages when your suggestions are requested of you and shown. I can't change them after they've been shown. Duplication is not ideal, but it would work for your use case. Another option would be to make the toggle more accessible. The code for that is trivial and you can put it in your init script, then bind it to a key from your keymap:

atom.commands.add('atom-workspace', {
  'autocomplete-lua:toggle-arguments': () => {
    const oldValue = atom.config.get('autocomplete-lua:useSnippets')
    atom.config.set('autocomplete-lua:useSnippets', !oldValue)
  }
})

This is JS, you might have to convert it to CoffeeScript. Try it and see if mode switching works for you.

ThaisRobba commented 7 years ago

Toggling feels a bit clunky - like I forget to set it, so I have to clean the autocompleted result anyway.

One thing that I found pretty useful is using a custom binding to remove the function signature - sadly depends on an extra package. I'm using the following:

atom.commands.add 'atom-text-editor',
  "custom:remove-function-signature": (event) ->
    editorElement = atom.views.getView(atom.workspace.getActiveTextEditor())
    atom.commands.dispatch(editorElement, 'bracket-matcher:select-inside-brackets')
    atom.commands.dispatch(editorElement, 'core:delete')
    atom.commands.dispatch(editorElement, 'core:backspace')

I have it bound to shift-backspace. Perhaps I'll suggest this command to the bracket-matcher packages.