Esempio n. 1
0
        private static CommandOrCodeAction?DisableDiagnostic(DocumentUri documentUri,
                                                             DiagnosticCode diagnosticCode,
                                                             BicepFile bicepFile,
                                                             TextSpan span,
                                                             ImmutableArray <int> lineStarts)
        {
            if (diagnosticCode.String is null)
            {
                return(null);
            }

            var disabledDiagnosticsCache = bicepFile.DisabledDiagnosticsCache;

            (int diagnosticLine, _) = TextCoordinateConverter.GetPosition(bicepFile.LineStarts, span.Position);

            TextEdit?textEdit;
            int      previousLine = diagnosticLine - 1;

            if (disabledDiagnosticsCache.TryGetDisabledNextLineDirective(previousLine) is { } disableNextLineDirectiveEndPositionAndCodes)
            {
                textEdit = new TextEdit
                {
                    Range   = new Range(previousLine, disableNextLineDirectiveEndPositionAndCodes.endPosition, previousLine, disableNextLineDirectiveEndPositionAndCodes.endPosition),
                    NewText = ' ' + diagnosticCode.String
                };
            }
Esempio n. 2
0
        /// <summary>
        /// Asserts that there is a diagnostic with the specified code and source location.
        /// If the assertion succeeded, returns an result object for further fluent assertions.
        /// </summary>
        public DiagnosticAssertResult AssertDiagnosticAt(DiagnosticCode code, TextPosition position)
        {
            var diagnostic = Diagnostics.SingleOrDefault(x => x.Code == code && x.Position == position);

            Assert.That(diagnostic, Is.Not.Null, $"The diagnostic {code} did not exist at " +
                        $"({position.Line},{position.ByteInLine})");

            return(new DiagnosticAssertResult(diagnostic));
        }
Esempio n. 3
0
        /// <summary>
        /// Asserts that there is a diagnostic with the specified code and source location.
        /// If the assertion succeeded, returns an result object for further fluent assertions.
        /// </summary>
        public DiagnosticAssertResult AssertDiagnosticAt(DiagnosticCode code, int line, int offset)
        {
            var diagnostic = Diagnostics.SingleOrDefault(x =>
                                                         x.Code == code && x.Position.Line == line && x.Position.ByteInLine == offset);

            Assert.That(diagnostic, Is.Not.Null, $"The diagnostic {code} did not exist at ({line},{offset})");

            return(new DiagnosticAssertResult(diagnostic));
        }
 public ActionResult Edit(DiagnosticCode diagnosticCode)
 {
     if (ModelState.IsValid)
     {
         _ctx.Entry(diagnosticCode).State = EntityState.Modified;
         _ctx.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(diagnosticCode));
 }
Esempio n. 5
0
 /// <summary>
 /// Creates a compilation diagnostic with diagnostic code and source position.
 /// </summary>
 /// <param name="code">The diagnostic code.</param>
 /// <param name="position">The position within the source file.</param>
 /// <param name="filename">The source file name (optional if no associated file).</param>
 /// <param name="moduleName">The module name.</param>
 /// <param name="actual">Optional actual value encountered.</param>
 /// <param name="expected">Optional expected value.</param>
 public Diagnostic(DiagnosticCode code, TextPosition position,
                   string?filename, string moduleName,
                   string?actual, string?expected)
 {
     Code     = code;
     Position = position;
     Filename = filename;
     Module   = moduleName;
     Actual   = actual;
     Expected = expected;
 }
Esempio n. 6
0
        public void SimpleTest(string expected)
        {
            var model  = new DiagnosticCode();
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = JsonConvert.DeserializeObject <DiagnosticCode>(expected);

            deresult.ShouldBeEquivalentTo(model);
        }
        public ActionResult DeleteDiagnoticCode(int id)
        {
            DiagnosticCode diagnosticCode = _ctx.DiagnosticCodes.Find(id);

            if (diagnosticCode != null)
            {
                _ctx.DiagnosticCodes.Remove(diagnosticCode);
            }
            _ctx.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 8
0
        public void SimpleTest(string expected)
        {
            var model  = new DiagnosticCode();
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject <DiagnosticCode>(expected);

            deresult.Should().BeEquivalentTo(model);
        }
Esempio n. 9
0
        //Create DiagnosisCode
        public void CreateDiagnosisCode(DiagnosticCodeCreate model)
        {
            var entity = new DiagnosticCode()
            {
                Name        = model.Name,
                ICD10Code   = model.ICD10Code,
                Price       = model.Price,
                DiagnosisId = model.DiagnosisId
            };

            _ctx.DiagnosticCodes.Add(entity);
            _ctx.SaveChanges();
        }
Esempio n. 10
0
 /// <summary>
 /// Eats a token and returns whether it is of the specified type.
 /// If it is not, additionally logs an error.
 /// </summary>
 /// <param name="expectedType">The expected token type.</param>
 /// <param name="errorCode">The error code to log if the token is not of the expected type.</param>
 private bool ExpectToken(TokenType expectedType, DiagnosticCode errorCode)
 {
     if (_lexer.PeekTokenType() == expectedType)
     {
         _lexer.GetToken();
         return(true);
     }
     else
     {
         _diagnosticSink.Add(errorCode, _lexer.Position, ReadTokenIntoString());
         return(false);
     }
 }
        public static string ToDisplayString(this DiagnosticCode kind)
        {
            switch (kind)
            {
            case DiagnosticCode.UnrecognizedCharacter: return(DiagnosticsResources.UnrecognizedCharacter);

            case DiagnosticCode.UnterminatedStringLiteral: return(DiagnosticsResources.UnterminatedStringLiteral);

            case DiagnosticCode.UnexpectedTokenFound: return(DiagnosticsResources.UnexpectedTokenFound);

            case DiagnosticCode.UnexpectedEndOfStream: return(DiagnosticsResources.UnexpectedEndOfStream);

            case DiagnosticCode.UnexpectedStatementInsteadOfNewLine: return(DiagnosticsResources.UnexpectedStatementInsteadOfNewLine);

            case DiagnosticCode.UnexpectedTokenInsteadOfStatement: return(DiagnosticsResources.UnexpectedTokenInsteadOfStatement);

            case DiagnosticCode.TwoSubModulesWithTheSameName: return(DiagnosticsResources.TwoSubModulesWithTheSameName);

            case DiagnosticCode.TwoLabelsWithTheSameName: return(DiagnosticsResources.TwoLabelsWithTheSameName);

            case DiagnosticCode.GoToUndefinedLabel: return(DiagnosticsResources.GoToUndefinedLabel);

            case DiagnosticCode.PropertyHasNoSetter: return(DiagnosticsResources.PropertyHasNoSetter);

            case DiagnosticCode.AssigningNonSubModuleToEvent: return(DiagnosticsResources.AssigningNonSubModuleToEvent);

            case DiagnosticCode.UnassignedExpressionStatement: return(DiagnosticsResources.UnassignedExpressionStatement);

            case DiagnosticCode.InvalidExpressionStatement: return(DiagnosticsResources.InvalidExpressionStatement);

            case DiagnosticCode.UnsupportedArrayBaseExpression: return(DiagnosticsResources.UnsupportedArrayBaseExpression);

            case DiagnosticCode.ValueIsNotANumber: return(DiagnosticsResources.ValueIsNotANumber);

            case DiagnosticCode.UnsupportedDotBaseExpression: return(DiagnosticsResources.UnsupportedDotBaseExpression);

            case DiagnosticCode.ExpectedExpressionWithAValue: return(DiagnosticsResources.ExpectedExpressionWithAValue);

            case DiagnosticCode.LibraryMemberNotFound: return(DiagnosticsResources.LibraryMemberNotFound);

            case DiagnosticCode.UnexpectedArgumentsCount: return(DiagnosticsResources.UnexpectedArgumentsCount);

            case DiagnosticCode.UnsupportedInvocationBaseExpression: return(DiagnosticsResources.UnsupportedInvocationBaseExpression);

            case DiagnosticCode.LibraryMemberDeprecatedFromOlderVersion: return(DiagnosticsResources.LibraryMemberDeprecatedFromOlderVersion);

            case DiagnosticCode.LibraryMemberNeedsDesktop: return(DiagnosticsResources.LibraryMemberNeedsDesktop);

            default: throw ExceptionUtilities.UnexpectedValue(kind);
            }
        }
Esempio n. 12
0
 /// <summary>
 /// Eats a token and returns whether it is an identifier.
 /// If it is not, additionally logs an error.
 /// </summary>
 /// <param name="errorCode">The error code to log if the token is not an identifier.</param>
 /// <param name="identifier">The read identifier.</param>
 private bool ExpectIdentifier(DiagnosticCode errorCode, out string identifier)
 {
     if (_lexer.PeekTokenType() == TokenType.Identifier)
     {
         identifier = ReadTokenIntoString();
         return(true);
     }
     else
     {
         _diagnosticSink.Add(errorCode, _lexer.Position, ReadTokenIntoString());
         identifier = string.Empty;
         return(false);
     }
 }
Esempio n. 13
0
        private static DiagnosticDescriptor Rule(DiagnosticCode diagnosticCode, string title, Category category,
                                                 DiagnosticSeverity defaultSeverity, LocalizableString messageFormat = null, LocalizableString description = null)
        {
            var diagnosticName = DiagnosticCodeMapping.GetOrAdd(diagnosticCode, d => d.ToString());
            var categoryName   = CategoryMapping.GetOrAdd(category, c => c.ToString());

            return(new DiagnosticDescriptor(
                       id: diagnosticName,
                       title: title,
                       messageFormat: messageFormat ?? title,
                       category: categoryName,
                       defaultSeverity: defaultSeverity,
                       isEnabledByDefault: true,
                       description: description));
        }
Esempio n. 14
0
        private bool TryParseType(DiagnosticCode noIdentifierError, [NotNullWhen(true)] out TypeSyntax?type)
        {
            type = null;

            if (!ExpectIdentifier(noIdentifierError, out var typeName))
            {
                return(false);
            }
            if (!NameParsing.IsValidFullName(typeName))
            {
                _diagnosticSink.Add(DiagnosticCode.InvalidTypeName, _lexer.LastPosition, typeName);
                return(false);
            }

            type = new TypeNameSyntax(typeName, _lexer.LastPosition);
            return(true);
        }
Esempio n. 15
0
 private static DiagnosticDescriptor CreateDescriptor(DiagnosticCode code, string title, string messageFormat, DiagnosticSeverity severity = DiagnosticSeverity.Error)
 {
     string[] tags = severity == DiagnosticSeverity.Error ? new[] { WellKnownDiagnosticTags.NotConfigurable } : Array.Empty <string>();
     return(new DiagnosticDescriptor(code.Format(), title, messageFormat, "RestEaseGeneration", severity, isEnabledByDefault: true, customTags: tags));
 }
Esempio n. 16
0
 public void Add(DiagnosticCode code, TextPosition position)
 {
     _diagnostics.Add(new Diagnostic(code, position, _filename, _moduleName, null, null));
 }
Esempio n. 17
0
        public void Add(DiagnosticCode code, TextPosition position, string?actual, string?expected)
        {
            var diagnostic = new Diagnostic(code, position, string.Empty, string.Empty, actual, expected);

            _diagnostics.Add(diagnostic);
        }
Esempio n. 18
0
 /// <summary>
 /// Format the code as e.g. REST001
 /// </summary>
 public static string Format(this DiagnosticCode code)
 {
     return($"REST{(int)code:D3}");
 }
Esempio n. 19
0
		private Token CreateBadToken (string spelling, DiagnosticCode code)
		{
			return new BadToken (spelling, code, position, Line, Column, FirstOnLine);
		}
Esempio n. 20
0
 protected void Error(DiagnosticCode diagnostic, FileLocation location)
 {
     ReceiveDiagnostic(new DiagnosticInfo(diagnostic, location), true);
 }
Esempio n. 21
0
 public Diagnostic(DiagnosticCode code, TextRange range, params string[] args)
 {
     this.Code  = code;
     this.Range = range;
     this.args  = args;
 }
Esempio n. 22
0
		public BadToken(string Spelling, DiagnosticCode Diagnostic, int StartCharacterPosition, int StartLine, int StartColumn, bool FirstOnLine)
			: base(Token.Type.Bad, StartCharacterPosition, StartLine, StartColumn, FirstOnLine)
		{
			this.Spelling = Spelling;
			this.Diagnostic = Diagnostic;
		}
Esempio n. 23
0
 public DiagMsg(DiagnosticCode code)
 {
     Code = code;
     _msgArgs = null;
 }
Esempio n. 24
0
 public I18nTextCompileException(DiagnosticCode code, string message, string filePath = null, int linePos = 0) : base(message)
 {
     this.Code     = code;
     this.FilePath = filePath;
     this.LinePos  = linePos;
 }
Esempio n. 25
0
 public void Add(DiagnosticCode code, TextPosition position, string?actual, string?expected)
 {
     _diagnostics.Add(new Diagnostic(code, position, _filename, _moduleName, actual, expected));
 }
Esempio n. 26
0
 public DiagnosticFacts(DiagnosticCode code)
 {
     Description = Resources.ResourceManager.GetString("DESCRIPTION_" + code.ToString());
     Enum.TryParse <Severity>(Resources.ResourceManager.GetString("SEVERITY_" + code.ToString()), out var severity);
     Severity = severity;
 }
Esempio n. 27
0
 /// <summary>
 /// Initialises a new instance of the <see cref="ImplementationCreationException"/> class
 /// </summary>
 /// <param name="code">Code of this error</param>
 /// <param name="message">Message to use</param>
 public ImplementationCreationException(DiagnosticCode code, string message)
     : base(message)
 {
     this.Code = code;
 }
Esempio n. 28
0
 public void Add(DiagnosticCode code, TextPosition position)
 {
     DiagnosticCount++;
 }
Esempio n. 29
0
 public static void ReceiveDiagnostic(this IDiagnosticReceiver receiver, DiagnosticCode code, FileLocation?location, bool isError) =>
 receiver.ReceiveDiagnostic(new DiagnosticInfo(code, location), isError);
Esempio n. 30
0
 public void Add(DiagnosticCode code, TextPosition position, string?actual, string?expected)
 {
     DiagnosticCount++;
 }
Esempio n. 31
0
        public void Add(DiagnosticCode code, TextPosition position)
        {
            var diagnostic = new Diagnostic(code, position, string.Empty, string.Empty, null, null);

            _diagnostics.Add(diagnostic);
        }
Esempio n. 32
0
		private void Error (DiagnosticCode code , TextSpan loc)
		{
			if (current.Kind == Token.Type.Bad)
				code = ((BadToken)current).Diagnostic;
			diagnostics.Add (new Diagnostic (code, loc));
		}
Esempio n. 33
0
 public Diagnostic(DiagnosticCode Code, TextSpan Location)
 {
     this.Code     = Code;
     this.Location = Location;
 }
Esempio n. 34
0
 public BadToken(string Spelling, DiagnosticCode Diagnostic, int StartCharacterPosition, int StartLine, int StartColumn, bool FirstOnLine)
     : base(Token.Type.Bad, StartCharacterPosition, StartLine, StartColumn, FirstOnLine)
 {
     this.Spelling   = Spelling;
     this.Diagnostic = Diagnostic;
 }
Esempio n. 35
0
		public Diagnostic(DiagnosticCode Code, TextSpan Location)
		{
			this.Code = Code;
			this.Location = Location;
		}
Esempio n. 36
0
 public DiagMsg(DiagnosticCode code, params string[] msgArgs)
 {
     Code = code;
     _msgArgs = msgArgs;
 }