diff --git a/playground/server.mjs b/playground/server.mjs index a88e1daf3d3..d26d03ba06a 100644 --- a/playground/server.mjs +++ b/playground/server.mjs @@ -80,24 +80,16 @@ const readExamples = async () => { const id = entry.name; const directory = path.join(examplesDirectory, id); const sourcePaths = ['Cargo.toml', ...await listRustFiles(directory)]; - const [guideSource, files] = await Promise.all([ - readFile(path.join(directory, 'GUIDE.md'), 'utf8'), - Promise.all(sourcePaths.map(async filePath => ({ - languageId: filePath.endsWith('.rs') ? 'rust' : 'toml', - path: filePath, - source: await readFile(path.join(directory, filePath), 'utf8'), - target: path.posix.join('examples', id, filePath), - uri: pathToFileURL(path.join(directory, filePath)).href, - }))), - ]); + const files = await Promise.all(sourcePaths.map(async filePath => ({ + languageId: filePath.endsWith('.rs') ? 'rust' : 'toml', + path: filePath, + source: await readFile(path.join(directory, filePath), 'utf8'), + target: path.posix.join('examples', id, filePath), + uri: pathToFileURL(path.join(directory, filePath)).href, + }))); return { directory, files, - guide: { - path: 'GUIDE.md', - source: guideSource, - target: path.posix.join('examples', id, 'GUIDE.md'), - }, id, title: titleFromId(id), }; @@ -112,10 +104,15 @@ const vite = await createViteServer({ const server = http.createServer(async (request, response) => { if (request.method === 'GET' && request.url === '/api/info') { - const [examples, revision] = await Promise.all([readExamples(), gitRevision()]); + const [examples, guideSource, revision] = await Promise.all([ + readExamples(), + readFile(path.join(workspaceDirectory, 'GUIDE.md'), 'utf8'), + gitRevision(), + ]); sendJson(response, 200, { revision, examples: examples.map(({ directory: _directory, ...example }) => example), + guide: { path: 'GUIDE.md', source: guideSource, target: 'GUIDE.md' }, rootUri: pathToFileURL(workspaceDirectory).href, }); return; diff --git a/playground/src/main.ts b/playground/src/main.ts index 1e2d7bbc8d0..f1ffdf85b98 100644 --- a/playground/src/main.ts +++ b/playground/src/main.ts @@ -33,13 +33,13 @@ type PlaygroundGuide = { type PlaygroundExample = { files: PlaygroundFile[]; - guide: PlaygroundGuide; id: string; title: string; }; type PlaygroundInfo = { examples: PlaygroundExample[]; + guide: PlaygroundGuide; rootUri: string; revision: string; }; @@ -263,8 +263,6 @@ const main = async () => { const fileByUri = new Map(allFiles.map(entry => [entry.file.uri, entry])); const views = new Map(); const containers = new Map(); - const markdownViews = new Map(); - const markdownContainers = new Map(); const exampleButtons = new Map(); const fileButtons = new Map(); let activeExampleId = initialExample.id; @@ -314,10 +312,6 @@ const main = async () => { exampleButtons.forEach((button, candidate) => { button.dataset.active = String(candidate === example.id); }); - markdownContainers.forEach((container, candidate) => { - container.hidden = candidate !== example.id; - }); - guidePath.textContent = `${example.id}://${example.guide.path}`; renderFileTree(example); if (selectDefaultFile) { const current = fileByUri.get(activeUri); @@ -426,33 +420,25 @@ const main = async () => { views.set(file.uri, view); }); - info.examples.forEach(example => { - const container = document.createElement('div'); - container.className = 'markdown-container'; - container.hidden = example.id !== activeExampleId; - markdownEditorParent.append(container); - markdownContainers.set(example.id, container); - - const view = new EditorView({ - doc: storedFiles[example.guide.target] ?? example.guide.source, - extensions: [ - basicSetup, - markdown(), - oneDark, - playgroundLinkDecorations, - markdownFileNavigation(openFileTarget), - EditorView.lineWrapping, - EditorView.updateListener.of(update => { - if (update.docChanged) { - saveStoredFile(example.guide.target, update.state.doc.toString()); - } - }), - ], - parent: container, - }); - markdownViews.set(example.id, view); + const markdownView = new EditorView({ + doc: storedFiles[info.guide.target] ?? info.guide.source, + extensions: [ + basicSetup, + markdown(), + oneDark, + playgroundLinkDecorations, + markdownFileNavigation(openFileTarget), + EditorView.lineWrapping, + EditorView.updateListener.of(update => { + if (update.docChanged) { + saveStoredFile(info.guide.target, update.state.doc.toString()); + } + }), + ], + parent: markdownEditorParent, }); + guidePath.textContent = info.guide.path; selectExample(activeExampleId); lspStatus.textContent = 'rust-analyzer connected'; lspStatus.dataset.state = 'ready'; @@ -490,9 +476,8 @@ const main = async () => { const view = views.get(file.uri); view?.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: file.source } }); }); - const markdownView = markdownViews.get(example.id); - markdownView?.dispatch({ - changes: { from: 0, to: markdownView.state.doc.length, insert: example.guide.source }, + markdownView.dispatch({ + changes: { from: 0, to: markdownView.state.doc.length, insert: info.guide.source }, }); }); }; diff --git a/playground/src/style.css b/playground/src/style.css index 4a061aac1af..6cd72b2eda9 100644 --- a/playground/src/style.css +++ b/playground/src/style.css @@ -204,7 +204,6 @@ h1 { #editors, #markdown-editor, -.markdown-container, .editor-container, .cm-editor { height: 100%; diff --git a/playground/workspace/GUIDE.md b/playground/workspace/GUIDE.md new file mode 100644 index 00000000000..3bced1b2c3e --- /dev/null +++ b/playground/workspace/GUIDE.md @@ -0,0 +1,19 @@ +# LiteLLM Rust examples + +Each example is a standalone binary Cargo package with its own `main` function. A link's URI scheme selects the example crate; the rest is a path relative to that crate. + +## Proc macro + +- [Open the entry point](proc-macro://src/main.rs#L1) +- [Open the derived data model](proc-macro://src/proof.rs#L3) +- [Open its Cargo manifest](proc-macro://Cargo.toml#L1) + +`CompilerProof` derives Serde's `Serialize` and `Deserialize` procedural macros and references `litellm_core::Error`. + +## In-repo dependency + +- [Open the main function](error-type://src/main.rs#L3) +- [Open the report module](error-type://src/report.rs#L1) +- [Open its Cargo manifest](error-type://Cargo.toml#L1) + +This example prints the fully qualified name of `litellm_core::Error`. No model or network request is involved. diff --git a/playground/workspace/examples/error-type/GUIDE.md b/playground/workspace/examples/error-type/GUIDE.md deleted file mode 100644 index 07e8c0182b6..00000000000 --- a/playground/workspace/examples/error-type/GUIDE.md +++ /dev/null @@ -1,9 +0,0 @@ -# In-repo dependency app - -This standalone binary package imports a type directly from LiteLLM's Rust crate. - -- [Open the main function](error-type://src/main.rs#L3) -- [Open the report module](error-type://src/report.rs#L1) -- [Open its Cargo manifest](error-type://Cargo.toml#L1) - -Run the example to print the fully qualified name of `litellm_core::Error`. No model or network request is involved. diff --git a/playground/workspace/examples/proc-macro/GUIDE.md b/playground/workspace/examples/proc-macro/GUIDE.md deleted file mode 100644 index e65ec60bcad..00000000000 --- a/playground/workspace/examples/proc-macro/GUIDE.md +++ /dev/null @@ -1,9 +0,0 @@ -# Proc macro app - -This example is a standalone binary Cargo package with its own `main` function. - -- [Open the entry point](proc-macro://src/main.rs#L1) -- [Open the derived data model](proc-macro://src/proof.rs#L3) -- [Open its Cargo manifest](proc-macro://Cargo.toml#L1) - -`CompilerProof` derives Serde's `Serialize` and `Deserialize` procedural macros. The app also references `litellm_core::Error` from the in-repo LiteLLM Rust crate.