Skip to content

Commit

Permalink
Pull projection printing into dynamic renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinleroy committed Jul 8, 2024
1 parent 639daa8 commit cc3123e
Show file tree
Hide file tree
Showing 12 changed files with 2,823 additions and 2,067 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tmp/
dist/
node_modules/
profile.json
.direnv/

# Ignore generated credentials from google-github-actions/auth
gha-creds-*.json
Expand Down
96 changes: 96 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};

outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
in {
devShell = with pkgs; mkShell {
buildInputs = [
llvmPackages_latest.llvm
llvmPackages_latest.lld

guile
nodejs_22
nodePackages.pnpm
toolchain
] ++ lib.optional stdenv.isDarwin libiconv;

# FIXME: this is darwin specific vvv but the flake should work for all systems
RUSTC_LINKER = "${pkgs.llvmPackages.clangUseLLVM}/bin/clang";
RUSTFLAGS = "-Clink-arg=-fuse-ld=${pkgs.mold}/bin/mold";
};
});
}
2 changes: 1 addition & 1 deletion ide/packages/common/src/func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export function fnInputsAndOutput<T>(args: T[]): [T[], T] {
export const isNamedRegion = (r: Region) => r.type === "Named";

export function isNamedGenericArg(ga: GenericArg) {
return ("Lifetime" in ga) ? isNamedRegion(ga.Lifetime) : true;
return "Lifetime" in ga ? isNamedRegion(ga.Lifetime) : true;
}

export const isNamedBoundRegion = (br: BoundRegionKind) =>
Expand Down
45 changes: 44 additions & 1 deletion ide/packages/panoptes/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ import {
isSysMsgPin,
isSysMsgUnpin
} from "@argus/common/lib";
import { DefPathRender } from "@argus/print/context";
import { IcoComment } from "@argus/print/Icons";
import Indented from "@argus/print/Indented";
import {
AllowPathTrim,
AllowProjectionSubst,
DefPathRender
} from "@argus/print/context";
import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react";
import _ from "lodash";
import { observer } from "mobx-react";
Expand Down Expand Up @@ -120,6 +126,43 @@ const CustomPathRenderer = observer(
}
);

const CustomProjectionRender = ({
original,
projection,
ctx
}: {
original: React.ReactElement;
projection: React.ReactElement;
ctx: TypeContext;
}) => {
const content = (
<AllowPathTrim.Provider value={false}>
<AllowProjectionSubst.Provider value={false}>
<p> This type is from a projection:</p>
<p>Projected type:</p>
<Indented>{projection}</Indented>
<p>Full path:</p>
<Indented>{original}</Indented>
</AllowProjectionSubst.Provider>
</AllowPathTrim.Provider>
);
const setStore = () =>
MiniBufferDataStore.set({ kind: "projection", content, ctx });
const resetStore = () => MiniBufferDataStore.reset();
return (
<>
{projection}
<span
onMouseEnter={setStore}
onMouseLeave={resetStore}
style={{ verticalAlign: "super", fontSize: "0.25rem" }}
>
<IcoComment />
</span>
</>
);
};

