Sublime Forum

Php (core) function autocomplete and parameter hints

#1

I’m running ST3 on OSX and my for whatever reason Sublime has quit auto-completing PHP function names and providing parameter hints

ie, on my windows machine
“strp<tab>”
results in
"strpos(haystack, needle) " (where haystack is highlighted so it’ll be replaced as I continue to type.

What gives? I’ve looked at preference files but don’t see any smoking gun.
I’m guessing reinstalling ST3 will, at-best, keep my current packages and preferences?

Thanks

0 Likes

#2

Some quick digging shows that those sorts of completions are coming from the PHP.sublime-completions file. A small excerpt of which is:

{ "trigger": "strncmp", "contents": "strncmp(${1:str1}, ${2:str2}, ${3:len})" },
{ "trigger": "strpbrk", "contents": "strpbrk(${1:haystack}, ${2:char_list})" },
{ "trigger": "strpos", "contents": "strpos(${1:haystack}, ${2:needle})" },
{ "trigger": "strptime", "contents": "strptime(${1:date}, ${2:format})" },
{ "trigger": "strrchr", "contents": "strrchr(${1:haystack}, ${2:needle})" },
{ "trigger": "strrev", "contents": "strrev(${1:string})" },

These completions trigger only for PHP, so a possible problem might be that it doesn’t realize that you’re using PHP (e.g. if you were just entering code in a scratch buffer or something). If that was the case the syntax highlighting would not look right.

Another possibility would be if you have added something (either explicitly or through installing a package on one machine that doesn’t appear on the other) that is overriding this file with one that doesn’t have the completions that you’re interested in.

One other thing that comes to mind (but seems unlikely) would be a key binding issue of some sort; does autocomplete for other languages work or is the problem just restricted to PHP?

0 Likes

#3

I’ve played around with this a little bit more, including on my Mac, and it seems to work just fine for me. From experimentation (PHP is not one of my languages) I think what might be biting you is that first thing I said above “it doesn’t realize that you’re using PHP”.

For more explanation, the file that I mentioned above that includes the completions also specifies the syntax scope that the completions will be used in. For simplicity here we’ll say that scope is source.php; if that scope is not set for any particular location in the file, the completions won’t work at that location.

Presumably due to the fact that PHP is used embedded inside e.g. an HTML page, the source.php scope doesn’t spring into existence unless you’re inside a <$php $> tag. Also, the overall syntax for the file has to be set to PHP as well; it will work in sample.php but not in sample.html, which makes sense since by default a server wouldn’t handle such a file as PHP.

Here’s an example:

At first, pressing Tab just inserts spaces, but once I go up and open a <$php tag, it works as one might expect. Note also that as soon as I type <$ you can see the syntax highlighting kick in (on the = and strings), which is an extra clue that it’s ready to go.

0 Likes

#4

I’m guessing it has something in my /default/Preferences.sublime-settings

// Controls what scopes auto complete will be triggered in
"auto_complete_selector": "meta.tag - punctuation.definition.tag.begin, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc",

// Additional situations to trigger auto complete
"auto_complete_triggers": [ {"selector": "text.html", "characters": "<"} ],

I’ll try to compare the differences.

0 Likes

#5

Also be sure you are using the latest dev build. There was a bug affecting autocomplete of PHP inside of HTML inside of PHP for a couple of builds. Not sure if this is related.

2 Likes

#6

Hi,
I had a basic experience with Netbeans, the auto completion or parameter info I don’t know what it is called that was very good esp with PHP.
Please see below pictures and link:
https://netbeans.org/kb/71/php/editorguide.html#ParameterHints

Can we do this the same as above with sublime text? Is there any way?

Thank you.

0 Likes

#7

I think you have two choices. There may be more plugins that I didn’t aware of but I do not think anyone beats LSP.

  • LSP with your preferred PHP LSP server implementation (I recommend intelephense due to its fast response but if you don’t want to install Node.js, then PHP Language server.)

  • IntelliDocs with custom keybindings.

    { "keys": ["ctrl+alt+h"], "command": "intelli_docs" },
    

I install both because LSP won’t help in non-project. LSP is much more powerful and preferred but it needs some setup.

0 Likes

#8

thanks, it is very good but not with variables:

example in sublime text: $con = mysqli_connect(host, user, password, database, port, socket)
example with netbeans: $con = mysqli_connect($host, $user, $password, $database, $port, $socket)

if there is any way please, if it there is no other way I am thank you in advanced.

0 Likes

#9

It looks like some non-core functions are missing in IntelliDocs.

LSP (intelephense) seems to be helpful though.


0 Likes