Review Request 118168: Find the type of array keys and use it to support enumeration values in plugin.qmltypes

Denis Steckelmacher steckdenis at yahoo.fr
Sun May 18 11:34:27 UTC 2014


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/118168/
-----------------------------------------------------------

(Updated May 18, 2014, 11:34 a.m.)


Status
------

This change has been marked as submitted.


Review request for KDevelop.


Repository: kdev-qmljs


Description
-------

Enumeration values are handled like this un plugin.qmltypes files:

Enum {
  name: "enumeration"
  values: {
    "first_value": 1,
    "second_value": 2
  }
}

This patch supports this syntax by handling array keys (or dictionary keys, using Pythonic terms). It therefore has two effects:

* Enumeration values are shown in code-completion proposals, and are correctly identified as being values belonging to an enumeration.
* Array keys have their type guessed, even in plain Javascript files.

This patch adds a visit(PropertyNameAndValueList*) method in DeclarationBuilder. The problem with PropertyNameAndValueList is that there is only one such node for the whole array. In my above example, this visit() method is therefore called only once, even if there are two keys in the array. In the JS AST, PropertyNameAndValueList only contains IdentifierNodes and ExpressionNodes. There is no "PropertyNameAndValueEntry" that I can visit. This explain why visit(PropertyNameAndValueList) does strange things, like closing the declaration it has just opened, or calling "visit(node->next)". Normally, things like that should be handled by the nodes themselves, but the JS AST does not do that. If there is a better solution, I would be very glad to implement it!


Diffs
-----

  tests/files/plugins.qml e2a870c 
  duchain/declarationbuilder.cpp 009b90d 
  tests/files/helloworld.js 885aaa3 
  duchain/declarationbuilder.h 1808e4d 

Diff: https://git.reviewboard.kde.org/r/118168/diff/


Testing
-------

This patch adds three unit tests. The first ones checks that enumeration values are correctly recognized. The second one verifies that the type of an array key is correctly deduced, and the third one is there just to ensure that DeclarationBuilder explores all the keys in an array and doesn't stop after the first one.


Thanks,

Denis Steckelmacher

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20140518/1a2168a0/attachment.html>


More information about the KDevelop-devel mailing list