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

No completion for template type member. #359

Closed
nickenchev opened this issue Apr 30, 2020 · 5 comments
Closed

No completion for template type member. #359

nickenchev opened this issue Apr 30, 2020 · 5 comments

Comments

@nickenchev
Copy link

nickenchev commented Apr 30, 2020

Not quite sure if this is a duplicate of (#358), but I'm not getting completions when accessing 'member'.

struct A
{
	void test() { }
};

template<typename T>
struct B
{
	T member;

	void test()
	{
		member.  <-- no completions
	}
};

System information
clangd version 10.0.0
Emacs with emacs-lsp
Operating system: Arch Linux

@HighCommander4
Copy link

HighCommander4 commented Apr 30, 2020

What completion proposals are you expecting?

@nickenchev
Copy link
Author

I should probably rewrite this as I realize now my original post makes no sense, and I didn't provide enough info as to why I'm posting this to begin with. Apologies.

This is a very simplified version of what I have in my project.

nesmemory.hpp

class NESMemory
{
	static constexpr unsigned int ppuRegistersSize = 8;
	static constexpr unsigned int ppuSize = 8184;
	static constexpr unsigned int apuIORegistersSize = 24;

	const NESCart &cart;

public:
	NESMemory(const NESCart &cart) : cart(cart) {}

	MappedAddress mapAddress(const MemAddress &address) const
	{
...
	}
// bunch of stuff for memory mapping
}


mem6502.hpp

template<typename Mapping>
class Mem6502
{
	byte fetchByte() { ... }
	byte fetchAbsolute() { ... }
// and a bynch of other methods for accessing memory
}

core6502.hpp

template<typename Memory, typename Mapping, bool DecimalMode>
class Core
{
	Memory memory;
public:
	void step();
...
}

core6502.cpp

template<typename Memory, typename Mapping, bool DecimalMode>
void Core<Memory, Mapping, DecimalMode>::step()
{
...
	memory. <-- completions here
...
}
...
template class mos6502::Core<Mem6502<NESMemory>, NESMemory, false>;

nes.hpp

class NES
{
	using Memory = mos6502::Mem6502<NESMemory>;

	const NESCart &cart;
	const NESMemory mapping;
	mos6502::Core<Memory, NESMemory, false> cpu;
...
};

I wasn't really thinking this through when I originally posted this, what had me confused is that I when I opened the project in KDevelop (I don't use it regularly), I noticed that I can get completions into Mem6502 members, while typing memory. in the step() definition inside core6502.cpp. This makes no sense to me as I don't see how it could really figure that out from the declaration of Core. My guess is that its showing "prospective" candidates based on the index KDevelop has built up over the codebase, and knows that I should "maybe" be seeing those particular completions from Mem6502, I don't know. To be honest, I don't think I should have even posted this issue as it isn't an issue, and it doesn't quite make sense.

@nickenchev
Copy link
Author

It looks like KDevelop is just showing generic text completions, and hasn't "magically" figured out any "prospective" completions. Sorry to waste your time.

@HighCommander4
Copy link

Thanks for the clarification.

Providing completion proposals for members of template parameters is an interesting challenge.

There are some heuristics that could be employed, such as looking at what arguments the template is instantiated with in the translation unit (or possibly in the entire project, like you suggest) and offering their members.

However, it's also worth noting that C++20 Concepts offer a nice solution for this. With Concepts, you can express the fact that "Memory should be a type that provides a member function named step()" in the code, and clangd can use this information to provide that completion (and some work has already been done on that in #261).

@nickenchev
Copy link
Author

That's very interesting, concepts is an area I haven't looked into at all yet. There's a lot of talk about concepts but they always seem to feel like a far off thing in my head and I still haven't learned much about them. Thank you for pointing me into that direction!

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

No branches or pull requests

2 participants