Skip to content

Commit

Permalink
Fix completion lookup method
Browse files Browse the repository at this point in the history
Fix the symbol lookup function, hence actually looking up stuff.
Scope-aware completion is effective.
  • Loading branch information
suzizecat committed Dec 30, 2024
1 parent 2af32df commit 98da348
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion indexer/index_reference_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace diplomat::index
bool ReferenceVisitor::_add_reference_from_stx(const slang::SourceRange & loc,
const std::string_view& name)
{
spdlog::info(" Found reference for name {}", name);
spdlog::debug(" Found reference for name {}", name);
IndexRange node_loc(loc,*_sm);
IndexFile* parent_file = _index->add_file(node_loc.start.file);

Expand Down
10 changes: 9 additions & 1 deletion indexer/index_scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,24 @@ namespace diplomat::index {
{
const IndexScope* lu_scope = this;
std::vector<const IndexSymbol*> ret;
bool keep_going = false;
do {
for(auto& symb : std::views::values(lu_scope->_content))
{
ret.push_back(symb);
}

if(lu_scope->get_parent_access())
{
lu_scope = lu_scope->_parent;
keep_going = true;
}
else
{
keep_going = false;
}

} while (lu_scope->get_parent_access());
} while (keep_going);

return ret;
}
Expand Down
9 changes: 8 additions & 1 deletion lsp-server/diplomat/src/diplomat_lsp_binds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,37 @@ json DiplomatLSP::_h_completion(slsp::types::CompletionParams params)

if(trigger_scope)
{
spdlog::info("Required completion on valid scope");
for(const di::IndexSymbol* symb : trigger_scope->get_visible_symbols() )
{
if(symb->get_source_location().value_or(trigger_location) > trigger_location)
continue;

CompletionItem record;
record.label = symb->get_name();
record.kind = CompletionItemKind::CompletionItemKind_Variable;
result.items.push_back(record);
}
}
else
{
// Propose symbols from the whole file.

spdlog::info("Required completion on full file");
for(const auto& symb : _index->get_file(trigger_location.file)->get_symbols() )
{
if(symb->get_source_location().value_or(trigger_location) > trigger_location)
continue;

CompletionItem record;
record.label = symb->get_name();
record.kind = CompletionItemKind::CompletionItemKind_Variable;
result.items.push_back(record);
}
}

spdlog::info(" Returned {} propositions",result.items.size());

return result;
}

Expand Down Expand Up @@ -733,4 +740,4 @@ json DiplomatLSP::_h_list_symbols(json& params)
// }

return ret;
}
}

0 comments on commit 98da348

Please sign in to comment.