const App = observer(({ config }: { config: PanoptesConfig }) => {
const [openFiles, setOpenFiles] = useState(buildInitialData(config));
const [showHidden, setShowHidden] = useState(false);
Expand Down
17 changes: 13 additions & 4 deletions ide/packages/panoptes/src/MiniBuffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,27 @@ const MiniBuffer = observer(() => {
}

const unpinClick = () => MiniBufferDataStore.unpin();
const heading = data.kind === "path" ? <h2>Definition Path</h2> : null;
const heading =
data.kind === "path" ? (
<h2>Definition Path</h2>
) : data.kind === "projection" ? (
<h2>Type Projection</h2>
) : null;
const pinned = data.pinned ? <IcoPinned onClick={unpinClick} /> : null;
const Content =
data.kind === "path" ? (
<PrintDefPathFull defPath={data.path} />
) : data.kind === "projection" ? (
data.content
) : null;

return (
<>
<div id="MiniBuffer">
{pinned}
{heading}
<div className="Data">
<TyCtxt.Provider value={data.ctx}>
<PrintDefPathFull defPath={data.path} />
</TyCtxt.Provider>
<TyCtxt.Provider value={data.ctx}>{Content}</TyCtxt.Provider>
</div>
</div>
<div className="spacer">{"\u00A0"}</div>
Expand Down
20 changes: 13 additions & 7 deletions ide/packages/panoptes/src/signals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ class HighlightTargetStore {
export const highlightedObligation = new HighlightTargetStore();

export type BufferDataKind = {
pinned?: boolean;
ctx: TypeContext;
pinned: boolean;
} & {
kind: "path";
path: DefinedPath;
};
} & (
| {
kind: "path";
path: DefinedPath;
}
| {
kind: "projection";
content: React.ReactElement;
}
);

class MiniBufferData {
data?: BufferDataKind;
Expand All @@ -59,10 +65,10 @@ class MiniBufferData {
}
}

set(data: Omit<BufferDataKind, "pinned">) {
set(data: BufferDataKind) {
// Don't override data that is pinned.
if (this.data === undefined || !this.data.pinned) {
this.data = { pinned: false, ...data };
this.data = { ...data, pinned: false } as BufferDataKind;
}
}

Expand Down
12 changes: 12 additions & 0 deletions ide/packages/print/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ export const DefPathRender = createContext(
</>
)
);

export const ProjectionPathRender = createContext(
({
original,
projection: _prj,
ctx: _ctx
}: {
original: ReactElement;
projection: ReactElement;
ctx: TypeContext;
}) => original
);
4 changes: 2 additions & 2 deletions ide/packages/print/src/private/syntax.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export const Dsp = (

/**
* Highlight the children as placeholders, this means they aren't concrete types.
*
*
* For Argus, this usually means changing the foreground to something softer.
*/
export const Placeholder = ({ children }: React.PropsWithChildren) => (
<span className="placeholder">{children}</span>
);

/**
* Highlight the children as Rust keywords
* Highlight the children as Rust keywords
*/
export const Kw = ({ children }: React.PropsWithChildren) => (
<span className="kw">{children}</span>
Expand Down
45 changes: 26 additions & 19 deletions ide/packages/print/src/private/ty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ import {
import {} from "@floating-ui/react";
import _, { isObject } from "lodash";
import React, { useContext } from "react";
import Comment from "../Comment";
import Indented from "../Indented";
import { Toggle } from "../Toggle";
import { AllowPathTrim, AllowProjectionSubst, TyCtxt } from "../context";
import { AllowProjectionSubst, ProjectionPathRender, TyCtxt } from "../context";
import { PrintConst } from "./const";
import { PrintDefPath } from "./path";
import {
Expand Down Expand Up @@ -121,23 +119,32 @@ export const PrintTyProjected = ({
original,
projection
}: { original: TyVal; projection: TyVal }) => {
const Content = (
<AllowPathTrim.Provider value={false}>
<AllowProjectionSubst.Provider value={false}>
<p> This type is from a projection:</p>
<p>Projected type:</p>
<Indented>
<PrintTyValue o={projection} />
</Indented>
<p>Full path:</p>
<Indented>
<PrintTyValue o={original} />
</Indented>
</AllowProjectionSubst.Provider>
</AllowPathTrim.Provider>
const RenderProjection = useContext(ProjectionPathRender);
const tyCtx = useContext(TyCtxt)!;
return (
<RenderProjection
original={<PrintTyValue o={original} />}
projection={<PrintTyValue o={projection} />}
ctx={tyCtx}
/>
);

return <Comment Child={<PrintTyValue o={projection} />} Content={Content} />;
// const Content = (
// <AllowPathTrim.Provider value={false}>
// <AllowProjectionSubst.Provider value={false}>
// <p> This type is from a projection:</p>
// <p>Projected type:</p>
// <Indented>
// <PrintTyValue o={projection} />
// </Indented>
// <p>Full path:</p>
// <Indented>
// <PrintTyValue o={original} />
// </Indented>
// </AllowProjectionSubst.Provider>
// </AllowPathTrim.Provider>
// );

// return <Comment Child={<PrintTyValue o={projection} />} Content={Content} />;
};

export const PrintTyValue = ({ o }: { o: TyVal }) => {
Expand Down
Loading

0 comments on commit cc3123e

Please sign in to comment.