Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang diagnostics location_extent zeros when source has a certain type of error #859

Closed
joelhock opened this issue Oct 20, 2017 · 1 comment · Fixed by #860
Closed

clang diagnostics location_extent zeros when source has a certain type of error #859

joelhock opened this issue Oct 20, 2017 · 1 comment · Fixed by #860

Comments

@joelhock
Copy link

ycmd commit is a12a0a3 on mac, but also happens with older 2e62515

This might be a libclang bug, but with a source file with errors such as this, the location_extent values for all diagnostics are zeros.

class A {
    A() // my 'missing semicolon' location_extent is wrong
};

i_ruin_everything // i'm the stinker line that causes all the location_extent problems

A::A() {
}

another_error // my location_extent is wrong, too

diagnostics look like:

[
    {
        "kind": "ERROR",
        "text": "expected ';' at end of declaration list",
        "ranges": [],
        "location": {
            "filepath": "source.cc",
            "column_num": 8,
            "line_num": 2
        },
        "location_extent": {
            "start": {
                "filepath": "",
                "column_num": 0,
                "line_num": 0
            },
            "end": {
                "filepath": "",
                "column_num": 0,
                "line_num": 0
            }
        },
        "fixit_available": true
    },
    {
        "kind": "ERROR",
        "text": "unknown type name 'i_ruin_everything'",
        "ranges": [],
        "location": {
            "filepath": "source.cc",
            "column_num": 1,
            "line_num": 5
        },
        "location_extent": {
            "start": {
                "filepath": "",
                "column_num": 0,
                "line_num": 0
            },
            "end": {
                "filepath": "",
                "column_num": 0,
                "line_num": 0
            }
        },
        "fixit_available": false
    },
    {
        "kind": "ERROR",
        "text": "constructor cannot have a return type",
        "ranges": [
            {
                "start": {
                    "filepath": "",
                    "column_num": 0,
                    "line_num": 0
                },
                "end": {
                    "filepath": "",
                    "column_num": 0,
                    "line_num": 0
                }
            },
            {
                "start": {
                    "filepath": "source.cc",
                    "column_num": 4,
                    "line_num": 7
                },
                "end": {
                    "filepath": "source.cc",
                    "column_num": 5,
                    "line_num": 7
                }
            }
        ],
        "location": {
            "filepath": "source.cc",
            "column_num": 4,
            "line_num": 7
        },
        "location_extent": {
            "start": {
                "filepath": "",
                "column_num": 0,
                "line_num": 0
            },
            "end": {
                "filepath": "",
                "column_num": 0,
                "line_num": 0
            }
        },
        "fixit_available": false
    },
    {
        "kind": "ERROR",
        "text": "unknown type name 'another_error'",
        "ranges": [],
        "location": {
            "filepath": "source.cc",
            "column_num": 1,
            "line_num": 10
        },
        "location_extent": {
            "start": {
                "filepath": "",
                "column_num": 0,
                "line_num": 0
            },
            "end": {
                "filepath": "",
                "column_num": 0,
                "line_num": 0
            }
        },
        "fixit_available": false
    },
    {
        "kind": "ERROR",
        "text": "expected unqualified-id",
        "ranges": [],
        "location": {
            "filepath": "source.cc",
            "column_num": 50,
            "line_num": 10
        },
        "location_extent": {
            "start": {
                "filepath": "",
                "column_num": 0,
                "line_num": 0
            },
            "end": {
                "filepath": "",
                "column_num": 0,
                "line_num": 0
            }
        },
        "fixit_available": false
    }
]
@micbou
Copy link
Collaborator

micbou commented Oct 20, 2017

Thanks for the example. Should be fixed by PR #860.

zzbot added a commit that referenced this issue Oct 22, 2017
[READY] Fix empty location extent after missing semicolon

We currently use the following (convoluted) method to compute the location extent of a diagnostic i.e. the range of the identifier where the diagnostic occurred:
 - obtain a range from [the `clang_getCursorExtent` function](https://clang.llvm.org/doxygen/group__CINDEX__CURSOR__SOURCE.html#ga79f6544534ab73c78a8494c4c0bc2840), which is supposed to contain our identifier;
 - extract all the tokens from that range with [`clang_tokenize`](https://clang.llvm.org/doxygen/group__CINDEX__LEX.html#ga6b315a71102d4f6c95eb68894a3bda8a);
 - find the token with the same starting position as the diagnostic;
 - use the length of that token to get the ending position;
 - compute the range.

Unfortunately, this doesn't always work as shown in issue #859, In that case, `clang_getCursorExtent` returns an empty range for all diagnostics after the missing semicolon.

This PR fixes that issue by extracting the tokens from the diagnostic position to the immediate next character then using `clang_getTokenExtent` to get the range of the identifier (multiline identifiers are supported).

Fixes #859.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/860)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants