- Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Environment
- OS and Version: Windows 10
- VS Code Version: 1.102.3
- C/C++ Extension Version: 1.27.7
- If using SSH remote, specify OS of remote machine: [not using remote]
Bug Summary and Steps to Reproduce
Bug Summary:
When writing a docstring comment above a symbol (variable, function, #define), the docstring also grabs docstrings from lines above the start of the comment if:
- The comments are all line comments (ie
//
not/*
) - The non-comment line before the start of the comment contains a
]
character - The lines above the
]
-line contain more line comments
Reproduced example:
// docstring for my_variable int my_variable[1]; // comment for my_float float my_float;
This results in the on-hover docstring for my_float
containing the docstring for my_variable
as well:
Expected behaviour:
I would expect that my_float
would only contain its own docstring. This was reproduced by making my_variable
into a non-array:
Though I could see value in this docstring copying if it was consistent. As it is, it's governed by some seemingly arcane rules:
Into the weeds:
- I could not reproduce this with C-style comments (ie
/* comment */
) - This transference only happens if the non-comment line contains a
]
, but it could be anywhere.#define _ ]
works, or just]
on its own - This only works with at most one line containing
]
above it, unless[
is used elsewhere (see later) - If the
]
-line has an end-of-line comment, that gets applied as a docstring to the variable on that line but doesn't get included in the second symbol's comment:
// docstring 1 int my_variable[1]; // docstring 2 // docstring 3 float my_float;
Results in my_float
getting "docstring 1\ndocstring 3" for its docstring and my_variable getting "docstring 2".
- If there is an opening square bracket somewhere on a different line, you can get more distant comment additions.
// docstring 1 #define a [] // docstring 2 #define b #define _ ] // docstring 3 float c;
Results in the following docstrings:
- a: "docstring 1"
- b: "docstring 1\ndocstring 2"
- c: "docstring 1\ndocstring 2\ndocstring 3"
Adding a newline between a
and b
or removing the ]
from a
's line can remove docstring 1 from b
, but not c
.
I'm not sure if this is the shadows of some feature or functionality I don't use that just isn't properly detecting when the []
characters are outside comments or something. I first noticed this behaviour almost a year ago but thought the pass-through was specific to #define
s and so didn't dig further. I investigated today because I saw a place where docstring multiple-assignment could be useful, only to discover how cursed the behaviour really was.
Configuration and Logs
I renamed c_cpp_properties.json entirely and restarted; I could still reproduce this issue.
Other Extensions
No response
Additional context
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status