summaryrefslogtreecommitdiff
path: root/Userland/DevTools/HackStudio
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2022-03-31 19:09:29 +0300
committerAndreas Kling <kling@serenityos.org>2022-03-31 19:10:15 +0200
commit9cd27d1e1578ce948694121479d9cbabe6795910 (patch)
tree41e18de0fbf458069d3b20327b3d7f20922377bd /Userland/DevTools/HackStudio
parent597ca68e2d9da78505693e7db4eef47271e2ca68 (diff)
downloadserenity-9cd27d1e1578ce948694121479d9cbabe6795910.zip
LanguageServers/Cpp: Add SemanticType::PreprocessorMacro
This adds a new semantic token type, PreprocessorMacro. Calls to preprocessor macros will now be highlighted when semantic highlighting is enabled in Hack Studio.
Diffstat (limited to 'Userland/DevTools/HackStudio')
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/ConnectionFromClient.cpp4
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp13
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h1
3 files changed, 14 insertions, 4 deletions
diff --git a/Userland/DevTools/HackStudio/LanguageServers/ConnectionFromClient.cpp b/Userland/DevTools/HackStudio/LanguageServers/ConnectionFromClient.cpp
index 741774ae69..d1f29a4199 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/ConnectionFromClient.cpp
+++ b/Userland/DevTools/HackStudio/LanguageServers/ConnectionFromClient.cpp
@@ -149,8 +149,8 @@ void ConnectionFromClient::get_tokens_info(String const& filename)
return;
}
- auto token_info = m_autocomplete_engine->get_tokens_info(filename);
- async_tokens_info_result(move(token_info));
+ auto tokens_info = m_autocomplete_engine->get_tokens_info(filename);
+ async_tokens_info_result(move(tokens_info));
}
}
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp
index c6560ec011..4485f2b3c1 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp
@@ -429,15 +429,21 @@ RefPtr<Declaration> CppComprehensionEngine::find_declaration_of(const DocumentDa
Optional<GUI::AutocompleteProvider::ProjectLocation> CppComprehensionEngine::find_preprocessor_definition(const DocumentData& document, const GUI::TextPosition& text_position)
{
Position cpp_position { text_position.line(), text_position.column() };
+ auto substitution = find_preprocessor_substitution(document, cpp_position);
+ if (!substitution.has_value())
+ return {};
+ return GUI::AutocompleteProvider::ProjectLocation { substitution->defined_value.filename, substitution->defined_value.line, substitution->defined_value.column };
+}
+Optional<Cpp::Preprocessor::Substitution> CppComprehensionEngine::find_preprocessor_substitution(DocumentData const& document, Cpp::Position const& cpp_position)
+{
// Search for a replaced preprocessor token that intersects with text_position
for (auto& substitution : document.preprocessor().substitutions()) {
if (substitution.original_tokens.first().start() > cpp_position)
continue;
if (substitution.original_tokens.first().end() < cpp_position)
continue;
-
- return GUI::AutocompleteProvider::ProjectLocation { substitution.defined_value.filename, substitution.defined_value.line, substitution.defined_value.column };
+ return substitution;
}
return {};
}
@@ -978,6 +984,9 @@ GUI::AutocompleteProvider::TokenInfo::SemanticType CppComprehensionEngine::get_t
GUI::AutocompleteProvider::TokenInfo::SemanticType CppComprehensionEngine::get_semantic_type_for_identifier(DocumentData const& document, Position position)
{
+ if (find_preprocessor_substitution(document, position).has_value())
+ return GUI::AutocompleteProvider::TokenInfo::SemanticType::PreprocessorMacro;
+
auto decl = find_declaration_of(document, GUI::TextPosition { position.line, position.column });
if (!decl)
return GUI::AutocompleteProvider::TokenInfo::SemanticType::Identifier;
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h
index 370c5c9939..91eb1f1b64 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h
@@ -127,6 +127,7 @@ private:
Vector<StringView> scope_of_reference_to_symbol(const ASTNode&) const;
Optional<GUI::AutocompleteProvider::ProjectLocation> find_preprocessor_definition(const DocumentData&, const GUI::TextPosition&);
+ Optional<Cpp::Preprocessor::Substitution> find_preprocessor_substitution(DocumentData const&, Cpp::Position const&);
OwnPtr<DocumentData> create_document_data(String&& text, const String& filename);
Optional<Vector<GUI::AutocompleteProvider::Entry>> try_autocomplete_property(const DocumentData&, const ASTNode&, Optional<Token> containing_token) const;