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

Support constants #347

Merged
merged 11 commits into from
Apr 17, 2017
Merged

Support constants #347

merged 11 commits into from
Apr 17, 2017

Conversation

jens1o
Copy link
Contributor

@jens1o jens1o commented Apr 10, 2017

Yes, I used the master branch. So I have less problems 😉

resolves #84 and fixes #48

@jens1o
Copy link
Contributor Author

jens1o commented Apr 10, 2017

Seems to work(excluding the code style). Did I missed something @felixfbecker?

@codecov
Copy link

codecov bot commented Apr 10, 2017

Codecov Report

Merging #347 into master will decrease coverage by 0.09%.
The diff coverage is 88.88%.

@@             Coverage Diff             @@
##             master     #347     +/-   ##
===========================================
- Coverage      84.2%   84.11%   -0.1%     
- Complexity      815      826     +11     
===========================================
  Files            59       59             
  Lines          1722     1712     -10     
===========================================
- Hits           1450     1440     -10     
  Misses          272      272
Impacted Files Coverage Δ Complexity Δ
src/Index/Index.php 68.62% <ø> (ø) 21 <0> (ø) ⬇️
src/DefinitionResolver.php 81.79% <75%> (-0.06%) 281 <0> (+5)
src/Protocol/SymbolInformation.php 96.66% <92.85%> (+1.21%) 31 <0> (+6) ⬆️

@jens1o
Copy link
Contributor Author

jens1o commented Apr 17, 2017

any news on this?

{
// print TEST_PROPERTY ? 'true' : 'false';
// Get hover for TEST_PROPERTY
$reference = $this->getReferenceLocations('TEST_PROPERTY')[0];
Copy link
Owner

Choose a reason for hiding this comment

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

Please name it TEST_DEFINE_CONSTANT or something like that, TEST_PROPERTY is confusing

@@ -58,9 +58,10 @@ public function testEmptyQueryReturnsAllSymbols()
new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestInterface'), ''),
new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('test_function()'), ''),
new SymbolInformation('ChildClass', SymbolKind::CLASS_, $this->getDefinitionLocation('ChildClass'), ''),
new SymbolInformation('define', SymbolKind::CONSTANT, $this->getDefinitionLocation('TEST_PROPERTY'), ''),
Copy link
Owner

Choose a reason for hiding this comment

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

If this is the defined constant, shouldn't the symbol name be TEST_PROPERTY (or TEST_DEFINE_CONSTANT), not define?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because it's the name of it. The value is the TEST_PROPERTY. But I can change that if you want.

Copy link
Owner

Choose a reason for hiding this comment

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

What do you mean with value? A SymbolInformation has a name, and the name of the defined constant is TEST_PROPERTY. What value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, that's a bug. The name had been overwritten...

@felixfbecker felixfbecker changed the title 🚀 support constants Support constants Apr 17, 2017
&& isset($node->args[0])
&& $node->args[0]->value instanceof Node\Scalar\String_
) {
$symbol->name = (string)$node->args[0]->value->value;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd added this because otherwise it would get renamed immediatly in line 98(105)

Copy link
Owner

Choose a reason for hiding this comment

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

l98 only sets containerName?

Copy link
Contributor Author

@jens1o jens1o Apr 17, 2017

Choose a reason for hiding this comment

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

In that line?

} else if (isset($node->name)) {
             $symbol->name = (string)$node->name;
} 

I'd debugged a bit and figured out that without this method it will be set to define(which is the name of the node). But we want the value as a name, so that's why.

Copy link
Owner

Choose a reason for hiding this comment

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

You don't wanna check the exact same condition twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to. Otherwise it would return null in this line: https://github.com/jens1o/php-language-server/blob/7380acc49fbacb4d5a6b3a7bf76d6dd55eed2043/src/Protocol/SymbolInformation.php#L88-L90

And otherwise it would get resetted when I don't check it twice.

Copy link
Owner

@felixfbecker felixfbecker Apr 17, 2017

Choose a reason for hiding this comment

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

yeah, I see, but there are better options like setting the name early and checking later if the name is already set, or keeping a boolean flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay. I'll do that.

@jens1o jens1o added the feature label Apr 17, 2017
@jens1o
Copy link
Contributor Author

jens1o commented Apr 17, 2017

Seems to work, did I missed something else? Would love to see this published asap, I need this in my personal project. 😄

@jens1o
Copy link
Contributor Author

jens1o commented Apr 17, 2017

Sorry for all these commits with the code style... I know my codestyle pretty well and forget to switch to other projects very often...

@@ -87,10 +99,13 @@ public static function fromNode(Node $node, string $fqn = null)
} else if ($node instanceof Node\Expr\ClosureUse) {
$symbol->name = $node->var;
} else if (isset($node->name)) {
Copy link
Owner

Choose a reason for hiding this comment

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

this is equivalent to else if (isset($node->name) && !isset($symbol->name)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I would do this like I did, for readability, but I changed it.

Copy link
Contributor Author

@jens1o jens1o Apr 17, 2017

Choose a reason for hiding this comment

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

Don't seems to be identical... This is what I meant. Should I revert it?

Copy link
Contributor Author

@jens1o jens1o left a comment

Choose a reason for hiding this comment

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

Ah, nice idea... lgtm

@felixfbecker felixfbecker merged commit b1cc7bf into felixfbecker:master Apr 17, 2017
lialan pushed a commit to lambdalab/php-language-server that referenced this pull request Apr 30, 2017
zfy0701 pushed a commit to lambdalab/php-language-server that referenced this pull request May 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support define() constants
2 participants