Help on DUChain/Code Completion stuff (again)

Milian Wolff mail at milianw.de
Sat Jul 31 15:52:19 UTC 2010


On Saturday 31 July 2010 17:33:35 Victor Vicente de Carvalho wrote:
> Hi
folks,
> 
> since I've almost finished the debug part for my erlang plugin,
I'm
> starting to dig into code completion stuff. So some questions
arrived:
> 
> 1 - I need the DUChain to get Code Completion working? I mean
that because
> I'm not interested on type inference and this kind of stuff
since Erlang is
> dynamically typed, but code completion is good for the
fellas. I'm looking
> for displaying litte information on CC, just the
module and functions with
> a possible documentation from them.
> Ex: the
user writes "lists:" and press ctrl+space
> 
> the code completion shows up
with functions that were matched from the
> module "lists"

You need to have
the information about what "lists:" means and what is contained there. PHP
is also dynamic but we use the DUChain to give as much information from
static analysis as possible and it rocks. E.g.:

MyClass::

1) find
declaration of MyClass
2) find publically accessible static members and
functions in that class
3) world domination

Imo having a DUChain is good
for code completion, as it gives you the required informations about what
elements are available.

I don't know erlang, so maybe I'm wrong here...

>
2 - I've managed to fetch the functions from a module on my
>
DeclarationBuilder, but not the arguments from them. I've seen that the
>
function declaration class only have a addDefaultParameter. How I can add
>
common parameters for it?

I remember that Adymo had similar problems in
Ruby, but take a look at this commit from him, does it help?

~~~

Author:
dymo <dymo at 283d02a7-25f6-0310-bc7c-ecb5cbfe19da>
Date:   Thu Feb 25 00:58:01
2010 +0000

    Parse ruby function arguments, build AST nodes for them,
declarations and types.
    This also introduces type builder to the ruby
support. Currently it constructs
    types for classes, functions and
function arguments.
    
    Note, that quickopen still doesn't show the
arguments (but it already knows that
    functions have types and doesn't
print "..." instead of args anymore).
    
    
    git-svn-id:
svn+ssh://svn.kde.org/home/kde/trunk/playground/devtools/kdevelop4-extra-plu
gins/ruby at 1095782 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

~~~

If I understand
it correctly, it's still not fixed for him apparently. Anyhow, to my
knowledge a function in the DUChain has it's arguments in the argument
context. Maybe take a look at PHP's DeclarationBuilder and ContextBuilder,
most notably visitFunctionDeclarationStatement and visitParameter.

> 3 -
Erlang, as a functional languange, supports "matching parameters" like:
> 
>
func ( Param1 = { [ H | T ] , atom, Variable } , Param2 ) ->
>    ok.
> 
>
this means that on my Ast I may have an entire expression inside a
>
parameter, and may have items that are not variables (like atom). Saying
>
again, I'm not interested in digging into that as I won't bet able to do
>
much with that, so how can I display what is inside the function parameter
>
list  in a "raw string" way?

You could add your own type and write
arbitrary strings in it.

> 4 - I'm willing to parse Erlang default
libraries, so I'll have to fetch
> the ones present on erlang instalation
dir. I need to create a context for
> them too?

If you want to access their
data somehow afterwards, i.e. to find the declarations in them then yes - of
course you need to create contexts for them too :)

You should be able to
"simply" add parsejobs for those files from inside your LanguageSupport
plugin upon loading it. That should trigger a normal ParseJob call
eventually and you could do what you do for the other Erlang files. Or ar e
the installed erlang files somewhat different (binary? packed? ...)

> 5 -
If I have to implement DUChain for question 1, what contexts do I need?
>
I'm asking this since the simplicity of what I'm trying to do.

TopDUContext
of course, but that's more or less done automatically in
AbstractContextBuilder::build()

Then a DUContext for each function and one
for it's arguments, see above. Then if Erlang has something like "classes"
or something similar to it, a context for that. Same if something like
namespaces exists.

Bye, hope this helps.

-- 
Milian
Wolff
mail at milianw.de
http://milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20100731/bf8e3c77/attachment.sig>


More information about the KDevelop-devel mailing list