aBothe / Mono-D

D Add-In for MonoDevelop
http://wiki.dlang.org/Mono-D
Other
113 stars 26 forks source link

Completion for alias this #598

Closed etcimon closed 9 years ago

etcimon commented 9 years ago

I rely a lot on the alias this overload method, especially when using reference counting. It basically works exactly like inheritance but for structs/classes and without the override when overriding a method.

At the moment I need to do this to have completion :

alias HTTPClientConnection = /*FreeListRef! disabled for IDE */HTTPClientConnectionImpl;

Here's an example of how it should work:

struct A {
    void hello();
}

struct AliasThis {
    alias this A;
}

void main() {
    AliasThis str;
    str.hello |
         //   ^ no completion
}
aBothe commented 9 years ago

Okay, a nicely reproducable test case. I even think that this should already work in some way.

etcimon commented 9 years ago

Okay, a nicely reproducable test case. I even think that this should already work in some way.

Through the years, I think I've learned how to avoid over-complicating things. Examples should be 80% of the talk

To get back to this issue, I do believe the simplest implementation should also cover the most complex use cases, I wish I knew everything you know about the Mono-D's internals, so that I could pull it off myself :-p Have you considered writing a small wiki about the architecture of Mono-D and a reference to a similar guide for MonoDevelop? The source is a nice guide in itself, but sometimes you also need a higher-level view to have a chance at getting smart enough to grasp the structure and concepts that are used in it.

aBothe commented 9 years ago

Good idea.

aBothe commented 9 years ago

Is alias this A; correct? In my test cases, I only have alias __conn this;. Are both syntaxes allowed?

etcimon commented 9 years ago

Oh you're right, I always get it the other way around. It should be alias A this

Hmm, no idea why my FreeListRef is having issues then

aBothe commented 9 years ago

So, is it working then?

etcimon commented 9 years ago

Well yes and no, it's more of a complex issue than I thought

https://github.com/etcimon/vibe.d/blob/http2/source/vibe/http/client.d#L262

Completion doesn't work here if I use FreeListRef on m_http2Context here:

https://github.com/etcimon/vibe.d/blob/http2/source/vibe/http/client.d#L1117

Defined as alias this here:

https://github.com/etcimon/vibe.d/blob/http2/source/vibe/utils/memory.d#L700

I'll try and isolate it more

etcimon commented 9 years ago

It's the pointer type:

struct A {
    void hello();
}

struct AliasThis {
    @property A* get();

    alias get this;
}

void main() {
    AliasThis str;
    str.he
        //   ^ no completion
}
aBothe commented 9 years ago

In the actual code, will get() be executed then as soon as I try to access hello?

etcimon commented 9 years ago

In the actual code, will get() be executed then as soon as I try to access hello?

yes, Exactly.

Actually, the property feature works, it's only the pointer types:

struct A {
    void hello();
}
alias TR = A*;
struct AliasThis {
    alias TR this;
}

void main() {
    AliasThis str;
    str.hel
        //   ^ no completion
}
aBothe commented 9 years ago

it's part of v2.10.3

etcimon commented 9 years ago

The test works but that doesn't solve my issue :( I found out that the alias get this has a @property const(TR) get(); overload and the mix of both, const and non-const options is enough to break the completion. Here's a test:

struct A {
    void hello();
}

struct AliasThis {
    @property const(A) get() const;
    @property A get();
    alias get this;
}

void main() {
    AliasThis str;
    str.hel
    //   ^ no completion
}
aBothe commented 9 years ago

I thought we'd left this age of const-everywhere-ness that makes the entire code unreadable.

etcimon commented 9 years ago

I thought we'd left this age of const-everywhere-ness that makes the entire code unreadable.

Hmm, I don't think it's a bad thing to have const-ness, and it does make in param work correctly. I'm not sure how I could rewrite that overload for the completion to work with freelists, is it easy to fix on the IDE?

aBothe commented 9 years ago

I could discard any second findings for now, or enum through all found get-overloads. What would you prefer?

etcimon commented 9 years ago

Discard second findings, no chances for duplicates that way I guess? Scanning a const type seems to show non-const methods as well, so nothing gets lost.

I guess you could also filter out any const resolution if non-const is found, just in case you decide to filter out const members eventually

aBothe commented 9 years ago

I just want a rather elegant code on how to handle these alias-this definitions, that's it :smile:

aBothe commented 9 years ago

v2.10.4

etcimon commented 9 years ago

awesome

aBothe commented 9 years ago

Nah, I'm not proud of how I've fixed this.. just another foreach and likely incomplete state gathering - that's bad :/

etcimon commented 9 years ago

Nah, I'm not proud of how I've fixed this.. just another foreach and likely incomplete state gathering - that's bad :/

It's not a compiler, yet I'm not even bothering to compile more than once a month anymore. I can't find anything else bothering me in the IDE. Except maybe the lack of docs, maybe I can take a few months to write them and clean up in a few months once I'm done with the whole web stack and my main project.