diff --git a/blueprintcompiler/errors.py b/blueprintcompiler/errors.py index 2a14040..e89ec31 100644 --- a/blueprintcompiler/errors.py +++ b/blueprintcompiler/errors.py @@ -128,6 +128,10 @@ class CompileWarning(CompileError): color = Colors.YELLOW +class DeprecatedWarning(CompileWarning): + pass + + class UpgradeWarning(CompileWarning): category = "upgrade" color = Colors.PURPLE diff --git a/blueprintcompiler/language/common.py b/blueprintcompiler/language/common.py index f1c6bb9..e45cddc 100644 --- a/blueprintcompiler/language/common.py +++ b/blueprintcompiler/language/common.py @@ -33,6 +33,7 @@ from ..errors import ( CodeAction, CompileError, CompileWarning, + DeprecatedWarning, MultipleErrors, UpgradeWarning, ) diff --git a/blueprintcompiler/language/gobject_property.py b/blueprintcompiler/language/gobject_property.py index 526b308..68f8c6d 100644 --- a/blueprintcompiler/language/gobject_property.py +++ b/blueprintcompiler/language/gobject_property.py @@ -99,7 +99,7 @@ class Property(AstNode): hints = [] if self.gir_property.deprecated_doc: hints.append(self.gir_property.deprecated_doc) - raise CompileWarning( + raise DeprecatedWarning( f"{self.gir_property.signature} is deprecated", hints=hints, ) diff --git a/blueprintcompiler/language/gobject_signal.py b/blueprintcompiler/language/gobject_signal.py index 1c60bbf..721c443 100644 --- a/blueprintcompiler/language/gobject_signal.py +++ b/blueprintcompiler/language/gobject_signal.py @@ -142,7 +142,7 @@ class Signal(AstNode): hints = [] if self.gir_signal.deprecated_doc: hints.append(self.gir_signal.deprecated_doc) - raise CompileWarning( + raise DeprecatedWarning( f"{self.gir_signal.signature} is deprecated", hints=hints, ) diff --git a/blueprintcompiler/language/types.py b/blueprintcompiler/language/types.py index 1d9911b..e7b1867 100644 --- a/blueprintcompiler/language/types.py +++ b/blueprintcompiler/language/types.py @@ -63,7 +63,7 @@ class TypeName(AstNode): hints = [] if self.gir_type.deprecated_doc: hints.append(self.gir_type.deprecated_doc) - raise CompileWarning( + raise DeprecatedWarning( f"{self.gir_type.full_name} is deprecated", hints=hints, ) diff --git a/blueprintcompiler/lsp.py b/blueprintcompiler/lsp.py index e8c37f3..54a36c8 100644 --- a/blueprintcompiler/lsp.py +++ b/blueprintcompiler/lsp.py @@ -391,6 +391,9 @@ class LanguageServer: else DiagnosticSeverity.Error, } + if isinstance(err, DeprecationWarning): + result["tags"] = [DiagnosticTag.Deprecated] + if len(err.references) > 0: result["relatedInformation"] = [ { diff --git a/blueprintcompiler/lsp_utils.py b/blueprintcompiler/lsp_utils.py index 7f46680..2d1072e 100644 --- a/blueprintcompiler/lsp_utils.py +++ b/blueprintcompiler/lsp_utils.py @@ -119,6 +119,11 @@ class DiagnosticSeverity(enum.IntEnum): Hint = 4 +class DiagnosticTag(enum.IntEnum): + Unnecessary = 1 + Deprecated = 2 + + @dataclass class SemanticToken: start: int diff --git a/tests/test_samples.py b/tests/test_samples.py index 1273805..bacca80 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -29,7 +29,12 @@ from gi.repository import Gtk from blueprintcompiler import decompiler, parser, tokenizer, utils from blueprintcompiler.completions import complete -from blueprintcompiler.errors import CompileError, MultipleErrors, PrintableError +from blueprintcompiler.errors import ( + CompileError, + DeprecatedWarning, + MultipleErrors, + PrintableError, +) from blueprintcompiler.outputs.xml import XmlOutput from blueprintcompiler.tokenizer import Token, TokenType, tokenize @@ -59,7 +64,7 @@ class TestSamples(unittest.TestCase): warnings = [ warning for warning in warnings - if "is deprecated" not in warning.message + if not isinstance(warning, DeprecatedWarning) ] if errors: