Re: [Vala] Getting all the symbols from my code



Yes is a great idea, let me know if I can help
El may. 8, 2016 7:01 AM, "Dmitry Golovin" <dima golovin in> escribió:

07.05.2016, 15:35, "Al Thomas" <astavale yahoo co uk>:
 From: Dmitry Golovin <dima golovin in>
 Sent: Saturday, 7 May 2016, 9:01
 Subject: [Vala] Getting all the symbols from my code

 I want to have a list of all the symbols from my code.

 First I create a CodeContext, then I add all the external packages and
source
 files, then visit each file with a Parser.

 I expect to get all the CodeNodes from my code, but I only get the
top-level

 ones. Is it possible to get all the children of each CodeNode?

You probably want to be looking at a CodeVisitor. So this file

I think writes out Vala symbols for a VAPI:
https://git.gnome.org/browse/vala/tree/vala/valacodewriter.vala

I understand other tools have done similar to what you are attempting:
https://git.gnome.org/browse/anjuta/tree/plugins/language-support-vala
https://git.gnome.org/browse/gnome-builder/tree/plugins/vala-pack

Given a lot of IDE tools are re-implementing this there is probably
a case for a libvalaidetools that talks to libvala and provides a stable
API. That would be a signifiant project. I would suggest the Vala build
system also be switched to non-recursive make first so it is easier to
add any new code.

Al

Thanks for the code reference, Al! I will check it out.

For now I created some kind of Type detection, but I'm not sure if it is
done right. Here is my code (please excuse formatting, I think it is more
readable this way if you use monotype font):

    foreach (var src in context.get_source_files()) {
        print("\n" + src.get_relative_filename() + ":\n");
        foreach (var node in src.get_nodes()) {
            print(node.to_string() + " -- ");
            if (node is Expression) {
 print("Expression");
            } else if (node is Symbol) {                    print("Symbol
");
                if (node is Constant) {
 print("Constant");
                } else if (node is Namespace) {
 print("Namespace");
                } else if (node is Subroutine) {
print("Subroutine ");
                    if (node is Constructor) {
print("Constructor");
                    } else if (node is Destructor) {
print("Destructor");
                    } else if (node is Method) {
print("Method");
                    } else if (node is PropertyAccessor) {
print("PropertyAccessor");
                    } else {
print("-"); }
                } else if (node is TypeSymbol) {
print("TypeSymbol ");
                    if (node is Delegate) {
 print("Delegate");
                    } else if (node is Enum) {
print("Enum");
                    } else if (node is ErrorCode) {
 print("ErrorCode");
                    } else if (node is ErrorDomain) {
 print("ErrorDomain");
                    } else if (node is ObjectTypeSymbol) {
print("ObjectTypeSymbol ");
                        if (node is Class) {
print("Class");
                        } else if (node is Interface) {
 print("Interface");
                        } else {
print("-"); }
                    } else if (node is Struct) {
print("Struct");
                    } else {
print("-"); }
                } else if (node is Variable) {
print("Variable ");
                    if (node is Field) {
print("Field");
                    } else if (node is LocalVariable) {
 print("LocalVariable");
                    } else if (node is Vala.Parameter) {
print("Parameter");
                    } else {
print("-"); }
                } else {
print("-"); }
            } else {                                        print("-"); }
            print("\n");
        }
    }

The idea of having somehow standardized libvalaidetools is great. This can
be simple API library providing completion, code navigation, dependency
management, some standard vala-project file format, etc. So that anyone
could turn his favorite text editor into full-featured Vala IDE using this
library.

Regards,
Dmitry
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]