From a689150a8b6536fdaa7822585ec661cc83e291ec Mon Sep 17 00:00:00 2001 From: James Westman Date: Thu, 25 Jan 2024 20:02:02 -0600 Subject: [PATCH] errors: Print code actions in error message Previously they were only exposed by the language server, but now the command line will print the old and new text. --- blueprintcompiler/errors.py | 10 ++++++++++ docs/index.rst | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/blueprintcompiler/errors.py b/blueprintcompiler/errors.py index 73fd45d..a28c05d 100644 --- a/blueprintcompiler/errors.py +++ b/blueprintcompiler/errors.py @@ -107,6 +107,16 @@ at {filename} line {line_num} column {col_num}: for hint in self.hints: stream.write(f"{Colors.FAINT}hint: {hint}{Colors.CLEAR}\n") + for i, action in enumerate(self.actions): + old = ( + action.edit_range.text + if action.edit_range is not None + else self.range.text + ) + stream.write( + f"suggestion: replace {Colors.RED}{old}{Colors.CLEAR} with {Colors.GREEN}{action.replace_with}{Colors.CLEAR}\n" + ) + for ref in self.references: line_num, col_num = utils.idx_to_pos(ref.range.start + 1, code) line = code.splitlines(True)[line_num] diff --git a/docs/index.rst b/docs/index.rst index 9347c7b..06547c2 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -26,7 +26,7 @@ Blueprint is a markup language and compiler for GTK 4 user interfaces. using Gtk 4.0; - template $MyAppWindow : ApplicationWindow { + template MyAppWindow : ApplicationWindow { default-width: 600; default-height: 300; title: _("Hello, Blueprint!"); @@ -35,7 +35,7 @@ Blueprint is a markup language and compiler for GTK 4 user interfaces. HeaderBar {} Label { - label: bind template.main_text; + label: bind MyAppWindow.main_text; } }