Skip to content

Commit

Permalink
enough for now
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew committed Jan 18, 2025
1 parent ec1da3f commit c819093
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 19 deletions.
1 change: 1 addition & 0 deletions apps/lil-buddy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"color-buddy-color-namer": "*",
"color-buddy-palette": "*",
"color-buddy-palette-lint": "*",
"fracturedjsonjs": "^4.0.2",
"monaco-editor": "^0.45.0",
"openai": "^4.78.1",
"tailwindcss": "^3.3.5"
Expand Down
14 changes: 14 additions & 0 deletions apps/lil-buddy/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import type { Palette, StringPalette } from "color-buddy-palette";
import type { LintProgram, LintResult } from "color-buddy-palette-lint";
import { linter } from "color-buddy-palette-lint";

import { Formatter, FracturedJsonOptions, EolStyle } from "fracturedjsonjs";

const options = new FracturedJsonOptions();
options.MaxTotalLineLength = 120;
options.MaxInlineComplexity = 2;
options.JsonEolStyle = EolStyle.Crlf;

const formatter = new Formatter();
formatter.Options = options;

export function JSONStringify(obj: string) {
return formatter.Reformat(obj);
}

type ColorSpace = keyof typeof ColorSpaceDirectory;
export const colorPickerConfig = Object.fromEntries(
(Object.keys(ColorSpaceDirectory) as ColorSpace[]).map((name: ColorSpace) => {
Expand Down
10 changes: 9 additions & 1 deletion apps/lil-buddy/src/linting/FocusedTest.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
result: { kind: "invalid" } as LintResult,
error: null,
} as any as ReturnType<typeof runLint>;
$: lintRun = testPal ? runLint(lint, blameMode, testPal) : nullLint;
$: lintRun = testPal ? handleLint(lint, blameMode, testPal) : nullLint;
function handleLint(lint: LintProgram, blameMode: any, testPal: any) {
try {
return runLint(lint, blameMode, testPal);
} catch (e) {
console.error(e);
return nullLint;
}
}
$: lintResult = lintRun.result;
$: currentLintAppliesToCurrentPalette = (lint?.requiredTags || []).every(
Expand Down
33 changes: 16 additions & 17 deletions apps/lil-buddy/src/linting/MainTab.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<script lang="ts">
import { PREBUILT_LINTS } from "color-buddy-palette-lint";
import { PREBUILT_LINTS, prettyPrintLL } from "color-buddy-palette-lint";
import store from "../stores/store";
import { newId } from "../lib/utils";
import { buttonStyle } from "../lib/styles";
import LintMeta from "./LintMeta.svelte";
import { JSONStringify } from "../lib/utils";
import MonacoEditor from "../components/MonacoEditor.svelte";
import Nav from "../components/Nav.svelte";
import DeleteLint from "./DeleteLint.svelte";
Expand All @@ -22,7 +24,15 @@
// run this lint
let errors: any = null;
let debugCompare = false;
function generatePrettyText(program: string): string {
try {
return prettyPrintLL(JSON.parse(program));
} catch (e) {
console.log(e);
return "parsing error";
}
}
</script>

<div class="w-full flex">
Expand Down Expand Up @@ -79,25 +89,14 @@
<button
class={buttonStyle}
on:click={() => {
store.setCurrentLintProgram(JSON.stringify(program) || "");
store.setCurrentLintProgram(JSONStringify(program) || "");
}}
>
Clean up Program
</button>
<div class="flex justify-between">
<div class="flex flex-col">
<div class="font-bold">Show Compare Debug In Terminal</div>
<div>
<Nav
tabs={["Show", "Hide"]}
isTabSelected={(x) => (debugCompare ? "Show" : "Hide") === x}
selectTab={(x) => {
debugCompare = x === "Show";
}}
/>
</div>
</div>
</div>
</div>
<div>
{generatePrettyText(program)}
</div>
<MonacoEditor
value={program}
Expand Down
10 changes: 9 additions & 1 deletion apps/lil-buddy/src/linting/summary-nodes/QuantifierNode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@
return [];
}
$: nodeResult = evaluateNode(node, inducedVariables, pal);
function handleEval(node: any, inducedVariables: any, pal: any) {
try {
return evaluateNode(node, inducedVariables, pal);
} catch (e) {
console.error(e);
return { result: "error" };
}
}
$: nodeResult = handleEval(node, inducedVariables, pal);
function checkWhere(node: any, color: Color, varb: string): boolean {
if (!node) return true;
Expand Down
2 changes: 2 additions & 0 deletions packages/palette-lint/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
GenerateAST,
Environment,
LLTypes,
prettyPrintLL,
} from "./lint-language/lint-language";
import { suggestMCFix } from "./linter-tools/monte-carlo-fix";
import { suggestLintFix } from "./linter-tools/lint-fixer";
Expand All @@ -13,6 +14,7 @@ export {
LLTypes,
PREBUILT_LINTS,
linter,
prettyPrintLL,
suggestLintFix,
suggestMCFix,
};
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6409,6 +6409,11 @@ fracturedjsonjs@^4.0.1:
resolved "https://registry.npmjs.org/fracturedjsonjs/-/fracturedjsonjs-4.0.1.tgz"
integrity sha512-KMhSx7o45aPVj4w27dwdQyKJkNU8oBqw8UiK/s3VzsQB3+pKQ/3AqG/YOEQblV2BDuYE5dKp0OMf8RDsshrjTA==

fracturedjsonjs@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/fracturedjsonjs/-/fracturedjsonjs-4.0.2.tgz#ca6ba0212ab00fa9b18ad4918653e66f3c93bf97"
integrity sha512-+vGJH9wK0EEhbbn50V2sOebLRaar1VL3EXr02kxchIwpkhQk0ItrPjIOtYPYuU9hNFpVzxjrPgzjtMJih+ae4A==

[email protected]:
version "0.5.2"
resolved "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz"
Expand Down

0 comments on commit c819093

Please sign in to comment.