Example #1
0
        public RootPathConfiguration ResolveRootPathForDocument(RhetosDocument rhetosDocument)
        {
            try
            {
                var fromDirective = ResolveRootPathFromDocumentDirective(rhetosDocument);
                if (fromDirective != null && !string.IsNullOrEmpty(fromDirective.RootPath))
                {
                    return(fromDirective);
                }

                var fromConfiguration = GetRootPathFromConfigurationInParentFolders(Path.GetDirectoryName(rhetosDocument.DocumentUri.LocalPath));
                if (fromConfiguration.rootPath != null)
                {
                    return(new RootPathConfiguration(fromConfiguration.rootPath, RootPathConfigurationType.ConfigurationFile, fromConfiguration.configurationPath));
                }

                var fromDetected = GetRootPathInParentFolders(Path.GetDirectoryName(rhetosDocument.DocumentUri.LocalPath));
                if (fromDetected != null)
                {
                    return(new RootPathConfiguration(fromDetected, RootPathConfigurationType.DetectedRhetosApp, fromDetected));
                }
            }
            catch (Exception e)
            {
                return(new RootPathConfiguration(null, RootPathConfigurationType.None, e.Message));
            }

            return(new RootPathConfiguration(null, RootPathConfigurationType.None, null));
        }
Example #2
0
        private CodeAnalysisResult GetAnalysisWithErrorReporting(RhetosDocument rhetosDocument, LineChr?lineChr)
        {
            var analysisResult = rhetosDocument.GetAnalysis(lineChr);

            if (analysisResult.AllErrors.Any())
            {
                Console.WriteLine($"Errors during parsing:");
                Console.WriteLine(string.Join("\n", analysisResult.AllErrors.Select(a => $"\t{a.Code} {a.Message}")));
                //throw new InvalidOperationException($"Result encountered {analysisResult.AllErrors.Count()} errors. Expected 0.");
            }

            return(analysisResult);
        }
Example #3
0
        public CodeAnalysisResult GetSuccessfulAnalysis(RhetosDocument rhetosDocument, LineChr?lineChr = null)
        {
            var analysisResult = rhetosDocument.GetAnalysis(lineChr);

            if (analysisResult.SuccessfulRun)
            {
                return(analysisResult);
            }

            Console.WriteLine("Analysis failed with errors:");
            Console.WriteLine(string.Join("\n", analysisResult.AllErrors.Select(a => $"\t{a.Code} {a.Message}")));
            Assert.Fail($"Analysis failed with {analysisResult.AllErrors.Count()} errors.");
            return(null);
        }
Example #4
0
        public RootPathConfiguration ResolveRootPathFromDocumentDirective(RhetosDocument rhetosDocument)
        {
            try
            {
                var fromDirective = GetRootPathFromText(rhetosDocument.TextDocument.Text);
                if (fromDirective != null)
                {
                    var absolutePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(rhetosDocument.DocumentUri.LocalPath), fromDirective));
                    return(new RootPathConfiguration(absolutePath, RootPathConfigurationType.SourceDirective, rhetosDocument.DocumentUri.LocalPath));
                }

                return(null);
            }
            catch (Exception e)
            {
                return(new RootPathConfiguration(null, RootPathConfigurationType.None, e.Message));
            }
        }
 public RootPathConfiguration ResolveRootPathForDocument(RhetosDocument rhetosDocument)
 {
     return(new RootPathConfiguration(rhetosProjectContext.ProjectRootPath, RootPathConfigurationType.DetectedRhetosApp, ""));
 }