README: document nit_env.sh
[nit.git] / src / doc / vim_autocomplete.nit
index 7799da5..ad5e891 100644 (file)
@@ -31,7 +31,7 @@ module vim_autocomplete
 import modelbuilder
 import phase
 import modelize::modelize_class
-import model_utils
+import model::model_collect
 
 redef class ToolContext
        # Phase generating the files for the Vim plugin
@@ -78,6 +78,7 @@ redef class MEntity
                        for i in 2.times do stream.write line_separator
                        stream.write mdoc.content.join(line_separator)
                end
+               write_extra_doc(mainmodule, stream)
 
                stream.write "\n"
        end
@@ -89,6 +90,9 @@ redef class MEntity
 
        # Doc to use in completion
        private fun complete_mdoc: nullable MDoc do return mdoc
+
+       # Extra auto documentation to append to the `stream`
+       private fun write_extra_doc(mainmodule: MModule, stream: Writer) do end
 end
 
 redef class MMethodDef
@@ -148,6 +152,63 @@ redef class MClassDef
        end
 end
 
+redef class MClassType
+       redef fun write_extra_doc(mainmodule, stream)
+       do
+               # Super classes
+               stream.write line_separator*2
+               stream.write "## Class hierarchy"
+
+               var direct_supers = [for s in mclass.in_hierarchy(mainmodule).direct_greaters do s.name]
+               if not direct_supers.is_empty then
+                       alpha_comparator.sort direct_supers
+                       stream.write line_separator
+                       stream.write "* Direct super classes: "
+                       stream.write direct_supers.join(", ")
+               end
+
+               var supers = [for s in mclass.in_hierarchy(mainmodule).greaters do s.name]
+               supers.remove mclass.name
+               if not supers.is_empty then
+                       alpha_comparator.sort supers
+                       stream.write line_separator
+                       stream.write "* All super classes: "
+                       stream.write supers.join(", ")
+               end
+
+               var direct_subs = [for s in mclass.in_hierarchy(mainmodule).direct_smallers do s.name]
+               if not direct_subs.is_empty then
+                       alpha_comparator.sort direct_subs
+                       stream.write line_separator
+                       stream.write "* Direct sub classes: "
+                       stream.write direct_subs.join(", ")
+               end
+
+               var subs = [for s in mclass.in_hierarchy(mainmodule).smallers do s.name]
+               subs.remove mclass.name
+               if not subs.is_empty then
+                       alpha_comparator.sort subs
+                       stream.write line_separator
+                       stream.write "* All sub classes: "
+                       stream.write subs.join(", ")
+               end
+
+               # List other properties
+               stream.write line_separator*2
+               stream.write "## Properties"
+               stream.write line_separator
+               var props = mclass.collect_accessible_mproperties(protected_visibility).to_a
+               alpha_comparator.sort props
+               for prop in props do
+                       if mclass.name == "Object" or prop.intro.mclassdef.mclass.name != "Object" then
+                               prop.write_synopsis(mainmodule, stream)
+                       end
+               end
+       end
+
+       redef fun complete_mdoc do return mclass.intro.mdoc
+end
+
 private class AutocompletePhase
        super Phase
 
@@ -181,7 +242,7 @@ private class AutocompletePhase
                        # Can it be instantiated?
                        if mclass.kind != interface_kind and mclass.kind != abstract_kind then
 
-                               for prop in mclass.all_mproperties(mainmodule, public_visibility) do
+                               for prop in mclass.collect_accessible_mproperties(public_visibility) do
                                        if prop isa MMethod and prop.is_init then
                                                mclass_intro.target_constructor = prop.intro
                                                mclass_intro.write_doc(mainmodule, constructors_stream)
@@ -220,8 +281,77 @@ private class AutocompletePhase
                        stream.close
                        var error = stream.last_error
                        if error != null then
-                               toolcontext.error(null, "Failed to write Vim autocomplete file: {error}")
+                               toolcontext.error(null, "Error: failed to write Vim autocomplete file: {error}.")
                        end
                end
        end
 end
+
+redef class MModule
+       redef fun write_extra_doc(mainmodule, stream)
+       do
+               # Introduced classes
+               var class_intros = collect_intro_mclasses(protected_visibility).to_a
+               if class_intros.not_empty then
+                       alpha_comparator.sort class_intros
+                       stream.write line_separator*2
+                       stream.write "## Introduced classes"
+
+                       for c in class_intros do
+                               stream.write line_separator
+                               stream.write "* {c.name}"
+                               var doc = c.intro.mdoc
+                               if doc != null then stream.write ": {doc.content.first}"
+                       end
+               end
+
+               # Introduced properties
+               var prop_intros = new Array[MPropDef]
+               for c in mclassdefs do
+                       prop_intros.add_all c.collect_intro_mpropdefs(protected_visibility)
+               end
+
+               if prop_intros.not_empty then
+                       alpha_comparator.sort prop_intros
+                       stream.write line_separator*2
+                       stream.write "## Introduced properties"
+                       stream.write line_separator
+
+                       for p in prop_intros do
+                               p.mproperty.write_synopsis(mainmodule, stream)
+                       end
+               end
+       end
+end
+
+redef class MProperty
+       private fun write_synopsis(mainmodule: MModule, stream: Writer)
+       do
+               if visibility == public_visibility then
+                       stream.write "+ "
+               else stream.write "~ " # protected_visibility
+
+               if self isa MMethod then
+                       if is_new and name != "new" then
+                               stream.write "new "
+                       else if is_init and name != "init" then
+                               stream.write "init "
+                       end
+               end
+
+               stream.write name
+
+               if self isa MMethod then
+                       var intro = intro
+                       assert intro isa MMethodDef
+                       stream.write intro.msignature.to_s
+               end
+
+               var mdoc = intro.mdoc
+               if mdoc != null then
+                       stream.write "  # "
+                       stream.write mdoc.content.first
+               end
+               stream.write line_separator
+       end
+end