Skip to content

Commit

Permalink
Fix link in CSS error reporting (#3569).
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigogiraoserrao committed Oct 24, 2023
1 parent 9e5bc82 commit 2918011
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/textual/css/stylesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,28 @@ def __rich_console__(
error_count += 1

if token.path:
path = Path(token.path)
filename = path.name
# The display path may end with a ":SomeWidget".
display_path = Path(token.path).absolute()
link_path = str(display_path).split(":")[0]
filename = display_path.name
else:
path = None
display_path = ""
link_path = ""
filename = "<unknown>"

if token.referenced_by:
line_idx, col_idx = token.referenced_by.location
else:
line_idx, col_idx = token.location
line_no, col_no = line_idx + 1, col_idx + 1
path_string = f"{path.absolute() if path else filename}:{line_no}:{col_no}"
path_string = f"{display_path or filename}:{line_no}:{col_no}"
link_style = Style(
link=f"file://{path.absolute()}" if path else None,
link=f"file://{link_path}" if link_path else None,
color="red",
bold=True,
italic=True,
)

path_text = Text(path_string, style=link_style)
title = Text.assemble(Text("Error at ", style="bold red"), path_text)
yield ""
Expand Down

0 comments on commit 2918011

Please sign in to comment.