idanarye / vim-dutyl

Coordinate D tools to work together for you

Home Page:http://www.vim.org/scripts/script.php?script_id=5003

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support comma completion in functions

HK47196 opened this issue · comments

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...

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.

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...