Skip to content

Commit f8b3c5b

Browse files
Restore lint icon functionality by adding a temporary dedicated gutter (#206)
* Add lint icon gutter Added an additional gutter at index 2 to display lint icons without removing line numbers. * Make sure icons in lint gutter take into account editor scale * fix gutter jitter behavior by not removing gutter once a lint has run --------- Co-authored-by: Nathan Lovato <12694995+NathanLovato@users.noreply.github.com>
1 parent 3441731 commit f8b3c5b

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

addons/GDQuest_GDScript_formatter/plugin.gd

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ var DEFAULT_SETTINGS = {
4747

4848
## Which gutter lint icons are shown in.
4949
## By default, gutter 0 is for breakpoints and 1 is for things like overrides.
50-
# FIXME: see other FIXME comment about gutter icons
51-
# const LINT_ICON_GUTTER := 2
50+
const GUTTER_LINT_ICON_INDEX = 2
51+
const GUTTER_LINT_ICONS_NAME = "gdscript_formatter_lint_icons"
5252

5353
var connection_list: Array[Resource] = []
5454
var installer: FormatterInstaller = null
@@ -600,26 +600,30 @@ func parse_lint_issue(line: String) -> Dictionary:
600600
func apply_lint_highlights(code_edit: CodeEdit, issues: Array) -> void:
601601
clear_lint_highlights(code_edit)
602602

603+
# Add and set up gutter for lint icons if not already present.
604+
# We check by name to avoid conflicts with gutters added by other addons.
605+
# Once added, the gutter is never removed so the layout doesn't shift on clear.
606+
var has_lint_gutter := false
607+
for i: int in code_edit.get_gutter_count():
608+
if code_edit.get_gutter_name(i) == GUTTER_LINT_ICONS_NAME:
609+
has_lint_gutter = true
610+
break
611+
if not has_lint_gutter:
612+
code_edit.add_gutter(GUTTER_LINT_ICON_INDEX)
613+
code_edit.set_gutter_name(GUTTER_LINT_ICON_INDEX, GUTTER_LINT_ICONS_NAME)
614+
code_edit.set_gutter_type(GUTTER_LINT_ICON_INDEX, CodeEdit.GutterType.GUTTER_TYPE_ICON)
615+
const EDITOR_ICON_DEFAULT_WIDTH = 16.0
616+
code_edit.set_gutter_width(GUTTER_LINT_ICON_INDEX, EDITOR_ICON_DEFAULT_WIDTH * EditorInterface.get_editor_scale())
617+
603618
for issue in issues:
604619
var line_number: int = issue.line
605620
var severity: String = issue.severity
606621

607-
# Set line background color based on severity
608-
var color: Color
609-
if severity == "error":
610-
color = Color(1, 0, 0, 0.1)
611-
else: # warning
612-
color = Color(1, 1, 0, 0.1)
613-
622+
var color := Color(1, 0, 0, 0.1) if severity == "error" else Color(1, 1, 0, 0.1)
614623
code_edit.set_line_background_color(line_number, color)
615-
616-
# FIXME: This currently removes line numbers as Godot's script editor uses all its gutters,
617-
# I commented out the code in case someone wants to solve it, otherwise this should be removed.
618-
#
619-
# var icon_name = "StatusError" if severity == "error" else "StatusWarning"
620-
# var icon = EditorInterface.get_editor_theme().get_icon(icon_name, "EditorIcons")
621-
# code_edit.set_gutter_type(LINT_ICON_GUTTER, CodeEdit.GutterType.GUTTER_TYPE_ICON)
622-
# code_edit.set_line_gutter_icon(line_number, LINT_ICON_GUTTER, icon)
624+
var icon_name := "StatusError" if severity == "error" else "StatusWarning"
625+
var icon := EditorInterface.get_editor_theme().get_icon(icon_name, "EditorIcons")
626+
code_edit.set_line_gutter_icon(line_number, GUTTER_LINT_ICON_INDEX, icon)
623627

624628

625629
## Prints a detailed summary of lint issues to the output
@@ -643,12 +647,19 @@ func print_lint_summary(issues: Array, script_path: String) -> void:
643647
print_rich("[b]=== End Linting Results ===[/b]\n")
644648

645649

646-
## Clears all lint highlighting from the code editor
650+
## Clears all lint highlighting from the code editor.
651+
## The lint gutter is intentionally kept so the layout does not shift.
647652
func clear_lint_highlights(code_edit: CodeEdit) -> void:
653+
var lint_gutter_index := -1
654+
for i: int in code_edit.get_gutter_count():
655+
if code_edit.get_gutter_name(i) == GUTTER_LINT_ICONS_NAME:
656+
lint_gutter_index = i
657+
break
658+
648659
for line in range(code_edit.get_line_count()):
649660
code_edit.set_line_background_color(line, Color(0, 0, 0, 0))
650-
# FIXME: See other FIXME comment about gutter icons
651-
# code_edit.set_line_gutter_icon(line, LINT_ICON_GUTTER, null)
661+
if lint_gutter_index != -1:
662+
code_edit.set_line_gutter_icon(line, lint_gutter_index, null)
652663

653664

654665
## Data structure to hold code editor state information

0 commit comments

Comments
 (0)