From ce16538903100466e4ce31cfd255ae70e958f867 Mon Sep 17 00:00:00 2001 From: ThaCuber <70547062+thacuber2a03@users.noreply.github.com> Date: Sat, 15 Mar 2025 10:26:22 -0400 Subject: [PATCH] add a __tostring method to every object (#1534) * added a stupid __tostring to every object * moved every __tostring to just after the :extend() call --------- Co-authored-by: Adam (cherry picked from commit 880e7f1fa1521cdf176f44627a27c901e187058e) --- data/core/commandview.lua | 5 ++++- data/core/contextmenu.lua | 2 ++ data/core/doc/highlighter.lua | 2 +- data/core/doc/init.lua | 1 + data/core/docview.lua | 3 ++- data/core/emptyview.lua | 2 ++ data/core/logview.lua | 4 ++-- data/core/nagview.lua | 2 ++ data/core/node.lua | 2 ++ data/core/rootview.lua | 3 ++- data/core/scrollbar.lua | 3 ++- data/core/statusview.lua | 4 ++++ data/core/titleview.lua | 2 ++ data/core/view.lua | 3 ++- data/plugins/projectsearch.lua | 3 ++- data/plugins/toolbarview.lua | 1 + data/plugins/treeview.lua | 2 ++ 17 files changed, 35 insertions(+), 9 deletions(-) diff --git a/data/core/commandview.lua b/data/core/commandview.lua index 305936b..0ec8b37 100644 --- a/data/core/commandview.lua +++ b/data/core/commandview.lua @@ -10,6 +10,8 @@ local View = require "core.view" ---@field super core.doc local SingleLineDoc = Doc:extend() +function SingleLineDoc:__tostring() return "SingleLineDoc" end + function SingleLineDoc:insert(line, col, text) SingleLineDoc.super.insert(self, line, col, text:gsub("\n", "")) end @@ -18,6 +20,8 @@ end ---@field super core.docview local CommandView = DocView:extend() +function CommandView:__tostring() return "CommandView" end + CommandView.context = "application" local max_suggestions = 10 @@ -391,5 +395,4 @@ function CommandView:draw() end end - return CommandView diff --git a/data/core/contextmenu.lua b/data/core/contextmenu.lua index d59609d..8b3f3fb 100644 --- a/data/core/contextmenu.lua +++ b/data/core/contextmenu.lua @@ -33,6 +33,8 @@ local DIVIDER = {} ---@field current_scale number local ContextMenu = Object:extend() +function ContextMenu:__tostring() return "ContextMenu" end + ---A unique value representing the divider in a context menu. ContextMenu.DIVIDER = DIVIDER diff --git a/data/core/doc/highlighter.lua b/data/core/doc/highlighter.lua index b136704..ed0385c 100644 --- a/data/core/doc/highlighter.lua +++ b/data/core/doc/highlighter.lua @@ -7,6 +7,7 @@ local Object = require "core.object" local Highlighter = Object:extend() +function Highlighter:__tostring() return "Highlighter" end function Highlighter:new(doc) self.doc = doc @@ -126,5 +127,4 @@ function Highlighter:each_token(idx) return tokenizer.each_token(self:get_line(idx).tokens) end - return Highlighter diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 9a3165e..3033c30 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -8,6 +8,7 @@ local common = require "core.common" ---@class core.doc : core.object local Doc = Object:extend() +function Doc:__tostring() return "Doc" end local function split_lines(text) local res = {} diff --git a/data/core/docview.lua b/data/core/docview.lua index 2c95ea3..3752a1c 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -11,6 +11,8 @@ local View = require "core.view" ---@field super core.view local DocView = View:extend() +function DocView:__tostring() return "DocView" end + DocView.context = "session" local function move_to_line_offset(dv, line, col, offset) @@ -591,5 +593,4 @@ function DocView:draw() self:draw_scrollbar() end - return DocView diff --git a/data/core/emptyview.lua b/data/core/emptyview.lua index 865dc55..6596b2a 100644 --- a/data/core/emptyview.lua +++ b/data/core/emptyview.lua @@ -6,6 +6,8 @@ local View = require "core.view" ---@field super core.view local EmptyView = View:extend() +function EmptyView:__tostring() return "EmptyView" end + function EmptyView:get_name() return "Get Started" end diff --git a/data/core/logview.lua b/data/core/logview.lua index 0d10283..9296211 100644 --- a/data/core/logview.lua +++ b/data/core/logview.lua @@ -33,9 +33,10 @@ local function get_item_height(item) return h end - local LogView = View:extend() +function LogView:__tostring() return "LogView" end + LogView.context = "session" @@ -222,5 +223,4 @@ function LogView:draw() LogView.super.draw_scrollbar(self) end - return LogView diff --git a/data/core/nagview.lua b/data/core/nagview.lua index b66da75..5f0d0a9 100644 --- a/data/core/nagview.lua +++ b/data/core/nagview.lua @@ -15,6 +15,8 @@ local noop = function() end ---@field super core.view local NagView = View:extend() +function NagView:__tostring() return "NagView" end + function NagView:new() NagView.super.new(self) self.size.y = 0 diff --git a/data/core/node.lua b/data/core/node.lua index 2ce52cc..6327257 100644 --- a/data/core/node.lua +++ b/data/core/node.lua @@ -9,6 +9,8 @@ local View = require "core.view" ---@class core.node : core.object local Node = Object:extend() +function Node:__tostring() return "Node" end + function Node:new(type) self.type = type or "leaf" self.position = { x = 0, y = 0 } diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 3fc5d54..d284658 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -11,6 +11,8 @@ local DocView = require "core.docview" ---@field mouse core.view.position local RootView = View:extend() +function RootView:__tostring() return "RootView" end + function RootView:new() RootView.super.new(self) self.root_node = Node() @@ -494,5 +496,4 @@ function RootView:draw() end end - return RootView diff --git a/data/core/scrollbar.lua b/data/core/scrollbar.lua index 5e64b19..8c5513b 100644 --- a/data/core/scrollbar.lua +++ b/data/core/scrollbar.lua @@ -19,6 +19,8 @@ local Object = require "core.object" ---@class core.scrollbar : core.object local Scrollbar = Object:extend() +function Scrollbar:__tostring() return "Scrollbar" end + ---@class ScrollbarOptions ---@field direction "v" | "h" @Vertical or Horizontal ---@field alignment "s" | "e" @Start or End (left to right, top to bottom) @@ -339,5 +341,4 @@ function Scrollbar:draw() self:draw_thumb() end - return Scrollbar diff --git a/data/core/statusview.lua b/data/core/statusview.lua index 9c4e33f..af4ff0f 100644 --- a/data/core/statusview.lua +++ b/data/core/statusview.lua @@ -34,6 +34,8 @@ local Object = require "core.object" ---@field hide_messages boolean local StatusView = View:extend() +function StatusView:__tostring() return "StatusView" end + ---Space separator ---@type string StatusView.separator = " " @@ -72,6 +74,8 @@ StatusView.separator2 = " | " ---@field cached_item core.statusview.styledtext local StatusViewItem = Object:extend() +function StatusViewItem:__tostring() return "StatusViewItem" end + ---Available StatusViewItem options. ---@class core.statusview.item.options : table ---A condition to evaluate if the item should be displayed. If a string diff --git a/data/core/titleview.lua b/data/core/titleview.lua index 69315be..4ab44eb 100644 --- a/data/core/titleview.lua +++ b/data/core/titleview.lua @@ -29,6 +29,8 @@ local title_commands = { ---@field super core.view local TitleView = View:extend() +function TitleView:__tostring() return "TitleView" end + local function title_view_height() return style.font:get_height() + style.padding.y * 2 end diff --git a/data/core/view.lua b/data/core/view.lua index 77378b9..320b54f 100644 --- a/data/core/view.lua +++ b/data/core/view.lua @@ -48,6 +48,8 @@ local Scrollbar = require "core.scrollbar" ---@field current_scale number local View = Object:extend() +function View:__tostring() return "View" end + -- context can be "application" or "session". The instance of objects -- with context "session" will be closed when a project session is -- terminated. The context "application" is for functional UI elements. @@ -307,5 +309,4 @@ end function View:draw() end - return View diff --git a/data/plugins/projectsearch.lua b/data/plugins/projectsearch.lua index 4501937..edecd00 100644 --- a/data/plugins/projectsearch.lua +++ b/data/plugins/projectsearch.lua @@ -9,6 +9,8 @@ local View = require "core.view" ---@class plugins.projectsearch.resultsview : core.view local ResultsView = View:extend() +function ResultsView:__tostring() return "ResultsView" end + ResultsView.context = "session" function ResultsView:new(path, text, fn) @@ -237,7 +239,6 @@ function ResultsView:draw() self:draw_scrollbar() end - ---@param path string ---@param text string ---@param fn fun(line_text:string):... diff --git a/data/plugins/toolbarview.lua b/data/plugins/toolbarview.lua index e91438c..129c5e2 100644 --- a/data/plugins/toolbarview.lua +++ b/data/plugins/toolbarview.lua @@ -8,6 +8,7 @@ local View = require "core.view" local ToolbarView = View:extend() +function ToolbarView:__tostring() return "ToolbarView" end function ToolbarView:new() ToolbarView.super.new(self) diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index 00801fd..63c0fd4 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -38,6 +38,8 @@ end local TreeView = View:extend() +function TreeView:__tostring() return "TreeView" end + function TreeView:new() TreeView.super.new(self) self.scrollable = true