HvyIndustries / crane

PHP Intellisense/code-completion for VS Code

Home Page:https://hvy.io/crane

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Autocompleting odd behaviour

vladdeSV opened this issue · comments

Platform : darwin
VSCode Version : 1.14.1
Crane Version : 0.3.6

Bug: Autocompleting a class method appends parenthesises () when parenthesises are already present, but not when missing.

gif

Intended: If on empty line, autocompleting a class method should automatically add () after method name. If () already are present, no parens should be added.

Observed: The opposite of intended. Parens get appended only of other parens are present, and not when parens are missing.


EDIT: This might be an unrelated to the issue at hand. Upon some more testing it seems the execute function (in gif above) is a public function in a class. Very odd behaviour I must say.

If I'd take a guess, I would believe there was an faulty check such as

if (areParensPresent) {
    addParens();
}

The autocompleting feature does not behave properly at all. Take a look at the following gif:

gif

No autocompletion happens if a string is present on the same line, after the class name.

Thanks for reporting this, I'll look into it!

There is some code that says if a method has no parameters, then add the parenthesis. If it does have parameters, don't add any because pressing the ( key will trigger the code completion to show the method signature suggestion box. It's a subtle hint to the user that you need to add some parameters to the method call. In hindsight, maybe too subtle...

private getFunctionInsertText(node: MethodNode)
{
    let text = node.name;

    if (node.params.length == 0) {
        text += "()";
    }

    return text;
}

suggestionBuilder.ts:780(ish)

The method signature provider isn't implemented yet, so I'll just make this always add the () onto the end when inserting.

Combined with the new functionality to display phpdoc comments in the code completion documentation section in v0.4.0, it should be easier to distinguish if a method needs any parameters or not.

Heyo, good response!

While you're at it: When you do the following:

  • writeMyClass::
  • type first three letters of method
  • press backspace
  • press ctrl+space

Then the methods do not appear in the suggestion box.

Any ideas why?

Its an annoying limitation of how the code works out which suggestions to show you.

I need to come up with a better way to work out the scope of what you're looking for suggestions for. Right now, (amongst others) : is a trigger character that will correctly show you suggestions, so you just need to retype that to get suggestions for the class

Ah okay.

Finally: do you know why autocompletion does not work if there is something in the parenthesises?

aka MyClass::|($foo) (where | represents the cursor) does not show any suggestions, even when retyping a :

I'm not sure why that happens, but improving the reliability of code completion is something I'm working on!