Skip to content

Commit

Permalink
Reduce complexity with early-out if.
Browse files Browse the repository at this point in the history
Signed-off-by: Henner Zeller <[email protected]>
  • Loading branch information
hzeller committed Nov 9, 2021
1 parent 072175f commit 07c204f
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions verilog/tools/ls/verible-lsp-adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,25 +182,26 @@ std::vector<verible::lsp::DocumentHighlight> CreateHighlightRanges(
if (!current) return result;
const verible::LineColumn cursor{p.position.line, p.position.character};
const verible::TextStructureView &text = current->parser().Data();
const verible::TokenInfo cursor_token = text.FindTokenAt(cursor);

if (cursor_token.token_enum() == SymbolIdentifier) {
// Find all the symbols with the same name in the buffer.
// Note, this is very simplistic as it does _not_ take scopes into account.
// For that, we'd need the symbol table, but that implementation is not
// complete yet.
for (const verible::TokenInfo &tok : text.TokenStream()) {
if (tok.token_enum() != cursor_token.token_enum()) continue;
if (tok.text() != cursor_token.text()) continue;
const verible::LineColumnRange range = text.GetRangeForToken(tok);
result.push_back(verible::lsp::DocumentHighlight{
.range = {
.start = {.line = range.start.line,
.character = range.start.column},
.end = {.line = range.end.line, .character = range.end.column},
}});
}
const verible::TokenInfo cursor_token = text.FindTokenAt(cursor);
if (cursor_token.token_enum() != SymbolIdentifier) return result;

// Find all the symbols with the same name in the buffer.
// Note, this is very simplistic as it does _not_ take scopes into account.
// For that, we'd need the symbol table, but that implementation is not
// complete yet.
for (const verible::TokenInfo &tok : text.TokenStream()) {
if (tok.token_enum() != cursor_token.token_enum()) continue;
if (tok.text() != cursor_token.text()) continue;
const verible::LineColumnRange range = text.GetRangeForToken(tok);
result.push_back(verible::lsp::DocumentHighlight{
.range = {
.start = {.line = range.start.line,
.character = range.start.column},
.end = {.line = range.end.line, .character = range.end.column},
}});
}

return result;
}

Expand Down

0 comments on commit 07c204f

Please sign in to comment.