add real nixpkgs metadata from enhanced nixdoc

This commit is contained in:
hsjobeki 2022-12-03 15:25:32 +01:00
parent f1dfe18b0a
commit 334a8271aa
12 changed files with 3652 additions and 428 deletions

View File

@ -1,28 +1,19 @@
import { import { ListItemText, Paper, Stack, Typography } from "@mui/material";
Box, import { DocItem } from "../../types/nix";
Card,
ListItemText,
Paper,
Stack,
Typography,
} from "@mui/material";
interface FunctionItemProps { interface FunctionItemProps {
selected: boolean; selected: boolean;
name: String; name: String;
info: { docItem: DocItem;
"attr-path": String;
source: String;
from: String;
to: String;
};
} }
export default function FunctionItem(props: FunctionItemProps) { export default function FunctionItem(props: FunctionItemProps) {
const { name, info, selected } = props; const { name, docItem, selected } = props;
const { fn_type, category } = docItem;
return ( return (
<Paper <Paper
elevation={0} elevation={0}
sx={{ sx={{
cursor: "pointer",
display: "flex", display: "flex",
justifyContent: "left", justifyContent: "left",
px: 2, px: 2,
@ -31,11 +22,14 @@ export default function FunctionItem(props: FunctionItemProps) {
borderColor: selected ? "action.selected" : "none", borderColor: selected ? "action.selected" : "none",
borderWidth: 1, borderWidth: 1,
borderStyle: selected ? "solid" : "none", borderStyle: selected ? "solid" : "none",
"&:hover": {
backgroundColor: "action.hover",
},
}} }}
> >
<Stack> <Stack>
<ListItemText primary={name} secondary={info["attr-path"]} /> <ListItemText primary={name} secondary={category} />
<Typography>{`${info.from} -> ${info.to} `}</Typography> <Typography>{`${fn_type} `}</Typography>
</Stack> </Stack>
</Paper> </Paper>
); );

View File

@ -1,8 +1,15 @@
import { Box, Typography, Container, Link, useTheme } from "@mui/material"; import {
Box,
Typography,
Container,
Link,
useTheme,
IconButton,
} from "@mui/material";
import { Image } from "../image"; import { Image } from "../image";
import nixSnowflake from "../../public/nix-snowflake.svg"; import nixSnowflake from "../../public/nix-snowflake.svg";
import GitHubIcon from "@mui/icons-material/GitHub";
// import Link from "next/link"; // import Link from "next/link";
export interface LayoutProps { export interface LayoutProps {
children: React.ReactNode; children: React.ReactNode;
} }
@ -20,7 +27,9 @@ export function Layout(props: LayoutProps) {
: "rgb(23, 17, 22)", : "rgb(23, 17, 22)",
}} }}
> >
<header> <header
// style={{ position: "sticky", top: 0, width: "100%", zIndex: 100 }}
>
<Box <Box
sx={{ sx={{
position: "fixed", position: "fixed",
@ -51,15 +60,35 @@ export function Layout(props: LayoutProps) {
color: "#fff", color: "#fff",
}} }}
> >
<Image <Box
src={nixSnowflake} sx={{
alt="nix-logo" display: {
height={90} xs: "none",
style={{ md: "block",
marginBottom: "-1rem", },
}} }}
/> >
<Image
src={nixSnowflake}
alt="nix-logo"
height={90}
style={{
marginBottom: "-1rem",
}}
/>
</Box>
<Box sx={{ ml: 1 }} component="span">{`noog\u03BBe`}</Box> <Box sx={{ ml: 1 }} component="span">{`noog\u03BBe`}</Box>
<IconButton sx={{ float: "right", top: "1em", right: "1em" }}>
<GitHubIcon
fontSize="large"
sx={{
display: {
xs: "none",
md: "block",
},
}}
/>
</IconButton>
</Typography> </Typography>
</Box> </Box>
</header> </header>

View File

@ -8,46 +8,77 @@ import {
ListItemText, ListItemText,
Typography, Typography,
} from "@mui/material"; } from "@mui/material";
import Highlight from "react-highlight";
import LocalLibraryIcon from "@mui/icons-material/LocalLibrary"; import LocalLibraryIcon from "@mui/icons-material/LocalLibrary";
import InputIcon from "@mui/icons-material/Input"; import InputIcon from "@mui/icons-material/Input";
import OutputIcon from "@mui/icons-material/Output"; import { DocItem } from "../../types/nix";
import { FuncData } from "../../types/nix"; import CodeIcon from "@mui/icons-material/Code";
interface PreviewProps { interface PreviewProps {
func: FuncData; docItem: DocItem;
} }
export const Preview = (props: PreviewProps) => { export const Preview = (props: PreviewProps) => {
const { func } = props; const { docItem } = props;
const { name, description, category, example, fn_type } = docItem;
const prefix = category.split(/([\/.])/gm).at(4);
return ( return (
<Box sx={{ p: 1, width: "100%" }}> <Box sx={{ p: 1, width: "100%" }}>
<Typography variant="h2">{func.name}</Typography> <Typography variant="h2">{`${prefix}.${name}`}</Typography>
<List sx={{ width: "100%" }}> <List sx={{ width: "100%" }}>
<ListItem> <ListItem>
<ListItemIcon> <ListItemIcon>
<LocalLibraryIcon /> <LocalLibraryIcon />
</ListItemIcon> </ListItemIcon>
<ListItemText <ListItemText
primary={func.info["attr-path"]} sx={{
secondary={func.info["doc-url"]} overflow: "hidden",
textOverflow: "ellipsis",
}}
primary={category.replace("./", "nixpkgs/")}
secondary={description}
/> />
<ListItemSecondaryAction> <ListItemSecondaryAction>
<Link href={func.info["doc-url"]}>View Docs</Link> <Link href={"#"}>View Docs</Link>
</ListItemSecondaryAction> </ListItemSecondaryAction>
</ListItem> </ListItem>
<ListItem> <ListItem>
<ListItemIcon> <ListItemIcon>
<InputIcon /> <InputIcon />
</ListItemIcon> </ListItemIcon>
<ListItemText primary={func.info.from} secondary="argument type" /> <ListItemText
sx={{
overflow: "hidden",
textOverflow: "ellipsis",
}}
primary={fn_type}
secondary="function signature"
/>
</ListItem> </ListItem>
<ListItem> <ListItem
sx={{
backgroundColor: "background.paper",
}}
>
<ListItemIcon> <ListItemIcon>
<OutputIcon /> <CodeIcon />
</ListItemIcon> </ListItemIcon>
<ListItemText primary={func.info.to} secondary="return type" /> <ListItemText
sx={{
overflow: "hidden",
textOverflow: "ellipsis",
}}
disableTypography
primary={
<Typography sx={{ color: "text.secondary" }}>Example</Typography>
}
secondary={
<Box sx={{ mt: -2, pl: 1.5 }}>
<Highlight className="nix">{example}</Highlight>
</Box>
}
/>
</ListItem> </ListItem>
<ListItem></ListItem>
</List> </List>
</Box> </Box>
); );

View File

@ -123,6 +123,21 @@
"type": "github" "type": "github"
} }
}, },
"flake-utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils-pre-commit": { "flake-utils-pre-commit": {
"locked": { "locked": {
"lastModified": 1644229661, "lastModified": 1644229661,
@ -201,6 +216,30 @@
"type": "indirect" "type": "indirect"
} }
}, },
"nixdoc-fork": {
"inputs": {
"flake-utils": [
"nixdoc-fork",
"rust-overlay",
"flake-utils"
],
"nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1670069861,
"narHash": "sha256-K+uqDkNkw5W3Rv6kIfJ43htAkhZwqNrVXg+pW6lNez4=",
"owner": "hsjobeki",
"repo": "nixdoc",
"rev": "29813f73b02d85c57856afe8bc09d3ab308bfe55",
"type": "github"
},
"original": {
"owner": "hsjobeki",
"repo": "nixdoc",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1665580254, "lastModified": 1665580254,
@ -216,6 +255,38 @@
"type": "indirect" "type": "indirect"
} }
}, },
"nixpkgs_2": {
"locked": {
"lastModified": 1669919498,
"narHash": "sha256-cndPLdFj2V0OchIgz1sOVKZXOi+ETgSq/OqCCbWsRoo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "14c7bd44711b04c05cb78412451005415310b6bd",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-22.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1665296151,
"narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "14ccaaedd95a488dd7ae142757884d8e125b3363",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"poetry2nix": { "poetry2nix": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -260,7 +331,8 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"dream2nix": "dream2nix" "dream2nix": "dream2nix",
"nixdoc-fork": "nixdoc-fork"
} }
}, },
"rust-analyzer-src": { "rust-analyzer-src": {
@ -279,6 +351,25 @@
"repo": "rust-analyzer", "repo": "rust-analyzer",
"type": "github" "type": "github"
} }
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1670034122,
"narHash": "sha256-EqmuOKucPWtMvCZtHraHr3Q3bgVszq1x2PoZtQkUuEk=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "a0d5773275ecd4f141d792d3a0376277c0fc0b65",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View File

