<div dir="ltr">Dear Nikolai,<div><br></div><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">You can get the unpreprocessed source code with e.g.<br>
<br>
auto *cppModelManager = CppModelManager::instance();<br>
auto *cppEditorDocument = cppModelManager->cppEditorDocument(document->fileName());<br>
if (cppEditorDocument) {<br>
    // Editor is opened and can provide us the source code...<br>
    const QByteArray source = cppEditorDocument->contents();<br>
    const uint end =  block.bytesEnd() - block.bytesBegin();<br>
    qDebug() << "Argument:" << source.mid(block.bytesBegin(), end);<br>
} else {<br>
    // Read source code from disk...<span class=""><br>
}<br>
<br></span></blockquote><div><br></div><div>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 <span style="color:rgb(128,0,128)">CppTools</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(128,0,128)">CppModelManager</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(0,0,0)">updateSourceFiles(). If this is correct then I do not need to worry about this case.</span></div><div> </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
To convert to line/column, document->translationUnit()->getPosition(...) should help you.<br></blockquote><div><br></div><div>I have attempted this but can't seem to get the correct answer for the line and column number for the arguments:</div><div>I have implemented the following to test:</div><div><br></div><div><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">        for</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,128,0)">const</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">CPlusPlus</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(128,0,128)">Document</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(128,0,128)">MacroUse</span><span style="color:rgb(0,0,0)">&</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">mac</span><span style="color:rgb(0,0,0)">:</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">macroUse</span><span style="color:rgb(0,0,0)">)</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">{</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">            </span><span style="color:rgb(128,128,0)">const</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">QVector</span><span style="color:rgb(0,0,0)"><</span><span style="color:rgb(128,0,128)">CPlusPlus</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(128,0,128)">Document</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(128,0,128)">Block</span><span style="color:rgb(0,0,0)">>&</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">args</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">mac</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(0,0,0)">arguments</span><span style="color:rgb(0,0,0)">();</span></pre><pre style="margin-top:0px;margin-bottom:0px"><font color="#000000">            qDebug() << "Macro      : " << mac.macro().name();<br></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">            </span><span style="color:rgb(0,0,128)">qDebug</span><span style="color:rgb(0,0,0)">()</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Macro</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Line</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">:</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">mac</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(0,0,0)">beginLine</span><span style="color:rgb(0,0,0)">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">            </span><span style="color:rgb(0,0,0)">docPtr</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(0,0,0)">translationUnit</span><span style="color:rgb(0,0,0)">()-></span><span style="color:rgb(0,0,0)">getPosition</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">mac</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(0,0,0)">utf16charsBegin</span><span style="color:rgb(0,0,0)">(),</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">&</span><span style="color:rgb(0,0,0)">line</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">&</span><span style="color:rgb(0,0,0)">column</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">            </span><span style="color:rgb(0,0,128)">qDebug</span><span style="color:rgb(0,0,0)">()</span><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Macro</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Position:</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">line</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">",</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">column</span><span style="color:rgb(0,0,0)">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">            </span><span style="color:rgb(128,128,0)">for</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,128,0)">const</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">CPlusPlus</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(128,0,128)">Document</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(128,0,128)">Block</span><span style="color:rgb(0,0,0)">&</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">block</span><span style="color:rgb(0,0,0)">:</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">args</span><span style="color:rgb(0,0,0)">)</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">{</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">                </span><span style="color:rgb(0,0,0)">docPtr</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(0,0,0)">translationUnit</span><span style="color:rgb(0,0,0)">()-></span><span style="color:rgb(0,0,0)">getPosition</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">block</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(0,0,0)">utf16charsBegin</span><span style="color:rgb(0,0,0)">(),</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">&</span><span style="color:rgb(0,0,0)">line</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">&</span><span style="color:rgb(0,0,0)">column</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">                </span><span style="color:rgb(0,0,128)">qDebug</span><span style="color:rgb(0,0,0)">()</span><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Block</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Position:</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">line</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">",</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)"><<</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">column</span><span style="color:rgb(0,0,0)">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">            </span><span style="color:rgb(0,0,0)">}</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">        </span><span style="color:rgb(0,0,0)">}</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"><br></span></pre></div><div>For the following line ( 47)</div><div><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(0,0,128)">MY_TEST_MACRO</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ab</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">+</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"This</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">is</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">a</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">\"strin\"</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">literal</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">+</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">QString</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(0,0,0)">number</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,128)">20</span><span style="color:rgb(0,0,0)">)</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">+</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"That</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">we</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">\"neerd\"</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">to</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">chegck</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">for</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">\"Spellig</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Mistakers\""</span><span style="color:rgb(0,0,0)">);</span></pre></div><div><br></div><div>I get on Linux: </div><div><div>Macro      :  "MY_TEST_MACRO"</div><div>Macro Line :  47</div><div>Macro Position:  47 ,  10</div><div>Block Position:  47 ,  24</div></div><div class="gmail_quote"><br></div>And on Windows:<br>Macro : "MY_TEST_MACRO"<br>Macro Line : 47<br>Macro Position: 49 , 3<br>Block Position: 50 , 1</div><div class="gmail_quote"><br></div><div class="gmail_quote">I am expecting:</div><div class="gmail_quote">Macro Position to be: 47, 5 and the Block Position to be: 47, 19</div><div class="gmail_quote"><br></div><div class="gmail_quote">Again I get different results on Windows and Linux, but worse than that it is not what I expected. Am I doing something wrong?</div><div class="gmail_quote">Previous issue with almost the same code is mentioned here: <a href="https://bugreports.qt.io/browse/QTCREATORBUG-14834">https://bugreports.qt.io/browse/QTCREATORBUG-14834</a><br><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
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.</blockquote><div> </div></div>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?</div></div><div class="gmail_extra"><br></div><div class="gmail_extra">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?</div><div class="gmail_extra"><br></div><div class="gmail_extra">Regards,</div><div class="gmail_extra">Carel</div><div class="gmail_extra"><br></div></div>