[Qt-creator] Parse macro arguments for Spell Checking

Carel Combrink carel.combrink at gmail.com
Tue Jan 26 21:03:44 CET 2016


Dear Nikolai,

You can get the unpreprocessed source code with e.g.
>
> auto *cppModelManager = CppModelManager::instance();
> auto *cppEditorDocument =
> cppModelManager->cppEditorDocument(document->fileName());
> if (cppEditorDocument) {
>     // Editor is opened and can provide us the source code...
>     const QByteArray source = cppEditorDocument->contents();
>     const uint end =  block.bytesEnd() - block.bytesBegin();
>     qDebug() << "Argument:" << source.mid(block.bytesBegin(), end);
> } else {
>     // Read source code from disk...
> }
>
>
The above works well, thank you. Regarding the "Read source code from
disk... " comment, when will it happen that the editor documents would not
be open? From my understanding the model manager will open the document
with a call to CppTools::CppModelManager::updateSourceFiles(). If this is
correct then I do not need to worry about this case.


To convert to line/column, document->translationUnit()->getPosition(...)
> should help you.
>

I have attempted this but can't seem to get the correct answer for the line
and column number for the arguments:
I have implemented the following to test:

        for(const CPlusPlus::Document::MacroUse& mac: macroUse) {

            const QVector<CPlusPlus::Document::Block>& args = mac.arguments();

            qDebug() << "Macro      : " << mac.macro().name();

            qDebug() << "Macro Line : " << mac.beginLine();

            docPtr->translationUnit()->getPosition(mac.utf16charsBegin(),
&line, &column);

            qDebug()  << "Macro Position: " << line << ", " << column;

            for(const CPlusPlus::Document::Block& block: args) {


docPtr->translationUnit()->getPosition(block.utf16charsBegin(), &line,
&column);

                qDebug()  << "Block Position: " << line << ", " << column;

            }

        }


For the following line ( 47)

    MY_TEST_MACRO(ab + "This is a \"strin\" literal " +
QString::number(20) + "That we \"neerd\" to chegck for \"Spellig
Mistakers\"");


I get on Linux:
Macro      :  "MY_TEST_MACRO"
Macro Line :  47
Macro Position:  47 ,  10
Block Position:  47 ,  24

And on Windows:
Macro : "MY_TEST_MACRO"
Macro Line : 47
Macro Position: 49 , 3
Block Position: 50 , 1

I am expecting:
Macro Position to be: 47, 5 and the Block Position to be: 47, 19

Again I get different results on Windows and Linux, but worse than that it
is not what I expected. Am I doing something wrong?
Previous issue with almost the same code is mentioned here:
https://bugreports.qt.io/browse/QTCREATORBUG-14834

Note that we are focusing on the clang code model, so in the long run the
> code we are speaking about here will vanish or be replaced.


I am assuming that even though the code model is planned to be replaced
with the clang code model there would still be an interface into the model.
Regarding my SpellChecker plugin, if this move happens I want to still be
able to allow for picking up spelling mistakes, thus I would then need to
interface to the code model that the clang processor built up. Do you have
any suggestions or comments around this and where I might start to look if
I want to start porting my plugin to make use of this?

As mentioned, I was hoping to start with the process to integrate my plugin
into Qt Creator once the above issue is solved, what is your
recommendations around this? Should I wait for the clang code model before
I attempt this or would it still be a good idea to start the integration
using the old code model?

Regards,
Carel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20160126/86ab1822/attachment.html>


More information about the Qt-creator mailing list