Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support comma completion in functions #12

Open
HK47196 opened this issue Apr 4, 2015 · 3 comments
Open

Support comma completion in functions #12

HK47196 opened this issue Apr 4, 2015 · 3 comments

Comments

@HK47196
Copy link

HK47196 commented Apr 4, 2015

dlang-community/DCD#193

@idanarye
Copy link
Owner

Not sure I should add it. When completing after a comma, you wouldn't want to overwrite the already written arguments, so I need to know both which argument the user is currently entering and to which argument it corresponds in the calltips returned from DCD - both require D parsing which is quite complex and I don't want to implement in Vim...

@HK47196
Copy link
Author

HK47196 commented Apr 11, 2015

I don't think so, unless I'm misunderstanding you. DCD doesn't report each argument individually it just gives calltips for the entire function.

I hacked together something when Schott first added it, not sure if it's acceptable or not. You can check out the diff here

https://gist.github.com/rsw0x/bc17e04cd14b811da900#file-gistfile1-txt

I basically just looked backwards for a comma if a parenthesis was found, and triggered it if so.

@idanarye
Copy link
Owner

Finding what to feed to DCD is not the problem. Let's, for example, say this is our buffer:

void foo(int x) {}
void foo(int x, string s) {}
void foo(int x, char c) {}

void main() {
    foo(1,

The byte position after the , is 101, so we feed it to dcd-client --cursorPos 101 and get:

calltips
void foo(int x)
void foo(int x, char c)
void foo(int x, string s)

So far, easy enough. But what now? Dutyl offers calltip completion by offering complete calls with the same argument names as the ones in the function signature, so it can offer to complete (x), (x, c) or (x, s). But all of these replace the 1 we have already entered for x! So we need to only offer c) or s). But for that, we need to know that we are currently completing from the second argument - which requires us to parse (1,) - and to know how to cut the calltips returned from DCD, which requires us to parse the calltips.

Now, based on this example it looks very easy, since we can just count commas, but what if we have complex types in the expression, like foo(bar(x, y),? We now need to parse it and figure out that the first comma does not belong to the argument list of foo but to some inner expression...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants