mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:27:35 +00:00
Everywhere: "file name" => "filename"
This commit is contained in:
parent
def1f1444a
commit
7ae7170d61
59 changed files with 181 additions and 181 deletions
|
@ -46,28 +46,28 @@ OwnPtr<Messages::LanguageServer::GreetResponse> ClientConnection::handle(const M
|
|||
|
||||
void ClientConnection::handle(const Messages::LanguageServer::FileOpened& message)
|
||||
{
|
||||
if (m_filedb.is_open(message.file_name())) {
|
||||
if (m_filedb.is_open(message.filename())) {
|
||||
return;
|
||||
}
|
||||
m_filedb.add(message.file_name(), message.file().take_fd());
|
||||
m_autocomplete_engine->file_opened(message.file_name());
|
||||
m_filedb.add(message.filename(), message.file().take_fd());
|
||||
m_autocomplete_engine->file_opened(message.filename());
|
||||
}
|
||||
|
||||
void ClientConnection::handle(const Messages::LanguageServer::FileEditInsertText& message)
|
||||
{
|
||||
dbgln_if(LANGUAGE_SERVER_DEBUG, "InsertText for file: {}", message.file_name());
|
||||
dbgln_if(LANGUAGE_SERVER_DEBUG, "InsertText for file: {}", message.filename());
|
||||
dbgln_if(LANGUAGE_SERVER_DEBUG, "Text: {}", message.text());
|
||||
dbgln_if(LANGUAGE_SERVER_DEBUG, "[{}:{}]", message.start_line(), message.start_column());
|
||||
m_filedb.on_file_edit_insert_text(message.file_name(), message.text(), message.start_line(), message.start_column());
|
||||
m_autocomplete_engine->on_edit(message.file_name());
|
||||
m_filedb.on_file_edit_insert_text(message.filename(), message.text(), message.start_line(), message.start_column());
|
||||
m_autocomplete_engine->on_edit(message.filename());
|
||||
}
|
||||
|
||||
void ClientConnection::handle(const Messages::LanguageServer::FileEditRemoveText& message)
|
||||
{
|
||||
dbgln_if(LANGUAGE_SERVER_DEBUG, "RemoveText for file: {}", message.file_name());
|
||||
dbgln_if(LANGUAGE_SERVER_DEBUG, "RemoveText for file: {}", message.filename());
|
||||
dbgln_if(LANGUAGE_SERVER_DEBUG, "[{}:{} - {}:{}]", message.start_line(), message.start_column(), message.end_line(), message.end_column());
|
||||
m_filedb.on_file_edit_remove_text(message.file_name(), message.start_line(), message.start_column(), message.end_line(), message.end_column());
|
||||
m_autocomplete_engine->on_edit(message.file_name());
|
||||
m_filedb.on_file_edit_remove_text(message.filename(), message.start_line(), message.start_column(), message.end_line(), message.end_column());
|
||||
m_autocomplete_engine->on_edit(message.filename());
|
||||
}
|
||||
|
||||
void ClientConnection::handle(const Messages::LanguageServer::AutoCompleteSuggestions& message)
|
||||
|
@ -87,17 +87,17 @@ void ClientConnection::handle(const Messages::LanguageServer::AutoCompleteSugges
|
|||
|
||||
void ClientConnection::handle(const Messages::LanguageServer::SetFileContent& message)
|
||||
{
|
||||
dbgln_if(LANGUAGE_SERVER_DEBUG, "SetFileContent: {}", message.file_name());
|
||||
auto document = m_filedb.get(message.file_name());
|
||||
dbgln_if(LANGUAGE_SERVER_DEBUG, "SetFileContent: {}", message.filename());
|
||||
auto document = m_filedb.get(message.filename());
|
||||
if (!document) {
|
||||
m_filedb.add(message.file_name(), message.content());
|
||||
VERIFY(m_filedb.is_open(message.file_name()));
|
||||
m_filedb.add(message.filename(), message.content());
|
||||
VERIFY(m_filedb.is_open(message.filename()));
|
||||
} else {
|
||||
const auto& content = message.content();
|
||||
document->set_text(content.view());
|
||||
}
|
||||
VERIFY(m_filedb.is_open(message.file_name()));
|
||||
m_autocomplete_engine->on_edit(message.file_name());
|
||||
VERIFY(m_filedb.is_open(message.filename()));
|
||||
m_autocomplete_engine->on_edit(message.filename());
|
||||
}
|
||||
|
||||
void ClientConnection::handle(const Messages::LanguageServer::FindDeclaration& message)
|
||||
|
|
|
@ -337,9 +337,9 @@ void ParserAutoComplete::file_opened([[maybe_unused]] const String& file)
|
|||
set_document_data(file, create_document_data_for(file));
|
||||
}
|
||||
|
||||
Optional<GUI::AutocompleteProvider::ProjectLocation> ParserAutoComplete::find_declaration_of(const String& file_name, const GUI::TextPosition& identifier_position)
|
||||
Optional<GUI::AutocompleteProvider::ProjectLocation> ParserAutoComplete::find_declaration_of(const String& filename, const GUI::TextPosition& identifier_position)
|
||||
{
|
||||
const auto* document_ptr = get_or_create_document_data(file_name);
|
||||
const auto* document_ptr = get_or_create_document_data(filename);
|
||||
if (!document_ptr)
|
||||
return {};
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
virtual Vector<GUI::AutocompleteProvider::Entry> get_suggestions(const String& file, const GUI::TextPosition& autocomplete_position) override;
|
||||
virtual void on_edit(const String& file) override;
|
||||
virtual void file_opened([[maybe_unused]] const String& file) override;
|
||||
virtual Optional<GUI::AutocompleteProvider::ProjectLocation> find_declaration_of(const String& file_name, const GUI::TextPosition& identifier_position) override;
|
||||
virtual Optional<GUI::AutocompleteProvider::ProjectLocation> find_declaration_of(const String& filename, const GUI::TextPosition& identifier_position) override;
|
||||
|
||||
private:
|
||||
struct DocumentData {
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
namespace LanguageServers {
|
||||
|
||||
RefPtr<const GUI::TextDocument> FileDB::get(const String& file_name) const
|
||||
RefPtr<const GUI::TextDocument> FileDB::get(const String& filename) const
|
||||
{
|
||||
auto absolute_path = to_absolute_path(file_name);
|
||||
auto absolute_path = to_absolute_path(filename);
|
||||
auto document_optional = m_open_files.get(absolute_path);
|
||||
if (!document_optional.has_value())
|
||||
return nullptr;
|
||||
|
@ -21,60 +21,60 @@ RefPtr<const GUI::TextDocument> FileDB::get(const String& file_name) const
|
|||
return document_optional.value();
|
||||
}
|
||||
|
||||
RefPtr<GUI::TextDocument> FileDB::get(const String& file_name)
|
||||
RefPtr<GUI::TextDocument> FileDB::get(const String& filename)
|
||||
{
|
||||
auto document = reinterpret_cast<const FileDB*>(this)->get(file_name);
|
||||
auto document = reinterpret_cast<const FileDB*>(this)->get(filename);
|
||||
if (document.is_null())
|
||||
return nullptr;
|
||||
return adopt_ref(*const_cast<GUI::TextDocument*>(document.leak_ref()));
|
||||
}
|
||||
|
||||
RefPtr<const GUI::TextDocument> FileDB::get_or_create_from_filesystem(const String& file_name) const
|
||||
RefPtr<const GUI::TextDocument> FileDB::get_or_create_from_filesystem(const String& filename) const
|
||||
{
|
||||
auto absolute_path = to_absolute_path(file_name);
|
||||
auto absolute_path = to_absolute_path(filename);
|
||||
auto document = get(absolute_path);
|
||||
if (document)
|
||||
return document;
|
||||
return create_from_filesystem(absolute_path);
|
||||
}
|
||||
|
||||
RefPtr<GUI::TextDocument> FileDB::get_or_create_from_filesystem(const String& file_name)
|
||||
RefPtr<GUI::TextDocument> FileDB::get_or_create_from_filesystem(const String& filename)
|
||||
{
|
||||
auto document = reinterpret_cast<const FileDB*>(this)->get_or_create_from_filesystem(file_name);
|
||||
auto document = reinterpret_cast<const FileDB*>(this)->get_or_create_from_filesystem(filename);
|
||||
if (document.is_null())
|
||||
return nullptr;
|
||||
return adopt_ref(*const_cast<GUI::TextDocument*>(document.leak_ref()));
|
||||
}
|
||||
|
||||
bool FileDB::is_open(const String& file_name) const
|
||||
bool FileDB::is_open(const String& filename) const
|
||||
{
|
||||
return m_open_files.contains(to_absolute_path(file_name));
|
||||
return m_open_files.contains(to_absolute_path(filename));
|
||||
}
|
||||
|
||||
bool FileDB::add(const String& file_name, int fd)
|
||||
bool FileDB::add(const String& filename, int fd)
|
||||
{
|
||||
auto document = create_from_fd(fd);
|
||||
if (!document)
|
||||
return false;
|
||||
|
||||
m_open_files.set(to_absolute_path(file_name), document.release_nonnull());
|
||||
m_open_files.set(to_absolute_path(filename), document.release_nonnull());
|
||||
return true;
|
||||
}
|
||||
|
||||
String FileDB::to_absolute_path(const String& file_name) const
|
||||
String FileDB::to_absolute_path(const String& filename) const
|
||||
{
|
||||
if (LexicalPath { file_name }.is_absolute()) {
|
||||
return file_name;
|
||||
if (LexicalPath { filename }.is_absolute()) {
|
||||
return filename;
|
||||
}
|
||||
VERIFY(!m_project_root.is_null());
|
||||
return LexicalPath { String::formatted("{}/{}", m_project_root, file_name) }.string();
|
||||
return LexicalPath { String::formatted("{}/{}", m_project_root, filename) }.string();
|
||||
}
|
||||
|
||||
RefPtr<GUI::TextDocument> FileDB::create_from_filesystem(const String& file_name) const
|
||||
RefPtr<GUI::TextDocument> FileDB::create_from_filesystem(const String& filename) const
|
||||
{
|
||||
auto file = Core::File::open(to_absolute_path(file_name), Core::IODevice::ReadOnly);
|
||||
auto file = Core::File::open(to_absolute_path(filename), Core::IODevice::ReadOnly);
|
||||
if (file.is_error()) {
|
||||
dbgln("failed to create document for {} from filesystem", file_name);
|
||||
dbgln("failed to create document for {} from filesystem", filename);
|
||||
return nullptr;
|
||||
}
|
||||
return create_from_file(*file.value());
|
||||
|
@ -117,10 +117,10 @@ RefPtr<GUI::TextDocument> FileDB::create_from_file(Core::File& file) const
|
|||
return document;
|
||||
}
|
||||
|
||||
void FileDB::on_file_edit_insert_text(const String& file_name, const String& inserted_text, size_t start_line, size_t start_column)
|
||||
void FileDB::on_file_edit_insert_text(const String& filename, const String& inserted_text, size_t start_line, size_t start_column)
|
||||
{
|
||||
VERIFY(is_open(file_name));
|
||||
auto document = get(file_name);
|
||||
VERIFY(is_open(filename));
|
||||
auto document = get(filename);
|
||||
VERIFY(document);
|
||||
GUI::TextPosition start_position { start_line, start_column };
|
||||
document->insert_at(start_position, inserted_text, &s_default_document_client);
|
||||
|
@ -128,12 +128,12 @@ void FileDB::on_file_edit_insert_text(const String& file_name, const String& ins
|
|||
dbgln_if(FILE_CONTENT_DEBUG, "{}", document->text());
|
||||
}
|
||||
|
||||
void FileDB::on_file_edit_remove_text(const String& file_name, size_t start_line, size_t start_column, size_t end_line, size_t end_column)
|
||||
void FileDB::on_file_edit_remove_text(const String& filename, size_t start_line, size_t start_column, size_t end_line, size_t end_column)
|
||||
{
|
||||
// TODO: If file is not open - need to get its contents
|
||||
// Otherwise- somehow verify that respawned language server is synced with all file contents
|
||||
VERIFY(is_open(file_name));
|
||||
auto document = get(file_name);
|
||||
VERIFY(is_open(filename));
|
||||
auto document = get(filename);
|
||||
VERIFY(document);
|
||||
GUI::TextPosition start_position { start_line, start_column };
|
||||
GUI::TextRange range {
|
||||
|
@ -153,7 +153,7 @@ RefPtr<GUI::TextDocument> FileDB::create_with_content(const String& content)
|
|||
return document;
|
||||
}
|
||||
|
||||
bool FileDB::add(const String& file_name, const String& content)
|
||||
bool FileDB::add(const String& filename, const String& content)
|
||||
{
|
||||
auto document = create_with_content(content);
|
||||
if (!document) {
|
||||
|
@ -161,7 +161,7 @@ bool FileDB::add(const String& file_name, const String& content)
|
|||
return false;
|
||||
}
|
||||
|
||||
m_open_files.set(to_absolute_path(file_name), document.release_nonnull());
|
||||
m_open_files.set(to_absolute_path(filename), document.release_nonnull());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,22 +15,22 @@ namespace LanguageServers {
|
|||
|
||||
class FileDB final {
|
||||
public:
|
||||
RefPtr<const GUI::TextDocument> get(const String& file_name) const;
|
||||
RefPtr<GUI::TextDocument> get(const String& file_name);
|
||||
RefPtr<const GUI::TextDocument> get_or_create_from_filesystem(const String& file_name) const;
|
||||
RefPtr<GUI::TextDocument> get_or_create_from_filesystem(const String& file_name);
|
||||
bool add(const String& file_name, int fd);
|
||||
bool add(const String& file_name, const String& content);
|
||||
RefPtr<const GUI::TextDocument> get(const String& filename) const;
|
||||
RefPtr<GUI::TextDocument> get(const String& filename);
|
||||
RefPtr<const GUI::TextDocument> get_or_create_from_filesystem(const String& filename) const;
|
||||
RefPtr<GUI::TextDocument> get_or_create_from_filesystem(const String& filename);
|
||||
bool add(const String& filename, int fd);
|
||||
bool add(const String& filename, const String& content);
|
||||
|
||||
void set_project_root(const String& root_path) { m_project_root = root_path; }
|
||||
|
||||
void on_file_edit_insert_text(const String& file_name, const String& inserted_text, size_t start_line, size_t start_column);
|
||||
void on_file_edit_remove_text(const String& file_name, size_t start_line, size_t start_column, size_t end_line, size_t end_column);
|
||||
String to_absolute_path(const String& file_name) const;
|
||||
bool is_open(const String& file_name) const;
|
||||
void on_file_edit_insert_text(const String& filename, const String& inserted_text, size_t start_line, size_t start_column);
|
||||
void on_file_edit_remove_text(const String& filename, size_t start_line, size_t start_column, size_t end_line, size_t end_column);
|
||||
String to_absolute_path(const String& filename) const;
|
||||
bool is_open(const String& filename) const;
|
||||
|
||||
private:
|
||||
RefPtr<GUI::TextDocument> create_from_filesystem(const String& file_name) const;
|
||||
RefPtr<GUI::TextDocument> create_from_filesystem(const String& filename) const;
|
||||
RefPtr<GUI::TextDocument> create_from_fd(int fd) const;
|
||||
RefPtr<GUI::TextDocument> create_from_file(Core::File&) const;
|
||||
static RefPtr<GUI::TextDocument> create_with_content(const String&);
|
||||
|
|
|
@ -2,10 +2,10 @@ endpoint LanguageServer
|
|||
{
|
||||
Greet(String project_root) => ()
|
||||
|
||||
FileOpened(String file_name, IPC::File file) =|
|
||||
FileEditInsertText(String file_name, String text, i32 start_line, i32 start_column) =|
|
||||
FileEditRemoveText(String file_name, i32 start_line, i32 start_column, i32 end_line, i32 end_column) =|
|
||||
SetFileContent(String file_name, String content) =|
|
||||
FileOpened(String filename, IPC::File file) =|
|
||||
FileEditInsertText(String filename, String text, i32 start_line, i32 start_column) =|
|
||||
FileEditRemoveText(String filename, i32 start_line, i32 start_column, i32 end_line, i32 end_column) =|
|
||||
SetFileContent(String filename, String content) =|
|
||||
|
||||
AutoCompleteSuggestions(GUI::AutocompleteProvider::ProjectLocation location) =|
|
||||
SetAutoCompleteMode(String mode) =|
|
||||
|
|
|
@ -164,10 +164,10 @@ void AutoComplete::file_opened([[maybe_unused]] const String& file)
|
|||
set_document_data(file, create_document_data_for(file));
|
||||
}
|
||||
|
||||
Optional<GUI::AutocompleteProvider::ProjectLocation> AutoComplete::find_declaration_of(const String& file_name, const GUI::TextPosition& identifier_position)
|
||||
Optional<GUI::AutocompleteProvider::ProjectLocation> AutoComplete::find_declaration_of(const String& filename, const GUI::TextPosition& identifier_position)
|
||||
{
|
||||
dbgln_if(SH_LANGUAGE_SERVER_DEBUG, "find_declaration_of({}, {}:{})", file_name, identifier_position.line(), identifier_position.column());
|
||||
const auto& document = get_or_create_document_data(file_name);
|
||||
dbgln_if(SH_LANGUAGE_SERVER_DEBUG, "find_declaration_of({}, {}:{})", filename, identifier_position.line(), identifier_position.column());
|
||||
const auto& document = get_or_create_document_data(filename);
|
||||
auto position = resolve(document, identifier_position);
|
||||
auto result = document.node->hit_test_position(position);
|
||||
if (!result.matching_node) {
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
virtual Vector<GUI::AutocompleteProvider::Entry> get_suggestions(const String& file, const GUI::TextPosition& position) override;
|
||||
virtual void on_edit(const String& file) override;
|
||||
virtual void file_opened([[maybe_unused]] const String& file) override;
|
||||
virtual Optional<GUI::AutocompleteProvider::ProjectLocation> find_declaration_of(const String& file_name, const GUI::TextPosition& identifier_position) override;
|
||||
virtual Optional<GUI::AutocompleteProvider::ProjectLocation> find_declaration_of(const String& filename, const GUI::TextPosition& identifier_position) override;
|
||||
|
||||
private:
|
||||
struct DocumentData {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue