lsp: Mark deprecation warnings

Some editors use different styling (e.g. strikethrough) for deprecation
warnings.
This commit is contained in:
James Westman 2023-07-23 18:04:10 -05:00
parent 94db929f74
commit 950b141d26
8 changed files with 23 additions and 5 deletions

View file

@ -128,6 +128,10 @@ class CompileWarning(CompileError):
color = Colors.YELLOW color = Colors.YELLOW
class DeprecatedWarning(CompileWarning):
pass
class UpgradeWarning(CompileWarning): class UpgradeWarning(CompileWarning):
category = "upgrade" category = "upgrade"
color = Colors.PURPLE color = Colors.PURPLE

View file

@ -33,6 +33,7 @@ from ..errors import (
CodeAction, CodeAction,
CompileError, CompileError,
CompileWarning, CompileWarning,
DeprecatedWarning,
MultipleErrors, MultipleErrors,
UpgradeWarning, UpgradeWarning,
) )

View file

@ -99,7 +99,7 @@ class Property(AstNode):
hints = [] hints = []
if self.gir_property.deprecated_doc: if self.gir_property.deprecated_doc:
hints.append(self.gir_property.deprecated_doc) hints.append(self.gir_property.deprecated_doc)
raise CompileWarning( raise DeprecatedWarning(
f"{self.gir_property.signature} is deprecated", f"{self.gir_property.signature} is deprecated",
hints=hints, hints=hints,
) )

View file

@ -142,7 +142,7 @@ class Signal(AstNode):
hints = [] hints = []
if self.gir_signal.deprecated_doc: if self.gir_signal.deprecated_doc:
hints.append(self.gir_signal.deprecated_doc) hints.append(self.gir_signal.deprecated_doc)
raise CompileWarning( raise DeprecatedWarning(
f"{self.gir_signal.signature} is deprecated", f"{self.gir_signal.signature} is deprecated",
hints=hints, hints=hints,
) )

View file

@ -63,7 +63,7 @@ class TypeName(AstNode):
hints = [] hints = []
if self.gir_type.deprecated_doc: if self.gir_type.deprecated_doc:
hints.append(self.gir_type.deprecated_doc) hints.append(self.gir_type.deprecated_doc)
raise CompileWarning( raise DeprecatedWarning(
f"{self.gir_type.full_name} is deprecated", f"{self.gir_type.full_name} is deprecated",
hints=hints, hints=hints,
) )

View file

@ -391,6 +391,9 @@ class LanguageServer:
else DiagnosticSeverity.Error, else DiagnosticSeverity.Error,
} }
if isinstance(err, DeprecationWarning):
result["tags"] = [DiagnosticTag.Deprecated]
if len(err.references) > 0: if len(err.references) > 0:
result["relatedInformation"] = [ result["relatedInformation"] = [
{ {

View file

@ -119,6 +119,11 @@ class DiagnosticSeverity(enum.IntEnum):
Hint = 4 Hint = 4
class DiagnosticTag(enum.IntEnum):
Unnecessary = 1
Deprecated = 2
@dataclass @dataclass
class SemanticToken: class SemanticToken:
start: int start: int

View file

@ -29,7 +29,12 @@ from gi.repository import Gtk
from blueprintcompiler import decompiler, parser, tokenizer, utils from blueprintcompiler import decompiler, parser, tokenizer, utils
from blueprintcompiler.completions import complete 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.outputs.xml import XmlOutput
from blueprintcompiler.tokenizer import Token, TokenType, tokenize from blueprintcompiler.tokenizer import Token, TokenType, tokenize
@ -59,7 +64,7 @@ class TestSamples(unittest.TestCase):
warnings = [ warnings = [
warning warning
for warning in warnings for warning in warnings
if "is deprecated" not in warning.message if not isinstance(warning, DeprecatedWarning)
] ]
if errors: if errors: