Review Request 118743: Make every QML/JS file see the other QML/JS files in its directory
steckdenis at yahoo.fr
Sun Jun 15 11:23:36 UTC 2014
This is an automatically generated e-mail. To reply, visit:
(Updated June 15, 2014, 11:23 a.m.)
Review request for KDevelop.
Import the contexts of the files in the same directory every time a file is parsed (so that it can be updated when a file appears), and simplify the code by removing the line that added the current context into the top-context of an other file.
Put DUChainWriteLocker outside the while loop, and ensure that the current file doesn't try to import itself (the check now uses the URL of the file instead of its TopDUContext, because the TopDUContext is available only after a parse has finished for a given file: this prevents some files from being parsed 3 times instead of 2, and greatly speeds up the testsuite that now runs in 1.90s instead of 2.60).
If a directory contains a.js, b.js and c.js, a.js imports b.js and c.js, b.js imports a.js and c.js, and c.js imports a.js and b.js. This way, every file can see the declarations of all the other files. This brings two important features:
* The same code is used for QML files. Because this patch also declares the top-level component of a MyComponent.qml QML file as MyComponent, QML files can now instantiate the top-level component of other files. This is the "custom components" feature.
This patch is a bit simpler than what I've imagined, but here are some remarks that I have about the code:
* I use QFileInfo because I've not found a static method that takes a file path and returns the path of its parent directory (a simple section('/', 0, -2) would have been enough if every operating system used / separators). QDirIterator is easy to use, but is it okay to use these classes in KDE code?
* Every file includes every other file in the same directory. When there are many files in a directory, this can become quite huge, but KDevelop seems to handle imported parent contexts in a quite efficient manner.
* I filter out the files in /kdevqmljssupport/, because they are big and numerous. I don't want all 24 of them to include all the others and to be parsed every time KDevelop starts.
* The "class" of the top-level QML component of a file is not anonymous anymore but has a name, hence the small changes in the unit tests.
Two tests are added: one declares a JS variable in a file and uses it in another file (and checks that the use count is 1), the other instantiates the top-level QML component of "test.qml" in "plugins.qml" and checks that the uses are okay.
Some other unit tests needed to be changed because top-level QML components now have a class name. With these changes, the whole testsuite continues to pass and has not been slowed down by this patch.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the KDevelop-devel