summaryrefslogtreecommitdiff
path: root/Userland/DevTools/HackStudio/LanguageServers
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/DevTools/HackStudio/LanguageServers')
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/CMakeLists.txt3
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp25
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h8
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/LexerAutoComplete.cpp (renamed from Userland/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.cpp)10
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/LexerAutoComplete.h (renamed from Userland/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.h)4
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/LanguageServer.ipc1
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.h1
7 files changed, 42 insertions, 10 deletions
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CMakeLists.txt b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CMakeLists.txt
index de9569d8ca..7d34577447 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CMakeLists.txt
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CMakeLists.txt
@@ -1,7 +1,8 @@
set(SOURCES
ClientConnection.cpp
main.cpp
- AutoComplete.cpp
+ LexerAutoComplete.cpp
+ ParserAutoComplete.cpp
)
set(GENERATED_SOURCES
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp
index 5881dbbeee..c3cdedeef4 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.cpp
@@ -25,7 +25,8 @@
*/
#include "ClientConnection.h"
-#include "AutoComplete.h"
+#include "LexerAutoComplete.h"
+#include "ParserAutoComplete.h"
#include <AK/Debug.h>
#include <AK/HashMap.h>
#include <LibCore/File.h>
@@ -146,7 +147,16 @@ void ClientConnection::handle(const Messages::LanguageServer::AutoCompleteSugges
return;
}
- auto suggestions = AutoComplete::get_suggestions(document->text(), { (size_t)message.cursor_line(), (size_t)max(message.cursor_column(), message.cursor_column() - 1) });
+ Vector<GUI::AutocompleteProvider::Entry> suggestions;
+ switch (m_auto_complete_mode) {
+ case AutoCompleteMode::Lexer:
+ suggestions = LexerAutoComplete::get_suggestions(document->text(), { (size_t)message.cursor_line(), (size_t)max(message.cursor_column(), message.cursor_column() - 1) });
+ break;
+ case AutoCompleteMode::Parser: {
+ auto engine = ParserAutoComplete(document->text());
+ suggestions = engine.get_suggestions({ (size_t)message.cursor_line(), (size_t)max(message.cursor_column(), message.cursor_column() - 1) });
+ }
+ }
post_message(Messages::LanguageClient::AutoCompleteSuggestions(move(suggestions)));
}
@@ -170,4 +180,15 @@ void ClientConnection::handle(const Messages::LanguageServer::SetFileContent& me
document->set_text(content.view());
}
+void ClientConnection::handle(const Messages::LanguageServer::SetAutoCompleteMode& message)
+{
+#ifdef DEBUG_CPP_LANGUAGE_SERVER
+ dbgln("SetAutoCompleteMode: {}", message.mode());
+#endif
+ if (message.mode() == "Parser")
+ m_auto_complete_mode = AutoCompleteMode::Parser;
+ else
+ m_auto_complete_mode = AutoCompleteMode::Lexer;
+}
+
}
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h
index d0a7b4558c..3389ba8231 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h
@@ -55,10 +55,18 @@ private:
virtual void handle(const Messages::LanguageServer::FileEditRemoveText&) override;
virtual void handle(const Messages::LanguageServer::SetFileContent&) override;
virtual void handle(const Messages::LanguageServer::AutoCompleteSuggestions&) override;
+ virtual void handle(const Messages::LanguageServer::SetAutoCompleteMode&) override;
RefPtr<GUI::TextDocument> document_for(const String& file_name);
HashMap<String, NonnullRefPtr<GUI::TextDocument>> m_open_files;
+
+ enum class AutoCompleteMode {
+ Lexer,
+ Parser
+ };
+
+ AutoCompleteMode m_auto_complete_mode { AutoCompleteMode::Lexer };
};
}
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/LexerAutoComplete.cpp
index b864563b4e..9a31679728 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.cpp
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/LexerAutoComplete.cpp
@@ -24,14 +24,14 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "AutoComplete.h"
+#include "LexerAutoComplete.h"
#include <AK/Debug.h>
#include <AK/HashTable.h>
#include <LibCpp/Lexer.h>
namespace LanguageServers::Cpp {
-Vector<GUI::AutocompleteProvider::Entry> AutoComplete::get_suggestions(const String& code, const GUI::TextPosition& autocomplete_position)
+Vector<GUI::AutocompleteProvider::Entry> LexerAutoComplete::get_suggestions(const String& code, const GUI::TextPosition& autocomplete_position)
{
auto lines = code.split('\n', true);
Cpp::Lexer lexer(code);
@@ -52,14 +52,14 @@ Vector<GUI::AutocompleteProvider::Entry> AutoComplete::get_suggestions(const Str
return suggestions;
}
-StringView AutoComplete::text_of_token(const Vector<String>& lines, const Cpp::Token& token)
+StringView LexerAutoComplete::text_of_token(const Vector<String>& lines, const Cpp::Token& token)
{
ASSERT(token.m_start.line == token.m_end.line);
ASSERT(token.m_start.column <= token.m_end.column);
return lines[token.m_start.line].substring_view(token.m_start.column, token.m_end.column - token.m_start.column + 1);
}
-Optional<size_t> AutoComplete::token_in_position(const Vector<Cpp::Token>& tokens, const GUI::TextPosition& position)
+Optional<size_t> LexerAutoComplete::token_in_position(const Vector<Cpp::Token>& tokens, const GUI::TextPosition& position)
{
for (size_t token_index = 0; token_index < tokens.size(); ++token_index) {
auto& token = tokens[token_index];
@@ -74,7 +74,7 @@ Optional<size_t> AutoComplete::token_in_position(const Vector<Cpp::Token>& token
return {};
}
-Vector<GUI::AutocompleteProvider::Entry> AutoComplete::identifier_prefixes(const Vector<String>& lines, const Vector<Cpp::Token>& tokens, size_t target_token_index)
+Vector<GUI::AutocompleteProvider::Entry> LexerAutoComplete::identifier_prefixes(const Vector<String>& lines, const Vector<Cpp::Token>& tokens, size_t target_token_index)
{
auto partial_input = text_of_token(lines, tokens[target_token_index]);
Vector<GUI::AutocompleteProvider::Entry> suggestions;
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.h b/Userland/DevTools/HackStudio/LanguageServers/Cpp/LexerAutoComplete.h
index b4096bd793..e482818cfc 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.h
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/LexerAutoComplete.h
@@ -36,9 +36,9 @@ namespace LanguageServers::Cpp {
using namespace ::Cpp;
-class AutoComplete {
+class LexerAutoComplete {
public:
- AutoComplete() = delete;
+ LexerAutoComplete() = delete;
static Vector<GUI::AutocompleteProvider::Entry> get_suggestions(const String& code, const GUI::TextPosition& autocomplete_position);
diff --git a/Userland/DevTools/HackStudio/LanguageServers/LanguageServer.ipc b/Userland/DevTools/HackStudio/LanguageServers/LanguageServer.ipc
index de16fa14ec..405dbbab88 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/LanguageServer.ipc
+++ b/Userland/DevTools/HackStudio/LanguageServers/LanguageServer.ipc
@@ -8,4 +8,5 @@ endpoint LanguageServer = 8001
SetFileContent(String file_name, String content) =|
AutoCompleteSuggestions(String file_name, i32 cursor_line, i32 cursor_column) =|
+ SetAutoCompleteMode(String mode) =|
}
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.h b/Userland/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.h
index bb7fc14bd9..cea922037e 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.h
+++ b/Userland/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.h
@@ -56,6 +56,7 @@ private:
virtual void handle(const Messages::LanguageServer::FileEditRemoveText&) override;
virtual void handle(const Messages::LanguageServer::SetFileContent&) override;
virtual void handle(const Messages::LanguageServer::AutoCompleteSuggestions&) override;
+ virtual void handle(const Messages::LanguageServer::SetAutoCompleteMode&) override { }
RefPtr<GUI::TextDocument> document_for(const String& file_name);