@@ -70,9 +70,15 @@ static bool reportError(
7070{
7171 auto * fileResolver = static_cast <WorkspaceFileResolver*>(frontend.fileResolver );
7272 std::filesystem::path rootUriPath = fileResolver->rootUri .fsPath ();
73- std::string humanReadableName = fileResolver->getHumanReadableModuleName (error.moduleName );
7473 auto path = fileResolver->resolveToRealPath (error.moduleName );
7574
75+ // For consistency, we want to map the error.moduleName to a relative path (if it is a real path)
76+ Luau::ModuleName errorFriendlyName = error.moduleName ;
77+ if (!fileResolver->isVirtualPath (error.moduleName ))
78+ errorFriendlyName = std::filesystem::proximate (*path, rootUriPath).generic_string ();
79+
80+ std::string humanReadableName = fileResolver->getHumanReadableModuleName (errorFriendlyName);
81+
7682 if (isIgnoredFile (rootUriPath, *path, ignoreGlobPatterns))
7783 return false ;
7884
@@ -90,16 +96,18 @@ static void reportWarning(ReportFormat format, const char* name, const Luau::Lin
9096 report (format, name, warning.location , Luau::LintWarning::getName (warning.code ), warning.text .c_str ());
9197}
9298
93- static bool analyzeFile (Luau::Frontend& frontend, const char * name, ReportFormat format, bool annotate, std::vector<std::string>& ignoreGlobPatterns)
99+ static bool analyzeFile (
100+ Luau::Frontend& frontend, const std::filesystem::path& path, ReportFormat format, bool annotate, std::vector<std::string>& ignoreGlobPatterns)
94101{
95102 Luau::CheckResult cr;
103+ Luau::ModuleName name = path.generic_string ();
96104
97105 if (frontend.isDirty (name))
98106 cr = frontend.check (name);
99107
100108 if (!frontend.getSourceModule (name))
101109 {
102- fprintf (stderr, " Error opening %s \n " , name) ;
110+ std::cerr << " Error opening " << name << " \n " ;
103111 return false ;
104112 }
105113
@@ -109,7 +117,9 @@ static bool analyzeFile(Luau::Frontend& frontend, const char* name, ReportFormat
109117
110118 Luau::LintResult lr = frontend.lint (name);
111119
112- std::string humanReadableName = frontend.fileResolver ->getHumanReadableModuleName (name);
120+ // For the human readable module name, we use a relative version
121+ auto errorFriendlyName = std::filesystem::proximate (path).generic_string ();
122+ std::string humanReadableName = frontend.fileResolver ->getHumanReadableModuleName (errorFriendlyName);
113123 for (auto & error : lr.errors )
114124 reportWarning (format, humanReadableName.c_str (), error);
115125 for (auto & warning : lr.warnings )
@@ -168,6 +178,11 @@ int startAnalyze(int argc, char** argv)
168178 else
169179 {
170180 auto path = std::filesystem::path (argv[i]);
181+
182+ // If the path is not absolute, then we want to construct it into an absolute path
183+ // by appending it to the current working directory
184+ path = std::filesystem::absolute (path);
185+
171186 if (path != " -" && !std::filesystem::exists (path))
172187 {
173188 std::cerr << " Cannot get " << path << " : path does not exist\n " ;
@@ -293,7 +308,7 @@ int startAnalyze(int argc, char** argv)
293308 int failed = 0 ;
294309
295310 for (const std::filesystem::path& path : files)
296- failed += !analyzeFile (frontend, path. relative_path (). generic_string (). c_str () , format, annotate, ignoreGlobPatterns);
311+ failed += !analyzeFile (frontend, path, format, annotate, ignoreGlobPatterns);
297312
298313 if (!fileResolver.configErrors .empty ())
299314 {
0 commit comments