Skip to content

Commit

Permalink
Pass Cursor to IdentifierExplorer
Browse files Browse the repository at this point in the history
  • Loading branch information
tkers committed Apr 15, 2020
1 parent bc0df0f commit 0851be7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
36 changes: 25 additions & 11 deletions packages/liphe/components/Explorer/Function.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export const DetailedFunctionExplorer: React.FC<{
const [contextType, ...argsTypes] = type.args;

const bodyCursor = cursor.prop("node").prop("body");
const argsCursor = cursor
.prop("node")
.prop("lambdaList")
.prop("positionalArguments");

return (
<div className={styles.function}>
Expand All @@ -102,14 +106,16 @@ export const DetailedFunctionExplorer: React.FC<{
"None"
) : (
<ul className={styles.functionArguments}>
{args.map((arg, argPosition) => {
{Cursor.map(argsCursor, (arg, argPosition) => {
return (
<li key={arg.name}>
<IdentifierExplorer identifier={arg} /> -{" "}
<TypeExplorer type={argsTypes[argPosition]} />
</li>
argPosition > 0 && (
<li key={arg.value.name}>
<IdentifierExplorer cursor={arg} /> -{" "}
<TypeExplorer type={argsTypes[argPosition - 1]} />
</li>
)
);
})}
}).slice(1)}
</ul>
)}
</FunctionInfoSection>
Expand Down Expand Up @@ -145,16 +151,24 @@ export const FunctionExplorer: React.FC<{
}> = ({ cursor }) => {
const fn = cursor.value;
const bodyCursor = cursor.prop("node").prop("body");
const argsCursor = cursor
.prop("node")
.prop("lambdaList")
.prop("positionalArguments");
return (
<div>
<span title={typeToString(fn.info.selfType)}>
<strong>λ</strong>
</span>{" "}
{fn.node.lambdaList.positionalArguments.slice(1).map((i) => (
<>
<IdentifierExplorer identifier={i} />{" "}
</>
))}
{Cursor.map(
argsCursor,
(c, i) =>
i > 0 && (
<>
<IdentifierExplorer cursor={c} />{" "}
</>
)
).slice(1)}
{" "}
{Cursor.map(bodyCursor, (c, i) => {
return (
Expand Down
7 changes: 4 additions & 3 deletions packages/liphe/components/Explorer/Identifier.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as Delisp from "@delisp/core";
import * as React from "react";
import { Cursor } from "./common";

export const IdentifierExplorer: React.FC<{
identifier: Delisp.Identifier;
}> = ({ identifier }) => {
cursor: Cursor<Delisp.Identifier>;
}> = ({ cursor }) => {
return (
<code>
<span style={{ color: "#0000aa" }}>{identifier.name}</span>
<span style={{ color: "#0000aa" }}>{cursor.value.name}</span>
</code>
);
};
2 changes: 1 addition & 1 deletion packages/liphe/components/Explorer/Record.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const RecordExplorer: React.FC<{
{Cursor.map(fieldCursor, (c) => {
return (
<li key={c.value.label.name}>
<IdentifierExplorer identifier={c.value.label} />{" "}
<IdentifierExplorer cursor={c.prop("label")} />{" "}
<ExpressionExplorer cursor={c.prop("value")} />
</li>
);
Expand Down

0 comments on commit 0851be7

Please sign in to comment.