Skip to content

[9.0] Support depthOffset in MD docs headings for nesting functions (#126984) #127092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* [`ST_X`](../../functions-operators/spatial-functions.md#esql-st_x)
* [`ST_Y`](../../functions-operators/spatial-functions.md#esql-st_y)
* [preview] [`ST_ENVELOPE`](../../functions-operators/spatial-functions.md#esql-st_envelope)
* [preview] [`ST_XMAX`](../../functions-operators/spatial-functions.md#esql-st_xmax)
* [preview] [`ST_XMIN`](../../functions-operators/spatial-functions.md#esql-st_xmin)
* [preview] [`ST_YMAX`](../../functions-operators/spatial-functions.md#esql-st_ymax)
* [preview] [`ST_YMIN`](../../functions-operators/spatial-functions.md#esql-st_ymin)
* [preview] [`ST_XMAX`](../../functions-operators/spatial-functions.md#esql-st_xmax)
* [preview] [`ST_XMIN`](../../functions-operators/spatial-functions.md#esql-st_xmin)
* [preview] [`ST_YMAX`](../../functions-operators/spatial-functions.md#esql-st_ymax)
* [preview] [`ST_YMIN`](../../functions-operators/spatial-functions.md#esql-st_ymin)
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
*/
String appendix() default "";

/**
* Adjusts documentation heading level (0=standard, 1=subheading, etc).
* Used to create logical nesting between related functions.
*/
int depthOffset() default 0;

/**
* The position the function can appear in the language.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class StXMax extends UnaryScalarFunction {
returnType = "double",
description = "Extracts the maximum value of the `x` coordinates from the supplied geometry.\n"
+ "If the geometry is of type `geo_point` or `geo_shape` this is equivalent to extracting the maximum `longitude` value.",
examples = @Example(file = "spatial_shapes", tag = "st_x_y_min_max")
examples = @Example(file = "spatial_shapes", tag = "st_x_y_min_max"),
depthOffset = 1 // So this appears as a subsection of ST_ENVELOPE
)
public StXMax(
Source source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class StXMin extends UnaryScalarFunction {
returnType = "double",
description = "Extracts the minimum value of the `x` coordinates from the supplied geometry.\n"
+ "If the geometry is of type `geo_point` or `geo_shape` this is equivalent to extracting the minimum `longitude` value.",
examples = @Example(file = "spatial_shapes", tag = "st_x_y_min_max")
examples = @Example(file = "spatial_shapes", tag = "st_x_y_min_max"),
depthOffset = 1 // So this appears as a subsection of ST_ENVELOPE
)
public StXMin(
Source source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class StYMax extends UnaryScalarFunction {
returnType = "double",
description = "Extracts the maximum value of the `y` coordinates from the supplied geometry.\n"
+ "If the geometry is of type `geo_point` or `geo_shape` this is equivalent to extracting the maximum `latitude` value.",
examples = @Example(file = "spatial_shapes", tag = "st_x_y_min_max")
examples = @Example(file = "spatial_shapes", tag = "st_x_y_min_max"),
depthOffset = 1 // So this appears as a subsection of ST_ENVELOPE
)
public StYMax(
Source source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class StYMin extends UnaryScalarFunction {
returnType = "double",
description = "Extracts the minimum value of the `y` coordinates from the supplied geometry.\n"
+ "If the geometry is of type `geo_point` or `geo_shape` this is equivalent to extracting the minimum `latitude` value.",
examples = @Example(file = "spatial_shapes", tag = "st_x_y_min_max")
examples = @Example(file = "spatial_shapes", tag = "st_x_y_min_max"),
depthOffset = 1 // So this appears as a subsection of ST_ENVELOPE
)
public StYMin(
Source source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ private void renderDocs(FunctionDefinition definition) throws IOException {
}
boolean hasExamples = renderExamples(info);
boolean hasAppendix = renderAppendix(info.appendix());
renderFullLayout(info.preview(), info.appliesTo(), hasExamples, hasAppendix, hasFunctionOptions);
renderFullLayout(info, hasExamples, hasAppendix, hasFunctionOptions);
renderKibanaInlineDocs(name, null, info);
renderKibanaFunctionDefinition(name, null, info, description.args(), description.variadic());
}
Expand Down Expand Up @@ -627,16 +627,12 @@ private void appendLifeCycleAndVersion(StringBuilder appliesToText, FunctionAppl
}
}

private void renderFullLayout(
boolean preview,
FunctionAppliesTo[] functionAppliesTos,
boolean hasExamples,
boolean hasAppendix,
boolean hasFunctionOptions
) throws IOException {
private void renderFullLayout(FunctionInfo info, boolean hasExamples, boolean hasAppendix, boolean hasFunctionOptions)
throws IOException {
String headingMarkdown = "#".repeat(2 + info.depthOffset());
StringBuilder rendered = new StringBuilder(
DOCS_WARNING + """
## `$UPPER_NAME$` [esql-$NAME$]
$HEAD$ `$UPPER_NAME$` [esql-$NAME$]
$PREVIEW_CALLOUT$
**Syntax**

Expand All @@ -645,10 +641,11 @@ private void renderFullLayout(
:class: text-center
:::

""".replace("$NAME$", name)
""".replace("$HEAD$", headingMarkdown)
.replace("$NAME$", name)
.replace("$CATEGORY$", category)
.replace("$UPPER_NAME$", name.toUpperCase(Locale.ROOT))
.replace("$PREVIEW_CALLOUT$", makePreviewText(preview, functionAppliesTos))
.replace("$PREVIEW_CALLOUT$", makePreviewText(info.preview(), info.appliesTo()))
);
for (String section : new String[] { "parameters", "description", "types" }) {
rendered.append(addInclude(section));
Expand Down Expand Up @@ -777,6 +774,11 @@ public String appendix() {
return orig.appendix().replace(baseName, name);
}

@Override
public int depthOffset() {
return orig.depthOffset();
}

@Override
public FunctionType type() {
return orig.type();
Expand Down