Skip to content

Commit

Permalink
Optimize textDocument/definition for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdufault committed Feb 13, 2018
1 parent aae6f45 commit 2fab426
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/messages/text_document_definition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,32 @@ struct TextDocumentDefinitionHandler
const std::string& buffer = working_file->buffer_content;
std::string query = LexWordAroundPos(request->params.position, buffer);

int best_score = kMinScore;
int best_i = 0;
std::vector<int> score, dp;
int best_score = INT_MAX;
int best_i = -1;
for (int i = 0; i < (int)db->symbols.size(); ++i) {
if (db->symbols[i].kind == SymbolKind::Invalid)
continue;
std::string_view detailed_name = db->GetSymbolDetailedName(i);
if (detailed_name.size() > score.size()) {
score.resize(detailed_name.size());
dp.resize(detailed_name.size());
}
int t = FuzzyEvaluate(query, detailed_name, score, dp);
if (t > best_score) {
best_score = t;
size_t idx = detailed_name.find(query);
if (idx == std::string::npos)
continue;

int score = detailed_name.size() - query.size();
assert(score >= 0);
if (score < best_score) {
best_score = score;
best_i = i;
}
if (score == 0)
break;
}
Maybe<Use> use = GetDefinitionSpellingOfSymbol(db, db->symbols[best_i]);
if (use) {
optional<lsLocation> ls_loc = GetLsLocation(db, working_files, *use);
if (ls_loc)
out.result.push_back(*ls_loc);
if (best_i != -1) {
Maybe<Use> use = GetDefinitionSpellingOfSymbol(db, db->symbols[best_i]);
if (use) {
optional<lsLocation> ls_loc = GetLsLocation(db, working_files, *use);
if (ls_loc)
out.result.push_back(*ls_loc);
}
}
}
}
Expand Down

0 comments on commit 2fab426

Please sign in to comment.