diff --git a/codemod/src/main.rs b/codemod/src/main.rs index c993a22..9e19389 100644 --- a/codemod/src/main.rs +++ b/codemod/src/main.rs @@ -287,7 +287,7 @@ fn indent_list_item_content(body: &str, indent: &str) -> String { if line_nr > 0 { res.push_str(&format!("{} {}\n", indent, line.trim())); } else { - res.push_str(&format!("{}",line.trim())) + res.push_str(&format!("{}", line.trim())) } } res @@ -314,8 +314,10 @@ fn format_comment(text: &str, token: &SyntaxToken) -> String { let mut markdown = parse_doc_comment(&lines.join("\n"), indentation + 2); if let Some(argument_docs) = get_argument_docs(token, &indent_2) { - markdown.push_str(&format!("\n\n{indent_2}# Arguments")); - markdown.push_str(&format!("\n\n{argument_docs}")); + if !argument_docs.trim().is_empty() { + markdown.push_str(&format!("\n\n{indent_2}# Arguments")); + markdown.push_str(&format!("\n\n{argument_docs}")); + } } return format!("/**\n{}\n{}*/", markdown, indent_1); diff --git a/pesto/src/alias.rs b/pesto/src/alias.rs index 6f9813f..457b6b1 100644 --- a/pesto/src/alias.rs +++ b/pesto/src/alias.rs @@ -23,6 +23,7 @@ use crate::pasta::{AliasList, Docs, ValuePath}; /// Match Non-Primop /// Eq position pub fn find_aliases(item: &Docs, list: &Vec<&Docs>) -> AliasList { + dbg!("find alias for", &item.path); let res: AliasList = list .iter() .filter_map(|other| { @@ -54,6 +55,7 @@ pub fn find_aliases(item: &Docs, list: &Vec<&Docs>) -> AliasList { None } (false, false) => { + dbg!("this case", s_meta.countApplied); if s_meta.countApplied != Some(0) { if item.path.last() == other.path.last() { return Some(other.path.clone()); @@ -61,8 +63,7 @@ pub fn find_aliases(item: &Docs, list: &Vec<&Docs>) -> AliasList { } if s_meta.position == o_meta.position - && s_meta.countApplied == Some(0) - && s_meta.countApplied == o_meta.countApplied + && (s_meta.countApplied == Some(0) || o_meta.countApplied == Some(0)) { return Some(other.path.clone()); } diff --git a/pesto/test_data/aliases/fold.expect b/pesto/test_data/aliases/fold.expect new file mode 100644 index 0000000..ace3724 --- /dev/null +++ b/pesto/test_data/aliases/fold.expect @@ -0,0 +1,30 @@ +[ + { + "aliases": [ + [ + "lib", + "lists", + "foldr" + ] + ], + "path": [ + "lib", + "lists", + "fold" + ] + }, + { + "aliases": [ + [ + "lib", + "lists", + "fold" + ] + ], + "path": [ + "lib", + "lists", + "foldr" + ] + } +] \ No newline at end of file diff --git a/pesto/test_data/aliases/fold.json b/pesto/test_data/aliases/fold.json new file mode 100644 index 0000000..2aab973 --- /dev/null +++ b/pesto/test_data/aliases/fold.json @@ -0,0 +1,42 @@ +[ + { + "docs": { + "attr": { + "position": { + "column": 3, + "file": "/nix/store/ba0p7n38ncj0gx55yj2vddx189nkljs0-nixpkgs-migrated/lib/lists.nix", + "line": 108 + } + }, + "lambda": { + "isPrimop": false, + "position": { + "column": 11, + "file": "/nix/store/ba0p7n38ncj0gx55yj2vddx189nkljs0-nixpkgs-migrated/lib/lists.nix", + "line": 95 + } + } + }, + "path": ["lib", "lists", "fold"] + }, + { + "docs": { + "attr": { + "position": { + "column": 3, + "file": "/nix/store/ba0p7n38ncj0gx55yj2vddx189nkljs0-nixpkgs-migrated/lib/lists.nix", + "line": 95 + } + }, + "lambda": { + "isPrimop": false, + "position": { + "column": 11, + "file": "/nix/store/ba0p7n38ncj0gx55yj2vddx189nkljs0-nixpkgs-migrated/lib/lists.nix", + "line": 95 + } + } + }, + "path": ["lib", "lists", "foldr"] + } +] diff --git a/website/src/app/f/[...path]/layout.tsx b/website/src/app/f/[...path]/layout.tsx index 40fe88b..ee53d77 100644 --- a/website/src/app/f/[...path]/layout.tsx +++ b/website/src/app/f/[...path]/layout.tsx @@ -11,7 +11,21 @@ export default function SearchLayout({ children }: { children: ReactNode }) {
- {children} + + {children} + ); } diff --git a/website/src/app/f/[...path]/page.tsx b/website/src/app/f/[...path]/page.tsx index 1c45bdc..0897e60 100644 --- a/website/src/app/f/[...path]/page.tsx +++ b/website/src/app/f/[...path]/page.tsx @@ -47,15 +47,16 @@ const Toc = async (props: TocProps) => { sx={{ display: { xs: "none", - lg: "block", + md: "block", }, - position: "fixed", - top: "6rem", - right: "1.8em", + position: "sticky", + top: "3.7rem", + p: 1, + order: 3, whiteSpace: "nowrap", }} > - Table of Contents + On this page {headings.map((h, idx) => ( @@ -88,9 +89,10 @@ export default async function Page(props: { params: { path: string[] } }) { const mdxSource = item?.content?.content || ""; const meta = item?.meta; + const signature = meta?.signature || (item && findType(item)) || ""; const { args: argTypes, returns: retTypes } = interpretType( meta?.path[meta?.path?.length - 1], - meta?.signature || (item && findType(item)) || "" + signature ); const position = @@ -107,6 +109,11 @@ export default async function Page(props: { params: { path: string[] } }) { meta?.is_primop && meta?.primop_meta ? getPrimopDescription(meta.primop_meta) + mdxSource : mdxSource; + // Skip generating this builtin. + // It is internal information of noogle. + if (meta?.title === "builtins.lambdaMeta") { + return undefined; + } return ( <> @@ -118,11 +125,18 @@ export default async function Page(props: { params: { path: string[] } }) { maxWidth: "100vw", minHeight: "calc(100vh - 3.7rem)", overflow: "hidden", + gridColumnStart: 2, p: { xs: 1, md: 2 }, bgcolor: "background.paper", }} > + {meta?.path && + meta.path.map((attr, idx) => ( + + {attr} + + ))} No documentation found yet. + {!position && (
@@ -227,6 +242,28 @@ export default async function Page(props: { params: { path: string[] } }) {
)} + {position && ( + + + + )}
)} )} - {!!meta?.aliases?.length && ( -
- - - Noogle also knows - - - - Aliases - -
    - {meta?.aliases?.map((a) => ( -
  • - {a.join(".")} -
  • - ))} -
-
- )} +
+ {(!!meta?.aliases?.length || !!signature) && ( + <> + + + Noogle also knows + + + )} + {!!meta?.aliases?.length && ( + <> + + Aliases + +
    + {meta?.aliases?.map((a) => ( +
  • + {a.join(".")} +
  • + ))} +
+ + )} + {!!signature && !meta?.signature && ( + <> + + Detected Type + + + + )} +
diff --git a/website/src/components/BackButton.tsx b/website/src/components/BackButton.tsx index 7c13eb2..3410b12 100644 --- a/website/src/components/BackButton.tsx +++ b/website/src/components/BackButton.tsx @@ -21,7 +21,7 @@ export const BackButton = () => { } }; return ( - handleBack()}> + handleBack()} aria-label="Back"> ); diff --git a/website/src/components/Excerpt.tsx b/website/src/components/Excerpt.tsx deleted file mode 100644 index 5a4f011..0000000 --- a/website/src/components/Excerpt.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import { Doc } from "@/models/data"; -import bash from "highlight.js/lib/languages/bash"; -import haskell from "highlight.js/lib/languages/haskell"; -import nix from "highlight.js/lib/languages/nix"; -import rehypeHighlight from "rehype-highlight"; - -import { rehypeExtractExcerpt } from "@/excerpt"; -import Markdown from "react-markdown"; -import { HighlightBaseline } from "./HighlightBaseline"; -import rehypeStringify from "rehype-stringify"; -import remarkParse from "remark-parse"; -import remarkRehype from "remark-rehype"; -import { unified } from "unified"; -import { useEffect, useState } from "react"; - -const getExcerpt = async (content: string): Promise => { - const processor = unified() - .use(remarkParse) - .use(remarkRehype) - .use(rehypeExtractExcerpt) - .use(rehypeStringify); - - const result = await processor.process(content); - return result.data["excerpt"] as string; -}; - -export const Excerpt = ({ meta, content }: Doc) => { - const mdxSource = content?.content || ""; - const [excerpt, setExcerpt] = useState(""); - useEffect(() => { - getExcerpt(mdxSource).then((r) => setExcerpt(r)); - }, [mdxSource]); - return ( - <> - - - {excerpt} - - - ); -}; diff --git a/website/src/components/PagefindResults.tsx b/website/src/components/PagefindResults.tsx index 546c0b5..ee433e0 100644 --- a/website/src/components/PagefindResults.tsx +++ b/website/src/components/PagefindResults.tsx @@ -3,7 +3,6 @@ import { Box, Chip, Container, - Divider, IconButton, LinearProgress, Link, @@ -17,17 +16,15 @@ import { } from "@mui/material"; import React, { useEffect, useMemo, useState } from "react"; -// import { useMiniSearch } from "react-minisearch"; - -// import { Doc, data } from "@/models/data"; import { EmptyRecordsPlaceholder } from "./emptyRecordsPlaceholder"; import { useSearchParams } from "next/navigation"; -// import { Excerpt } from "./Excerpt"; import { useRouter } from "next/navigation"; import { PagefindResult, RawResult, usePagefindSearch } from "./Pagefind"; import { Clear } from "@mui/icons-material"; import { useFilter } from "./layout/filterContext"; +// import d from "./example.json"; + export type BasicListItem = { item: React.ReactNode; key: string; @@ -35,9 +32,6 @@ export type BasicListItem = { const useMobile = () => useMediaQuery(useTheme().breakpoints.down("md")); -// interface SearchResultsProps { -// pageItems: PagefindResult[]; -// } export function PagefindResults() { const params = useSearchParams(); const router = useRouter(); @@ -87,6 +81,7 @@ export function PagefindResults() { const loadData = async () => { let items = await Promise.all(pageItems.map(async (r) => await r.data())); setItems(items); + // setItems(d); }; loadData(); }, [pageItems]); @@ -132,7 +127,6 @@ export function PagefindResults() { component="span" variant="subtitle1" sx={{ - color: "text.secondary", p: 1, textTransform: "capitalize", }} @@ -148,7 +142,6 @@ export function PagefindResults() { component="span" variant="subtitle1" sx={{ - color: "text.secondary", p: 1, textTransform: "capitalize", }} @@ -160,6 +153,7 @@ export function PagefindResults() { handleReset("filter")} + aria-label="clear filter" > @@ -175,9 +169,8 @@ export function PagefindResults() { component="span" variant="subtitle1" sx={{ - color: "text.secondary", p: 1, - textTransform: "capitalize", + textTransform: "none", }} > handleReset("term")} + aria-label="clear term" > @@ -197,11 +191,11 @@ export function PagefindResults() { /> )} - + {items.length ? ( items.map(({ meta, excerpt, url }, idx) => ( - - + + - - + )) ) : ( - + } - secondary={} + secondary={""} /> { return ( {showDivider && } - + { top: 0, width: "100%", py: 1.2, - zIndex: 1, + zIndex: 1000, backgroundColor: theme.palette.mode === "light" ? "primary.main" : "#101010", display: "grid", @@ -39,8 +39,9 @@ export const Header = () => { sx={{ color: "primary.contrastText", }} + aria-label="Home" > - + @@ -51,7 +52,7 @@ export const Header = () => { display: { xs: "block", md: "none" }, }} > - + @@ -79,6 +80,7 @@ export const Header = () => { xs: "none", md: "block", }, + color: "primary.contrastText", }} > @@ -88,7 +90,15 @@ export const Header = () => { }> - + diff --git a/website/src/components/layout/layout.tsx b/website/src/components/layout/layout.tsx index b09a805..a4b9bca 100644 --- a/website/src/components/layout/layout.tsx +++ b/website/src/components/layout/layout.tsx @@ -7,7 +7,6 @@ import { Typography, } from "@mui/material"; import GitHubIcon from "@mui/icons-material/GitHub"; -import PublicIcon from "@mui/icons-material/Public"; import { Background } from "./Background"; export interface LayoutProps { @@ -20,25 +19,14 @@ export const SocialIcons = () => { - + - - - - - - - ); }; diff --git a/website/src/components/markdownPreview/MarkdownPreview.tsx b/website/src/components/markdownPreview/MarkdownPreview.tsx index 0e755f3..00746ba 100644 --- a/website/src/components/markdownPreview/MarkdownPreview.tsx +++ b/website/src/components/markdownPreview/MarkdownPreview.tsx @@ -1,6 +1,8 @@ "use client"; import { useTheme } from "@mui/material"; import nix from "highlight.js/lib/languages/nix"; +import haskell from "highlight.js/lib/languages/haskell"; +import bash from "highlight.js/lib/languages/bash"; import { useEffect } from "react"; import ReactMarkdown from "react-markdown"; import rehypeHighlight from "rehype-highlight"; @@ -32,7 +34,15 @@ export const MarkdownPreview = (props: MarkdownPreviewProps) => { h3: "h5", h4: "h6", }} - rehypePlugins={[[rehypeHighlight, { languages: { nix } }]]} + rehypePlugins={[ + [ + rehypeHighlight, + { + detect: true, + languages: { nix, haskell, bash, default: nix }, + }, + ], + ]} > {description} diff --git a/website/src/models/primop.ts b/website/src/models/primop.ts index d603683..9f5b206 100644 --- a/website/src/models/primop.ts +++ b/website/src/models/primop.ts @@ -4,5 +4,5 @@ export const getPrimopDescription = (meta: PrimopMatter) => { const args = meta?.args?.map((a) => `__${a}__`) || []; return !meta?.arity ? "" - : `Takes __${meta?.arity}__ arguments\n\n ${args.join(", ")} \n`; + : `Takes __${meta?.arity}__ arguments\n\n ${args.join(", ")} \n\n`; };