%s
"):format(def))
else
-- Properties should have a default value. If they don't or if the
-- default depends on the context, then `opt=nil` should be used to
@@ -284,31 +409,361 @@ create_type {
-- This adds a default value. It works for LDoc 1.4.5, but is a
-- private API and might break in the future.
- if auto_opt then
+ if item.tags["propertydefault"] and item.tags["propertydefault"][1] then
+ item:add_metadata(
+ "Default value",
+ ldoc.markup(item.tags["propertydefault"][1])
+ )
+ elseif auto_opt then
local mods = item.modifiers[item.parameter]
if mods then
mods[item.params[1]].opt = auto_opt
end
- else
+
+ item:add_metadata("Default value", ("%s
"):format(auto_opt))
+ elseif not sublist then
-- The default could not be determined automatically, it requires
-- an explicit `opt="..val.."
", ldoc.markup(desc), type)
+ end
+ end
+ end
+
-- Allow the template to be shorter by using a for-loop.
- for _, mt in ipairs {"propertyunit", "rangestart", "rangestop" } do
+ local has_start, has_allow_negative = false, false
+ for _, mt in ipairs(metadata_tags) do
local tag_desc = named_tags[mt]
if item.tags[mt] and item.tags[mt][1] then
+ has_start = has_start or mt == "rangestart"
+ has_allow_negative = has_allow_negative or mt == "negativeallowed"
local title = tag_desc.title or mt
- item:add_metadata(title, item.tags[mt][1])
+ item:add_metadata(title, ldoc.markup(item.tags[mt][1]))
end
end
+
+ if (prop_type_names["number"] or prop_type_names["integer"]) and not (has_start or has_allow_negative) then
+ print(
+ "WARNING: Property", item.name .." from "..item.module.name..
+ " has numeric type, please add either `@rangestart` or `@negativeallowed false`."
+ )
+ end
+
+ local tdesc = item.params.map[item.params[1]] and item.params.map[item.params[1]] or ""
+
+ -- Auto add the description for "simple" boolean.
+ if #prop_types == 1 and prop_types[1] == "boolean" and tdesc == "" then
+ tdesc = "`true` or `false`."
+ end
+
+ -- Handle custom type description and string "enum".
+ if #(item.tags["propertyvalue"] or {}) > 0 or tdesc ~= "" then
+
+ local mt = item:add_metadata("Valid values", ldoc.markup(tdesc))
+
+ local values, found_default = item.tags["propertyvalue"] or {}, false
+
+ for _, enum_val in ipairs(values) do
+ local parsed = item.parsed_tags["propertyvalue"][enum_val]
+ local val, desc = parsed.value.value, parsed.description
+
+ if val:sub(1,1) ~= '"' or val:sub(#val,#val) ~= '"' then
+ print(
+ "WARNING: Value `"..val.."` from property ".. item.name
+ .." from module "..item.module.name.. "should be a quoted string."
+ )
+ end
+
+ found_default = found_default or val == def
+
+ mt:add_metadata(""..val.."
", ldoc.markup(desc))
+ end
+
+ if def and #values > 0 and def:sub(1,9) ~= "beautiful" and not found_default then
+ print(
+ "WARNING: Property ".. item.name .." from "..item.module.name..
+ " has some `@propertyvalue`, but the default value is not among them."
+ )
+ end
+ end
+
+ -- @return is not displayed for properties, something important
+ -- might have been written there, so it's better to block it
+ if item.tags["return"] or item.tags["treturn"] then
+ print(
+ "WARNING: Property ".. item.name .." from "..item.module.name..
+ " has a `@return`, it is not rendered. Remove it."
+ )
+ end
end
}
@@ -405,12 +860,58 @@ all_theme_vars = create_type {
end
end,
finish_callback = function(item)
- if item.tags["beautiful_used_by"] then return end
+ if not item.tags["beautiful_used_by"] then
+ -- Every variable should be consumed by something. Better "park" some
+ -- variable in the constructors than leave them disconnected from the
+ -- global model.
+ print("WARNING: ", item.name, "is not used by anything, add @usebeautiful or @propbeautiful")
+ else
+ local prop, mn = nil, item.module.name:match("[.]?([^.]+)$")
+ -- If there is a property with the corresponding name and it doesn't
+ -- mention the `beautiful` variable, that's nearly always a bug.
+ for kind, items in item.module.kinds() do
+ if kind == "Object properties" then
+ for k in items do
+ for k2,v2 in k do
+ if item.name:match("[.]"..mn.."_"..k2.name.."$") then
+ prop = k2
+ break
+ end
+ if prop then break end
+ end
+ break
+ end
+ end
+ end
- -- Every variable should be consumed by something. Better "park" some
- -- variable in the constructors than leave them disconnected from the
- -- global model.
- print("WARNING: ", item.name, "is not used by anything, add @usebeautiful or @propbeautiful")
+ if prop then
+ local mention = false
+
+ if prop.tags.propbeautiful then mention = true end
+
+ if (not mention) and prop:default_of_param(prop.params[1]) == item.name then
+ mention = true
+ end
+
+ for _, v in ipairs((not mention) and prop.tags.usebeautiful or {}) do
+ local parsed = prop.parsed_tags.usebeautiful[v]
+ if parsed.name.value == item.name then
+ mention = true
+ break
+ end
+ end
+
+ if not mention then
+ print(
+ "WARNING: `"..item.name.. "` from `"..item.module.name.."` "..
+ "seems to match a property called `"..prop.name.."`. However, "..
+ "there is no mention of this `beautiful` "..
+ "variable in its documentation. Please add `@propbeautiful` or "..
+ "`[opt="..item.module.name.."]"
+ )
+ end
+ end
+ end
end
}
@@ -624,6 +1125,8 @@ add_custom_tag = function(args)
end
item.has_show_more = item.has_show_more or (not args.hidden)
+
+ return parsed
end
custom_tags[#custom_tags+1] = args
@@ -907,6 +1410,13 @@ add_custom_tag {
auto_subtags = false
}
+-- When a property cannot be `nil` or a function/method cannot return `nil`.
+add_custom_tag {
+ name = "nonnullable",
+ hidden = true,
+ auto_subtags = false
+}
+
-- When properties are integers, the value usually has a meaning, like the PID,
-- apoint or a pixel.
add_custom_tag {
@@ -921,22 +1431,109 @@ add_custom_tag {
add_custom_tag {
name = "propertyvalue",
hidden = true,
- auto_subtags = false
+ auto_subtags = false,
+ params = {
+ { name = "value" },
+ },
+}
+
+-- Some defaults are not values. They are either algorithms, chains od fallbacks
+-- or somehow inherited. `ldoc` `opt` can only parse single "words", thus a new
+-- tag is needed for textual description of the default value.
+add_custom_tag {
+ name = "propertydefault",
+ hidden = true,
+ auto_subtags = false,
+}
+
+-- Some properties have multiple possible types. Some also might support multiple
+-- "logical type" for the same datatype. For example `string` can be a path or
+-- some CSS/SVG or an integer have different meaning for positive vs.
+-- negative/zeroed.
+--
+-- This tag helps document those nuances.
+add_custom_tag {
+ name = "propertytype",
+ hidden = true,
+ auto_subtags = false,
+ params = {
+ { name = "typename" },
+ },
}
-- Some values, mostly bytes, have a minimum and maximum value.
add_custom_tag {
name = "rangestart",
- title = "Range starts",
+ title = "Minimum value",
hidden = true,
auto_subtags = false
}
add_custom_tag {
name = "rangestop",
- title = "Range stops",
+ title = "Maximum value",
hidden = true,
auto_subtags = false
}
+add_custom_tag {
+ name = "negativeallowed",
+ title = "Negative allowed",
+ hidden = true,
+ auto_subtags = false,
+ params = {
+ { name = "allowed" },
+ },
+}
+
+-- A lot of properties have the `table` value. Lua tables can be anything from
+-- "struct" to list to objects. For lists, then the type of the row needs to
+-- be specified.
+add_custom_tag {
+ name = "tablerowtype",
+ title = "Table content",
+ hidden = true,
+ auto_subtags = false,
+}
+add_custom_tag {
+ name = "tablerowkey",
+ title = "Row keys",
+ hidden = true,
+ auto_subtags = false,
+ params = {
+ { name = "type" },
+ { name = "name" },
+ },
+}
+
+-- When a `@property` takes a `function` value, then the function arguments
+-- much be provided. If there is none, then `@functionnoparam` must be explicitly
+-- specified. Same for the return value(s).
+add_custom_tag {
+ name = "functionnoparam",
+ hidden = true,
+ auto_subtags = false,
+}
+add_custom_tag {
+ name = "functionparam",
+ hidden = true,
+ auto_subtags = false,
+ params = {
+ { name = "type" },
+ { name = "name" },
+ },
+}
+add_custom_tag {
+ name = "functionnoreturn",
+ hidden = true,
+ auto_subtags = false,
+}
+add_custom_tag {
+ name = "functionreturn",
+ hidden = true,
+ auto_subtags = false,
+ params = {
+ { name = "type" },
+ },
+}
add_custom_tag {
name = "signalhandler",
@@ -1115,9 +1712,19 @@ local named_args = {
[ '(args)' ] = true,
}
+-- Some values come from external sources, we can't enforce the naming conventions
+-- on them. So far, they are all keyboard related.
local param_name_whitelist = {
- Mod2 = true,
- Lock = true,
+ Mod2 = true, Lock = true, Control = true, Mod1 = true, ISO_Level3_Shift = true,
+ Mod4 = true, Insert = true, Delete = true, Next = true, Prior = true, Left = true,
+ Up = true, Right = true, Down = true, KP_End = true, KP_Down = true,
+ KP_Next = true, KP_Left = true, KP_Begin = true, KP_Right = true,
+ KP_Home = true, KP_Up = true, KP_Prior = true, KP_Insert = true, KP_Delete = true,
+ KP_Divide = true, KP_Multiply = true, KP_Subtract = true, KP_Add = true,
+ KP_Enter = true, Escape = true, Tab = true, space = true, Return = true,
+ XF86MonBrightnessUp = true, XF86MonBrightnessDown = true,
+ XF86AudioRaiseVolume = true, XF86AudioLowerVolume = true, XF86AudioMute = true,
+ XF86AudioPlay = true, XF86AudioPrev = true, XF86AudioNext = true, XF86AudioStop = true,
}
-- Sections which are hidden by default, but visible when clicked.
@@ -1293,13 +1900,15 @@ local function init_custom_types(item)
-- Recursive way to annotate property-like objects.
local amt
- amt = function(self, title, value, children)
+ amt = function(self, title, description, datatype)
self.metadata[#self.metadata+1] = {
title = title,
- value = value,
- children = children or {},
+ datatype = datatype,
+ description = description,
+ metadata = {},
add_metadata = amt
}
+ return self.metadata[#self.metadata]
end
item.add_metadata = amt
diff --git a/docs/ldoc.css b/docs/ldoc.css
index eda56fa4d..c86acc14e 100644
--- a/docs/ldoc.css
+++ b/docs/ldoc.css
@@ -47,6 +47,12 @@ td span.types {
width: 100%;
}
+td span.inline_types {
+ color: #a4c7ff;
+ flex-flow: nowrap;
+ width: 100%;
+}
+
.type {
flex-basis: auto;
font-weight: bold;
diff --git a/docs/ldoc.ltp b/docs/ldoc.ltp
index f6a74af5c..e7cf8b4ec 100644
--- a/docs/ldoc.ltp
+++ b/docs/ldoc.ltp
@@ -257,7 +257,7 @@
Default value: | $(item:default_of_param(item.params[1])) |
$(metadata.title): | $(metadata.value) |
$(child.title): | $(child.value) |
+ + $(metadata.title)$(#(metadata.metadata or {}) > 0 and ":" or "") + +# if metadata.datatype then + ($(metadata.datatype)) +# end + | +# if metadata.description and not metadata.description:match("^[\t\n ]*$") then +: $(metadata.description) | +# end +
Valid values: | $(M(item.params.map[item.params[1]],item)) |