vim doc: extract writing the synopsis of a property
[nit.git] / src / doc / vim_autocomplete.nit
index edbc126..bcd512f 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
@@ -197,32 +197,11 @@ redef class MClassType
                stream.write line_separator*2
                stream.write "## Properties"
                stream.write line_separator
-               var props = mclass.all_mproperties(mainmodule, protected_visibility).to_a
+               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
-
-                               if prop.visibility == public_visibility then
-                                       stream.write "+ "
-                               else stream.write "~ " # protected_visibility
-
-                               if prop isa MMethod then
-                                       if prop.is_init and prop.name != "init" then stream.write "init "
-                                       if prop.is_new and prop.name != "new" then stream.write "new "
-                               end
-
-                               stream.write prop.name
-
-                               if prop isa MMethod then
-                                       stream.write prop.intro.msignature.to_s
-                               end
-
-                               var mdoc = prop.intro.mdoc
-                               if mdoc != null then
-                                       stream.write "  # "
-                                       stream.write mdoc.content.first
-                               end
-                               stream.write line_separator
+                               prop.write_synopsis(mainmodule, stream)
                        end
                end
        end
@@ -263,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)
@@ -302,8 +281,40 @@ 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 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