Example #1
0
        // routines used for a first round of checking for syntactic errors related to how statements can be formatted (e.g. a non-empty statement ending in '}' is certainly incorrect)

        /// <summary>
        /// For any fragment where the code only consistes of whitespace,
        /// adds a warning to the returned diagnostics if such a fragment terminates in a semicolon,
        /// adds an error to the returned diagnostics if it ends in and opening bracket.
        /// Throws an ArgumentNullException if the given diagnostics or fragments are null.
        /// </summary>
        private static IEnumerable <Diagnostic> CheckForEmptyFragments(this IEnumerable <CodeFragment> fragments, string filename)
        {
            if (fragments == null)
            {
                throw new ArgumentNullException(nameof(fragments));
            }
            // opting to not complain about semicolons not following code anywhere in the file (i.e. on any scope)
            var diagnostics = fragments.Where(snippet => snippet.Text.Length == 0 && snippet.FollowedBy == ';')
                              .Select(snippet => Warnings.EmptyStatementWarning(filename, snippet.GetRange().End))
                              .Concat(fragments.Where(snippet => snippet.Text.Length == 0 && snippet.FollowedBy == '{')
                                      .Select(snippet => Errors.MisplacedOpeningBracketError(filename, snippet.GetRange().End)));

            return(diagnostics.ToList()); // in case fragments change
        }
Example #2
0
 private static string Code(QsCompilerDiagnostic msg)
 {
     if (msg.Diagnostic.IsError)
     {
         return(Errors.Error(msg.Code));
     }
     else if (msg.Diagnostic.IsWarning)
     {
         return(Warnings.Warning(msg.Code));
     }
     else if (msg.Diagnostic.IsInformation)
     {
         return(Informations.Information(msg.Code));
     }
     else
     {
         throw new NotImplementedException("Hints are currently not supported - they need to be added to Diagnostics.fs in the QsLanguageProcessor, and here.");
     }
 }