@@ -156,32 +156,25 @@ void MessageHandler::textDocument_documentSymbol(JsonReader &reader,
156156    syms.reserve (file->symbol2refcnt .size ());
157157
158158    /* *
159-      * std::heap is a max heap (we swap lhs/rhs to make a min heap) 
160-      * 
161159     * with 2 ranges that start at the same Position, we want the wider one 
162-      * first 
163-      * 
160+      * first (swap lhs/rhs) 
164161     */  
165162    auto  sym_cmp = [](ExtentRef const  &lhs, ExtentRef const  &rhs) {
166-       return  rhs .extent .start  < lhs .extent .start  ||
167-              (rhs .extent .start  == lhs .extent .start  &&
168-               lhs .extent .end  < rhs .extent .end );
163+       return  lhs .extent .start  < rhs .extent .start  ||
164+              (lhs .extent .start  == rhs .extent .start  &&
165+               rhs .extent .end  < lhs .extent .end );
169166    };
170167
171168    for  (auto  [sym, refcnt] : file->symbol2refcnt ) {
172169      if  (refcnt <= 0  || !sym.extent .valid ())
173170        continue ;
174171      syms.push_back (sym);
175-       std::push_heap (std::begin (syms), std::end (syms), sym_cmp);
176172    }
173+     std::sort (std::begin (syms), std::end (syms), sym_cmp);
177174
178175    std::vector<DocumentSymbol> result;
179176    std::stack<DocumentSymbol *> indent;
180-     while  (!syms.empty ()) {
181-       std::pop_heap (std::begin (syms), std::end (syms), sym_cmp);
182-       auto  sym = syms.back ();
183-       syms.pop_back ();
184- 
177+     for  (auto  sym : syms) {
185178      DocumentSymbol ds;
186179      if  (auto  range = getLsRange (wf, sym.range )) {
187180        ds.selectionRange  = *range;
@@ -194,7 +187,7 @@ void MessageHandler::textDocument_documentSymbol(JsonReader &reader,
194187              range1 && range1->includes (*range))
195188            ds.range  = *range1;
196189      }
197-       withEntity (db, sym, [&, sym = sym ](const  auto  &entity) {
190+       withEntity (db, sym, [&](const  auto  &entity) {
198191        auto  const  *def = entity.anyDef ();
199192        if  (!def)
200193          return ;
0 commit comments