Skip to content

Conversation

@phil-nelson
Copy link
Contributor

@phil-nelson phil-nelson commented Dec 12, 2017

This adds some basic support for completing foreach keys/values. For a complete list of what works have a look at the test, but I believe most "normal" cases work.

Limitations:

  • Using list() for values is unsupported. This isn't straightforward, and as far as I can tell we don't support a straight up list() (outside a foreach) for completion
  • No support for iterating public object properties
  • No support for \Traversable objects

I think implementing these limitations is probably more significant work than what's here. I think the cases that work are probably the most used/popular, so even given these limitations I think this would be worth having. We can work on the missing bits in the future.

Closes #200

@codecov
Copy link

codecov bot commented Dec 12, 2017

Codecov Report

Merging #551 into master will increase coverage by 0.64%.
The diff coverage is 92.85%.

@@             Coverage Diff             @@
##             master    #551      +/-   ##
===========================================
+ Coverage     80.86%   81.5%   +0.64%     
- Complexity      877     898      +21     
===========================================
  Files            61      61              
  Lines          2028    2055      +27     
===========================================
+ Hits           1640    1675      +35     
+ Misses          388     380       -8
Impacted Files Coverage Δ Complexity Δ
src/Server/TextDocument.php 75.37% <100%> (+0.18%) 56 <0> (ø) ⬇️
src/CompletionProvider.php 94.51% <100%> (+0.17%) 108 <0> (+6) ⬆️
src/DefinitionResolver.php 86.69% <90.9%> (+1.64%) 318 <0> (+15) ⬆️
src/Indexer.php 60.75% <0%> (+2.53%) 18% <0%> (ø) ⬇️

if ($collectionType instanceof Types\Array_) {
return $collectionType->getKeyType();
}
return new Types\Mixed_();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code style; no brackets at the end.

@andreymrt
Copy link

@phil-nelson can you please take a look at #561 could be related to your PR on foreach completion.
Following code snippet makes the lang server throw an exception

<?php
foreach($Calendar as $day)
	echo $day->Date->format("D");

While, this one is fine:

<?php
foreach($Calendar as $day)
	echo $day->format("D");

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants