public DiagnosticDependencyModel(
            string originalItemSpec,
            DiagnosticMessageSeverity severity,
            string code,
            string message,
            bool isVisible,
            IImmutableDictionary <string, string> properties)
            : base(
                originalItemSpec,
                originalItemSpec,
                flags: severity == DiagnosticMessageSeverity.Error
                    ? s_errorFlags
                    : s_warningFlags,
                isResolved: false,
                isImplicit: false,
                properties: properties,
                isTopLevel: false,
                isVisible: isVisible)
        {
            Requires.NotNullOrEmpty(originalItemSpec, nameof(originalItemSpec));
            Requires.NotNullOrEmpty(message, nameof(message));

            _severity = severity;

            Name    = message;
            Caption = string.IsNullOrWhiteSpace(code) ? message : string.Concat(code.ToUpperInvariant(), " ", message);
        }
Esempio n. 2
0
        private void AddDiagnostics(List <DiagnosticMessage> messages,
                                    LibraryDescription library,
                                    string message,
                                    DiagnosticMessageSeverity severity,
                                    string errorCode)
        {
            // A (in project.json) -> B (unresolved) (not in project.json)
            foreach (var source in GetRangesWithSourceLocations(library).Distinct())
            {
                // We only care about things requested in this project
                if (!string.Equals(_projectPath, source.SourceFilePath))
                {
                    continue;
                }

                messages.Add(
                    new DiagnosticMessage(
                        errorCode,
                        message,
                        source.SourceFilePath,
                        severity,
                        source.SourceLine,
                        source.SourceColumn,
                        library));
            }
        }
Esempio n. 3
0
        public DiagnosticDependencyModel(
            string providerType,
            string originalItemSpec,
            DiagnosticMessageSeverity severity,
            string code,
            string message,
            ProjectTreeFlags flags,
            bool isVisible,
            IImmutableDictionary <string, string> properties)
            : base(providerType, originalItemSpec, originalItemSpec, flags, resolved: false, isImplicit: false, properties: properties)
        {
            Requires.NotNullOrEmpty(originalItemSpec, nameof(originalItemSpec));
            Requires.NotNullOrEmpty(message, nameof(message));

            code     = code ?? string.Empty;
            Name     = message;
            Caption  = $"{code.ToUpperInvariant()} {message}".TrimStart();
            TopLevel = false;
            Visible  = isVisible;
            Flags    = Flags.Union(DependencyTreeFlags.DiagnosticNodeFlags);

            if (severity == DiagnosticMessageSeverity.Error)
            {
                IconSet  = s_errorIconSet;
                Flags    = Flags.Union(DependencyTreeFlags.DiagnosticErrorNodeFlags);
                Priority = Dependency.DiagnosticsErrorNodePriority;
            }
            else
            {
                IconSet  = s_warningIconSet;
                Flags    = Flags.Union(DependencyTreeFlags.DiagnosticWarningNodeFlags);
                Priority = Dependency.DiagnosticsWarningNodePriority;
            }
        }
Esempio n. 4
0
 public FSharpDiagnosticMessage(
     string errorCode,
     int startColumn,
     int startLine,
     string filePath,
     string message,
     DiagnosticMessageSeverity severity)
     : base(errorCode, message, filePath, severity, startLine, startColumn)
 {
 }
Esempio n. 5
0
 public ITaskItem Add(string diagnosticCode, string message, string filePath, DiagnosticMessageSeverity severity, int startLine, int startColumn)
 => Add(
     diagnosticCode,
     message,
     filePath,
     severity,
     startLine,
     startColumn,
     targetFrameworkMoniker: null,
     packageId: null);
   public FSharpDiagnosticMessage(
 string errorCode,
 int startColumn,
 int startLine,
 string filePath,
 string message,
 DiagnosticMessageSeverity severity)
       : base(errorCode, message, filePath, severity, startLine, startColumn)
   {
   }
Esempio n. 7
0
 public DiagnosticMessage(string message, string filePath, DiagnosticMessageSeverity severity, int startLine, int startColumn)
     : this(
         message,
         $"{filePath}({startLine},{startColumn}): {severity.ToString().ToLowerInvariant()}: {message}",
         filePath,
         severity,
         startLine,
         startColumn,
         endLine : startLine,
         endColumn : startColumn)
 {
 }
Esempio n. 8
0
 public DiagnosticMessage(string errorCode, string message, string filePath, DiagnosticMessageSeverity severity, int startLine, int startColumn, object source)
     : this(errorCode,
             message,
             $"{filePath}({startLine},{startColumn}): {severity.ToString().ToLowerInvariant()} {errorCode}: {message}",
             filePath,
             severity,
             startLine,
             startColumn,
             endLine: startLine,
             endColumn: startColumn,
             source: source)
 {
 }
Esempio n. 9
0
 public DiagnosticMessage(string errorCode, string message, string formattedMessage, string filePath, 
                          DiagnosticMessageSeverity severity, int startLine, int startColumn, int endLine, int endColumn)
     : this(errorCode, 
            message,
            formattedMessage,
            filePath,
            severity,
            startLine,
            startColumn,
            endLine,
            endColumn,
            source: null)
 {
 }
Esempio n. 10
0
 public DiagnosticMessage(string errorCode, string message, string filePath, DiagnosticMessageSeverity severity, int startLine, int startColumn, object source)
     : this(
         errorCode,
         message,
         $"{filePath}({startLine},{startColumn}): {severity.ToString().ToLowerInvariant()} {errorCode}: {message}",
         filePath,
         severity,
         startLine,
         startColumn,
         endLine : startLine,
         endColumn : startColumn,
         source : source)
 {
 }
Esempio n. 11
0
 public DiagnosticMessage(string errorCode, string message, string formattedMessage, string filePath,
                          DiagnosticMessageSeverity severity, int startLine, int startColumn, int endLine, int endColumn)
     : this(errorCode,
            message,
            formattedMessage,
            filePath,
            severity,
            startLine,
            startColumn,
            endLine,
            endColumn,
            source : null)
 {
 }
Esempio n. 12
0
        public ITaskItem Add(
            string diagnosticCode,
            string message,
            string filePath,
            DiagnosticMessageSeverity severity,
            int startLine,
            int startColumn,
            int endLine,
            int endColumn,
            string targetFrameworkMoniker,
            string packageId,
            bool logToMSBuild = true)
        {
            string itemspec =
                (string.IsNullOrEmpty(targetFrameworkMoniker) ? string.Empty : $"{targetFrameworkMoniker}/") +
                (string.IsNullOrEmpty(packageId) ? string.Empty : $"{packageId}/") +
                diagnosticCode;

            var diagnostic = new TaskItem(itemspec, new Dictionary <string, string>
            {
                { MetadataKeys.DiagnosticCode, diagnosticCode },
                { MetadataKeys.Message, message },
                { MetadataKeys.FilePath, filePath ?? string.Empty },
                { MetadataKeys.Severity, severity.ToString() },

                { MetadataKeys.StartLine, startLine.ToString() },
                { MetadataKeys.StartColumn, startColumn.ToString() },
                { MetadataKeys.EndLine, endLine.ToString() },
                { MetadataKeys.EndColumn, endColumn.ToString() },

                { MetadataKeys.ParentTarget, targetFrameworkMoniker ?? string.Empty },
                { MetadataKeys.ParentPackage, packageId ?? string.Empty },
            });

            _diagnosticMessages.Add(diagnostic);

            if (logToMSBuild)
            {
                LogToMSBuild(diagnosticCode, message, filePath, severity, startLine, startColumn, endLine, endColumn);
            }

            return(diagnostic);
        }
Esempio n. 13
0
 public DiagnosticMessage(
     string message,
     string formattedMessage,
     string filePath,
     DiagnosticMessageSeverity severity,
     int startLine,
     int startColumn,
     int endLine,
     int endColumn)
 {
     Message          = message;
     SourceFilePath   = filePath;
     Severity         = severity;
     StartLine        = startLine;
     EndLine          = endLine;
     StartColumn      = startColumn;
     EndColumn        = endColumn;
     FormattedMessage = formattedMessage;
 }
Esempio n. 14
0
 public ITaskItem Add(
     string diagnosticCode,
     string message,
     string filePath,
     DiagnosticMessageSeverity severity,
     int startLine,
     int startColumn,
     string targetFrameworkMoniker,
     string packageId,
     bool logToMSBuild = true)
 => Add(
     diagnosticCode,
     message,
     filePath,
     severity,
     startLine,
     startColumn,
     endLine: startLine,
     endColumn: startColumn,
     targetFrameworkMoniker: targetFrameworkMoniker,
     packageId: packageId,
     logToMSBuild: logToMSBuild);
Esempio n. 15
0
 public DiagnosticMessage(
     string errorCode,
     string message,
     string formattedMessage,
     string filePath,
     DiagnosticMessageSeverity severity,
     int startLine,
     int startColumn,
     int endLine,
     int endColumn,
     object source)
 {
     ErrorCode        = errorCode;
     Message          = message;
     SourceFilePath   = filePath;
     Severity         = severity;
     StartLine        = startLine;
     EndLine          = endLine;
     StartColumn      = startColumn;
     EndColumn        = endColumn;
     FormattedMessage = formattedMessage;
     Source           = source;
 }
