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 <adamdharrison@gmail.com>
(cherry picked from commit 880e7f1fa1521cdf176f44627a27c901e187058e)
This commit is contained in:
ThaCuber
2025-05-18 22:54:38 +08:00
committed by takase1121
parent fdd5ab8ed0
commit ce16538903
17 changed files with 35 additions and 9 deletions
+4 -1
View File
@@ -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
+2
View File
@@ -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
+1 -1
View File
@@ -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
+1
View File
@@ -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 = {}
+2 -1
View File
@@ -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
+2
View File
@@ -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
+2 -2
View File
@@ -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
+2
View File
@@ -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
+2
View File
@@ -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 }
+2 -1
View File
@@ -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
+2 -1
View File
@@ -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
+4
View File
@@ -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
+2
View File
@@ -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
+2 -1
View File
@@ -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
+2 -1
View File
@@ -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):...
+1
View File
@@ -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)
+2
View File
@@ -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