Improve hover tool tips and function docs (#5538)

* Improve hover tool tips and function docs

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)

* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Nick Cameron
2025-02-27 22:03:37 +13:00
committed by GitHub
parent 2efea3ec06
commit 1104d908c0
71 changed files with 390 additions and 88 deletions

View File

@ -9,7 +9,11 @@ Returns the angle to match the given length for x.
```js
angleToMatchLengthX(tag: TagIdentifier, to: number, sketch: Sketch) -> number
angleToMatchLengthX(
tag: TagIdentifier,
to: number,
sketch: Sketch,
) -> number
```

View File

@ -9,7 +9,11 @@ Returns the angle to match the given length for y.
```js
angleToMatchLengthY(tag: TagIdentifier, to: number, sketch: Sketch) -> number
angleToMatchLengthY(
tag: TagIdentifier,
to: number,
sketch: Sketch,
) -> number
```

View File

@ -9,7 +9,11 @@ Draw a line segment relative to the current origin using the polar
measure of some angle and distance.
```js
angledLine(data: AngledLineData, sketch: Sketch, tag?: TagDeclarator) -> Sketch
angledLine(
data: AngledLineData,
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,11 @@ Create a line segment from the current 2-dimensional sketch origin
along some angle (in degrees) for some relative length in the 'x' dimension.
```js
angledLineOfXLength(data: AngledLineData, sketch: Sketch, tag?: TagDeclarator) -> Sketch
angledLineOfXLength(
data: AngledLineData,
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,11 @@ Create a line segment from the current 2-dimensional sketch origin
along some angle (in degrees) for some relative length in the 'y' dimension.
```js
angledLineOfYLength(data: AngledLineData, sketch: Sketch, tag?: TagDeclarator) -> Sketch
angledLineOfYLength(
data: AngledLineData,
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,11 @@ Draw an angled line from the current origin, constructing a line segment
such that the newly created line intersects the desired target line segment.
```js
angledLineThatIntersects(data: AngledLineThatIntersectsData, sketch: Sketch, tag?: TagDeclarator) -> Sketch
angledLineThatIntersects(
data: AngledLineThatIntersectsData,
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,11 @@ Create a line segment from the current 2-dimensional sketch origin
along some angle (in degrees) for some length, ending at the provided value in the 'x' dimension.
```js
angledLineToX(data: AngledLineToData, sketch: Sketch, tag?: TagDeclarator) -> Sketch
angledLineToX(
data: AngledLineToData,
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,11 @@ Create a line segment from the current 2-dimensional sketch origin
along some angle (in degrees) for some length, ending at the provided value in the 'y' dimension.
```js
angledLineToY(data: AngledLineToData, sketch: Sketch, tag?: TagDeclarator) -> Sketch
angledLineToY(
data: AngledLineToData,
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,12 @@ Set the appearance of a solid. This only works on solids, not sketches or indivi
This will work on any solid, including extruded solids, revolved solids, and shelled solids.
```js
appearance(solidSet: SolidSet, color: String, metalness?: number, roughness?: number) -> SolidSet
appearance(
solidSet: SolidSet,
color: String,
metalness?: number,
roughness?: number,
) -> SolidSet
```

View File

@ -11,7 +11,11 @@ The arc is constructed such that the current position of the sketch is placed al
Unless this makes a lot of sense and feels like what you're looking for to construct your shape, you're likely looking for tangentialArc.
```js
arc(data: ArcData, sketch: Sketch, tag?: TagDeclarator) -> Sketch
arc(
data: ArcData,
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,11 @@ Draw a 3 point arc.
The arc is constructed such that the start point is the current position of the sketch and two more points defined as the end and interior point. The interior point is placed between the start point and end point. The radius of the arc will be controlled by how far the interior point is placed from the start and end.
```js
arcTo(data: ArcToData, sketch: Sketch, tag?: TagDeclarator) -> Sketch
arcTo(
data: ArcToData,
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,10 @@ Check a value at runtime, and raise an error if the argument provided
is false.
```js
assert(data: bool, message: string) -> ()
assert(
data: bool,
message: string,
) -> ()
```

View File

@ -9,7 +9,12 @@ Check that a numerical value equals another at runtime,
otherwise raise an error.
```js
assertEqual(left: number, right: number, epsilon: number, message: string) -> ()
assertEqual(
left: number,
right: number,
epsilon: number,
message: string,
) -> ()
```

View File

@ -9,7 +9,11 @@ Check that a numerical value is greater than another at runtime,
otherwise raise an error.
```js
assertGreaterThan(left: number, right: number, message: string) -> ()
assertGreaterThan(
left: number,
right: number,
message: string,
) -> ()
```

View File

@ -9,7 +9,11 @@ Check that a numerical value is greater than or equal to another at runtime,
otherwise raise an error.
```js
assertGreaterThanOrEq(left: number, right: number, message: string) -> ()
assertGreaterThanOrEq(
left: number,
right: number,
message: string,
) -> ()
```

View File

@ -9,7 +9,11 @@ Check that a numerical value is less than to another at runtime,
otherwise raise an error.
```js
assertLessThan(left: number, right: number, message: string) -> ()
assertLessThan(
left: number,
right: number,
message: string,
) -> ()
```

View File

@ -9,7 +9,11 @@ Check that a numerical value is less than or equal to another at runtime,
otherwise raise an error.
```js
assertLessThanOrEq(left: number, right: number, message: string) -> ()
assertLessThanOrEq(
left: number,
right: number,
message: string,
) -> ()
```

View File

@ -9,7 +9,10 @@ Compute the four quadrant arctangent of Y and X (in radians).
```js
atan2(y: number, x: number) -> number
atan2(
y: number,
x: number,
) -> number
```
### Tags

View File

@ -9,7 +9,11 @@ Draw a smooth, continuous, curved line segment from the current origin to
the desired (x, y), using a number of control points to shape the curve's shape.
```js
bezierCurve(data: BezierData, sketch: Sketch, tag?: TagDeclarator) -> Sketch
bezierCurve(
data: BezierData,
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,12 @@ Cut a straight transitional edge along a tagged path.
Chamfer is similar in function and use to a fillet, except a fillet will blend the transition along an edge, rather than cut a sharp, straight transitional edge.
```js
chamfer(solid: Solid, length: number, tags: [EdgeReference], tag?: TagDeclarator) -> Solid
chamfer(
solid: Solid,
length: number,
tags: [EdgeReference],
tag?: TagDeclarator,
) -> Solid
```

View File

@ -9,7 +9,11 @@ Construct a 2-dimensional circle, of the specified radius, centered at
the provided (x, y) origin point.
```js
circle(data: CircleData, sketchSurfaceOrGroup: SketchOrSurface, tag?: TagDeclarator) -> Sketch
circle(
data: CircleData,
sketchSurfaceOrGroup: SketchOrSurface,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,13 @@ Construct a circle derived from 3 points.
```js
circleThreePoint(p1: [number], p2: [number], p3: [number], sketchSurfaceOrGroup: SketchOrSurface, tag?: TagDeclarator) -> Sketch
circleThreePoint(
p1: [number],
p2: [number],
p3: [number],
sketchSurfaceOrGroup: SketchOrSurface,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,10 @@ Construct a line segment from the current origin back to the profile's
origin, ensuring the resulting 2-dimensional sketch is not open-ended.
```js
close(sketch: Sketch, tag?: TagDeclarator) -> Sketch
close(
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,10 @@ Extend a 2-dimensional sketch through a third dimension in order to
create new 3-dimensional volume, or if extruded into an existing volume, cut into an existing solid.
```js
extrude(sketchSet: SketchSet, length: number) -> SolidSet
extrude(
sketchSet: SketchSet,
length: number,
) -> SolidSet
```

View File

@ -9,7 +9,13 @@ Blend a transitional edge along a tagged path, smoothing the sharp edge.
Fillet is similar in function and use to a chamfer, except a chamfer will cut a sharp transition along an edge while fillet will smoothly blend the transition.
```js
fillet(solid: Solid, radius: number, tags: [EdgeReference], tolerance?: number, tag?: TagDeclarator) -> Solid
fillet(
solid: Solid,
radius: number,
tags: [EdgeReference],
tolerance?: number,
tag?: TagDeclarator,
) -> Solid
```

View File

@ -9,7 +9,14 @@ Create a helix.
```js
helix(revolutions: number, angleStart: number, ccw?: bool, radius: number, axis: Axis3dOrEdgeReference, length?: number) -> HelixValue
helix(
revolutions: number,
angleStart: number,
ccw?: bool,
radius: number,
axis: Axis3dOrEdgeReference,
length?: number,
) -> HelixValue
```

View File

@ -9,7 +9,10 @@ Create a helix on a cylinder.
```js
helixRevolutions(data: HelixRevolutionsData, solid: Solid) -> Solid
helixRevolutions(
data: HelixRevolutionsData,
solid: Solid,
) -> Solid
```

View File

@ -9,7 +9,10 @@ Use a 2-dimensional sketch to cut a hole in another 2-dimensional sketch.
```js
hole(holeSketch: SketchSet, sketch: Sketch) -> Sketch
hole(
holeSketch: SketchSet,
sketch: Sketch,
) -> Sketch
```

View File

@ -9,7 +9,10 @@ Make the inside of a 3D object hollow.
Remove volume from a 3-dimensional shape such that a wall of the provided thickness remains around the exterior of the shape.
```js
hollow(thickness: number, solid: Solid) -> Solid
hollow(
thickness: number,
solid: Solid,
) -> Solid
```

View File

@ -15,7 +15,10 @@ For formats lacking unit data (such as STL, OBJ, or PLY files), the default unit
Note: The import command currently only works when using the native Modeling App.
```js
import(filePath: String, options?: ImportFormat) -> ImportedGeometry
import(
filePath: String,
options?: ImportFormat,
) -> ImportedGeometry
```

View File

@ -9,7 +9,10 @@ Compute the angle of the given leg for x.
```js
legAngX(hypotenuse: number, leg: number) -> number
legAngX(
hypotenuse: number,
leg: number,
) -> number
```
### Tags

View File

@ -9,7 +9,10 @@ Compute the angle of the given leg for y.
```js
legAngY(hypotenuse: number, leg: number) -> number
legAngY(
hypotenuse: number,
leg: number,
) -> number
```
### Tags

View File

@ -9,7 +9,10 @@ Compute the length of the given leg.
```js
legLen(hypotenuse: number, leg: number) -> number
legLen(
hypotenuse: number,
leg: number,
) -> number
```
### Tags

View File

@ -9,7 +9,12 @@ Extend the current sketch with a new straight line.
```js
line(sketch: Sketch, endAbsolute?: [number], end?: [number], tag?: TagDeclarator) -> Sketch
line(
sketch: Sketch,
endAbsolute?: [number],
end?: [number],
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,13 @@ Create a 3D surface or solid by interpolating between two or more sketches.
The sketches need to closed and on the same plane.
```js
loft(sketches: [Sketch], vDegree: NonZeroU32, bezApproximateRational: bool, baseCurveIndex?: integer, tolerance?: number) -> Solid
loft(
sketches: [Sketch],
vDegree: NonZeroU32,
bezApproximateRational: bool,
baseCurveIndex?: integer,
tolerance?: number,
) -> Solid
```

View File

@ -9,7 +9,10 @@ Compute the logarithm of the number with respect to an arbitrary base.
The result might not be correctly rounded owing to implementation details; `log2()` can produce more accurate results for base 2, and `log10()` can produce more accurate results for base 10.
```js
log(num: number, base: number) -> number
log(
num: number,
base: number,
) -> number
```
### Tags

View File

@ -9,7 +9,10 @@ Apply a function to every element of a list.
Given a list like `[a, b, c]`, and a function like `f`, returns `[f(a), f(b), f(c)]`
```js
map(array: [KclValue], mapFn: FunctionSource) -> [KclValue]
map(
array: [KclValue],
mapFn: FunctionSource,
) -> [KclValue]
```

View File

@ -11,7 +11,10 @@ Only works on unclosed sketches for now.
Mirror occurs around a local sketch axis rather than a global axis.
```js
mirror2d(data: Mirror2dData, sketchSet: SketchSet) -> [Sketch]
mirror2d(
data: Mirror2dData,
sketchSet: SketchSet,
) -> [Sketch]
```

View File

@ -9,7 +9,10 @@ Offset a plane by a distance along its normal.
For example, if you offset the 'XZ' plane by 10, the new plane will be parallel to the 'XZ' plane and 10 units away from it.
```js
offsetPlane(plane: PlaneData, offset: number) -> Plane
offsetPlane(
plane: PlaneData,
offset: number,
) -> Plane
```

View File

@ -9,7 +9,14 @@ Repeat a 2-dimensional sketch some number of times along a partial or
complete circle some specified number of times. Each object may additionally be rotated along the circle, ensuring orentation of the solid with respect to the center of the circle is maintained.
```js
patternCircular2d(sketchSet: SketchSet, instances: integer, center: [number], arcDegrees: number, rotateDuplicates: bool, useOriginal?: bool) -> [Sketch]
patternCircular2d(
sketchSet: SketchSet,
instances: integer,
center: [number],
arcDegrees: number,
rotateDuplicates: bool,
useOriginal?: bool,
) -> [Sketch]
```

View File

@ -9,7 +9,15 @@ Repeat a 3-dimensional solid some number of times along a partial or
complete circle some specified number of times. Each object may additionally be rotated along the circle, ensuring orentation of the solid with respect to the center of the circle is maintained.
```js
patternCircular3d(solidSet: SolidSet, instances: integer, axis: [number], center: [number], arcDegrees: number, rotateDuplicates: bool, useOriginal?: bool) -> [Solid]
patternCircular3d(
solidSet: SolidSet,
instances: integer,
axis: [number],
center: [number],
arcDegrees: number,
rotateDuplicates: bool,
useOriginal?: bool,
) -> [Solid]
```

View File

@ -9,7 +9,13 @@ Repeat a 2-dimensional sketch along some dimension, with a dynamic amount
of distance between each repetition, some specified number of times.
```js
patternLinear2d(sketchSet: SketchSet, instances: integer, distance: number, axis: [number], useOriginal?: bool) -> [Sketch]
patternLinear2d(
sketchSet: SketchSet,
instances: integer,
distance: number,
axis: [number],
useOriginal?: bool,
) -> [Sketch]
```

View File

@ -11,7 +11,13 @@ of distance between each repetition, some specified number of times.
///
```js
patternLinear3d(solidSet: SolidSet, instances: integer, distance: number, axis: [number], useOriginal?: bool) -> [Solid]
patternLinear3d(
solidSet: SolidSet,
instances: integer,
distance: number,
axis: [number],
useOriginal?: bool,
) -> [Solid]
```

View File

@ -35,7 +35,12 @@ The transform function returns a transform object. All properties of the object
- `rotation.origin` (either "local" i.e. rotate around its own center, "global" i.e. rotate around the scene's center, or a 3D point, defaults to "local")
```js
patternTransform(solidSet: SolidSet, instances: integer, transform: FunctionSource, useOriginal?: bool) -> [Solid]
patternTransform(
solidSet: SolidSet,
instances: integer,
transform: FunctionSource,
useOriginal?: bool,
) -> [Solid]
```

View File

@ -9,7 +9,12 @@ Just like patternTransform, but works on 2D sketches not 3D solids.
```js
patternTransform2d(sketchSet: SketchSet, instances: integer, transform: FunctionSource, useOriginal?: bool) -> [Sketch]
patternTransform2d(
sketchSet: SketchSet,
instances: integer,
transform: FunctionSource,
useOriginal?: bool,
) -> [Sketch]
```

View File

@ -9,7 +9,11 @@ Create a regular polygon with the specified number of sides that is either inscr
```js
polygon(data: PolygonData, sketchSurfaceOrGroup: SketchOrSurface, tag?: TagDeclarator) -> Sketch
polygon(
data: PolygonData,
sketchSurfaceOrGroup: SketchOrSurface,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,10 @@ Compute the number to a power.
```js
pow(num: number, pow: number) -> number
pow(
num: number,
pow: number,
) -> number
```
### Tags

View File

@ -9,7 +9,10 @@ Append an element to the end of an array.
Returns a new array with the element appended.
```js
push(array: [KclValue], elem: KclValue) -> KclValue
push(
array: [KclValue],
elem: KclValue,
) -> KclValue
```

View File

@ -9,7 +9,11 @@ Take a starting value. Then, for each element of an array, calculate the next va
using the previous value and the element.
```js
reduce(array: [KclValue], start: KclValue, reduceFn: FunctionSource) -> KclValue
reduce(
array: [KclValue],
start: KclValue,
reduceFn: FunctionSource,
) -> KclValue
```

View File

@ -9,7 +9,10 @@ Compute the remainder after dividing `num` by `div`.
If `num` is negative, the result will be too.
```js
rem(num: number, divisor: number) -> number
rem(
num: number,
divisor: number,
) -> number
```
### Tags

View File

@ -11,7 +11,10 @@ This, like extrude, is able to create a 3-dimensional solid from a 2-dimensional
Revolve occurs around a local sketch axis rather than a global axis.
```js
revolve(data: RevolveData, sketch: Sketch) -> Solid
revolve(
data: RevolveData,
sketch: Sketch,
) -> Solid
```

View File

@ -23,7 +23,15 @@ So, in the context of a 3D model:
When rotating a part around an axis, you specify the axis of rotation and the angle of rotation.
```js
rotate(solid: Solid, roll?: number, pitch?: number, yaw?: number, axis?: [number], angle?: number, global?: bool) -> Solid
rotate(
solid: Solid,
roll?: number,
pitch?: number,
yaw?: number,
axis?: [number],
angle?: number,
global?: bool,
) -> Solid
```

View File

@ -11,7 +11,11 @@ By default the transform is applied in local sketch axis, therefore the origin w
If you want to apply the transform in global space, set `global` to `true`. The origin of the model will move. If the model is not centered on origin and you scale globally it will look like the model moves and gets bigger at the same time. Say you have a square `(1,1) - (1,2) - (2,2) - (2,1)` and you scale by 2 globally it will become `(2,2) - (2,4)`...etc so the origin has moved from `(1.5, 1.5)` to `(2,2)`.
```js
scale(solid: Solid, scale: [number], global?: bool) -> Solid
scale(
solid: Solid,
scale: [number],
global?: bool,
) -> Solid
```

View File

@ -9,7 +9,11 @@ Remove volume from a 3-dimensional shape such that a wall of the
provided thickness remains, taking volume starting at the provided face, leaving it open in that direction.
```js
shell(solidSet: SolidSet, thickness: number, faces: [FaceTag]) -> SolidSet
shell(
solidSet: SolidSet,
thickness: number,
faces: [FaceTag],
) -> SolidSet
```

View File

@ -9,7 +9,11 @@ Start a new profile at a given point.
```js
startProfileAt(to: [number], sketchSurface: SketchSurface, tag?: TagDeclarator) -> Sketch
startProfileAt(
to: [number],
sketchSurface: SketchSurface,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -17,7 +17,10 @@ This is important to understand because if you were to then sketch on the result
The point is if you want to export the result of a sketch on a face, you only need to export the final Solid that was created from the sketch on the face, since it will include all the parent faces and Solids.
```js
startSketchOn(data: SketchData, tag?: FaceTag) -> SketchSurface
startSketchOn(
data: SketchData,
tag?: FaceTag,
) -> SketchSurface
```

View File

@ -9,7 +9,12 @@ Extrude a sketch along a path.
This, like extrude, is able to create a 3-dimensional solid from a 2-dimensional sketch. However, unlike extrude, this creates a solid by using the extent of the sketch as its path. This is useful for creating more complex shapes that can't be created with a simple extrusion.
```js
sweep(sketch: Sketch, path: SweepPath, sectional?: bool, tolerance?: number) -> Solid
sweep(
sketch: Sketch,
path: SweepPath,
sectional?: bool,
tolerance?: number,
) -> Solid
```

View File

@ -9,7 +9,11 @@ Draw a curved line segment along part of an imaginary circle.
The arc is constructed such that the last line segment is placed tangent to the imaginary circle of the specified radius. The resulting arc is the segment of the imaginary circle from that tangent point for 'offset' degrees along the imaginary circle.
```js
tangentialArc(data: TangentialArcData, sketch: Sketch, tag?: TagDeclarator) -> Sketch
tangentialArc(
data: TangentialArcData,
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,11 @@ Starting at the current sketch's origin, draw a curved line segment along
some part of an imaginary circle until it reaches the desired (x, y) coordinates.
```js
tangentialArcTo(to: [number], sketch: Sketch, tag?: TagDeclarator) -> Sketch
tangentialArcTo(
to: [number],
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,11 @@ Starting at the current sketch's origin, draw a curved line segment along
some part of an imaginary circle until it reaches a point the given (x, y) distance away.
```js
tangentialArcToRelative(delta: [number], sketch: Sketch, tag?: TagDeclarator) -> Sketch
tangentialArcToRelative(
delta: [number],
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,11 @@ Move a solid.
```js
translate(solid: Solid, translate: [number], global?: bool) -> Solid
translate(
solid: Solid,
translate: [number],
global?: bool,
) -> Solid
```

View File

@ -9,7 +9,11 @@ Draw a line relative to the current origin to a specified distance away
from the current position along the 'x' axis.
```js
xLine(length: number, sketch: Sketch, tag?: TagDeclarator) -> Sketch
xLine(
length: number,
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,11 @@ Draw a line parallel to the X axis, that ends at the given X.
E.g. if the previous line ended at (1, 1), then xLineTo(4) draws a line from (1, 1) to (4, 1)
```js
xLineTo(to: number, sketch: Sketch, tag?: TagDeclarator) -> Sketch
xLineTo(
to: number,
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,11 @@ Draw a line relative to the current origin to a specified distance away
from the current position along the 'y' axis.
```js
yLine(length: number, sketch: Sketch, tag?: TagDeclarator) -> Sketch
yLine(
length: number,
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -9,7 +9,11 @@ Draw a line parallel to the Y axis, that ends at the given Y.
E.g. if the previous line ended at (1, 1), then yLineTo(4) draws a line from (1, 1) to (1, 4)
```js
yLineTo(to: number, sketch: Sketch, tag?: TagDeclarator) -> Sketch
yLineTo(
to: number,
sketch: Sketch,
tag?: TagDeclarator,
) -> Sketch
```

View File

@ -28,6 +28,7 @@ export default function lspHoverExt(
'.cm-tooltip': {
fontSize: '12px',
maxWidth: '400px',
padding: '2px',
},
}),
]

View File

@ -1,5 +1,5 @@
import { Text } from '@codemirror/state'
import { Marked } from '@ts-stack/markdown'
import { Marked, MarkedOptions } from '@ts-stack/markdown'
import type * as LSP from 'vscode-languageserver-protocol'
import { isArray } from '../lib/utils'
@ -43,14 +43,18 @@ export function offsetToPos(doc: Text, offset: number) {
}
}
const markedOptions: MarkedOptions = {
gfm: true,
}
export function formatMarkdownContents(
contents: LSP.MarkupContent | LSP.MarkedString | LSP.MarkedString[]
): string {
if (isArray(contents)) {
return contents.map((c) => formatMarkdownContents(c) + '\n\n').join('')
} else if (typeof contents === 'string') {
return Marked.parse(contents)
return Marked.parse(contents, markedOptions)
} else {
return Marked.parse(contents.value)
return Marked.parse(contents.value, markedOptions)
}
}

View File

@ -542,7 +542,7 @@ fn generate_function(internal_fn: Box<dyn StdLibFn>) -> Result<BTreeMap<String,
"summary": internal_fn.summary(),
"description": internal_fn.description(),
"deprecated": internal_fn.deprecated(),
"fn_signature": internal_fn.fn_signature(),
"fn_signature": internal_fn.fn_signature(true),
"tags": internal_fn.tags(),
"examples": examples,
"is_utilities": internal_fn.tags().contains(&"utilities".to_string()),

View File

@ -4,7 +4,10 @@
mod gen_std_tests;
pub mod kcl_doc;
use std::path::Path;
use std::{
fmt::{self, Write},
path::Path,
};
use anyhow::Result;
use schemars::JsonSchema;
@ -89,6 +92,17 @@ pub struct StdLibFnArg {
pub label_required: bool,
}
impl fmt::Display for StdLibFnArg {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.name)?;
if !self.required {
f.write_char('?')?;
}
f.write_str(": ")?;
f.write_str(&self.type_)
}
}
fn its_true() -> bool {
true
}
@ -419,20 +433,29 @@ pub trait StdLibFn: std::fmt::Debug + Send + Sync {
})
}
fn fn_signature(&self) -> String {
fn fn_signature(&self, include_name: bool) -> String {
let mut signature = String::new();
signature.push_str(&format!("{}(", self.name()));
for (i, arg) in self.args(false).iter().enumerate() {
if i > 0 {
signature.push_str(", ");
}
if arg.required {
signature.push_str(&format!("{}: {}", arg.name, arg.type_));
} else {
signature.push_str(&format!("{}?: {}", arg.name, arg.type_));
}
if include_name {
signature.push_str(&self.name());
}
let args = self.args(false);
if args.is_empty() {
signature.push_str("()");
} else if args.len() == 1 {
signature.push('(');
signature.push_str(&args[0].to_string());
signature.push(')');
} else {
signature.push('(');
for a in args {
signature.push_str("\n ");
signature.push_str(&a.to_string());
signature.push(',');
}
signature.push('\n');
signature.push(')');
}
if let Some(return_value) = self.return_value(false) {
signature.push_str(&format!(" -> {}", return_value.type_));
}
@ -444,7 +467,7 @@ pub trait StdLibFn: std::fmt::Debug + Send + Sync {
Ok(CompletionItem {
label: self.name(),
label_details: Some(CompletionItemLabelDetails {
detail: Some(self.fn_signature().replace(&self.name(), "")),
detail: Some(self.fn_signature(false)),
description: None,
}),
kind: Some(CompletionItemKind::FUNCTION),

View File

@ -1048,7 +1048,7 @@ impl LanguageServer for Backend {
contents: HoverContents::Markup(MarkupContent {
kind: MarkupKind::Markdown,
value: format!(
"```{}{}```\n{}",
"```\n{}{}\n```\n\n{}",
name,
if let Some(detail) = &label_details.detail {
detail

View File

@ -902,10 +902,13 @@ async fn test_kcl_lsp_on_hover() {
.unwrap();
// Check the hover.
if let Some(hover) = hover {
assert_eq!(hover.contents, tower_lsp::lsp_types::HoverContents::Markup(tower_lsp::lsp_types::MarkupContent { kind: tower_lsp::lsp_types::MarkupKind::Markdown, value: "```startSketchOn(data: SketchData, tag?: FaceTag) -> SketchSurface```\nStart a new 2-dimensional sketch on a specific plane or face.\n\n### Sketch on Face Behavior\n\nThere are some important behaviors to understand when sketching on a face:\n\nThe resulting sketch will _include_ the face and thus Solid that was sketched on. So say you were to export the resulting Sketch / Solid from a sketch on a face, you would get both the artifact of the sketch on the face and the parent face / Solid itself.\n\nThis is important to understand because if you were to then sketch on the resulting Solid, it would again include the face and parent Solid that was sketched on. This could go on indefinitely.\n\nThe point is if you want to export the result of a sketch on a face, you only need to export the final Solid that was created from the sketch on the face, since it will include all the parent faces and Solids.".to_string() }));
} else {
panic!("Expected hover");
match hover.unwrap().contents {
tower_lsp::lsp_types::HoverContents::Markup(tower_lsp::lsp_types::MarkupContent { value, .. }) => {
value.contains("startSketchOn");
value.contains("-> SketchSurface");
value.contains("Start a new 2-dimensional sketch on a specific");
}
_ => unreachable!(),
}
}