Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntelliSense always suggests "<?php" when in HTML #372

Closed
cstuder opened this issue May 2, 2017 · 46 comments · Fixed by #527, #593 or felixfbecker/vscode-php-intellisense#267
Closed

Comments

@cstuder
Copy link

cstuder commented May 2, 2017

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)

@felixfbecker
Copy link
Owner

This is because we need to set the triggerCharacters to > because a sequence like -> is not supported. See microsoft/language-server-protocol#138

@cstuder
Copy link
Author

cstuder commented May 3, 2017

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 ?)

@felixfbecker
Copy link
Owner

I don't understand how removing that condition would help

@felixfbecker felixfbecker removed the debt label May 3, 2017
@cstuder
Copy link
Author

cstuder commented May 3, 2017

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.

@felixfbecker
Copy link
Owner

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.

@cstuder
Copy link
Author

cstuder commented May 3, 2017

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?

@felixfbecker
Copy link
Owner

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

@abeebola
Copy link

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

@felixfbecker
Copy link
Owner

Express your need for this on microsoft/language-server-protocol#138 :)

@abeebola
Copy link

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

@ingageco
Copy link

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

@technomav
Copy link

technomav commented Sep 9, 2017

@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 <?php suggestion. And after turn this on, this is keep starts showing.
I don't know the structure and process of intellisense so i am helpless.
Sir if you can fix it then please. :)

@Ciantic
Copy link

Ciantic commented Sep 9, 2017

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

@tangorboyz
Copy link

tangorboyz commented Oct 16, 2017

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.

@tangorboyz
Copy link

tangorboyz commented Oct 16, 2017

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.

@tangorboyz
Copy link

tangorboyz commented Oct 16, 2017

https://github.com/Microsoft/vscode/issues/14166
You already did it.

@bcorcoran
Copy link

bcorcoran commented Oct 30, 2017

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.

$item = new CompletionItem('<?php', CompletionItemKind::KEYWORD);
$item->textEdit = new TextEdit(
new Range($pos, $pos),
stripStringOverlap($doc->getRange(new Range(new Position(0, 0), $pos)), '<?php')
);
$list->items[] = $item;

It's better to remove/comment this and have to type <?php manually the few times I need to than to constantly have to deal with a very frustrating "feature" whether or not it's your fault or not that it happens.

@renoirtech
Copy link

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.

@bcorcoran
Copy link

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

$item = new CompletionItem('<?php', CompletionItemKind::KEYWORD);
$item->textEdit = new TextEdit(
new Range($pos, $pos),
stripStringOverlap($doc->getRange(new Range(new Position(0, 0), $pos)), '<?php')
);
$list->items[] = $item;

@Jensen0710
Copy link

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

@valentinocossar
Copy link

Same for me, the problem of the suggest persists.

@bcorcoran
Copy link

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?

$item = new CompletionItem('<?php', CompletionItemKind::KEYWORD);
$item->textEdit = new TextEdit(
new Range($pos, $pos),
stripStringOverlap($doc->getRange(new Range(new Position(0, 0), $pos)), '<?php')
);
$list->items[] = $item;

@felixfbecker
Copy link
Owner

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).

@jens1o
Copy link
Contributor

jens1o commented Feb 6, 2018

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?

@felixfbecker
Copy link
Owner

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

@valentinocossar
Copy link

@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? 🙂

@felixfbecker
Copy link
Owner

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.

@WraithKenny
Copy link

WraithKenny commented Feb 6, 2018

@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.

@ghost
Copy link

ghost commented Feb 7, 2018

That tinny <?php thing is of minor importance when there is a gazillion of others to take care of. On the contrary, when it pops up at the most inappropriate moments it can cause mistakes. Please remove it permanently.

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

@cstuder
Copy link
Author

cstuder commented Feb 7, 2018

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.

@bcorcoran
Copy link

@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

@felixfbecker
Copy link
Owner

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

@bcorcoran
Copy link

Latest, I literally just updated a few minutes ago.

@felixfbecker
Copy link
Owner

felixfbecker commented Feb 7, 2018

Could you please still tell me the version number?

@bcorcoran
Copy link

0.7.5

@felixfbecker
Copy link
Owner

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

@bcorcoran
Copy link

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

@felixfbecker
Copy link
Owner

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

@bcorcoran
Copy link

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.

@felixfbecker
Copy link
Owner

felixfbecker commented Feb 7, 2018

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.

@bcorcoran
Copy link

bcorcoran commented Feb 8, 2018

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 <?php suggestion should go away if you don't type <?php

@felixfbecker
Copy link
Owner

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

cgxxv pushed a commit to cgxxv/php-language-server that referenced this issue Mar 25, 2022
cgxxv pushed a commit to cgxxv/php-language-server that referenced this issue Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment