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

Resolve expressions recursively #155

Merged
merged 13 commits into from
Nov 18, 2016
Merged

Resolve expressions recursively #155

merged 13 commits into from
Nov 18, 2016

Conversation

felixfbecker
Copy link
Owner

@felixfbecker felixfbecker commented Nov 17, 2016

Closes #54

Code changes:

A symbol is now represented in the index by an instance of the Definition class. This class holds the SymbolInformation, the FQN, and the type of the declaration (variable type, parameter type, function/method return type, property/constant type) in form of a phpDocumentor\Type object. This type is taken from type hints and docblocks (known limitation: docblocks only support FQNs, not aliased names). All the logic is moved into a new DefinitionResolver class that takes care of resolving any reference node to a Definition object. It has an all-new method resolveExpression(), that can take any Expr node and resolve it recursively to a phpDocumentor\Type.

Resulting Enhancements:

This means that we can now get the definition of any reference, no matter how nested. For example, if we have a method call, as long as we can resolve the left-hand side, we can resolve the whole expression. This works for indefinitely nested expressions, including array access (if the property is typed properly as a typed array via a docblock), property access and method return values. There is even some basic type inference - resolveExpression() will return the correct type for scalars, instantiations etc. so if you assign a variable in the scope, you don't need a docblock to specify the type. This even goes so far as an array will get a compound type of all values it is initialized with or a ternary will get a compound type of the possible branches.

The resolveExpression() method will be a great foundation for completion support #9

@codecov-io
Copy link

codecov-io commented Nov 17, 2016

Current coverage is 94.64% (diff: 96.07%)

Merging #155 into master will increase coverage by 0.63%

@@             master       #155   diff @@
==========================================
  Files            31         31          
  Lines           534        411   -123   
  Methods          69         67     -2   
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits            502        389   -113   
+ Misses           32         22    -10   
  Partials          0          0          
Diff Coverage File Path
••••••••• 92% src/Protocol/SymbolInformation.php
•••••••••• 100% src/NodeVisitor/ReferencesCollector.php
•••••••••• 100% src/NodeVisitor/VariableReferencesCollector.php
•••••••••• 100% src/Server/Workspace.php
•••••••••• 100% src/utils.php
•••••••••• 100% src/NodeVisitor/DefinitionCollector.php

Powered by Codecov. Last update c19aedc...54ad082

@felixfbecker felixfbecker merged commit 33211c6 into master Nov 18, 2016
@felixfbecker felixfbecker deleted the resolve-expression branch November 18, 2016 14:22
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.

Resolve types recursively
2 participants