private CodeAnalysisResult BlockedAnalysisResult() { var analysisResult = new CodeAnalysisResult(TextDocument, 0, 0); // if we have a failed initialization attempt, add it to error list if (rhetosProjectContext.InitializationError != null) { analysisResult.DslParserErrors.Add(rhetosProjectContext.InitializationError); } // document doesn't have a valid root path configured if (string.IsNullOrEmpty(RootPathConfiguration?.RootPath)) { var error = string.IsNullOrEmpty(RootPathConfiguration?.Context) ? "" : $" ({RootPathConfiguration.Context})"; var message = $"No valid RhetosProjectRootPath configuration was found for this document{error}. " + "If document is in folder subtree of Rhetos application, it must be built successfully at least once. " + "Otherwise, explicit paths may be set via '// <rhetosProjectRootPath=\"PATH\" />' source code directive or " + "by using 'rhetos-language-services.settings.json' configuration file."; analysisResult.DslParserErrors.Add(new CodeAnalysisError() { Message = message, Severity = CodeAnalysisError.ErrorSeverity.Warning }); } // there is a valid rootPath, but initialize has not been run yet, should be transient error until the next RhetosProjectMonitor cycle else if (!rhetosProjectContext.IsInitialized && rhetosProjectContext.InitializationError == null) { analysisResult.DslParserErrors.Add(new CodeAnalysisError() { Message = "Waiting for Rhetos Project initialization.", Severity = CodeAnalysisError.ErrorSeverity.Warning }); } // document's root path is different than path used to initialize RhetosAppContext else if (rhetosProjectContext.IsInitialized && !string.Equals(rhetosProjectContext.ProjectRootPath, RootPathConfiguration?.RootPath, StringComparison.InvariantCultureIgnoreCase)) { var message = $"Language Services have been initialized with Rhetos app at '{rhetosProjectContext.ProjectRootPath}'. " + $"This document is configured to use different Rhetos app at '{RootPathConfiguration.RootPath}'. No code analysis will be performed. " + "Restart Visual Studio if you want to use a different Rhetos app."; analysisResult.DslParserErrors.Add(new CodeAnalysisError() { Message = message, Severity = CodeAnalysisError.ErrorSeverity.Warning }); } return(analysisResult.AllErrors.Any() ? analysisResult : null); }
private void InitializeResult(LineChr?lineChr) { if (result != null) { throw new InvalidOperationException("Analysis already run."); } if (lineChr == null) { textDocument = fullTextDocument; } else { textDocument = new TextDocument(fullTextDocument.GetTruncatedAtNextEndOfLine(lineChr.Value), fullTextDocument.Uri); } result = lineChr == null ? new CodeAnalysisResult(textDocument, 0, 0) : new CodeAnalysisResult(textDocument, lineChr.Value.Line, lineChr.Value.Chr); }