" Call `git grep` on the word under the cursor
"
-" Shows declarations first, then all matches, in the preview window.
+" In the preview window, list introductions, declarations and then all matches.
fun NitGitGrep()
let word = expand("<cword>")
let out = tempname()
- execute 'silent !(git grep "\\(module\\|class\\|universal\\|interface\\|var\\|fun\\) '.word.'";'.
- \'echo; git grep '.word.') > '.out
+ execute 'silent !(git grep -n -e "\<\\(module\\|class\\|universal\\|interface\\|subset\\|var\\|fun\\)\> \<'.word.'\>" --and --not -e redef -- ''*.nit'';'.
+ \'git grep -n "redef \<\\(class\\|universal\\|interface\\|subset\\|var\\|fun\\)\> \<'.word.'\>" -- ''*.nit'';'.
+ \'echo; git grep -n -e "\<'.word.'\>" --and --not -e "\<\\(module\\|class\\|universal\\|interface\\|subset\\|var\\|fun\\)\> \<'.word.'\>" -- ''*.nit'') > '.out
" Open the preview window on a temp file
execute "silent pedit " . out
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"
# 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
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
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