LibGUI+LibCpp: Move C++ syntax highlighter to LibCpp
This makes LibGUI not depend on LibCpp.
This commit is contained in:
parent
b1f1f5afcf
commit
ff2438e0ce
Notes:
sideshowbarker
2024-07-18 22:32:37 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/ff2438e0cea
9 changed files with 23 additions and 23 deletions
|
@ -7,4 +7,4 @@ set(SOURCES
|
|||
)
|
||||
|
||||
serenity_app(TextEditor ICON app-text-editor)
|
||||
target_link_libraries(TextEditor LibWeb LibMarkdown LibGUI LibShell LibRegex LibDesktop)
|
||||
target_link_libraries(TextEditor LibWeb LibMarkdown LibGUI LibShell LibRegex LibDesktop LibCpp)
|
||||
|
|
|
@ -33,12 +33,12 @@
|
|||
#include <Applications/TextEditor/TextEditorWindowGML.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/MimeData.h>
|
||||
#include <LibCpp/SyntaxHighlighter.h>
|
||||
#include <LibDesktop/Launcher.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/ActionGroup.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/CppSyntaxHighlighter.h>
|
||||
#include <LibGUI/FilePicker.h>
|
||||
#include <LibGUI/FontPicker.h>
|
||||
#include <LibGUI/GMLSyntaxHighlighter.h>
|
||||
|
@ -469,7 +469,7 @@ TextEditorWidget::TextEditorWidget()
|
|||
syntax_menu.add_action(*m_plain_text_highlight);
|
||||
|
||||
m_cpp_highlight = GUI::Action::create_checkable("C++", [&](auto&) {
|
||||
m_editor->set_syntax_highlighter(make<GUI::CppSyntaxHighlighter>());
|
||||
m_editor->set_syntax_highlighter(make<Cpp::SyntaxHighlighter>());
|
||||
m_editor->update();
|
||||
});
|
||||
syntax_actions.add_action(*m_cpp_highlight);
|
||||
|
|
|
@ -33,5 +33,5 @@ set(SOURCES
|
|||
)
|
||||
|
||||
serenity_app(HackStudio ICON app-hack-studio)
|
||||
target_link_libraries(HackStudio LibWeb LibMarkdown LibGUI LibGfx LibCore LibVT LibDebug LibX86 LibDiff LibShell)
|
||||
target_link_libraries(HackStudio LibWeb LibMarkdown LibGUI LibCpp LibGfx LibCore LibVT LibDebug LibX86 LibDiff LibShell)
|
||||
add_dependencies(HackStudio CppLanguageServer)
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
#include <AK/LexicalPath.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCpp/SyntaxHighlighter.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/CppSyntaxHighlighter.h>
|
||||
#include <LibGUI/GMLSyntaxHighlighter.h>
|
||||
#include <LibGUI/INISyntaxHighlighter.h>
|
||||
#include <LibGUI/JSSyntaxHighlighter.h>
|
||||
|
@ -418,7 +418,7 @@ void Editor::set_document(GUI::TextDocument& doc)
|
|||
CodeDocument& code_document = static_cast<CodeDocument&>(doc);
|
||||
switch (code_document.language()) {
|
||||
case Language::Cpp:
|
||||
set_syntax_highlighter(make<GUI::CppSyntaxHighlighter>());
|
||||
set_syntax_highlighter(make<Cpp::SyntaxHighlighter>());
|
||||
m_language_client = get_language_client<LanguageClients::Cpp::ServerConnection>(project().root_path());
|
||||
break;
|
||||
case Language::GML:
|
||||
|
|
|
@ -2,6 +2,7 @@ set(SOURCES
|
|||
AST.cpp
|
||||
Lexer.cpp
|
||||
Parser.cpp
|
||||
SyntaxHighlighter.cpp
|
||||
)
|
||||
|
||||
serenity_lib(LibCpp cpp)
|
||||
|
|
|
@ -26,14 +26,14 @@
|
|||
|
||||
#include <AK/Debug.h>
|
||||
#include <LibCpp/Lexer.h>
|
||||
#include <LibGUI/CppSyntaxHighlighter.h>
|
||||
#include <LibCpp/SyntaxHighlighter.h>
|
||||
#include <LibGUI/TextEditor.h>
|
||||
#include <LibGfx/Font.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
|
||||
namespace GUI {
|
||||
namespace Cpp {
|
||||
|
||||
static TextStyle style_for_token_type(Gfx::Palette palette, Cpp::Token::Type type)
|
||||
static GUI::TextStyle style_for_token_type(const Gfx::Palette& palette, Cpp::Token::Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case Cpp::Token::Type::Keyword:
|
||||
|
@ -63,19 +63,19 @@ static TextStyle style_for_token_type(Gfx::Palette palette, Cpp::Token::Type typ
|
|||
}
|
||||
}
|
||||
|
||||
bool CppSyntaxHighlighter::is_identifier(void* token) const
|
||||
bool SyntaxHighlighter::is_identifier(void* token) const
|
||||
{
|
||||
auto cpp_token = static_cast<Cpp::Token::Type>(reinterpret_cast<size_t>(token));
|
||||
return cpp_token == Cpp::Token::Type::Identifier;
|
||||
}
|
||||
|
||||
bool CppSyntaxHighlighter::is_navigatable(void* token) const
|
||||
bool SyntaxHighlighter::is_navigatable(void* token) const
|
||||
{
|
||||
auto cpp_token = static_cast<Cpp::Token::Type>(reinterpret_cast<size_t>(token));
|
||||
return cpp_token == Cpp::Token::Type::IncludePath;
|
||||
}
|
||||
|
||||
void CppSyntaxHighlighter::rehighlight(Gfx::Palette palette)
|
||||
void SyntaxHighlighter::rehighlight(Gfx::Palette palette)
|
||||
{
|
||||
ASSERT(m_editor);
|
||||
auto text = m_editor->text();
|
||||
|
@ -103,7 +103,7 @@ void CppSyntaxHighlighter::rehighlight(Gfx::Palette palette)
|
|||
m_editor->update();
|
||||
}
|
||||
|
||||
Vector<SyntaxHighlighter::MatchingTokenPair> CppSyntaxHighlighter::matching_token_pairs() const
|
||||
Vector<SyntaxHighlighter::MatchingTokenPair> SyntaxHighlighter::matching_token_pairs() const
|
||||
{
|
||||
static Vector<SyntaxHighlighter::MatchingTokenPair> pairs;
|
||||
if (pairs.is_empty()) {
|
||||
|
@ -114,12 +114,12 @@ Vector<SyntaxHighlighter::MatchingTokenPair> CppSyntaxHighlighter::matching_toke
|
|||
return pairs;
|
||||
}
|
||||
|
||||
bool CppSyntaxHighlighter::token_types_equal(void* token1, void* token2) const
|
||||
bool SyntaxHighlighter::token_types_equal(void* token1, void* token2) const
|
||||
{
|
||||
return static_cast<Cpp::Token::Type>(reinterpret_cast<size_t>(token1)) == static_cast<Cpp::Token::Type>(reinterpret_cast<size_t>(token2));
|
||||
}
|
||||
|
||||
CppSyntaxHighlighter::~CppSyntaxHighlighter()
|
||||
SyntaxHighlighter::~SyntaxHighlighter()
|
||||
{
|
||||
}
|
||||
|
|
@ -28,17 +28,17 @@
|
|||
|
||||
#include <LibGUI/SyntaxHighlighter.h>
|
||||
|
||||
namespace GUI {
|
||||
namespace Cpp {
|
||||
|
||||
class CppSyntaxHighlighter final : public SyntaxHighlighter {
|
||||
class SyntaxHighlighter final : public GUI::SyntaxHighlighter {
|
||||
public:
|
||||
CppSyntaxHighlighter() { }
|
||||
virtual ~CppSyntaxHighlighter() override;
|
||||
SyntaxHighlighter() { }
|
||||
virtual ~SyntaxHighlighter() override;
|
||||
|
||||
virtual bool is_identifier(void*) const override;
|
||||
virtual bool is_navigatable(void*) const override;
|
||||
|
||||
virtual SyntaxLanguage language() const override { return SyntaxLanguage::Cpp; }
|
||||
virtual GUI::SyntaxLanguage language() const override { return GUI::SyntaxLanguage::Cpp; }
|
||||
virtual void rehighlight(Gfx::Palette) override;
|
||||
|
||||
protected:
|
|
@ -22,7 +22,6 @@ set(SOURCES
|
|||
ComboBox.cpp
|
||||
Command.cpp
|
||||
ControlBoxButton.cpp
|
||||
CppSyntaxHighlighter.cpp
|
||||
Desktop.cpp
|
||||
Dialog.cpp
|
||||
DisplayLink.cpp
|
||||
|
@ -111,4 +110,4 @@ set(GENERATED_SOURCES
|
|||
)
|
||||
|
||||
serenity_lib(LibGUI gui)
|
||||
target_link_libraries(LibGUI LibCore LibGfx LibIPC LibThread LibCpp LibShell LibRegex LibJS)
|
||||
target_link_libraries(LibGUI LibCore LibGfx LibIPC LibThread LibShell LibRegex LibJS)
|
||||
|
|
|
@ -48,4 +48,4 @@ target_link_libraries(test-web LibWeb)
|
|||
target_link_libraries(tt LibPthread)
|
||||
target_link_libraries(grep LibRegex)
|
||||
target_link_libraries(gunzip LibCompress)
|
||||
target_link_libraries(CppParserTest LibCpp)
|
||||
target_link_libraries(CppParserTest LibCpp LibGUI)
|
||||
|
|
Loading…
Add table
Reference in a new issue