summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/DevTools/HackStudio/Project.cpp15
-rw-r--r--Userland/DevTools/HackStudio/Project.h4
2 files changed, 15 insertions, 4 deletions
diff --git a/Userland/DevTools/HackStudio/Project.cpp b/Userland/DevTools/HackStudio/Project.cpp
index f83f2e8940..6db51516fc 100644
--- a/Userland/DevTools/HackStudio/Project.cpp
+++ b/Userland/DevTools/HackStudio/Project.cpp
@@ -70,15 +70,24 @@ void Project::for_each_text_file(Function<void(const ProjectFile&)> callback) co
});
}
-RefPtr<ProjectFile> Project::get_file(const String& path) const
+NonnullRefPtr<ProjectFile> Project::get_file(const String& path) const
{
+ auto full_path = to_absolute_path(path);
for (auto& file : m_files) {
- if (file.name() == path)
+ if (file.name() == full_path)
return file;
}
- auto file = ProjectFile::construct_with_name(path);
+ auto file = ProjectFile::construct_with_name(full_path);
m_files.append(file);
return file;
}
+String Project::to_absolute_path(const String& path) const
+{
+ if (LexicalPath { path }.is_absolute()) {
+ return path;
+ }
+ return LexicalPath { String::formatted("{}/{}", m_root_path, path) }.string();
+}
+
}
diff --git a/Userland/DevTools/HackStudio/Project.h b/Userland/DevTools/HackStudio/Project.h
index 6d3453e84e..afa1a49f9c 100644
--- a/Userland/DevTools/HackStudio/Project.h
+++ b/Userland/DevTools/HackStudio/Project.h
@@ -48,13 +48,15 @@ public:
String name() const { return LexicalPath(m_root_path).basename(); }
String root_path() const { return m_root_path; }
- RefPtr<ProjectFile> get_file(const String& path) const;
+ NonnullRefPtr<ProjectFile> get_file(const String& path) const;
void for_each_text_file(Function<void(const ProjectFile&)>) const;
private:
explicit Project(const String& root_path);
+ String to_absolute_path(const String&) const;
+
RefPtr<GUI::FileSystemModel> m_model;
mutable NonnullRefPtrVector<ProjectFile> m_files;