[Qt-creator] Parse macro arguments for Spell Checking
Nikolai Kosjar
nikolai.kosjar at theqtcompany.com
Fri Jan 22 12:04:16 CET 2016
Hi!
On 01/19/2016 09:20 PM, Carel Combrink wrote:
> What I am struggling with is to get the argument before the macro is
> replaced/expanded.
> Say I have the following on line 46:
>
> QStringstringLiteral=QStringLiteral("AStringLiteralwirthspelligmistakes");
> ...
> Now the issue: How do I get the actual argument:
> "AStringLiteralwirthspelligmistakes"
Use the offsets/positions from Document::Block with the unpreprocessed
source code to extract the arguments as strings. The arguments are not
stored separately to save memory.
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 second thing I will then need to do is to underline any spelling
> mistakes, so I would need to get the line and column number if possible,
> of the misspelled word before expanded.
To convert to line/column, document->translationUnit()->getPosition(...)
should help you.
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.
Nikolai
More information about the Qt-creator
mailing list