Esempio n. 16
0
        private static void AddDeprecatedDiagnosticMessage(
            JObject rawProject,
            Project project,
            string option,
            string message,
            DiagnosticMessageSeverity severity = DiagnosticMessageSeverity.Warning)
        {
            var lineInfo = rawProject.Value <IJsonLineInfo>(option);

            if (lineInfo == null)
            {
                return;
            }

            project.Diagnostics.Add(
                new DiagnosticMessage(
                    ErrorCodes.DOTNET1015,
                    $"The '{option}' option is deprecated. Use {message} instead.",
                    project.ProjectFilePath,
                    severity,
                    lineInfo.LineNumber,
                    lineInfo.LinePosition));
        }
Esempio n. 17
0
 public DiagnosticMessage(
     string errorCode,
     string message,
     string formattedMessage,
     string filePath,
     DiagnosticMessageSeverity severity,
     int startLine,
     int startColumn,
     int endLine,
     int endColumn,
     object source)
 {
     ErrorCode = errorCode;
     Message = message;
     SourceFilePath = filePath;
     Severity = severity;
     StartLine = startLine;
     EndLine = endLine;
     StartColumn = startColumn;
     EndColumn = endColumn;
     FormattedMessage = formattedMessage;
     Source = source;
 }
Esempio n. 18
0
        private void AddDiagnostics(List<DiagnosticMessage> messages, 
                                    LibraryDescription library, 
                                    string message, 
                                    DiagnosticMessageSeverity severity, 
                                    string errorCode)
        {
            // A (in project.json) -> B (unresolved) (not in project.json)
            foreach (var source in GetRangesWithSourceLocations(library).Distinct())
            {
                messages.Add(
                    new DiagnosticMessage(
                        errorCode,
                        message,
                        source.SourceFilePath,
                        severity,
                        source.SourceLine,
                        source.SourceColumn,
                        library));

            }
        }
Esempio n. 19
0
 public ITaskItem Add(string diagnosticCode, string message, string filePath, DiagnosticMessageSeverity severity)
 => Add(diagnosticCode, message, filePath, severity, startLine: 1, startColumn: 0);
Esempio n. 20
0
        private void AddDiagnostics(List<DiagnosticMessage> messages, 
                                    LibraryDescription library, 
                                    string message, 
                                    DiagnosticMessageSeverity severity, 
                                    string errorCode)
        {
            // A (in project.json) -> B (unresolved) (not in project.json)
            foreach (var source in GetRangesWithSourceLocations(library).Distinct())
            {
                // We only care about things requested in this project
                if (!string.Equals(_projectPath, source.SourceFilePath))
                {
                    continue;
                }

                messages.Add(
                    new DiagnosticMessage(
                        errorCode,
                        message,
                        source.SourceFilePath,
                        severity,
                        source.SourceLine,
                        source.SourceColumn,
                        library));

            }
        }
Esempio n. 21
0
 public DiagnosticMessage(string errorCode, string message, string filePath, DiagnosticMessageSeverity severity)
     : this(errorCode, message, filePath, severity, startLine : 1, startColumn : 0)
 {
 }
Esempio n. 22
0
        private void LogToMSBuild(string diagnosticCode, string message, string filePath, DiagnosticMessageSeverity severity, int startLine, int startColumn, int endLine, int endColumn)
        {
            switch (severity)
            {
            case DiagnosticMessageSeverity.Error:
                _log.LogError(
                    subcategory: null,
                    errorCode: diagnosticCode,
                    helpKeyword: null,
                    file: filePath,
                    lineNumber: startLine,
                    columnNumber: startColumn,
                    endLineNumber: endLine,
                    endColumnNumber: endColumn,
                    message: message);
                break;

            case DiagnosticMessageSeverity.Warning:
                _log.LogWarning(
                    subcategory: null,
                    warningCode: diagnosticCode,
                    helpKeyword: null,
                    file: filePath,
                    lineNumber: startLine,
                    columnNumber: startColumn,
                    endLineNumber: endLine,
                    endColumnNumber: endColumn,
                    message: message);
                break;

            case DiagnosticMessageSeverity.Info:
                _log.LogMessage(
                    subcategory: null,
                    code: diagnosticCode,
                    helpKeyword: null,
                    file: filePath,
                    lineNumber: startLine,
                    columnNumber: startColumn,
                    endLineNumber: endLine,
                    endColumnNumber: endColumn,
                    importance: MessageImportance.Normal,
                    message: message);
                break;
            }
        }
Esempio n. 23
0
 public DiagnosticMessage(string errorCode, string message, string filePath, DiagnosticMessageSeverity severity)
     : this(errorCode, message, filePath, severity, startLine: 1, startColumn: 0)
 {
 }