@ -1,10 +1,12 @@
{ {
inputs.dream2nix.url = "github:nix-community/dream2nix"; inputs.dream2nix.url = "github:nix-community/dream2nix";
inputs.nixdoc-fork.url = "github:hsjobeki/nixdoc";
outputs = inp: outputs = inp:
let let
system = "x86_64-linux";
inherit (builtins.fromJSON (builtins.readFile ./package.json)) name; inherit (builtins.fromJSON (builtins.readFile ./package.json)) name;
in in
inp.dream2nix.lib.makeFlakeOutputs { (inp.dream2nix.lib.makeFlakeOutputs {
systemsFromFile = ./nix_systems; systemsFromFile = ./nix_systems;
config.projectRoot = ./.; config.projectRoot = ./.;
source = ./.; source = ./.;
@ -15,6 +17,9 @@
]; ];
packageOverrides = { packageOverrides = {
${name}.staticPage = { ${name}.staticPage = {
preBuild = ''
cp ${inp.nixdoc-fork.packages.${system}.data} ./models/data.json
'';
installPhase = '' installPhase = ''
runHook preInstall runHook preInstall
@ -26,5 +31,9 @@
''; '';
}; };
}; };
}; });
# // {
# packages.${system}.nixi = inp.nixdoc-fork.packages.${system}.data;
# };
} }

