microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.52k stars 1.55k forks source link

Function prototypes with trailing macros do not display doc comments #8176

Open nmggithub opened 3 years ago

nmggithub commented 3 years ago

Bug type: Language Service

Describe the bug

Steps to reproduce (note: the examples below reference Linux header files)

  1. Open a C/C++ file
  2. Include unistd.h
  3. Try to use the fork function in the code
  4. Mouseover the function and observe there is no text describing the function
  5. Right-click the function and go to the definition
  6. See the comment is there
  7. Change __THROWNL to __THROW
  8. Go back to the code file and observe the comment now appears on mouseover

Expected behavior The comment appears on mouseover even when __THROWNL is present.

Additional context I am well aware this is likely an issue directly with my version of glibc, but I thought I'd bring the issue up here.

Colengms commented 3 years ago

Hi @nmggithub . Thanks for reporting this. I'm able to reproduce the issue with just:

#define MACRO

/* documention */
int foo() MACRO;

int main()
{
    foo();
    return 0;
}

I was not able to reproduce the issue in VS, so the issue would appear to be specific to the C/C++ Extension's implementation of doc comment parsing.

nmggithub commented 3 years ago

Hi @nmggithub . Thanks for reporting this. I'm able to reproduce the issue with just:

#define MACRO

/* documention */
int foo() MACRO;

int main()
{
  foo();
  return 0;
}

I was not able to reproduce the issue in VS, so the issue would appear to be specific to the C/C++ Extension's implementation of doc comment parsing.

This is interesting to me here because it appears (from my own testing) that the trailing macro __THROW actually does not cause VSCode to exhibit this behavior. I see what you mean though about trailing macros generally causing this behavior, but __THROW appears to be an exception. Modifying your code like so causes the correct behavior (the display of the comment text in the hover card):

#define __THROW

/* documention */
int foo() __THROW;

int main()
{
    foo();
    return 0;
}

I'm not sure what makes this the exception, but I wanted to make sure it was pointed out. It should also be noted that this is using our own __THROW macro, not the one offered by glibc. So it appears simply the name is the pertinent part.

Upon additional testing _THROW with a single underscore causes the correct behavior as well, but THROW with no underscores does not (and neither does ___THROW with three underscores). I'm not sure how relevant any of that is, but I thought I'd mention it.