<div dir="ltr">If you want to underline the error in an editor (rather than just having a red X in the gutter), it's a lot easier if the diagnostic includes the source range for you so you don't have to infer/calculate it yourself.<div>
<br></div><div>For diagnostics with no source range, do you think it's currently reliable to find the token at the location and underline it? I'm not sure. For example, if you are missing a semicolon at the end of a line, it would be nice if the expression with the missing semicolon were underlined to draw attention to it.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 22, 2014 at 3:42 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Tue, Apr 22, 2014 at 3:31 PM, Michael Bolin <<a href="mailto:bolinfest@gmail.com">bolinfest@gmail.com</a>> wrote:<br>

> Ah, if the contents of example.c are simply:<br>
><br>
> main() {}<br>
><br>
> And then I run:<br>
><br>
> clang example.c<br>
><br>
> I get:<br>
><br>
> example.c:1:1: warning: type specifier missing, defaults to 'int'<br>
> [-Wimplicit-int]<br>
> main() {}<br>
> ^~~~<br>
> 1 warning generated.<br>
><br>
> So there are ranges, just not for as many diagnostic types as I would<br>
> expect. Would patches to add more range information be welcome?<br>
<br>
</div>Depends if they add value - in the case of the return example, the<br>
diagnostic points to the one token that's relevant - it's not<br>
necessary to describe that with a range. (it could be a purely UI<br>
level feature to have diagnostics tokens be displayed as highlighted<br>
ranges - but it's not necessary to have all the diagnostics manually<br>
add the range of their one token to the diagnostic)<br>
<br>
Not sure what else might end up highlighted in your 'main' example<br>
(ie: why there's a range there since it's only over one token - I<br>
assume it's because it might be over multiple tokens in some cases,<br>
but don't know what those cases are)<br>
<br>
- David<br>
<div><div class="h5"><br>
><br>
><br>
><br>
> On Tue, Apr 22, 2014 at 3:26 PM, Michael Bolin <<a href="mailto:bolinfest@gmail.com">bolinfest@gmail.com</a>> wrote:<br>
>><br>
>> Hmm, I just tried running `clang -fdiagnostics-print-source-range-info<br>
>> example.c` and I got:<br>
>><br>
>> example.c:5:3: error: use of undeclared identifier 'retur'<br>
>>    retur 0;<br>
>>    ^<br>
>> 1 error generated.<br>
>><br>
>> So this has a caret identifying the source location, but there aren't any<br>
>> tildes showing the source range, as I would expect. From<br>
>> <a href="http://clang.llvm.org/diagnostics.html" target="_blank">http://clang.llvm.org/diagnostics.html</a>, I would expect most diagnostics to<br>
>> include a range.<br>
>><br>
>><br>
>><br>
>> On Tue, Apr 22, 2014 at 3:19 PM, Michael Bolin <<a href="mailto:bolinfest@gmail.com">bolinfest@gmail.com</a>><br>
>> wrote:<br>
>>><br>
>>> I am now calling clang_getDiagnosticNumRanges() from C and still get zero<br>
>>> for the number of ranges. Here is my C code (main.c) that creates a<br>
>>> CXTranslationUnit for a malformed file and dumps its diagnostics:<br>
>>><br>
>>> <a href="https://gist.github.com/bolinfest/11196200" target="_blank">https://gist.github.com/bolinfest/11196200</a><br>
>>><br>
>>> Here is the malformed file, example.c, that I am using for testing:<br>
>>><br>
>>> <a href="https://gist.github.com/bolinfest/11196225" target="_blank">https://gist.github.com/bolinfest/11196225</a><br>
>>><br>
>>> And here is the output when I run `./main.o example.c`:<br>
>>><br>
>>> <a href="https://gist.github.com/bolinfest/11196241" target="_blank">https://gist.github.com/bolinfest/11196241</a><br>
>>><br>
>>> As you can see, I can get pretty much everything for the diagnostic<br>
>>> (source location, category id, category name), but no source location. I<br>
>>> would expect to get a source range associated that identifies the misspelled<br>
>>> keyword. Any ideas? Are my expectations just wrong?<br>
>>><br>
>>> Thank you,<br>
>>> Michael<br>
>>><br>
>>><br>
>>><br>
>>> On Fri, Apr 18, 2014 at 1:06 PM, Michael Bolin <<a href="mailto:bolinfest@gmail.com">bolinfest@gmail.com</a>><br>
>>> wrote:<br>
>>>><br>
>>>> I am using the Python wrapper for libclang (cindex.py), and none of my<br>
>>>> diagnostics have any SourceRanges associated with them. When I create the<br>
>>>> translation unit, I even make sure that -fprint-source-range-info and<br>
>>>> -fdiagnostics-print-source-range-info are passed as arguments (though I<br>
>>>> don't know if that is strictly necessary).<br>
>>>><br>
>>>> AFAICT, I believe that the Python calling and configuration code is<br>
>>>> correct:<br>
>>>><br>
>>>>   conf.lib.clang_getDiagnosticNumRanges(self.diag)<br>
>>>><br>
>>>>   ("clang_getDiagnosticNumRanges",<br>
>>>>    [Diagnostic],<br>
>>>>    c_uint),<br>
>>>><br>
>>>> Are there any suggestions on how to debug this besides writing against<br>
>>>> libclang directly in C to make sure everything is working there?<br>
>>>><br>
>>>> Thank you,<br>
>>>> Michael<br>
>>>><br>
>>><br>
>><br>
><br>
><br>
</div></div>> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
><br>
</blockquote></div><br></div>