mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
lsp: Add code actions
"Did you mean" hints are automatically converted into code actions.
This commit is contained in:
parent
d89f2356b4
commit
d511b3f1e3
5 changed files with 82 additions and 16 deletions
|
@ -17,7 +17,7 @@
|
|||
#
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
|
||||
from dataclasses import dataclass
|
||||
import typing as T
|
||||
import sys, traceback
|
||||
from . import utils
|
||||
|
@ -45,13 +45,14 @@ class CompileError(PrintableError):
|
|||
|
||||
category = "error"
|
||||
|
||||
def __init__(self, message, start=None, end=None, did_you_mean=None, hints=None):
|
||||
def __init__(self, message, start=None, end=None, did_you_mean=None, hints=None, actions=None):
|
||||
super().__init__(message)
|
||||
|
||||
self.message = message
|
||||
self.start = start
|
||||
self.end = end
|
||||
self.hints = hints or []
|
||||
self.actions = actions or []
|
||||
|
||||
if did_you_mean is not None:
|
||||
self._did_you_mean(*did_you_mean)
|
||||
|
@ -72,6 +73,7 @@ class CompileError(PrintableError):
|
|||
self.hint(f"Did you mean `{recommend}` (note the capitalization)?")
|
||||
else:
|
||||
self.hint(f"Did you mean `{recommend}`?")
|
||||
self.actions.append(CodeAction(f"Change to `{recommend}`", recommend))
|
||||
else:
|
||||
self.hint("Did you check your spelling?")
|
||||
self.hint("Are your dependencies up to date?")
|
||||
|
@ -92,6 +94,12 @@ at {filename} line {line_num} column {col_num}:
|
|||
print()
|
||||
|
||||
|
||||
@dataclass
|
||||
class CodeAction:
|
||||
title: str
|
||||
replace_with: str
|
||||
|
||||
|
||||
class AlreadyCaughtError(Exception):
|
||||
""" Emitted when a validation has already failed and its error message
|
||||
should not be repeated. """
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue