mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-03 17:02:56 +00:00
HackStudio: Create Language enum from file extension or language name
This commit is contained in:
parent
1edaefca3a
commit
ba6cbf160b
Notes:
sideshowbarker
2024-07-18 21:41:20 +09:00
Author: https://github.com/itamar8910
Commit: ba6cbf160b
Pull-request: https://github.com/SerenityOS/serenity/pull/5654
Issue: https://github.com/SerenityOS/serenity/issues/5569
Issue: https://github.com/SerenityOS/serenity/issues/5574
Issue: https://github.com/SerenityOS/serenity/issues/5634
4 changed files with 68 additions and 12 deletions
|
@ -27,6 +27,7 @@ set(SOURCES
|
||||||
Git/GitRepo.cpp
|
Git/GitRepo.cpp
|
||||||
Git/GitWidget.cpp
|
Git/GitWidget.cpp
|
||||||
HackStudioWidget.cpp
|
HackStudioWidget.cpp
|
||||||
|
Language.cpp
|
||||||
LanguageClient.cpp
|
LanguageClient.cpp
|
||||||
Locator.cpp
|
Locator.cpp
|
||||||
Project.cpp
|
Project.cpp
|
||||||
|
|
|
@ -42,18 +42,7 @@ CodeDocument::CodeDocument(const String& file_path, Client* client)
|
||||||
: TextDocument(client)
|
: TextDocument(client)
|
||||||
, m_file_path(file_path)
|
, m_file_path(file_path)
|
||||||
{
|
{
|
||||||
LexicalPath lexical_path(file_path);
|
m_language = language_from_file_extension(LexicalPath { file_path }.extension());
|
||||||
|
|
||||||
if (lexical_path.has_extension(".cpp") || lexical_path.has_extension(".h"))
|
|
||||||
m_language = Language::Cpp;
|
|
||||||
else if (lexical_path.has_extension(".js"))
|
|
||||||
m_language = Language::JavaScript;
|
|
||||||
else if (lexical_path.has_extension(".gml"))
|
|
||||||
m_language = Language::GML;
|
|
||||||
else if (lexical_path.has_extension(".ini"))
|
|
||||||
m_language = Language::Ini;
|
|
||||||
else if (lexical_path.has_extension(".sh"))
|
|
||||||
m_language = Language::Shell;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeDocument::CodeDocument(Client* client)
|
CodeDocument::CodeDocument(Client* client)
|
||||||
|
|
60
Userland/DevTools/HackStudio/Language.cpp
Normal file
60
Userland/DevTools/HackStudio/Language.cpp
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020, the SerenityOS developers.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Language.h"
|
||||||
|
|
||||||
|
namespace HackStudio {
|
||||||
|
|
||||||
|
Language language_from_file_extension(const String& extension)
|
||||||
|
{
|
||||||
|
VERIFY(!extension.starts_with("."));
|
||||||
|
if (extension == "cpp" || extension == "h")
|
||||||
|
return Language::Cpp;
|
||||||
|
else if (extension == "js")
|
||||||
|
return Language::JavaScript;
|
||||||
|
else if (extension == "gml")
|
||||||
|
return Language::GML;
|
||||||
|
else if (extension == "ini")
|
||||||
|
return Language::Ini;
|
||||||
|
else if (extension == "sh")
|
||||||
|
return Language::Shell;
|
||||||
|
|
||||||
|
return Language::Unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
Language language_from_name(const String& name)
|
||||||
|
{
|
||||||
|
if (name == "Cpp")
|
||||||
|
return Language::Cpp;
|
||||||
|
if (name == "Javascript")
|
||||||
|
return Language::JavaScript;
|
||||||
|
if (name == "Shell")
|
||||||
|
return Language::Shell;
|
||||||
|
|
||||||
|
return Language::Unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -26,6 +26,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/String.h>
|
||||||
|
|
||||||
namespace HackStudio {
|
namespace HackStudio {
|
||||||
enum class Language {
|
enum class Language {
|
||||||
Unknown,
|
Unknown,
|
||||||
|
@ -35,4 +37,8 @@ enum class Language {
|
||||||
Ini,
|
Ini,
|
||||||
Shell,
|
Shell,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Language language_from_file_extension(const String&);
|
||||||
|
Language language_from_name(const String&);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue