mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
HackStudio: Don't take LexicalPath as argument
Also make use of LexicalPath::has_extension() in one place.
This commit is contained in:
parent
4befc2c282
commit
d410449d87
4 changed files with 19 additions and 17 deletions
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
namespace HackStudio {
|
namespace HackStudio {
|
||||||
|
|
||||||
NonnullRefPtr<CodeDocument> CodeDocument::create(const LexicalPath& file_path, Client* client)
|
NonnullRefPtr<CodeDocument> CodeDocument::create(const String& file_path, Client* client)
|
||||||
{
|
{
|
||||||
return adopt(*new CodeDocument(file_path, client));
|
return adopt(*new CodeDocument(file_path, client));
|
||||||
}
|
}
|
||||||
|
@ -38,17 +38,19 @@ NonnullRefPtr<CodeDocument> CodeDocument::create(Client* client)
|
||||||
return adopt(*new CodeDocument(client));
|
return adopt(*new CodeDocument(client));
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeDocument::CodeDocument(const LexicalPath& file_path, Client* client)
|
CodeDocument::CodeDocument(const String& file_path, Client* client)
|
||||||
: TextDocument(client)
|
: TextDocument(client)
|
||||||
, m_file_path(file_path)
|
, m_file_path(file_path)
|
||||||
{
|
{
|
||||||
if (file_path.basename().ends_with(".cpp") || file_path.basename().ends_with(".h"))
|
LexicalPath lexical_path(file_path);
|
||||||
|
|
||||||
|
if (lexical_path.has_extension(".cpp") || lexical_path.has_extension(".h"))
|
||||||
m_language = Language::Cpp;
|
m_language = Language::Cpp;
|
||||||
else if (file_path.basename().ends_with(".js"))
|
else if (lexical_path.has_extension(".js"))
|
||||||
m_language = Language::JavaScript;
|
m_language = Language::JavaScript;
|
||||||
else if (file_path.basename().ends_with(".ini"))
|
else if (lexical_path.has_extension(".ini"))
|
||||||
m_language = Language::Ini;
|
m_language = Language::Ini;
|
||||||
else if (file_path.basename().ends_with(".sh"))
|
else if (lexical_path.has_extension(".sh"))
|
||||||
m_language = Language::Shell;
|
m_language = Language::Shell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace HackStudio {
|
||||||
class CodeDocument final : public GUI::TextDocument {
|
class CodeDocument final : public GUI::TextDocument {
|
||||||
public:
|
public:
|
||||||
virtual ~CodeDocument() override;
|
virtual ~CodeDocument() override;
|
||||||
static NonnullRefPtr<CodeDocument> create(const LexicalPath& file_path, Client* client = nullptr);
|
static NonnullRefPtr<CodeDocument> create(const String& file_path, Client* client = nullptr);
|
||||||
static NonnullRefPtr<CodeDocument> create(Client* client = nullptr);
|
static NonnullRefPtr<CodeDocument> create(Client* client = nullptr);
|
||||||
|
|
||||||
const Vector<size_t>& breakpoint_lines() const { return m_breakpoint_lines; }
|
const Vector<size_t>& breakpoint_lines() const { return m_breakpoint_lines; }
|
||||||
|
@ -43,16 +43,16 @@ public:
|
||||||
Optional<size_t> execution_position() const { return m_execution_position; }
|
Optional<size_t> execution_position() const { return m_execution_position; }
|
||||||
void set_execution_position(size_t line) { m_execution_position = line; }
|
void set_execution_position(size_t line) { m_execution_position = line; }
|
||||||
void clear_execution_position() { m_execution_position.clear(); }
|
void clear_execution_position() { m_execution_position.clear(); }
|
||||||
const LexicalPath& file_path() const { return m_file_path; }
|
const String& file_path() const { return m_file_path; }
|
||||||
Language language() const { return m_language; }
|
Language language() const { return m_language; }
|
||||||
|
|
||||||
virtual bool is_code_document() const override final { return true; }
|
virtual bool is_code_document() const override final { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit CodeDocument(const LexicalPath& file_path, Client* client = nullptr);
|
explicit CodeDocument(const String& file_path, Client* client = nullptr);
|
||||||
explicit CodeDocument(Client* client = nullptr);
|
explicit CodeDocument(Client* client = nullptr);
|
||||||
|
|
||||||
LexicalPath m_file_path;
|
String m_file_path;
|
||||||
Language m_language { Language::Unknown };
|
Language m_language { Language::Unknown };
|
||||||
Vector<size_t> m_breakpoint_lines;
|
Vector<size_t> m_breakpoint_lines;
|
||||||
Optional<size_t> m_execution_position;
|
Optional<size_t> m_execution_position;
|
||||||
|
|
|
@ -483,12 +483,12 @@ void Editor::set_document(GUI::TextDocument& doc)
|
||||||
|
|
||||||
if (m_language_client) {
|
if (m_language_client) {
|
||||||
dbgln("Opening {}", code_document.file_path());
|
dbgln("Opening {}", code_document.file_path());
|
||||||
int fd = open(code_document.file_path().string().characters(), O_RDONLY | O_NOCTTY);
|
int fd = open(code_document.file_path().characters(), O_RDONLY | O_NOCTTY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror("open");
|
perror("open");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_language_client->open_file(code_document.file_path().string(), fd);
|
m_language_client->open_file(code_document.file_path(), fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -519,7 +519,7 @@ void Editor::update_autocomplete(const AutoCompleteRequestData& data)
|
||||||
};
|
};
|
||||||
|
|
||||||
m_language_client->request_autocomplete(
|
m_language_client->request_autocomplete(
|
||||||
code_document().file_path().string(),
|
code_document().file_path(),
|
||||||
data.position.line(),
|
data.position.line(),
|
||||||
data.position.column());
|
data.position.column());
|
||||||
}
|
}
|
||||||
|
@ -544,7 +544,7 @@ void Editor::on_edit_action(const GUI::Command& command)
|
||||||
if (command.is_insert_text()) {
|
if (command.is_insert_text()) {
|
||||||
const GUI::InsertTextCommand& insert_command = static_cast<const GUI::InsertTextCommand&>(command);
|
const GUI::InsertTextCommand& insert_command = static_cast<const GUI::InsertTextCommand&>(command);
|
||||||
m_language_client->insert_text(
|
m_language_client->insert_text(
|
||||||
code_document().file_path().string(),
|
code_document().file_path(),
|
||||||
insert_command.text(),
|
insert_command.text(),
|
||||||
insert_command.range().start().line(),
|
insert_command.range().start().line(),
|
||||||
insert_command.range().start().column());
|
insert_command.range().start().column());
|
||||||
|
@ -554,7 +554,7 @@ void Editor::on_edit_action(const GUI::Command& command)
|
||||||
if (command.is_remove_text()) {
|
if (command.is_remove_text()) {
|
||||||
const GUI::RemoveTextCommand& remove_command = static_cast<const GUI::RemoveTextCommand&>(command);
|
const GUI::RemoveTextCommand& remove_command = static_cast<const GUI::RemoveTextCommand&>(command);
|
||||||
m_language_client->remove_text(
|
m_language_client->remove_text(
|
||||||
code_document().file_path().string(),
|
code_document().file_path(),
|
||||||
remove_command.range().start().line(),
|
remove_command.range().start().line(),
|
||||||
remove_command.range().start().column(),
|
remove_command.range().start().column(),
|
||||||
remove_command.range().end().line(),
|
remove_command.range().end().line(),
|
||||||
|
@ -583,7 +583,7 @@ void Editor::flush_file_content_to_langauge_server()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_language_client->set_file_content(
|
m_language_client->set_file_content(
|
||||||
code_document().file_path().string(),
|
code_document().file_path(),
|
||||||
document().text());
|
document().text());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ ProjectFile::ProjectFile(const String& name)
|
||||||
GUI::TextDocument& ProjectFile::document() const
|
GUI::TextDocument& ProjectFile::document() const
|
||||||
{
|
{
|
||||||
if (!m_document) {
|
if (!m_document) {
|
||||||
m_document = CodeDocument::create(LexicalPath(m_name));
|
m_document = CodeDocument::create(m_name);
|
||||||
auto file_or_error = Core::File::open(m_name, Core::File::ReadOnly);
|
auto file_or_error = Core::File::open(m_name, Core::File::ReadOnly);
|
||||||
if (file_or_error.is_error()) {
|
if (file_or_error.is_error()) {
|
||||||
warnln("Couldn't open '{}': {}", m_name, file_or_error.error());
|
warnln("Couldn't open '{}': {}", m_name, file_or_error.error());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue