Review Request 118465: Provide code completion items for field member expressions

Denis Steckelmacher steckdenis at yahoo.fr
Mon Jun 2 09:53:13 UTC 2014


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

Review request for KDevelop.


Repository: kdev-qmljs


Description
-------

This patch adds support for field member expressions ("base.identifier") to the QML/JS code-completion. When "something." is typed by the user, KDevelop displays the list of symbols accessible from the inner context of something. "something" can be any expression recognized by ExpressionVisitor, so this will continue to work when ExpressionVisitor will be able to recognize "table["test"][repository.getIndice()].".

The patch is inspired from how Python handles such completion. The idea is to try to parse as much as possible of the line being edited, in order to have the most complete AST possible. When this is done, ExpressionVisitor is given the current context and visits this partial AST. The declaration it returns (if any) is used to get the code-completion items.

The only thing that doesn't quite please me in this patch is that I parse the current line several times (each time with one character removed from the left). It means that if the user is editing a very long line (say 200 characters), QmlJS::Document::parse will be called up to 200 times! Is there another mean to detect which part of the current line contains a valid expression? Do you think that it would be worth it to complexify the code by trying to skip more than one character each time (for instance, by skipping directly to the next dot or bracket).


Diffs
-----

  codecompletion/CMakeLists.txt 9b62fb4 
  codecompletion/context.h 0683974 
  codecompletion/context.cpp 1e57197 

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


Testing
-------

Manual testing shows that everything work as expected. For instance, the completions shown at the cursor (|) in this snippet are all the completions valid in button:

Label {
    id: foo
    bar: "baz"

    Button {
        id: button

        property int my_property;
    }

    onTest: {
        console.log(button.|); // my_property listed
    }
}


Thanks,

Denis Steckelmacher

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20140602/5e0e48e8/attachment.html>


More information about the KDevelop-devel mailing list