@@ -16,13 +16,10 @@ namespace Ark::internal
1616
1717 ImportSolver& ImportSolver::setup (const std::filesystem::path& root, const std::vector<Import>& origin_imports)
1818 {
19- if (is_directory (root))
20- m_root = root;
21- else
22- m_root = root.parent_path ();
19+ m_root = root.parent_path ();
2320
2421 for (const auto & origin_import : std::ranges::reverse_view (origin_imports))
25- m_imports.push (origin_import);
22+ m_imports.push ({ root, origin_import } );
2623
2724 return *this ;
2825 }
@@ -33,27 +30,27 @@ namespace Ark::internal
3330
3431 while (!m_imports.empty ())
3532 {
36- Import import = m_imports.top ();
37- m_logger.debug (" Importing {}" , import .toPackageString ());
33+ ImportWithSource source = m_imports.top ();
34+ m_logger.debug (" Importing {}" , source. import .toPackageString ());
3835
3936 // Remove the top element to process the other imports
4037 // It needs to be removed first because we might be adding
4138 // other imports later and don't want to pop THEM
4239 m_imports.pop ();
43- const auto package = import .toPackageString ();
40+ const auto package = source. import .toPackageString ();
4441
4542 if (m_packages.contains (package))
4643 {
4744 // merge the definition, so that we can generate valid Full Qualified Names in the name & scope resolver
48- m_packages[package].import .with_prefix |= import .with_prefix ;
49- m_packages[package].import .is_glob |= import .is_glob ;
50- for (auto && symbol : import .symbols )
45+ m_packages[package].import .with_prefix |= source. import .with_prefix ;
46+ m_packages[package].import .is_glob |= source. import .is_glob ;
47+ for (auto && symbol : source. import .symbols )
5148 m_packages[package].import .symbols .push_back (symbol);
5249 }
5350 else
5451 {
5552 // NOTE: since the "file" (=root) argument doesn't change between all calls, we could get rid of it
56- std::vector<Import > temp = parseImport (m_root, import );
53+ std::vector<ImportWithSource > temp = parseImport (source. file , source. import );
5754 for (auto & additional_import : std::ranges::reverse_view (temp))
5855 m_imports.push (additional_import);
5956 }
@@ -138,11 +135,11 @@ namespace Ark::internal
138135 return m_ast;
139136 }
140137
141- std::vector<Import > ImportSolver::parseImport (const std::filesystem::path& base_path , const Import& import )
138+ std::vector<ImportSolver::ImportWithSource > ImportSolver::parseImport (const std::filesystem::path& source , const Import& import )
142139 {
143- m_logger.traceStart (fmt::format (" parseImport {}" , base_path .string ()));
140+ m_logger.traceStart (fmt::format (" parseImport {}" , source .string ()));
144141
145- const auto path = findFile (base_path , import );
142+ const auto path = findFile (source , import );
146143 if (path.extension () == " .arkm" ) // Nothing to import in case of modules
147144 {
148145 // Creating an import node that will stay there when visiting the AST and
@@ -151,9 +148,11 @@ namespace Ark::internal
151148 module_node.push_back (Node (Keyword::Import));
152149
153150 auto package_node = Node (NodeType::List);
154- std::ranges::transform (import .package , std::back_inserter (package_node.list ()), [](const std::string& stem) {
155- return Node (NodeType::String, stem);
156- });
151+ std::ranges::transform (
152+ import .package ,
153+ std::back_inserter (package_node.list ()), [](const std::string& stem) {
154+ return Node (NodeType::String, stem);
155+ });
157156 module_node.push_back (package_node);
158157 // empty symbols list
159158 module_node.push_back (Node (NodeType::List));
@@ -177,7 +176,15 @@ namespace Ark::internal
177176 };
178177
179178 m_logger.traceEnd ();
180- return parser.imports ();
179+
180+ auto imports = parser.imports ();
181+ std::vector<ImportWithSource> output;
182+ std::ranges::transform (
183+ imports,
184+ std::back_inserter (output), [&path](const Import& i) {
185+ return ImportWithSource { path, i };
186+ });
187+ return output;
181188 }
182189
183190 std::optional<std::filesystem::path> testExtensions (const std::filesystem::path& folder, const std::string& package_path)
@@ -205,7 +212,7 @@ namespace Ark::internal
205212 // fallback, we couldn't find the file
206213 throw CodeError (
207214 fmt::format (" While processing file {}, couldn't import {}: file not found" ,
208- file.generic_string (), import .toPackageString ()),
215+ file.filename (). string (), import .toPackageString ()),
209216 CodeErrorContext (
210217 file.generic_string (),
211218 import .line ,
0 commit comments