Php-language-server: IntelliSense always suggests "<?php" when in HTML

Created on 2 May 2017  路  46Comments  路  Source: felixfbecker/php-language-server

Every time I close an HTML tag in a PHP file, IntelliSense suggests <?php as next string.

image

This is distracting when writing HTML: When I want to enter a linebreak, I first have to remove the suggestion before hitting Enter.

Is there a possibility to remove this particular suggestion?

(Using PHP IntelliSense V1.2.1 in Visual Studio Code 1.11.2 on Windows 10, php.suggest.basic is set to false)

enhancement

Most helpful comment

As the person who opened this issue I would like everybody to please relax. Pull requests are on their way.

You can upvote on the issue itself if you're bothered by the current behaviour.

@felixfbecker Thanks for you work and patience.

All 46 comments

This is because we need to set the triggerCharacters to > because a sequence like -> is not supported. See https://github.com/Microsoft/language-server-protocol/issues/138

Just found the responsable code line: https://github.com/felixfbecker/php-language-server/blob/master/src/CompletionProvider.php#L281

I would prefer to have the first condition removed:

} else if ($pos == new Position(0, 0)) {

My question is: Am I the only one who is annoyed by this? (Or am I the only one editing HTML in PHP files ?)

I don't understand how removing that condition would help

Sorry, I didn't make myself clear. Currently, the conditions are like this:

        } else if ($node instanceof Node\Stmt\InlineHTML || $pos == new Position(0, 0)) {

If I understand this correctly, the <?php-completion triggers on InlineHTML nodes and when the cursor is at the beginning of a document.

I propose to remove the first condition, so that line would only trigger on the second condition:

} else if ($pos == new Position(0, 0)) {

Before opening a pull request I would like to understand why this line is how it is and whether my propsal is actually wanted.

The line is how it is to propose a new opening tag inside HTML. That is as designed. The issue is just that the autocomplete pop up all the time because we need to set > as a trigger character.

Yes, so before we go around in further circles: Do you think my request to remove this autocomplete is reasonable and that I should try my hands on a pull request to remove it?

I don't think so, that is as designed - Microsoft needs to fix the trigger characters

Hello.... I am having this issue as well and it is annoying to be honest. Is there a workaround or something?

Express your need for this on https://github.com/Microsoft/language-server-protocol/issues/138 :)

Okay. I hope they do whatever is needed soon. Thanks.

Thanks for directing me here @felixfbecker - hopefully MS gets this fixed soon!

@felixfbecker sir, same thing is happening to me too. But i don't think this is microsoft language issue because when i turn off the intellisense then there is no I don't know the structure and process of intellisense so i am helpless.
Sir if you can fix it then please. :)

Keep throwing the pressure on that issue: https://github.com/Microsoft/language-server-protocol/issues/138 - if there is enough annoyance maybe the Microsoft can prioritize fixing that.

Ya, for example sometimes in php file we also include html, so the trigger for auto completion or IntelliSense should only work inside php tag (<?php ?>). If this is by design from vscode, then we should make a request for it.

this also happen in vscode. the suggestion for <?php also appear even after closing php tag (?>).
The problem doesn't happen after the extension has been disabled.

Just came here to voice my displeasure. IMHO this suggestion needs to be removed until it can be fixed.

It suggests <?php when I type literally any character.

This is a somewhat useless suggestion, anyway. Nobody is saving an appreciable amount of time by <?php being autocompleted. I am (we all are, I suspect), however, wasting time by having to clean up all the times I forget to hit escape and this garbage gets inserted.

Edit:

Commenting out lines 159:164 in src/CompletionProvider.php will stop this from happening.

https://github.com/felixfbecker/php-language-server/blob/1edbe35609c50dcd7d51219b07622f6e527b752b/src/CompletionProvider.php#L159-L164

It's better to remove/comment this and have to type

Since we have no alternatives i would like to vote to remove <?php sugestion until we have news from Microsoft/language-server-protocol#138

It is annoying so much everyone.

@renoirfaria It is already implemented?

Nice. The feature was never needed in my opinion

@jens1o it is? I am telling it since my Atom IDE keeps suggesting it. @felixfbecker elucidate me, please!

@renoirfaria https://github.com/atom/ide-php/issues/47 It still needs to support the feature ;) But the problem is resolved on the Language Server Side.

I will keep updating this thread with the new snippet to remove/comment until it's fixed:

Remove/comment these lines as of 12/20

https://github.com/felixfbecker/php-language-server/blob/9eea26df711920a7e04d4894fc4b9263ee783e11/src/CompletionProvider.php#L176-L181

Is it supposed to be fixed? Because it sure aren't for me...

Same for me, the problem of the suggest persists.

Still not sure why you don't just remove the lines I outlined? Nobody is saving time by having <?php auto-suggested. We are WASTING time having to hit escape or click out of the suggestion every time we type an HTML tag. @felixfbecker can you explain why you can't just remove this?

https://github.com/felixfbecker/php-language-server/blob/9eea26df711920a7e04d4894fc4b9263ee783e11/src/CompletionProvider.php#L176-L181

Sorry but I don't understand your argument. You expect autosuggestions for HTML tags, right? So wouldn't you expect a suggestion for <?php just like any other HTML tag? The issue that vscode users have is that VS Code proposes it on the > trigger character because it doesn't send the CompletionContext like Atom does. I would be fine with a PR defaulting to not propose it inside HTML if the CompletionContext was not sent (I think the suggestion at the very beginning of the file should be kept as that is reasonable).

I would be fine with a PR defaulting to not propose it inside HTML if the CompletionContext was not sent (I think the suggestion at the very beginning of the file should be kept as that is reasonable).

I'm going to do this now, so I don't get my notifications spammed with this (overstated) issue in the future.

Can we notify the vscode developers about the CompletionContext has being introduced?

The vscode developers introduced the CompletionContext themselves, but you can always express to them that there is a desire to have it implemented

@felixfbecker @jens1o Sorry to bother you, I'm new to VS Code. So we have to wait for the fix, to consider this issue really solved? 馃檪

From a language server standpoint, assuming a spec compliant client, there is no issue in the language server.
From a vscode user perspective, you'll either need to wait until vscode implements the parameter, or help out on the workaround I suggested.

@felixfbecker I'd basically never expect the <?php in the html context (and it's never appropriate in the php context obviously), except for possibly at the beginning of a file. The only other time it might be expected is immediately after switching from php context to html context via ?>. Generally tho, the suggestion of <?php even in those cases is of limited advantage.

That tinny

Of course @felixfbecker a big thank you from me too. Even with this, it still ranks as the best php intellisense out there!

As the person who opened this issue I would like everybody to please relax. Pull requests are on their way.

You can upvote on the issue itself if you're bothered by the current behaviour.

@felixfbecker Thanks for you work and patience.

@felixfbecker I am using Atom. This should illustrate why the <?php suggestion is irritating. Should I hit enter to try to get to a new line, I will end up with <div<?php

screen shot 2018-02-07 at 17 31 55

@bcorcoran what version of ide-php do you use?

Latest, I literally just updated a few minutes ago.

Could you please still tell me the version number?

0.7.5

Is that an automatic suggestion or did you invoke it with Cmd+Space? Could you post LSP logs?

It's automatic. How do I get LSP logs?

I don't know, I don't use Atom

Anyway, the solution is to delete/comment out the lines I have been posting. In the rare case that a <?php suggestion would be useful, I am happy to type it out manually rather than deal with it being suggested for literally any html tag. Sorry for being irritating about this, but it's an irritating issue.

rather than deal with it being suggested for literally any html tag

There should be no more autotriggered suggestions on the > in a client like Atom ide-php v0.7.5 (which should send CompletionContext) nor in VS Code (which sends no CompletionContext) with vscode-php-intellisense v2.2.7. This is unit tested in the language server. To help you further I would have to see LSP logs.

It triggers with any < and doesn't go away if you type other characters. That was what I was trying to illustrate with the screenshot.

  1. Type <
  2. <?php suggestion shows up
  3. Type anything else
  4. <?php suggestion does not go away.

I think the

I see that you also get a suggestion for div. Does that disappear if you don't type div? If not, then that sounds more like an Atom issue

Was this page helpful?
0 / 5 - 0 ratings