mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:58:12 +00:00
LanguageServers/Cpp: Add 'FindDeclaration' capability
The C++ LanguageServer can now find the matching declaration for variable names, function calls, struct/class types and properties. When clicking on one of the above with Ctrl pressed, HackStudio will ask the language server to find a matching declaration, and navigate to the result in the Editor. :^)
This commit is contained in:
parent
d3ff82ba80
commit
5bc82c0185
12 changed files with 150 additions and 38 deletions
|
@ -128,7 +128,7 @@ void ClientConnection::handle(const Messages::LanguageServer::SetFileContent& me
|
|||
|
||||
void ClientConnection::handle(const Messages::LanguageServer::SetAutoCompleteMode& message)
|
||||
{
|
||||
#ifdef DEBUG_CPP_LANGUAGE_SERVER
|
||||
#ifdef CPP_LANGUAGE_SERVER_DEBUG
|
||||
dbgln("SetAutoCompleteMode: {}", message.mode());
|
||||
#endif
|
||||
if (message.mode() == "Parser")
|
||||
|
@ -137,4 +137,23 @@ void ClientConnection::handle(const Messages::LanguageServer::SetAutoCompleteMod
|
|||
m_autocomplete_engine = make<LexerAutoComplete>(m_filedb);
|
||||
}
|
||||
|
||||
void ClientConnection::handle(const Messages::LanguageServer::FindDeclaration& message)
|
||||
{
|
||||
dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "FindDeclaration: {} {}:{}", message.file_name(), message.line(), message.column());
|
||||
auto document = m_filedb.get(message.file_name());
|
||||
if (!document) {
|
||||
dbgln("file {} has not been opened", message.file_name());
|
||||
return;
|
||||
}
|
||||
|
||||
GUI::TextPosition identifier_position = { (size_t)message.line(), (size_t)message.column() };
|
||||
auto location = m_autocomplete_engine->find_declaration_of(message.file_name(), identifier_position);
|
||||
if (!location.has_value()) {
|
||||
dbgln("could not find declaration");
|
||||
return;
|
||||
}
|
||||
dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "declaration location: {} {}:{}", location.value().file, location.value().line, location.value().column);
|
||||
post_message(Messages::LanguageClient::DeclarationLocation(location.value().file, location.value().line, location.value().column));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue