diff --git a/crates/tinymist-query/src/analysis/tyck/syntax.rs b/crates/tinymist-query/src/analysis/tyck/syntax.rs index f4d9b5cb..2b26d685 100644 --- a/crates/tinymist-query/src/analysis/tyck/syntax.rs +++ b/crates/tinymist-query/src/analysis/tyck/syntax.rs @@ -218,7 +218,7 @@ impl<'a> TypeChecker<'a> { name: name.clone(), docs: param_doc.docs.clone(), cano_type: (), - default: Some(eco_format!("{exp}")), + default: Some(exp.repr()), attrs: ParamAttrs::named(), }, ); diff --git a/crates/tinymist-query/src/completion.rs b/crates/tinymist-query/src/completion.rs index 48b9c4d4..cf3b0b8e 100644 --- a/crates/tinymist-query/src/completion.rs +++ b/crates/tinymist-query/src/completion.rs @@ -439,6 +439,6 @@ mod tests { #[test] fn test_pkgs() { - snapshot_testing("completion-pkgs", &run(TestConfig { pkg_mode: true })); + snapshot_testing("pkgs", &run(TestConfig { pkg_mode: true })); } } diff --git a/crates/tinymist-query/src/docs/package.rs b/crates/tinymist-query/src/docs/package.rs index 2e597dab..bc73ab31 100644 --- a/crates/tinymist-query/src/docs/package.rs +++ b/crates/tinymist-query/src/docs/package.rs @@ -221,7 +221,9 @@ pub fn package_docs(ctx: &mut AnalysisContext, spec: &PackageInfo) -> StrResult< if let Some(SymbolDocs::Function(sig)) = &sym.head.parsed_docs { let _ = writeln!(md, ""); let _ = writeln!(md, "```typc"); - let _ = writeln!(md, "let {name}({sig});", name = sym.head.name); + let _ = write!(md, "let {}", sym.head.name); + let _ = sig.print(&mut md); + let _ = writeln!(md, ";"); let _ = writeln!(md, "```"); let _ = writeln!(md, ""); } diff --git a/crates/tinymist-query/src/docs/symbol.rs b/crates/tinymist-query/src/docs/symbol.rs index 655d4cdd..b09c51d3 100644 --- a/crates/tinymist-query/src/docs/symbol.rs +++ b/crates/tinymist-query/src/docs/symbol.rs @@ -207,17 +207,19 @@ pub type UntypedSignatureDocs = SignatureDocsT<()>; /// Documentation about a signature. pub type SignatureDocs = SignatureDocsT; -impl fmt::Display for SignatureDocs { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl SignatureDocs { + /// Get the markdown representation of the documentation. + pub fn print(&self, f: &mut impl std::fmt::Write) -> fmt::Result { let mut is_first = true; - let mut write_sep = |f: &mut fmt::Formatter<'_>| { + let mut write_sep = |f: &mut dyn std::fmt::Write| { if is_first { is_first = false; - return Ok(()); + return f.write_str("\n "); } - f.write_str(", ") + f.write_str(",\n ") }; + f.write_char('(')?; for p in &self.pos { write_sep(f)?; f.write_str(&p.name)?; @@ -246,7 +248,7 @@ impl fmt::Display for SignatureDocs { let v = v.as_deref().unwrap_or("any"); let mut v = v.trim(); if v.starts_with('{') && v.ends_with('}') && v.len() > 30 { - v = "{ ... }" + v = "{ .. }" } if v.starts_with('`') && v.ends_with('`') && v.len() > 30 { v = "raw" @@ -258,9 +260,17 @@ impl fmt::Display for SignatureDocs { if let Some(t) = t { write!(f, ": {t}")?; } - write!(f, " = {v}")?; + if v.contains('\n') { + write!(f, " = {}", v.replace("\n", "\n "))?; + } else { + write!(f, " = {v}")?; + } } } + if !is_first { + f.write_str(",\n")?; + } + f.write_char(')')?; Ok(()) } @@ -303,7 +313,7 @@ fn format_ty(ty: Option<&Ty>, doc_ty: Option<&mut ShowTypeRepr>) -> TypeRepr { match doc_ty { Some(doc_ty) => doc_ty(ty), None => ty - .and_then(|ty| ty.describe()) + .and_then(|ty| ty.repr()) .map(|short| (short, format!("{ty:?}"))), } } diff --git a/crates/tinymist-query/src/fixtures/hover/snaps/test@annotate_fn.typ.snap b/crates/tinymist-query/src/fixtures/hover/snaps/test@annotate_fn.typ.snap index 167b9a4e..0df9b50e 100644 --- a/crates/tinymist-query/src/fixtures/hover/snaps/test@annotate_fn.typ.snap +++ b/crates/tinymist-query/src/fixtures/hover/snaps/test@annotate_fn.typ.snap @@ -4,6 +4,6 @@ expression: "JsonRepr::new_redacted(result, &REDACT_LOC)" input_file: crates/tinymist-query/src/fixtures/hover/annotate_fn.typ --- { - "contents": "```typc\nlet touying-fn-wrapper(fn: (..: []) => any | function, ..args: arguments, max-repetitions: int | none = none, repetitions: int | none = none) = none;\n```\n\n---\n## Parameters\n\n@positional `fn` — The `fn`.\n\n@named `max-repetitions` — The `max-repetitions`.\n\n@named `repetitions` — The `repetitions`.\n\n@rest `args` — The `args`.", + "contents": "```typc\nlet touying-fn-wrapper(\n fn: (..: []) => any | function,\n ..args: arguments,\n max-repetitions: int | none = none,\n repetitions: int | none = none,\n) = none;\n```\n\n---\n## Parameters\n\n@positional `fn` — The `fn`.\n\n@named `max-repetitions` — The `max-repetitions`.\n\n@named `repetitions` — The `repetitions`.\n\n@rest `args` — The `args`.", "range": "8:20:8:38" } diff --git a/crates/tinymist-query/src/fixtures/hover/snaps/test@builtin.typ.snap b/crates/tinymist-query/src/fixtures/hover/snaps/test@builtin.typ.snap index 55b89c04..10ce9e1a 100644 --- a/crates/tinymist-query/src/fixtures/hover/snaps/test@builtin.typ.snap +++ b/crates/tinymist-query/src/fixtures/hover/snaps/test@builtin.typ.snap @@ -4,6 +4,6 @@ expression: "JsonRepr::new_redacted(result, &REDACT_LOC)" input_file: crates/tinymist-query/src/fixtures/hover/builtin.typ --- { - "contents": "```typc\nlet table(..children: content, align: alignment | array | auto | function = auto, column-gutter: array | auto | integer | length = (), columns: array | auto | integer | length = (), fill: color = none, gutter: array | auto | integer | length = (), inset: inset = 0% + 5pt, row-gutter: array | auto | integer | length = (), rows: array | auto | integer | length = (), stroke: stroke = 1pt + black);\n```\n\n---\nA table of items.\n\nTables are used to arrange content in cells. Cells can contain arbitrary\ncontent, including multiple paragraphs and are specified in row-major order.\nFor a hands-on explanation of all the ways you can use and customize tables\nin Typst, check out the [table guide](https://typst.app/docs/guides/table-guide/).\n\nBecause tables are just grids with different defaults for some cell\nproperties (notably `stroke` and `inset`), refer to the [grid\ndocumentation](https://typst.app/docs/reference/layout/grid/) for more information on how to size the table tracks\nand specify the cell appearance properties.\n\nIf you are unsure whether you should be using a table or a grid, consider\nwhether the content you are arranging semantically belongs together as a set\nof related data points or similar or whether you are just want to enhance\nyour presentation by arranging unrelated content in a grid. In the former\ncase, a table is the right choice, while in the latter case, a grid is more\nappropriate. Furthermore, Typst will annotate its output in the future such\nthat screenreaders will announce content in `table` as tabular while a\ngrid's content will be announced no different than multiple content blocks\nin the document flow.\n\nNote that, to override a particular cell's properties or apply show rules on\ntable cells, you can use the [`table.cell`](https://typst.app/docs/reference/model/table/#definitions-cell) element. See its\ndocumentation for more information.\n\nAlthough the `table` and the `grid` share most properties, set and show\nrules on one of them do not affect the other.\n\nTo give a table a caption and make it [referenceable](https://typst.app/docs/reference/model/ref/), put it into a\n[figure].\n\n# Example\n\nThe example below demonstrates some of the most common table options.\n```typ\n#table(\n columns: (1fr, auto, auto),\n inset: 10pt,\n align: horizon,\n table.header(\n [], [*Volume*], [*Parameters*],\n ),\n image(\"cylinder.svg\"),\n $ pi h (D^2 - d^2) / 4 $,\n [\n $h$: height \\\n $D$: outer radius \\\n $d$: inner radius\n ],\n image(\"tetrahedron.svg\"),\n $ sqrt(2) / 12 a^3 $,\n [$a$: edge length]\n)\n```\n\nMuch like with grids, you can use [`table.cell`](https://typst.app/docs/reference/model/table/#definitions-cell) to customize\nthe appearance and the position of each cell.\n\n```typ\n>>> #set page(width: auto)\n>>> #set text(font: \"IBM Plex Sans\")\n>>> #let gray = rgb(\"#565565\")\n>>>\n#set table(\n stroke: none,\n gutter: 0.2em,\n fill: (x, y) =>\n if x == 0 or y == 0 { gray },\n inset: (right: 1.5em),\n)\n\n#show table.cell: it => {\n if it.x == 0 or it.y == 0 {\n set text(white)\n strong(it)\n } else if it.body == [] {\n // Replace empty cells with 'N/A'\n pad(..it.inset)[_N/A_]\n } else {\n it\n }\n}\n\n#let a = table.cell(\n fill: green.lighten(60%),\n)[A]\n#let b = table.cell(\n fill: aqua.lighten(60%),\n)[B]\n\n#table(\n columns: 4,\n [], [Exam 1], [Exam 2], [Exam 3],\n\n [John], [], a, [],\n [Mary], [], a, a,\n [Robert], b, a, b,\n)\n```\n\n## Parameters\n\n@named `align` — How to align the cells' content.\n\nThis can either be a single alignment, an array of alignments\n(corresponding to each column) or a function that returns an alignment.\nThe function receives the cells' column and row indices, starting from\nzero. If set to `auto`, the outer alignment is used.\n\n```typ\n#table(\n columns: 3,\n align: (left, center, right),\n [Hello], [Hello], [Hello],\n [A], [B], [C],\n)\n```\n\n@named `column-gutter` — The gaps between columns. Takes precedence over `gutter`. See the\n[grid documentation](https://typst.app/docs/reference/layout/grid/) for more information on gutters.\n\n@named `columns` — The column sizes. See the [grid documentation](https://typst.app/docs/reference/layout/grid/) for more\ninformation on track sizing.\n\n@named `fill` — How to fill the cells.\n\nThis can be a color or a function that returns a color. The function\nreceives the cells' column and row indices, starting from zero. This can\nbe used to implement striped tables.\n\n```typ\n#table(\n fill: (x, _) =>\n if calc.odd(x) { luma(240) }\n else { white },\n align: (x, y) =>\n if y == 0 { center }\n else if x == 0 { left }\n else { right },\n columns: 4,\n [], [*Q1*], [*Q2*], [*Q3*],\n [Revenue:], [1000 €], [2000 €], [3000 €],\n [Expenses:], [500 €], [1000 €], [1500 €],\n [Profit:], [500 €], [1000 €], [1500 €],\n)\n```\n\n@named `gutter` — The gaps between rows and columns. This is a shorthand for setting\n`column-gutter` and `row-gutter` to the same value. See the [grid\ndocumentation](https://typst.app/docs/reference/layout/grid/) for more information on gutters.\n\n@named `inset` — How much to pad the cells' content.\n\n```typ\n#table(\n inset: 10pt,\n [Hello],\n [World],\n)\n\n#table(\n columns: 2,\n inset: (\n x: 20pt,\n y: 10pt,\n ),\n [Hello],\n [World],\n)\n```\n\n@named `row-gutter` — The gaps between rows. Takes precedence over `gutter`. See the\n[grid documentation](https://typst.app/docs/reference/layout/grid/) for more information on gutters.\n\n@named `rows` — The row sizes. See the [grid documentation](https://typst.app/docs/reference/layout/grid/) for more information\non track sizing.\n\n@named `stroke` — How to [stroke] the cells.\n\nStrokes can be disabled by setting this to `none`.\n\nIf it is necessary to place lines which can cross spacing between cells\nproduced by the `gutter` option, or to override the stroke between\nmultiple specific cells, consider specifying one or more of\n[`table.hline`](https://typst.app/docs/reference/model/table/#definitions-hline) and [`table.vline`](https://typst.app/docs/reference/model/table/#definitions-vline)\nalongside your table cells.\n\nSee the [grid documentation](https://typst.app/docs/reference/layout/grid/#parameters-stroke) for more information on\nstrokes.\n\n@rest `children` — The contents of the table cells, plus any extra table lines specified\nwith the [`table.hline`](https://typst.app/docs/reference/model/table/#definitions-hline) and\n[`table.vline`](https://typst.app/docs/reference/model/table/#definitions-vline) elements.\n\n---\n[Open docs](https://typst.app/docs/reference/model/table/)", + "contents": "```typc\nlet table(\n ..children: content,\n align: alignment | array | auto | function = auto,\n column-gutter: array | auto | length | type = (),\n columns: array | auto | length | type = (),\n fill: color = none,\n gutter: array | auto | length | type = (),\n inset: inset = 0% + 5pt,\n row-gutter: array | auto | length | type = (),\n rows: array | auto | length | type = (),\n stroke: stroke = 1pt + black,\n);\n```\n\n---\nA table of items.\n\nTables are used to arrange content in cells. Cells can contain arbitrary\ncontent, including multiple paragraphs and are specified in row-major order.\nFor a hands-on explanation of all the ways you can use and customize tables\nin Typst, check out the [table guide](https://typst.app/docs/guides/table-guide/).\n\nBecause tables are just grids with different defaults for some cell\nproperties (notably `stroke` and `inset`), refer to the [grid\ndocumentation](https://typst.app/docs/reference/layout/grid/) for more information on how to size the table tracks\nand specify the cell appearance properties.\n\nIf you are unsure whether you should be using a table or a grid, consider\nwhether the content you are arranging semantically belongs together as a set\nof related data points or similar or whether you are just want to enhance\nyour presentation by arranging unrelated content in a grid. In the former\ncase, a table is the right choice, while in the latter case, a grid is more\nappropriate. Furthermore, Typst will annotate its output in the future such\nthat screenreaders will announce content in `table` as tabular while a\ngrid's content will be announced no different than multiple content blocks\nin the document flow.\n\nNote that, to override a particular cell's properties or apply show rules on\ntable cells, you can use the [`table.cell`](https://typst.app/docs/reference/model/table/#definitions-cell) element. See its\ndocumentation for more information.\n\nAlthough the `table` and the `grid` share most properties, set and show\nrules on one of them do not affect the other.\n\nTo give a table a caption and make it [referenceable](https://typst.app/docs/reference/model/ref/), put it into a\n[figure].\n\n# Example\n\nThe example below demonstrates some of the most common table options.\n```typ\n#table(\n columns: (1fr, auto, auto),\n inset: 10pt,\n align: horizon,\n table.header(\n [], [*Volume*], [*Parameters*],\n ),\n image(\"cylinder.svg\"),\n $ pi h (D^2 - d^2) / 4 $,\n [\n $h$: height \\\n $D$: outer radius \\\n $d$: inner radius\n ],\n image(\"tetrahedron.svg\"),\n $ sqrt(2) / 12 a^3 $,\n [$a$: edge length]\n)\n```\n\nMuch like with grids, you can use [`table.cell`](https://typst.app/docs/reference/model/table/#definitions-cell) to customize\nthe appearance and the position of each cell.\n\n```typ\n>>> #set page(width: auto)\n>>> #set text(font: \"IBM Plex Sans\")\n>>> #let gray = rgb(\"#565565\")\n>>>\n#set table(\n stroke: none,\n gutter: 0.2em,\n fill: (x, y) =>\n if x == 0 or y == 0 { gray },\n inset: (right: 1.5em),\n)\n\n#show table.cell: it => {\n if it.x == 0 or it.y == 0 {\n set text(white)\n strong(it)\n } else if it.body == [] {\n // Replace empty cells with 'N/A'\n pad(..it.inset)[_N/A_]\n } else {\n it\n }\n}\n\n#let a = table.cell(\n fill: green.lighten(60%),\n)[A]\n#let b = table.cell(\n fill: aqua.lighten(60%),\n)[B]\n\n#table(\n columns: 4,\n [], [Exam 1], [Exam 2], [Exam 3],\n\n [John], [], a, [],\n [Mary], [], a, a,\n [Robert], b, a, b,\n)\n```\n\n## Parameters\n\n@named `align` — How to align the cells' content.\n\nThis can either be a single alignment, an array of alignments\n(corresponding to each column) or a function that returns an alignment.\nThe function receives the cells' column and row indices, starting from\nzero. If set to `auto`, the outer alignment is used.\n\n```typ\n#table(\n columns: 3,\n align: (left, center, right),\n [Hello], [Hello], [Hello],\n [A], [B], [C],\n)\n```\n\n@named `column-gutter` — The gaps between columns. Takes precedence over `gutter`. See the\n[grid documentation](https://typst.app/docs/reference/layout/grid/) for more information on gutters.\n\n@named `columns` — The column sizes. See the [grid documentation](https://typst.app/docs/reference/layout/grid/) for more\ninformation on track sizing.\n\n@named `fill` — How to fill the cells.\n\nThis can be a color or a function that returns a color. The function\nreceives the cells' column and row indices, starting from zero. This can\nbe used to implement striped tables.\n\n```typ\n#table(\n fill: (x, _) =>\n if calc.odd(x) { luma(240) }\n else { white },\n align: (x, y) =>\n if y == 0 { center }\n else if x == 0 { left }\n else { right },\n columns: 4,\n [], [*Q1*], [*Q2*], [*Q3*],\n [Revenue:], [1000 €], [2000 €], [3000 €],\n [Expenses:], [500 €], [1000 €], [1500 €],\n [Profit:], [500 €], [1000 €], [1500 €],\n)\n```\n\n@named `gutter` — The gaps between rows and columns. This is a shorthand for setting\n`column-gutter` and `row-gutter` to the same value. See the [grid\ndocumentation](https://typst.app/docs/reference/layout/grid/) for more information on gutters.\n\n@named `inset` — How much to pad the cells' content.\n\n```typ\n#table(\n inset: 10pt,\n [Hello],\n [World],\n)\n\n#table(\n columns: 2,\n inset: (\n x: 20pt,\n y: 10pt,\n ),\n [Hello],\n [World],\n)\n```\n\n@named `row-gutter` — The gaps between rows. Takes precedence over `gutter`. See the\n[grid documentation](https://typst.app/docs/reference/layout/grid/) for more information on gutters.\n\n@named `rows` — The row sizes. See the [grid documentation](https://typst.app/docs/reference/layout/grid/) for more information\non track sizing.\n\n@named `stroke` — How to [stroke] the cells.\n\nStrokes can be disabled by setting this to `none`.\n\nIf it is necessary to place lines which can cross spacing between cells\nproduced by the `gutter` option, or to override the stroke between\nmultiple specific cells, consider specifying one or more of\n[`table.hline`](https://typst.app/docs/reference/model/table/#definitions-hline) and [`table.vline`](https://typst.app/docs/reference/model/table/#definitions-vline)\nalongside your table cells.\n\nSee the [grid documentation](https://typst.app/docs/reference/layout/grid/#parameters-stroke) for more information on\nstrokes.\n\n@rest `children` — The contents of the table cells, plus any extra table lines specified\nwith the [`table.hline`](https://typst.app/docs/reference/model/table/#definitions-hline) and\n[`table.vline`](https://typst.app/docs/reference/model/table/#definitions-vline) elements.\n\n---\n[Open docs](https://typst.app/docs/reference/model/table/)", "range": "0:20:0:25" } diff --git a/crates/tinymist-query/src/fixtures/hover/snaps/test@pagebreak.typ.snap b/crates/tinymist-query/src/fixtures/hover/snaps/test@pagebreak.typ.snap index 7cc8ffee..e7e47c3f 100644 --- a/crates/tinymist-query/src/fixtures/hover/snaps/test@pagebreak.typ.snap +++ b/crates/tinymist-query/src/fixtures/hover/snaps/test@pagebreak.typ.snap @@ -4,6 +4,6 @@ expression: "JsonRepr::new_redacted(result, &REDACT_LOC)" input_file: crates/tinymist-query/src/fixtures/hover/pagebreak.typ --- { - "contents": "```typc\nlet pagebreak(to: \"even\" | \"odd\" | none = none, weak: bool = false);\n```\n\n---\nA manual page break.\n\nMust not be used inside any containers.\n\n# Example\n```typ\nThe next page contains\nmore details on compound theory.\n#pagebreak()\n\n== Compound Theory\nIn 1984, the first ...\n```\n\n## Parameters\n\n@named `to` — If given, ensures that the next page will be an even/odd page, with an\nempty page in between if necessary.\n\n```typ\n#set page(height: 30pt)\n\nFirst.\n#pagebreak(to: \"odd\")\nThird.\n```\n\n@named `weak` — If `true`, the page break is skipped if the current page is already\nempty.\n\n---\n[Open docs](https://typst.app/docs/reference/layout/pagebreak/)", + "contents": "```typc\nlet pagebreak(\n to: none | str = none,\n weak: bool = false,\n);\n```\n\n---\nA manual page break.\n\nMust not be used inside any containers.\n\n# Example\n```typ\nThe next page contains\nmore details on compound theory.\n#pagebreak()\n\n== Compound Theory\nIn 1984, the first ...\n```\n\n## Parameters\n\n@named `to` — If given, ensures that the next page will be an even/odd page, with an\nempty page in between if necessary.\n\n```typ\n#set page(height: 30pt)\n\nFirst.\n#pagebreak(to: \"odd\")\nThird.\n```\n\n@named `weak` — If `true`, the page break is skipped if the current page is already\nempty.\n\n---\n[Open docs](https://typst.app/docs/reference/layout/pagebreak/)", "range": "0:20:0:29" } diff --git a/crates/tinymist-query/src/fixtures/hover/snaps/test@user.typ.snap b/crates/tinymist-query/src/fixtures/hover/snaps/test@user.typ.snap index 69fdbe16..f817a5db 100644 --- a/crates/tinymist-query/src/fixtures/hover/snaps/test@user.typ.snap +++ b/crates/tinymist-query/src/fixtures/hover/snaps/test@user.typ.snap @@ -4,6 +4,6 @@ expression: "JsonRepr::new_redacted(result, &REDACT_LOC)" input_file: crates/tinymist-query/src/fixtures/hover/user.typ --- { - "contents": "```typc\nlet f() = 1;\n```\n\n---\nTest", + "contents": "```typc\nlet f() = int;\n```\n\n---\nTest", "range": "3:20:3:21" } diff --git a/crates/tinymist-query/src/fixtures/hover/snaps/test@value_repr.typ.snap b/crates/tinymist-query/src/fixtures/hover/snaps/test@value_repr.typ.snap new file mode 100644 index 00000000..df6314e7 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/hover/snaps/test@value_repr.typ.snap @@ -0,0 +1,9 @@ +--- +source: crates/tinymist-query/src/hover.rs +expression: "JsonRepr::new_redacted(result, &REDACT_LOC)" +input_file: crates/tinymist-query/src/fixtures/hover/value_repr.typ +--- +{ + "contents": "```typc\nlet reconstruct(\n it,\n ..new-body: arguments,\n body-name: str = \"body\",\n labeled: bool = true,\n max-depth: int = 9999,\n wrapper: () => box = Closure(..),\n) = none;\n```\n\n---\n## Parameters\n\n@positional `it`\n\n@named `body-name`\n\n@named `labeled`\n\n@named `max-depth`\n\n@named `wrapper`\n\n@rest `new-body`", + "range": "1:20:1:31" +} diff --git a/crates/tinymist-query/src/fixtures/hover/value_repr.typ b/crates/tinymist-query/src/fixtures/hover/value_repr.typ new file mode 100644 index 00000000..417c9522 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/hover/value_repr.typ @@ -0,0 +1,2 @@ +#let reconstruct(body-name: "body", labeled: true, max-depth: 9999, wrapper: () => box(""), it, ..new-body) = { } +#(/* ident after */ reconstruct); diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-_size-to-pt.typ-2.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-_size-to-pt.typ-2.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-_size-to-pt.typ-2.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-_size-to-pt.typ-2.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-_size-to-pt.typ-3.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-_size-to-pt.typ-3.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-_size-to-pt.typ-3.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-_size-to-pt.typ-3.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-_size-to-pt.typ-4.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-_size-to-pt.typ-4.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-_size-to-pt.typ-4.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-_size-to-pt.typ-4.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-_size-to-pt.typ.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-_size-to-pt.typ.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-_size-to-pt.typ.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-_size-to-pt.typ.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-current-heading.typ-2.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-current-heading.typ-2.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-current-heading.typ-2.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-current-heading.typ-2.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-current-heading.typ-3.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-current-heading.typ-3.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-current-heading.typ-3.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-current-heading.typ-3.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-current-heading.typ-4.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-current-heading.typ-4.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-current-heading.typ-4.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-current-heading.typ-4.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-current-heading.typ.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-current-heading.typ.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-current-heading.typ.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-current-heading.typ.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-fit-to-height.typ-2.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-fit-to-height.typ-2.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-fit-to-height.typ-2.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-fit-to-height.typ-2.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-fit-to-height.typ-3.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-fit-to-height.typ-3.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-fit-to-height.typ-3.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-fit-to-height.typ-3.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-fit-to-height.typ.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-fit-to-height.typ.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-fit-to-height.typ.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-fit-to-height.typ.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-reconstruct.typ-2.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-reconstruct.typ-2.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-reconstruct.typ-2.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-reconstruct.typ-2.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-reconstruct.typ-3.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-reconstruct.typ-3.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-reconstruct.typ-3.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-reconstruct.typ-3.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-reconstruct.typ-4.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-reconstruct.typ-4.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-reconstruct.typ-4.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-reconstruct.typ-4.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-reconstruct.typ.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-reconstruct.typ.snap similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/snaps/test@touying-utils-reconstruct.typ.snap rename to crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-reconstruct.typ.snap diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-_size-to-pt.typ b/crates/tinymist-query/src/fixtures/pkgs/touying-utils-_size-to-pt.typ similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-_size-to-pt.typ rename to crates/tinymist-query/src/fixtures/pkgs/touying-utils-_size-to-pt.typ diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-current-heading.typ b/crates/tinymist-query/src/fixtures/pkgs/touying-utils-current-heading.typ similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-current-heading.typ rename to crates/tinymist-query/src/fixtures/pkgs/touying-utils-current-heading.typ diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-fit-to-height.typ b/crates/tinymist-query/src/fixtures/pkgs/touying-utils-fit-to-height.typ similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-fit-to-height.typ rename to crates/tinymist-query/src/fixtures/pkgs/touying-utils-fit-to-height.typ diff --git a/crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-reconstruct.typ b/crates/tinymist-query/src/fixtures/pkgs/touying-utils-reconstruct.typ similarity index 100% rename from crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-reconstruct.typ rename to crates/tinymist-query/src/fixtures/pkgs/touying-utils-reconstruct.typ diff --git a/crates/tinymist-query/src/fixtures/post_type_check/snaps/test@with_builtin.typ.snap b/crates/tinymist-query/src/fixtures/post_type_check/snaps/test@with_builtin.typ.snap index 0d0f357c..0a26cafb 100644 --- a/crates/tinymist-query/src/fixtures/post_type_check/snaps/test@with_builtin.typ.snap +++ b/crates/tinymist-query/src/fixtures/post_type_check/snaps/test@with_builtin.typ.snap @@ -4,4 +4,4 @@ description: "Check on \"(\" (17)" expression: literal_type input_file: crates/tinymist-query/src/fixtures/post_type_check/with_builtin.typ --- -( ⪯ (Type(integer) | Type(ratio))) +( ⪯ (Type(int) | Type(ratio))) diff --git a/crates/tinymist-query/src/fixtures/type_check/snaps/test@annotation_fn.typ.snap b/crates/tinymist-query/src/fixtures/type_check/snaps/test@annotation_fn.typ.snap index ba078b16..80986348 100644 --- a/crates/tinymist-query/src/fixtures/type_check/snaps/test@annotation_fn.typ.snap +++ b/crates/tinymist-query/src/fixtures/type_check/snaps/test@annotation_fn.typ.snap @@ -7,7 +7,7 @@ input_file: crates/tinymist-query/src/fixtures/type_check/annotation_fn.typ "fn" = Any "max-repetitions" = None "repetitions" = None -"touying-fn-wrapper" = ((( ⪯ Type(function)), "max-repetitions": ( ⪯ Type(integer)), "repetitions": ( ⪯ Type(integer)), ...: ( ⪯ Any)) => None).with(..("max-repetitions": None, "repetitions": None) => any) +"touying-fn-wrapper" = ((( ⪯ Type(function)), "max-repetitions": ( ⪯ Type(int)), "repetitions": ( ⪯ Type(int)), ...: ( ⪯ Any)) => None).with(..("max-repetitions": None, "repetitions": None) => any) --- 162..180 -> @touying-fn-wrapper 181..183 -> @fn diff --git a/crates/tinymist-query/src/fixtures/type_check/snaps/test@annotation_sum.typ.snap b/crates/tinymist-query/src/fixtures/type_check/snaps/test@annotation_sum.typ.snap index 24247ed5..e555fb06 100644 --- a/crates/tinymist-query/src/fixtures/type_check/snaps/test@annotation_sum.typ.snap +++ b/crates/tinymist-query/src/fixtures/type_check/snaps/test@annotation_sum.typ.snap @@ -4,7 +4,7 @@ expression: result input_file: crates/tinymist-query/src/fixtures/type_check/annotation_sum.typ --- "args" = Args -"sum" = (...: ( ⪯ Array)) => None +"sum" = (...: ( ⪯ Array)) => None --- 65..68 -> @sum 71..75 -> @args diff --git a/crates/tinymist-query/src/fixtures/type_check/snaps/test@fn_named.typ.snap b/crates/tinymist-query/src/fixtures/type_check/snaps/test@fn_named.typ.snap index 834a9026..62dd8626 100644 --- a/crates/tinymist-query/src/fixtures/type_check/snaps/test@fn_named.typ.snap +++ b/crates/tinymist-query/src/fixtures/type_check/snaps/test@fn_named.typ.snap @@ -3,7 +3,7 @@ source: crates/tinymist-query/src/analysis.rs expression: result input_file: crates/tinymist-query/src/fixtures/type_check/fn_named.typ --- -"d" = ( ⪰ 3 | Type(integer)) +"d" = ( ⪰ 3 | Type(int)) "foo" = (("d": Any) => Any).with(..("d": 3) => any) "x" = 3 --- diff --git a/crates/tinymist-query/src/fixtures/type_check/snaps/test@infer.typ.snap b/crates/tinymist-query/src/fixtures/type_check/snaps/test@infer.typ.snap index 55e21c81..9d840342 100644 --- a/crates/tinymist-query/src/fixtures/type_check/snaps/test@infer.typ.snap +++ b/crates/tinymist-query/src/fixtures/type_check/snaps/test@infer.typ.snap @@ -6,7 +6,7 @@ input_file: crates/tinymist-query/src/fixtures/type_check/infer.typ 1..6 -> Func(image) 1..18 -> Element(image) 21..25 -> Func(read) -21..37 -> (Type(bytes) | Type(string)) +21..37 -> (Type(bytes) | Type(str)) 40..44 -> Func(json) 40..57 -> Any 60..64 -> Func(yaml) diff --git a/crates/tinymist-query/src/fixtures/type_check/snaps/test@sig_template_set.typ.snap b/crates/tinymist-query/src/fixtures/type_check/snaps/test@sig_template_set.typ.snap index 9d72559a..4f3105cf 100644 --- a/crates/tinymist-query/src/fixtures/type_check/snaps/test@sig_template_set.typ.snap +++ b/crates/tinymist-query/src/fixtures/type_check/snaps/test@sig_template_set.typ.snap @@ -7,7 +7,7 @@ input_file: crates/tinymist-query/src/fixtures/type_check/sig_template_set.typ "class" = ( ⪰ "article" | "article" | "letter" | "article" | "letter") "content" = Any "font" = None -"tmpl" = ((Any, "authors": ( ⪯ (Type(array) | Type(string))), "class": Any, "font": ( ⪯ (TextFont | Array))) => Any).with(..("authors": (), "class": "article", "font": None) => any) +"tmpl" = ((Any, "authors": ( ⪯ (Type(array) | Type(str))), "class": Any, "font": ( ⪯ (TextFont | Array))) => Any).with(..("authors": (), "class": "article", "font": None) => any) --- 5..9 -> @tmpl 10..17 -> @content diff --git a/crates/tinymist-query/src/fixtures/type_check/snaps/test@tuple_map.typ.snap b/crates/tinymist-query/src/fixtures/type_check/snaps/test@tuple_map.typ.snap index 3e2d8d3b..c3a27954 100644 --- a/crates/tinymist-query/src/fixtures/type_check/snaps/test@tuple_map.typ.snap +++ b/crates/tinymist-query/src/fixtures/type_check/snaps/test@tuple_map.typ.snap @@ -3,10 +3,10 @@ source: crates/tinymist-query/src/analysis.rs expression: result input_file: crates/tinymist-query/src/fixtures/type_check/tuple_map.typ --- -"" = (( ⪯ (Type(bytes) | Type(decimal) | Type(float) | Type(integer) | Type(label) | Type(string) | Type(type) | Type(version)))) => Type(string) +"" = (( ⪯ (Type(bytes) | Type(decimal) | Type(float) | Type(int) | Type(label) | Type(str) | Type(type) | Type(version)))) => Type(str) "a" = (1, ) -"b" = (Type(string), ) -"f" = (( ⪯ (Type(bytes) | Type(decimal) | Type(float) | Type(integer) | Type(label) | Type(string) | Type(type) | Type(version)))) => Type(string) +"b" = (Type(str), ) +"f" = (( ⪯ (Type(bytes) | Type(decimal) | Type(float) | Type(int) | Type(label) | Type(str) | Type(type) | Type(version)))) => Type(str) "x" = Any --- 5..6 -> @a @@ -14,9 +14,9 @@ input_file: crates/tinymist-query/src/fixtures/type_check/tuple_map.typ 24..25 -> @x 24..35 -> @ 29..32 -> Type(string) -29..35 -> Type(string) +29..35 -> Type(str) 33..34 -> @x 42..43 -> @b 46..47 -> @a -46..54 -> (Type(string), ) +46..54 -> (Type(str), ) 52..53 -> @f diff --git a/crates/tinymist-query/src/fixtures/type_check/snaps/test@with.typ.snap b/crates/tinymist-query/src/fixtures/type_check/snaps/test@with.typ.snap index 235c623a..7296021b 100644 --- a/crates/tinymist-query/src/fixtures/type_check/snaps/test@with.typ.snap +++ b/crates/tinymist-query/src/fixtures/type_check/snaps/test@with.typ.snap @@ -5,7 +5,7 @@ input_file: crates/tinymist-query/src/fixtures/type_check/with.typ --- "f" = (Any) => Any "g" = ((Any) => Any).with(..(1) => any) -"x" = ( ⪰ Type(integer) | Type(integer)) +"x" = ( ⪰ Type(int) | Type(int)) "x" = 1 --- 5..6 -> @f diff --git a/crates/tinymist-query/src/hover.rs b/crates/tinymist-query/src/hover.rs index 329b565b..1f6c760f 100644 --- a/crates/tinymist-query/src/hover.rs +++ b/crates/tinymist-query/src/hover.rs @@ -256,7 +256,7 @@ fn def_tooltip( results.push(MarkedString::LanguageString(LanguageString { language: "typc".to_owned(), value: format!( - "let {name}({params}){result};", + "let {name}{params}{result};", name = def.name(), params = ParamTooltip(sig.as_ref()), result = @@ -372,7 +372,7 @@ impl fmt::Display for ParamTooltip<'_> { let Some(sig) = self.0 else { return Ok(()); }; - sig.fmt(f) + sig.print(f) } } diff --git a/crates/tinymist-query/src/syntax/def.rs b/crates/tinymist-query/src/syntax/def.rs index 8e06600a..555957eb 100644 --- a/crates/tinymist-query/src/syntax/def.rs +++ b/crates/tinymist-query/src/syntax/def.rs @@ -90,7 +90,7 @@ impl Expr { impl fmt::Display for Expr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - ExprFormatter::new(f).write_expr(self) + ExprFormatter::new(f, false).write_expr(self) } } @@ -571,7 +571,15 @@ pub enum Pattern { impl fmt::Display for Pattern { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - ExprFormatter::new(f).write_pattern(self) + ExprFormatter::new(f, false).write_pattern(self) + } +} + +impl Pattern { + pub(crate) fn repr(&self) -> EcoString { + let mut s = EcoString::new(); + let _ = ExprFormatter::new(&mut s, true).write_pattern(self); + s } } @@ -847,14 +855,15 @@ impl_internable!( ApplyExpr, ); -struct ExprFormatter<'a, 'b> { - f: &'a mut fmt::Formatter<'b>, +struct ExprFormatter<'a, T: fmt::Write> { + f: &'a mut T, + repr: bool, indent: usize, } -impl<'a, 'b> ExprFormatter<'a, 'b> { - fn new(f: &'a mut fmt::Formatter<'b>) -> Self { - Self { f, indent: 0 } +impl<'a, T: fmt::Write> ExprFormatter<'a, T> { + fn new(f: &'a mut T, repr: bool) -> Self { + Self { f, repr, indent: 0 } } fn write_decl(&mut self, d: &Decl) -> fmt::Result { @@ -1043,6 +1052,10 @@ impl<'a, 'b> ExprFormatter<'a, 'b> { } fn write_func(&mut self, func: &Interned) -> fmt::Result { + if self.repr { + return self.write_decl(&func.decl); + } + write!(self.f, "func[{:?}](", func.decl)?; self.write_pattern_sig(&func.params)?; write!(self.f, " = ")?; @@ -1130,12 +1143,20 @@ impl<'a, 'b> ExprFormatter<'a, 'b> { } fn write_contextual(&mut self, c: &Interned) -> fmt::Result { + if self.repr { + return self.f.write_str("content"); + } + self.f.write_str("contextual(")?; self.write_expr(c)?; self.f.write_str(")") } fn write_conditional(&mut self, c: &Interned) -> fmt::Result { + if self.repr { + return self.f.write_str("Expr(..)"); + } + self.f.write_str("if(")?; self.write_expr(&c.cond)?; self.f.write_str(", then = ")?; @@ -1146,6 +1167,10 @@ impl<'a, 'b> ExprFormatter<'a, 'b> { } fn write_while_loop(&mut self, w: &Interned) -> fmt::Result { + if self.repr { + return self.f.write_str("Expr(..)"); + } + self.f.write_str("while(")?; self.write_expr(&w.cond)?; self.f.write_str(", ")?; @@ -1154,6 +1179,10 @@ impl<'a, 'b> ExprFormatter<'a, 'b> { } fn write_for_loop(&mut self, f: &Interned) -> fmt::Result { + if self.repr { + return self.f.write_str("Expr(..)"); + } + self.f.write_str("for(")?; self.write_pattern(&f.pattern)?; self.f.write_str(", ")?; diff --git a/crates/tinymist-query/src/ty/builtin.rs b/crates/tinymist-query/src/ty/builtin.rs index 35e90ebb..0cf33ba8 100644 --- a/crates/tinymist-query/src/ty/builtin.rs +++ b/crates/tinymist-query/src/ty/builtin.rs @@ -263,7 +263,7 @@ impl fmt::Debug for BuiltinTy { BuiltinTy::Inset => write!(f, "Inset"), BuiltinTy::Outset => write!(f, "Outset"), BuiltinTy::Radius => write!(f, "Radius"), - BuiltinTy::Type(ty) => write!(f, "Type({})", ty.long_name()), + BuiltinTy::Type(ty) => write!(f, "Type({})", ty.short_name()), BuiltinTy::Element(e) => e.fmt(f), BuiltinTy::Tag(tag) => { let (name, id) = tag.as_ref(); diff --git a/crates/tinymist-query/src/ty/describe.rs b/crates/tinymist-query/src/ty/describe.rs index 27bc0c8f..f4a26bd9 100644 --- a/crates/tinymist-query/src/ty/describe.rs +++ b/crates/tinymist-query/src/ty/describe.rs @@ -6,12 +6,21 @@ use crate::ty::prelude::*; impl TypeScheme { /// Describe the given type with the given type scheme. pub fn describe(&self, ty: &Ty) -> Option { - let mut worker = TypeDescriber::default(); + let mut worker: TypeDescriber = TypeDescriber::default(); worker.describe_root(ty) } } impl Ty { + /// Describe the given type. + pub fn repr(&self) -> Option { + let mut worker = TypeDescriber { + repr: true, + ..Default::default() + }; + worker.describe_root(self) + } + /// Describe the given type. pub fn describe(&self) -> Option { let mut worker = TypeDescriber::default(); @@ -21,6 +30,7 @@ impl Ty { #[derive(Default)] struct TypeDescriber { + repr: bool, described: HashMap, results: HashSet, functions: Vec>, @@ -148,8 +158,11 @@ impl TypeDescriber { Ty::Builtin(BuiltinTy::Auto) => { return "auto".to_string(); } + Ty::Boolean(..) if self.repr => { + return "bool".to_string(); + } Ty::Boolean(None) => { - return "boolean".to_string(); + return "bool".to_string(); } Ty::Boolean(Some(b)) => { return b.to_string(); @@ -157,27 +170,19 @@ impl TypeDescriber { Ty::Builtin(b) => { return b.describe(); } + Ty::Value(v) if self.repr => return v.val.ty().short_name().to_string(), Ty::Value(v) => return v.val.repr().to_string(), Ty::Field(..) => { return "field".to_string(); } Ty::Args(..) => { - return "args".to_string(); + return "arguments".to_string(); } Ty::Pattern(..) => { return "pattern".to_string(); } - Ty::Select(..) => { - return "any".to_string(); - } - Ty::Unary(..) => { - return "any".to_string(); - } - Ty::Binary(..) => { - return "any".to_string(); - } - Ty::If(..) => { - return "any".to_string(); + Ty::Select(..) | Ty::Unary(..) | Ty::Binary(..) | Ty::If(..) => { + return "any".to_string() } } diff --git a/crates/tinymist-query/src/upstream/complete/ext.rs b/crates/tinymist-query/src/upstream/complete/ext.rs index f556210d..d5c9a422 100644 --- a/crates/tinymist-query/src/upstream/complete/ext.rs +++ b/crates/tinymist-query/src/upstream/complete/ext.rs @@ -909,7 +909,7 @@ fn type_completion( } else { ctx.completions.push(Completion { kind: CompletionKind::Syntax, - label: ty.long_name().into(), + label: ty.short_name().into(), apply: Some(eco_format!("${{{ty}}}")), detail: Some(eco_format!("A value of type {ty}.")), ..Completion::default() diff --git a/syntaxes/textmate/main.mts b/syntaxes/textmate/main.mts index 385d4b69..42b01fa3 100644 --- a/syntaxes/textmate/main.mts +++ b/syntaxes/textmate/main.mts @@ -96,7 +96,7 @@ const primitiveFunctions = { const primitiveTypes: textmate.PatternMatch = { match: - /\b(auto|any|none|false|true|str|int|float|bool|length|content)\b(?!-)/, + /\b(any|str|int|float|bool|length|content|array|dictionary|arguments)\b(?!-)/, name: "entity.name.type.primitive.typst", }; @@ -380,7 +380,12 @@ const markupEnterCode: textmate.Pattern = { ), enterExpression( "entity.name.type.primitive.hash.typst", - /(?=(?:auto|any|none|false|true|str|int|float|bool|length|content)\b(?!-))/ + /(?=(?:any|str|int|float|bool|length|content|array|dictionary|arguments)\b(?!-))/ + ), + enterExpression("keyword.other.none.hash.typst", /(?=(?:none)\b(?!-))/), + enterExpression( + "constant.language.boolean.hash.typst", + /(?=(?:false|true)\b(?!-))/ ), enterExpression( "entity.name.function.hash.typst", @@ -421,20 +426,25 @@ const floatUnit = (unit: RegExp, canDotSuff: boolean) => FLOAT_OR_INT.source + (canDotSuff ? "" : "(? { { include: "#primitiveFunctions" }, { include: "#primitiveTypes" }, // todo: enable if only if for completely right grammar + { include: "#keywordConstants" }, { include: "#identifier" }, { include: "#constants" }, { @@ -1373,6 +1384,7 @@ export const typst: textmate.Grammar = { markup, markupEnterCode, code, + keywordConstants, constants, primitiveColors, diff --git a/tests/e2e/main.rs b/tests/e2e/main.rs index cf0ad402..b90e6390 100644 --- a/tests/e2e/main.rs +++ b/tests/e2e/main.rs @@ -374,7 +374,7 @@ fn e2e() { }); let hash = replay_log(&tinymist_binary, &root.join("neovim")); - insta::assert_snapshot!(hash, @"siphash128_13:65fa45388648e656b1ec7cc30c48ad85"); + insta::assert_snapshot!(hash, @"siphash128_13:bafb35d07c168f6630fc455df6ba0a3"); } { @@ -385,7 +385,7 @@ fn e2e() { }); let hash = replay_log(&tinymist_binary, &root.join("vscode")); - insta::assert_snapshot!(hash, @"siphash128_13:79e7e3ea6fab006d0b4b510940e10ee9"); + insta::assert_snapshot!(hash, @"siphash128_13:1cd09a6f0362384cafcbf632da1a1d0"); } }