2553
models/data.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,341 +0,0 @@
import { NixFunctionSet, NixType } from "../types/nix";
export const nixFuns: NixFunctionSet = {
mapAttrs: {
"attr-path": "builtins.mapAttrs",
"doc-url":
"https://nixos.org/manual/nix/stable/language/builtins.html#builtins-mapAttrs",
source: "builtin",
from: "attrset",
to: "attrset",
},
"mapAttrs'": {
"attr-path": "lib.mapAttrs'",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-attrset",
source: "nixpkgs",
from: "attrset",
to: "attrset",
},
genAttrs: {
"attr-path": "lib.genAttrs",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-attrset",
source: "nixpkgs",
from: "list",
to: "attrset",
},
forEach: {
"attr-path": "lib.forEach",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
foldr: {
"attr-path": "lib.foldr",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "any",
},
foldl: {
"attr-path": "lib.foldl",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "any",
},
"foldl'": {
"attr-path": "lib.foldl'",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "any",
},
imap0: {
"attr-path": "lib.imap0",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
imap1: {
"attr-path": "lib.imap1",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
concatMap: {
"attr-path": "lib.concatMap",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
flatten: {
"attr-path": "lib.flatten",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
remove: {
"attr-path": "lib.remove",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
findSingle: {
"attr-path": "lib.findSingle",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "any",
},
findFirst: {
"attr-path": "lib.findFirst",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "any",
},
any: {
"attr-path": "lib.any",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "bool",
},
all: {
"attr-path": "lib.all",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "bool",
},
count: {
"attr-path": "lib.count",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "int",
},
optional: {
"attr-path": "lib.optional",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "bool",
to: "list",
},
optionals: {
"attr-path": "lib.optionals",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "bool",
to: "list",
},
toList: {
"attr-path": "lib.toList",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "any",
to: "list",
},
toString: {
"attr-path": "builtins.toString'",
"doc-url":
"https://nixos.org/manual/nix/stable/language/builtins.html#builtins-toString",
source: "builtin",
from: "any" as NixType,
to: "string" as NixType,
},
range: {
"attr-path": "lib.range",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "int",
to: "list",
},
partition: {
"attr-path": "lib.partition",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
"groupBy'": {
"attr-path": "lib.groupBy'",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
groupBy: {
"attr-path": "lib.groupBy",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
zipListsWith: {
"attr-path": "lib.zipListsWith",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
zipLists: {
"attr-path": "lib.zipLists",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
reverseList: {
"attr-path": "lib.reverseList",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
listDfs: {
"attr-path": "lib.listDfs",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "attrset",
},
toposort: {
"attr-path": "lib.toposort",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
sort: {
"attr-path": "lib.sort",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
compareLists: {
"attr-path": "lib.compareLists",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "int",
},
naturalSort: {
"attr-path": "lib.naturalSort",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
take: {
"attr-path": "lib.take",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
sublist: {
"attr-path": "lib.sublist",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
last: {
"attr-path": "lib.last",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "any",
},
init: {
"attr-path": "lib.init",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
crossLists: {
"attr-path": "lib.crossLists",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
unique: {
"attr-path": "lib.unique",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
intersectLists: {
"attr-path": "lib.intersectLists",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
subtractLists: {
"attr-path": "lib.subtractLists",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "list",
},
mutuallyExclusive: {
"attr-path": "lib.mutuallyExclusive",
"doc-url":
"https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-lists",
source: "nixpkgs",
from: "list",
to: "bool",
},
};

View File

@ -1,7 +1,3 @@
// const
const { PHASE_DEVELOPMENT_SERVER } = require("next/dist/shared/lib/constants");
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = (phase, { defaultConfig }) => { const nextConfig = (phase, { defaultConfig }) => {
@ -12,9 +8,6 @@ const nextConfig = (phase, { defaultConfig }) => {
loader: "custom", loader: "custom",
}, },
}; };
if (phase !== PHASE_DEVELOPMENT_SERVER) {
return { ...config, basePath: "", assetPrefix: "" };
}
return config; return config;
}; };

812
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -20,9 +20,14 @@
"@types/react-dom": "18.0.8", "@types/react-dom": "18.0.8",
"eslint": "8.27.0", "eslint": "8.27.0",
"eslint-config-next": "13.0.2", "eslint-config-next": "13.0.2",
"highlight.js": "^11.7.0",
"next": "13.0.2", "next": "13.0.2",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0", "react-dom": "18.2.0",
"react-highlight": "^0.15.0",
"typescript": "4.8.4" "typescript": "4.8.4"
},
"devDependencies": {
"@types/react-highlight": "^0.12.5"
} }
} }

View File

@ -2,23 +2,23 @@ import { BasicList, BasicListItem } from "../components/basicList";
import { useState, useMemo } from "react"; import { useState, useMemo } from "react";
import { Box } from "@mui/material"; import { Box } from "@mui/material";
import FunctionItem from "../components/functionItem/functionItem"; import FunctionItem from "../components/functionItem/functionItem";
import { NixType, nixTypes, FuncData } from "../types/nix"; import { NixType, nixTypes, MetaData, DocItem } from "../types/nix";
import { nixFuns } from "../models/nix";
import { Preview } from "../components/preview/preview"; import { Preview } from "../components/preview/preview";
import metadata from "../models/data.json";
// const mockData: FuncData[] = Object.entries(nixFuns).map(([key, value]) => ({
// name: key,
// info: value,
// }));
const mockData: FuncData[] = Object.entries(nixFuns).map(([key, value]) => ({ const data: MetaData = metadata as MetaData;
name: key,
info: value,
}));
const pipe = function pipe<T>(...fns: ((arr: T) => T)[]) {
(...fns: ((arr: FuncData[]) => FuncData[])[]) => return (x: T) => fns.reduce((v, f) => f(v), x);
(x: FuncData[]) => }
fns.reduce((v, f) => f(v), x);
const search = const search =
(term: string) => (term: string) =>
(data: FuncData[]): FuncData[] => { (data: MetaData): MetaData => {
return data.filter((item) => { return data.filter((item) => {
return Object.values(item).some((value) => { return Object.values(item).some((value) => {
const valueAsString = value.toString(); const valueAsString = value.toString();
@ -26,11 +26,44 @@ const search =
}); });
}); });
}; };
const preProcess = (a: string | undefined) => {
if (a?.match(/\[(.*)\]/)) {
return "list";
}
if (a?.toLowerCase()?.includes("attrset")) {
return "attrset";
}
return a;
};
const filter = const filter =
(to: NixType[], from: NixType[]) => (to: NixType[], from: NixType[]) =>
(data: FuncData[]): FuncData[] => { (data: MetaData): MetaData => {
return data.filter( return data.filter(
({ info }) => from.includes(info.from) && to.includes(info.to) // TODO: Implement proper type matching
({ name, fn_type }) => {
if (fn_type) {
const args = fn_type.split("->");
const front = args.slice(0, -1);
let firstTerm = front.at(0);
if (firstTerm?.includes("::")) {
firstTerm = firstTerm.split("::").at(1);
}
const inpArgs = [firstTerm, ...front.slice(1, -1)];
const parsedInpTypes = inpArgs.map(preProcess);
// const fn_from =
const fn_to = args.at(-1);
const parsedOutType = preProcess(fn_to);
if (name.includes("escapeShellArgs")) {
console.log({ args, inp_args: inpArgs, fn_to });
}
return (
from.some((f) => parsedInpTypes.join(" ").includes(f)) &&
to.some((t) => parsedOutType?.includes(t))
);
}
return false;
}
); );
}; };
@ -52,7 +85,7 @@ export default function FunctionsPage() {
}; };
const filteredData = useMemo( const filteredData = useMemo(
() => pipe(filter(to, from), search(term))(mockData), () => pipe(filter(to, from), search(term))(data),
[to, from, term] [to, from, term]
); );
@ -76,23 +109,27 @@ export default function FunctionsPage() {
}; };
const preRenderedItems: BasicListItem[] = filteredData.map( const preRenderedItems: BasicListItem[] = filteredData.map(
({ name, info }) => ({ (docItem: DocItem) => ({
item: ( item: (
<Box <Box
sx={{ sx={{
width: "100%", width: "100%",
height: "100%", height: "100%",
}} }}
onClick={() => handleSelect(name)} onClick={() => handleSelect(docItem.name)}
> >
<FunctionItem name={name} info={info} selected={selected === name} /> <FunctionItem
name={docItem.name}
docItem={docItem}
selected={selected === docItem.name}
/>
</Box> </Box>
), ),
key: name, key: docItem.name,
}) })
); );
const preview = ( const preview = (
<Preview func={mockData.find((f) => f.name === selected) || mockData[0]} /> <Preview docItem={data.find((f) => f.name === selected) || data[0]} />
); );
return ( return (

View File

@ -1,3 +1,15 @@
// {
// "category": "./lib/customisation.nix",
// "name": "overrideDerivation",
// "fn_type": null,
// "description": [
// "`overrideDerivation drv f' takes a derivation (i.e., the result\nof a call to the builtin function `derivation') and returns a new\nderivation in which the attributes of the original are overridden\naccording to the function `f'. The function `f' is called with\nthe original derivation attributes.",
// "`overrideDerivation' allows certain \"ad-hoc\" customisation\nscenarios (e.g. in ~/.config/nixpkgs/config.nix). For instance,\nif you want to \"patch\" the derivation returned by a package\nfunction in Nixpkgs to build another version than what the\nfunction itself provides, you can do something like this:",
// "mySed = overrideDerivation pkgs.gnused (oldAttrs: {\nname = \"sed-4.2.2-pre\";\nsrc = fetchurl {\nurl = ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2;\nsha256 = \"11nq06d131y4wmf3drm0yk502d2xc6n5qy82cg88rb9nqd2lj41k\";\n};\npatches = [];\n});",
// "For another application, see build-support/vm, where this\nfunction is used to build arbitrary derivations inside a QEMU\nvirtual machine."
// ],
// "example": null
// },
export type NixType = "attrset" | "list" | "string" | "int" | "bool" | "any"; export type NixType = "attrset" | "list" | "string" | "int" | "bool" | "any";
export const nixTypes: NixType[] = [ export const nixTypes: NixType[] = [
"any", "any",
@ -6,19 +18,30 @@ export const nixTypes: NixType[] = [
"string", "string",
"bool", "bool",
"int", "int",
]; ];
export type FuncData = { export type DocItem = {
category: string;
name: string; name: string;
info: NixFunctionMeta; fn_type?: string;
description?: string | string[];
example?: string | string[];
}; };
export type NixFunctionMeta = { export type MetaData = DocItem[];
"attr-path": string;
"doc-url": string;
source: string;
from: NixType;
to: NixType;
}
export type NixFunctionSet = {[name:string]: NixFunctionMeta}
// export type FuncData = {
// name: string;
// info: NixFunctionMeta;
// };
// export type NixFunctionMeta = {
// "attr-path": string;
// "doc-url": string;
// source: string;
// from: NixType;
// to: NixType;
// }
// export type NixFunctionSet = {[name:string]: NixFunctionMeta}