Skip to content

Completion member field listing order w.r.t. C++20 designated initializers #965

@Falkgaard

Description

@Falkgaard

Hi, with the addition of designated initializers with C++20 (https://en.cppreference.com/w/cpp/language/aggregate_initialization) and the limitation that designators for data members need to appear in the same order as they are defined in the struct, it would definitely be nice to have struct fields be listed in the order of definition so that users don't have to jump to the struct's definition (which can be a pain if it's a 15~80K LoC Vulkan-Hpp file, for instance) to check the order every time that they want to use aggregate initialization with designators. Is this possible?


Context and Test:

I'm using NeoVim with coc.nvim and coc-clangd, and the "suggest.defaultSortMethod": "none" set in my config (just in case it would default to alphabetical ordering or something), however, when I try to complete a . inside an aggregate initialization brace like this:

struct test {
	int  i;
	bool b;
	char c;
};

int main() {
	test t {
		. // <-- completion here
	};
}

it results in the following completion pop-up listing them in alphabetical order:

b : bool field [LS]
c : char field [LS]
i : int  field [LS] 
b~       field [LS]
c~       field [LS]
i~       field [LS]

instead of the more useful (for C++ designated initialization purposes, at least):

i : int  field [LS] 
b : bool field [LS]
c : char field [LS]
i~       field [LS]
b~       field [LS]
c~       field [LS]

If this is already possible, any additional info would be very welcome. And please let me know if this isn't a clangd-specific issue but rather specific to something like coc-clangd and I'll bring it up over there instead.

Keep up the great work!


edit:

Maybe this is covered by #306?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions