@@ -90,7 +90,7 @@ struct module_ext : public environment_extension {
9090 * of module different from that of a source file, so we use file names to index
9191 * the docstring map. */
9292 // TODO(Vtec234): lean::rb_map misbehaves here for some reason
93- std::map <std::string, std::string> m_module_docs;
93+ std::unordered_map <std::string, std::vector<std::pair<pos_info, std:: string>> > m_module_docs;
9494 // Map from declaration name to olean file where it was defined
9595 name_map<std::string> m_decl2olean;
9696 name_map<pos_info> m_decl2pos_info;
@@ -425,23 +425,25 @@ struct mod_doc_modification : public modification {
425425 LEAN_MODIFICATION (" mod_doc" )
426426
427427 std::string m_doc;
428+ pos_info m_pos;
428429
429430 mod_doc_modification () {}
430- /* * A docstring for a declaration in the module. */
431- mod_doc_modification (std::string const & doc) : m_doc(doc) {}
431+ /* * A module-level docstring . */
432+ mod_doc_modification (std::string const & doc, pos_info pos ) : m_doc(doc), m_pos(pos ) {}
432433
433434 void perform (environment & env) const override {
434435 // No-op. See `import_module` for actual action
435436 }
436437
437438 void serialize (serializer & s) const override {
438- s << m_doc;
439+ s << m_doc << m_pos ;
439440 }
440441
441442 static std::shared_ptr<modification const > deserialize (deserializer & d) {
442443 std::string doc;
443- d >> doc;
444- return std::make_shared<mod_doc_modification>(doc);
444+ pos_info pos;
445+ d >> doc >> pos;
446+ return std::make_shared<mod_doc_modification>(doc, pos);
445447 }
446448};
447449
@@ -535,11 +537,11 @@ environment add(environment const & env, certified_declaration const & d) {
535537 return add_decl_pos_info (new_env, _d.get_name ());
536538}
537539
538- environment add_doc_string (environment const & env, std::string const & doc) {
539- return add (env, std::make_shared<mod_doc_modification>(doc));
540+ environment add_doc_string (environment const & env, std::string const & doc, pos_info pos ) {
541+ return add (env, std::make_shared<mod_doc_modification>(doc, pos ));
540542}
541543
542- std::map <std::string, std::string> const & get_doc_strings (environment const & env) {
544+ std::unordered_map <std::string, std::vector<std::pair<pos_info, std:: string>> > const & get_doc_strings (environment const & env) {
543545 return get_extension (env).m_module_docs ;
544546}
545547
@@ -732,11 +734,7 @@ void import_module(modification_list const & modifications, std::string const &
732734 env = add_decl_olean (env, im->m_decl .get_decl ().m_name , file_name);
733735 } else if (auto mdm = dynamic_cast <mod_doc_modification const *>(m.get ())) {
734736 auto ext = get_extension (env);
735- if (ext.m_module_docs .count (file_name) != 0 ) {
736- ext.m_module_docs [file_name] += " \n " + mdm->m_doc ;
737- } else {
738- ext.m_module_docs [file_name] = mdm->m_doc ;
739- }
737+ ext.m_module_docs [file_name].emplace_back (mdm->m_pos , mdm->m_doc );
740738 env = update (env, ext);
741739 }
742740 }
0 commit comments