Improve hovers for KCL std lib fns (#6208)
Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
		@ -9,7 +9,15 @@ Create a helix.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
helix(revolutions: number(_), angleStart: number(deg), ccw?: bool, radius?: number(mm), axis?: Axis3d | Edge, length?: number(mm), cylinder?: Solid): Helix
 | 
			
		||||
helix(
 | 
			
		||||
  revolutions: number(_),
 | 
			
		||||
  angleStart: number(deg),
 | 
			
		||||
  ccw?: bool,
 | 
			
		||||
  radius?: number(mm),
 | 
			
		||||
  axis?: Axis3d | Edge,
 | 
			
		||||
  length?: number(mm),
 | 
			
		||||
  cylinder?: Solid,
 | 
			
		||||
): Helix
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -6,10 +6,14 @@ layout: manual
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Convert polar/sphere (azimuth, elevation, distance) coordinates tocartesian (x/y/z grid) coordinates.
 | 
			
		||||
Convert polar/sphere (azimuth, elevation, distance) coordinates to
 | 
			
		||||
cartesian (x/y/z grid) coordinates.
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
polar(angle: number(deg), length: number(mm)): [number(mm); 2]
 | 
			
		||||
polar(
 | 
			
		||||
  angle: number(deg),
 | 
			
		||||
  length: number(mm),
 | 
			
		||||
): [number(mm); 2]
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -18,7 +18,14 @@ You can provide more than one sketch to revolve, and they will all be
 | 
			
		||||
revolved around the same axis.
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
revolve(@sketches: [Sketch; 1+], axis: Axis2d | Edge, angle?: number(deg), tolerance?: number(mm), tagStart?: tag, tagEnd?: tag): Solid
 | 
			
		||||
revolve(
 | 
			
		||||
  @sketches: [Sketch; 1+],
 | 
			
		||||
  axis: Axis2d | Edge,
 | 
			
		||||
  angle?: number(deg),
 | 
			
		||||
  tolerance?: number(mm),
 | 
			
		||||
  tagStart?: tag,
 | 
			
		||||
  tagEnd?: tag,
 | 
			
		||||
): Solid
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -6,10 +6,16 @@ layout: manual
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Construct a 2-dimensional circle, of the specified radius, centered atthe provided (x, y) origin point.
 | 
			
		||||
Construct a 2-dimensional circle, of the specified radius, centered at
 | 
			
		||||
the provided (x, y) origin point.
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
circle(@sketch_or_surface: Sketch | Plane | Face, center: Point2d, radius: number, tag?: tag): Sketch
 | 
			
		||||
circle(
 | 
			
		||||
  @sketch_or_surface: Sketch | Plane | Face,
 | 
			
		||||
  center: Point2d,
 | 
			
		||||
  radius: number,
 | 
			
		||||
  tag?: tag,
 | 
			
		||||
): Sketch
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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(@sketches: [Sketch; 1+], axis: Axis2d | Edge): Sketch
 | 
			
		||||
mirror2d(
 | 
			
		||||
  @sketches: [Sketch; 1+],
 | 
			
		||||
  axis: Axis2d | Edge,
 | 
			
		||||
): Sketch
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
use std::{collections::HashSet, str::FromStr};
 | 
			
		||||
use std::{collections::HashSet, fmt, str::FromStr};
 | 
			
		||||
 | 
			
		||||
use regex::Regex;
 | 
			
		||||
use tower_lsp::lsp_types::{
 | 
			
		||||
@ -389,21 +389,23 @@ impl FnData {
 | 
			
		||||
    pub fn fn_signature(&self) -> String {
 | 
			
		||||
        let mut signature = String::new();
 | 
			
		||||
 | 
			
		||||
        signature.push('(');
 | 
			
		||||
        for (i, arg) in self.args.iter().enumerate() {
 | 
			
		||||
            if i > 0 {
 | 
			
		||||
                signature.push_str(", ");
 | 
			
		||||
            }
 | 
			
		||||
            match &arg.kind {
 | 
			
		||||
                ArgKind::Special => signature.push_str(&format!("@{}", arg.name)),
 | 
			
		||||
                ArgKind::Labelled(false) => signature.push_str(&arg.name),
 | 
			
		||||
                ArgKind::Labelled(true) => signature.push_str(&format!("{}?", arg.name)),
 | 
			
		||||
            }
 | 
			
		||||
            if let Some(ty) = &arg.ty {
 | 
			
		||||
                signature.push_str(&format!(": {ty}"));
 | 
			
		||||
        if self.args.is_empty() {
 | 
			
		||||
            signature.push_str("()");
 | 
			
		||||
        } else if self.args.len() == 1 {
 | 
			
		||||
            signature.push('(');
 | 
			
		||||
            signature.push_str(&self.args[0].to_string());
 | 
			
		||||
            signature.push(')');
 | 
			
		||||
        } else {
 | 
			
		||||
            signature.push('(');
 | 
			
		||||
            for a in &self.args {
 | 
			
		||||
                signature.push_str("\n  ");
 | 
			
		||||
                signature.push_str(&a.to_string());
 | 
			
		||||
                signature.push(',');
 | 
			
		||||
            }
 | 
			
		||||
            signature.push('\n');
 | 
			
		||||
            signature.push(')');
 | 
			
		||||
        }
 | 
			
		||||
        signature.push(')');
 | 
			
		||||
 | 
			
		||||
        if let Some(ty) = &self.return_type {
 | 
			
		||||
            signature.push_str(&format!(": {ty}"));
 | 
			
		||||
        }
 | 
			
		||||
@ -515,6 +517,20 @@ pub struct ArgData {
 | 
			
		||||
    pub docs: Option<String>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl fmt::Display for ArgData {
 | 
			
		||||
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 | 
			
		||||
        match &self.kind {
 | 
			
		||||
            ArgKind::Special => write!(f, "@{}", self.name)?,
 | 
			
		||||
            ArgKind::Labelled(false) => f.write_str(&self.name)?,
 | 
			
		||||
            ArgKind::Labelled(true) => write!(f, "{}?", self.name)?,
 | 
			
		||||
        }
 | 
			
		||||
        if let Some(ty) = &self.ty {
 | 
			
		||||
            write!(f, ": {ty}")?;
 | 
			
		||||
        }
 | 
			
		||||
        Ok(())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Clone, Copy, PartialEq)]
 | 
			
		||||
pub enum ArgKind {
 | 
			
		||||
    Special,
 | 
			
		||||
@ -766,8 +782,8 @@ trait ApplyMeta {
 | 
			
		||||
                    description = summary;
 | 
			
		||||
                    summary = None;
 | 
			
		||||
                    let d = description.as_mut().unwrap();
 | 
			
		||||
                    d.push_str(l);
 | 
			
		||||
                    d.push('\n');
 | 
			
		||||
                    d.push_str(l);
 | 
			
		||||
                }
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user