private CodeAnalysisResult BlockedAnalysisResult() { // we will check document root path configuration only if appContext is not initialized from current domain // this allows for integration scenarios such as unit testing if (rhetosAppContext.IsInitializedFromCurrentDomain) { return(null); } var analysisResult = new CodeAnalysisResult(TextDocument, 0, 0); var isInitialized = rhetosAppContext.IsInitialized; // if we have a failed initialization attempt, add it to error list if (RhetosAppContextInitializeError != null) { analysisResult.DslParserErrors.Add(RhetosAppContextInitializeError); } // 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 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 (!isInitialized && RhetosAppContextInitializeError == 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 (isInitialized && !string.Equals(rhetosAppContext.RootPath, RootPathConfiguration?.RootPath, StringComparison.InvariantCultureIgnoreCase)) { var message = $"Language Services have been initialized with Rhetos app at '{rhetosAppContext.RootPath}'. " + $"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); }