diff options
author | Itamar <itamar8910@gmail.com> | 2021-02-20 12:27:39 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-20 15:53:37 +0100 |
commit | 5bc82c01850844d67af07ed28cbd5a7910c9e88e (patch) | |
tree | 8ba7cfea3995d8c0135620e0e222d03fe84fd9cf /Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp | |
parent | d3ff82ba8087ccc357c3f3e893951a60620bddf0 (diff) | |
download | serenity-5bc82c01850844d67af07ed28cbd5a7910c9e88e.zip |
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. :^)
Diffstat (limited to 'Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp')
-rw-r--r-- | Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp index a13c10fc12..9d11e92c4f 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp @@ -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)); +} + } |