Merge: Nitsmell : Adding new code smells and print console updated
[nit.git] / src / doc / vim_autocomplete.nit
index bcd512f..0846e85 100644 (file)
@@ -45,6 +45,17 @@ redef class ToolContext
        do
                super
                option_context.add_option opt_vim_autocomplete
+               opt_vim_autocomplete.hidden = true
+       end
+end
+
+redef class Model
+
+       # Get a custom view for vimautocomplete.
+       private fun vim_view: ModelView do
+               var view = new ModelView(self)
+               view.min_visibility = protected_visibility
+               return view
        end
 end
 
@@ -78,6 +89,9 @@ redef class MEntity
                        for i in 2.times do stream.write line_separator
                        stream.write mdoc.content.join(line_separator)
                end
+
+               write_location(mainmodule, stream)
+
                write_extra_doc(mainmodule, stream)
 
                stream.write "\n"
@@ -93,6 +107,15 @@ redef class MEntity
 
        # Extra auto documentation to append to the `stream`
        private fun write_extra_doc(mainmodule: MModule, stream: Writer) do end
+
+       # Location (file and line when available) of related declarations
+       private fun write_location(mainmodule: MModule, stream: Writer)
+       do
+               for i in 2.times do stream.write line_separator
+               stream.write "## Location"
+               stream.write line_separator
+               stream.write "* {location}"
+       end
 end
 
 redef class MMethodDef
@@ -103,6 +126,26 @@ redef class MMethodDef
                        stream.write msignature.to_s
                end
        end
+
+       redef fun write_location(mainmodule, stream)
+       do
+               for i in 2.times do stream.write line_separator
+               stream.write "## Location of introduction and refinements"
+
+               # Group locations in the same file
+               var file_to_location = new MultiHashMap[nullable SourceFile, Location]
+               for c in mproperty.mpropdefs do
+                       file_to_location[c.location.file].add c.location
+               end
+
+               # Write one file per location
+               for file, locations in file_to_location do
+                       var l = locations.first
+                       stream.write line_separator
+                       stream.write "* {l}"
+                       if locations.length > 1 then stream.write " ({locations.length-1} more)"
+               end
+       end
 end
 
 redef class MAttributeDef
@@ -197,7 +240,7 @@ redef class MClassType
                stream.write line_separator*2
                stream.write "## Properties"
                stream.write line_separator
-               var props = mclass.collect_accessible_mproperties(protected_visibility).to_a
+               var props = mclass.collect_accessible_mproperties(model.protected_view).to_a
                alpha_comparator.sort props
                for prop in props do
                        if mclass.name == "Object" or prop.intro.mclassdef.mclass.name != "Object" then
@@ -207,6 +250,16 @@ redef class MClassType
        end
 
        redef fun complete_mdoc do return mclass.intro.mdoc
+
+       redef fun write_location(mainmodule, stream)
+       do
+               for i in 2.times do stream.write line_separator
+               stream.write "## Location of introduction and refinements"
+               for c in mclass.mclassdefs do
+                       stream.write line_separator
+                       stream.write "* {c.location}"
+               end
+       end
 end
 
 private class AutocompletePhase
@@ -242,7 +295,7 @@ private class AutocompletePhase
                        # Can it be instantiated?
                        if mclass.kind != interface_kind and mclass.kind != abstract_kind then
 
-                               for prop in mclass.collect_accessible_mproperties(public_visibility) do
+                               for prop in mclass.collect_accessible_mproperties(model.public_view) do
                                        if prop isa MMethod and prop.is_init then
                                                mclass_intro.target_constructor = prop.intro
                                                mclass_intro.write_doc(mainmodule, constructors_stream)
@@ -287,6 +340,43 @@ private class AutocompletePhase
        end
 end
 
+redef class MModule
+       redef fun write_extra_doc(mainmodule, stream)
+       do
+               # Introduced classes
+               var class_intros = collect_intro_mclasses(model.protected_view).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(model.protected_view)
+               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
@@ -307,7 +397,10 @@ redef class MProperty
                if self isa MMethod then
                        var intro = intro
                        assert intro isa MMethodDef
-                       stream.write intro.msignature.to_s
+                       var msignature = intro.msignature
+                       if msignature != null then
+                               stream.write msignature.to_s
+                       end
                end
 
                var mdoc = intro.mdoc