Fix examples + Copy example button#22
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the language-service sample to support example-specific deep links and a “copy example link” button, and wires in a separate examples script. It also updates the sample server to serve the new script.
Changes:
serve-sample.cjs: Adds routing to serve/examples.jsalongside existing sample assets.index.html: Includes a newexamples.jsscript beforeapp.js.app.js: Moves example data out of this file (now assumed to live inexamples.js), adds acopyExampleLinkhelper, and augments the examples sidebar with “copy link” buttons and URL-based example loading.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| samples/language-service-sample/serve-sample.cjs | Adds routing logic so /examples.js is served from the sample directory. |
| samples/language-service-sample/index.html | Loads the new examples.js script before app.js to provide example data and deep-link support. |
| samples/language-service-sample/app.js | Removes inline example definitions, consumes exampleCases from the external script, and implements the copy-link UX and URL-driven example loading. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (urlPath === '/' || urlPath === '/index.html') { | ||
| urlPath = 'samples/language-service-sample/index.html'; | ||
| } else if (urlPath === '/styles.css' || urlPath === '/app.js') { | ||
| } else if (urlPath === '/styles.css' || urlPath === '/app.js' || urlPath === '/examples.js') { |
There was a problem hiding this comment.
The server is configured to serve /examples.js from samples/language-service-sample/examples.js, but that file does not exist, so requests to this path will always return 404. Once examples.js is added (or if you decide to inline examples instead), this route should be updated accordingly.
| } else if (urlPath === '/styles.css' || urlPath === '/app.js' || urlPath === '/examples.js') { | |
| } else if (urlPath === '/styles.css' || urlPath === '/app.js') { |
| const examplesList = document.getElementById('examplesList'); | ||
| if (!examplesList) return; | ||
|
|
||
| examplesList.innerHTML = exampleCases.map(example => ` |
There was a problem hiding this comment.
exampleCases is referenced here but no longer defined in this file and there is no other definition in the repo, so this will throw a ReferenceError at runtime unless a global exampleCases is provided (e.g., by the new examples.js). Either reintroduce the data here or ensure examples.js exists, defines exampleCases on the global scope, and is loaded before this script.
| examplesList.innerHTML = exampleCases.map(example => ` | |
| const examples = (window.exampleCases || []); | |
| examplesList.innerHTML = examples.map(example => ` |
| <span>Saved to localStorage</span> | ||
| </div> | ||
|
|
||
| <script src="examples.js"></script> |
There was a problem hiding this comment.
This script tag loads examples.js, but there is no corresponding samples/language-service-sample/examples.js file in the repository, so the browser will 404 this request and any globals (like exampleCases) it is supposed to define will be missing. Please add the file to the sample folder or remove this tag and keep the examples inline.
| <script src="examples.js"></script> |
No description provided.