14

If I'm looking at Gjs code and see this line near the beginning:

const Gio = imports.gi.Gio;

How can I know what methods, constants, events, etc. are on 'Gio' (without doing a Google search)? Is there a file somewhere on my installation that contains that information?

Obviously I'm asking for any 'imports' statement, not Gio specifically.

Marcel Lamothe
  • 12,452
  • 9
  • 34
  • 44

2 Answers2

15

Some of imports statements import other javascript files:

  • imports.ui.* -> /usr/share/cinnamon/js/ui/*
  • imports.misc.* -> /usr/share/cinnamon/js/misc/*
  • imports.[cairo, dbus, format, gettext, jsUnit, lang, promise, signals] -> /usr/share/gjs-1.0/

For the imports.gi imports, Gnome Introspection is used to allow gjs to use C library.
So to get informations about those libraries I suggest you to look at the Gnome reference manuals:

But to conclude, there is a huge lack of documentation and examples. That makes difficult to develop with gjs.

UPDATE
Here other useful links:

Nicolas
  • 6,289
  • 4
  • 36
  • 51
  • 1
    Thank you! And yes, I'm finding it incredibly difficult to develop with gjs. As for the links you provided, I found those but it's not always obvious what the "C" function names (and parameters) are vs what they are in gjs - which is why I'm now using the instructions in the blog I posted to get the actual gjs documentation. – Marcel Lamothe Sep 23 '13 at 15:44
  • You're right, the most difficult is to find the conversion from the C statement to the gjs one. – Nicolas Sep 23 '13 at 23:21
  • 1
    For things under imports.gi, there is nowadays https://people.gnome.org/~gcampagna/docs/ that is quite ok for figuring out what is what. For general rules on how to map C documentation to equivalent Gjs there's https://wiki.gnome.org/Projects/Gjs/Mapping (useful for GObject Intrespection libraries not included in the gcampana docs). – Daniel Landau Dec 13 '15 at 12:53
  • You can also add entries to the search path: `imports.searchPath.push("/.../mymodule")` Files (and folders) under /.../mymodule will be importable by `imports.name_of_file` – olejorgenb Sep 14 '17 at 15:22
  • Would you please give us the new link for this dead link : St => https://developer.gnome.org/st/stable/ – sangorys Oct 30 '22 at 21:37
4

Since I got no answers I kept searching online and found this excellent blog post on how to generate HTML-formatted documentation from typelib files (such as Gio-2.0.typelib):

http://mathematicalcoffee.blogspot.com/2012/09/developing-gnome-shell-extensions_6.html

Marcel Lamothe
  • 12,452
  • 9
  • 34
  • 44
  • 2
    Not exactly an answer to this question, but linking to it anyway for the sheer quantity of hard-to-find information: GNOME shell: Javascript Source Documentation (extensions development) http://mathematicalcoffee.blogspot.com/2012/09/gnome-shell-javascript-source.html#fileUtils – Marcel Lamothe Sep 23 '13 at 19:02