2

I'm working on a C-Code based application, my IDE is Visual Studio Code (1.77.3) and I'm using frequently the outline view from Visual Studio Code, which currently looks like this:

VS Code: Outline layout

As you might see, there are a bunch of functions and declarations as part of the file network.c but when navigating through my code I'm not interested in the declarations. I just want to list all my function definitions and switch between them. Besides, some declarations just doesn't make any sense, e.g. "tNetworkParameters declaration" as seen in outline view above. Clicking to this leads me to the following section of code:

struct tNetworkParameters* create_netparams (int n_cluster)
{
    struct tNetworkParameters *net_params = malloc(sizeof(struct tNetworkParameters));

    net_params->n_cluster = n_cluster;
    net_params->domains   = calloc(n_cluster, (sizeof(char*) + PARAM_DOMAINSIZE*sizeof(char)));
    net_params->ports     = calloc(n_cluster, (sizeof(char*) + PARAM_PORTSIZE*sizeof(char)));

    return net_params;
}

It seems like VS Code is interpreting the return value of create_netparams(...) as a declaration. The definition of struct tNetworkParameters is placed in another header file called network-definition.h which is #include'd in the current file scope of network.c.

Does anyone know how to hide declarations in general via a workspace setting file? Though I think that interpreting the return value as declarations seems like a bug to me.

I know there are outline settings like "outline.showConstants": false, but I haven't found any outline setting corresponding to declarations. Let's say there would be a so called outline.declarations, then I would set them for all .c files used in my project, e.g.:

"[c]": {
    outline.declarations = False
}

Unfortunately I couldn't find something like this...

Kerby
  • 21
  • 3
  • 1
    please move the image to use Stack Overflow's imgur subdomain instead of imgur.com (just use the image upload function in the editor UI). Please list explicitly which ones in the screenshot are declarations. Just to be clear, you are saying "declarations" in the sense of the word that means "declared but not defined", right? – starball Apr 16 '23 at 20:52
  • 1
    Loosely related: https://github.com/microsoft/vscode-cpptools/issues/3117 – starball Apr 16 '23 at 21:04
  • @user thanks for helping me! Surprisingly I was now able to upload the image. Before it was not allowed. All the entries which have the tag "declaration" on the right are declarations for the functions of this specific .c file. And yes, "declarations" here means declared but not defined. The definitions of the functions are listed in the outline view without the "declaration" tag on the right. – Kerby Apr 17 '23 at 16:40
  • what is this "declaration tag" you are referring to? Are you referring to the icons to the left of the outline entry names? See https://code.visualstudio.com/api/references/icons-in-labels those are the icons for functions and structs. There's no distinction in those icons between what is a function/struct declaration and what is a function/struct definition. – starball Apr 17 '23 at 16:53

0 Answers0