Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Examples -- Continued #2272

Draft
wants to merge 86 commits into
base: main
Choose a base branch
from

Conversation

trillium
Copy link
Contributor

@trillium trillium commented Mar 25, 2024

This is following on from the work of #940
Might resolve:

This is currently a draft PR

  • Last updated 2024-10-04

Latest updates

  • Migrate more type usage from custom to @cursorless/common
  • Refactor loadingFixture
  • Rebased and fixed merge conflicts
  • Resolved @cursorless/common import errors
  • Switched to using some @cursorless/common types
    • More will need to be done on this

ToDos Immediate

  • Render clipboard interactions in finalState
  • Resolve type issues
    • Update generateHtml types
  • Get during state rendering
  • Get pendingDelete state to render
  • Resolve some bugs in the generation around creating selections

ToDos IceBox

  • Create animation out of initialState, during, and finalState
  • Define some kind of internal API so it can be called properly or something like that
Screenshot image
Older Screenshots image

Current issues

  • The during step that shows selection for deletion isn't being hit
    • Haven't updated the code to capture a pendingDeletion selection yet (loadFixtures.ts)
  • Color scheme is very bad, will need to pick something better eventually

Older changes

Summary of older changes
4e0b81cc SimeonC         All working with tests                                                           
3d2e85ff pre-commit-ci.. [pre-commit.ci] auto fixes from pre-commit.com hooks                             
47ca6352 SimeonC         wip: Delete workspace.json for cherry-pick - git cherry pick 070c870 - Delete .. 
  • Moved cursorless-rx/ ... /generate-exmples folder to packages/generate-examples to conform with monorepo
  • Updated loadFixture directory to point correctly to cursorless-vscode-e2e recorded folder
  • Resolved an error in packages/generate-examples/src/lib/generateHtml.ts @ SelectionParser.parse that made pnpm build fail
    • This might not be the right solution, but it the code it working again
  • Populated results from loadFixture with original data -- as of yet unused
  • Ran relevant pnpm install/setup commands

Checklist

@SimeonC
Copy link
Contributor

SimeonC commented Mar 26, 2024

Thanks for picking this up! If you need any help figuring out what I was doing let me know. I can answer questions but completely have no time to code outside of work commitments 😞

@trillium
Copy link
Contributor Author

All good, happy to see you're well :)

I'm definitely curious about the decisions you made to choose these libraries and what your vision was for how you wanted this feature to end up.

Recently I was looking for more opportunities for to learn what Cursorless can do and wanted a series of gifs that could demo its capabilities. We've already got all these test files so that seemed like a good place to start, and it turns out you already are plenty of the way there!

@SimeonC
Copy link
Contributor

SimeonC commented Mar 26, 2024

I think we just had the same desire, while I was learning Cursorless at the start I just wanted something like a "library" of examples of what each command could do. My overall thinking was just a "search command/scope/etc, see examples" type app, but never got past the "just make the HTML work" stage.

I don't think there was anything really "deep" in my decision-making, shiki lib had the ability to give me the objects/arrays that I could manipulate like a "middleware" to add all the highlighting/tokens before rendering the HTML (bonus that it had all the different styling options too). That was really the only decision I made, the rest is all just hard work figuring out how to make overlapping ranges highlight (no multi-ranges is the easy part), hence the tests cause I broke my own code so many times trying to fix it, I suddenly had a better appreciation for TDD 🤣

@trillium
Copy link
Contributor Author

trillium commented Mar 26, 2024

I think one of my main questions is where this will end up residing. Eg is it gonna be available locally via something like the cheat sheet or is it only online via the docs.

That might be a better question if Andreas or Pokey, but I think it affects how I would explore building this.

My first inclination was to see if anything could be reused from the Docusaurus space:

  • Use a build system to turn the test YAML files into MDX
  • Create a custom component to render the MDX with all the highlight, ranges, hats info in the grey matter area

If it's going to reside in the cheat sheet then there's no established components, theme etc to start from and something like shiki seems like the right choice.

I honestly have no idea though.

@SimeonC
Copy link
Contributor

SimeonC commented Mar 26, 2024

Sorry can't help you there, definitely a question for Pokey or Andreas as I didn't really figure out with them where was best.

@AndreasArvidsson
Copy link
Member

With the caveat that I haven't really read through the previous pull request we definitely want code examples in the online documentation. We might link from the cheat sheet to the online docs, but I don't think we should actually cram all the documentation into the cheat sheet itself.

@pokey
Copy link
Member

pokey commented Mar 26, 2024

A package is the way to go, but I'd recommend starting from a clean checkout of main and then proceeding as follows:

  1. Run the steps in the docs for creating a new package (your package is a library, so don't add private in step 4)
  2. Lift just the typescript files from Add the generate-examples library #940
  3. Take only whatever else you need from Add the generate-examples library #940 to actually make things work. There's a lot of nx cruft in that PR that we don't need anymore

I'm not sure generate-examples is the name I'd go with. I think the primary export of this package should be a react component whose input is a TestCaseFixture. So I think I'd maybe call the package test-case-component? @AndreasArvidsson any thoughts on name?

Fwiw you might want to look at the cheatsheet package, as that's an example of a package whose primary export is a react component

For local testing / experimentation, I'd just add a dummy page to our cursorless-org package so you can use our next.js local dev setup. That's what we do for our cheatsheet (https://github.com/cursorless-dev/cursorless/blob/main/packages/cursorless-org/src/pages/cheatsheet.tsx; actually deployed at https://www.cursorless.org/cheatsheet fwiw) You can just use a dummy fixture for now. See README at https://github.com/cursorless-dev/cursorless/tree/main/packages/cursorless-org for info on how to run local dev server

Once you have a working react component, we can look into getting it into docusaurus using mdx

Lmk if any of the above doesn't make sense, and feel free to drop into another meet-up if you get stuck!

@trillium
Copy link
Contributor Author

trillium commented Mar 27, 2024

I wanted to keep the commit record from @SimeonC if possible so I reconfigured a few things and it should be working properly. The code still builds in the same way it use to.

Still working on getting a test page to render similar to cheatsheet

@pokey
Copy link
Member

pokey commented Mar 27, 2024

ok no worries; looks like you managed to remove all the unnecessary nx stuff so that's fine 👍. I'd move all the lib/ stuff up to src/ dir tho; that lib subdir isn't a pattern we follow

@trillium
Copy link
Contributor Author

Moved files from src/lib/* to src/*

Though, that same pattern is in packages/cheatsheet/, but it's literally the only one

# find . -type d
./cheatsheet
./cheatsheet/node_modules
./cheatsheet/node_modules/@types
./cheatsheet/node_modules/.bin
./cheatsheet/node_modules/@fortawesome
./cheatsheet/node_modules/@testing-library
./cheatsheet/src
./cheatsheet/src/lib
./cheatsheet/src/lib/components
./cheatsheet/src/lib/sampleSpokenFormInfos
./cheatsheet/src/lib/hooks

@pokey
Copy link
Member

pokey commented Mar 27, 2024

Oh interesting. I wonder why we do that there. Probably same reason tbh; was migrated from the old nx semi-mono-repo and never changed

@trillium
Copy link
Contributor Author

trillium commented Mar 27, 2024

I've been working on mirroring the format of the cheatsheet for a componentsheet, I currently am getting stuck at module/types import from @cursorless/test-case-component but I think it's because I don't understand how to generate types for the test-case-component module.

I was also having a few issues just trying to understand how everything worked together by running cursorless-org pnpm dev and editing text in packages/cheatsheet/src/cheatsheet.tsx to see how changes propagated

I couldn't get anything to change e.g.:

  • edit packages/cheatsheet/src/cheatsheet.tsx
    • change h1 to Testy test Cursorless Cheatsheet
    • wait for next to confirm rebuild
    • see no changes on localhost:3000/cheatsheet

@pokey
Copy link
Member

pokey commented Apr 5, 2024

I've been working on mirroring the format of the cheatsheet for a componentsheet, I currently am getting stuck at module/types import from @cursorless/test-case-component but I think it's because I don't understand how to generate types for the test-case-component module.

could you possibly elaborate? not sure I follow

I was also having a few issues just trying to understand how everything worked together by running cursorless-org pnpm dev and editing text in packages/cheatsheet/src/cheatsheet.tsx to see how changes propagated

I couldn't get anything to change e.g.:

* edit `packages/cheatsheet/src/cheatsheet.tsx`
  
  * change `h1` to `Testy test Cursorless Cheatsheet`
  * wait for next to confirm rebuild
  * see no changes on `localhost:3000/cheatsheet`

Strange. I could have sworn that used to work 🤔. But yes I confirmed it's not working for me either. Here's a fix #2286

@AndreasArvidsson
Copy link
Member

I'm not sure generate-examples is the name I'd go with. I think the primary export of this package should be a react component whose input is a TestCaseFixture. So I think I'd maybe call the package test-case-component? @AndreasArvidsson any thoughts on name?

Test case component sounds good

@pokey
Copy link
Member

pokey commented Apr 7, 2024

fwiw #2286 now merged so hot reload should work once you do a git merge

@pokey
Copy link
Member

pokey commented Apr 7, 2024

I see there's a conflict in your lockfile. Generally easiest to just revert the lockfile to main and then do a pnpm install

@trillium
Copy link
Contributor Author

trillium commented Apr 9, 2024

Haven't made that much progress on this since last check in. Got content to render from packages/test-case-component just now though so that's progress!

I do my best to copy the cheatsheet page format from existing code to where applicable to test-case-component
Actions thusfar:

  • Add dependency test-case-component to cursorless-org copying cheatsheet's format
  • Create a text-case-component.tsx file for initial workings
    • Experiencing an error
import {
  TestCaseComponentPage
} from "@cursorless/test-case-component";
//              ~~~~~~~~~~~~~~~~~~~~~~~~~
import Head from "next/head";

// Cannot find module '@cursorless/test-case-component' or its corresponding type declarations.

I originally thought this was blocking me from getting the test-component-sheet page to render but that isn't blocking me any longer.

@trillium trillium force-pushed the generate-examples branch 3 times, most recently from fb05cec to 6e3c9cd Compare April 9, 2024 10:26
@trillium
Copy link
Contributor Author

trillium commented Apr 9, 2024

Thanks for taking some extra time before you all hopped off todays call :)

Notes

cursorless-org/component-sheet page

  • get yaml coming into component
  • hardcode ok for now
  • pass as props
  • can add a yaml dependency if needed
    • of type TestCaseFixture
      • let it be type:any for now
  • okay to stick with Jest if needed
    • cheatsheet might use Jest?

Test file

  • try to get tests to run before making any changes to structure
  • Cursorless uses Mocha for most tests
  • okay to stick with Jest if needed
    • cheatsheet might use Jest?

@pokey
Copy link
Member

pokey commented Apr 9, 2024

can add a yaml dependency if needed

* of type TestCaseFixture
  
  * let it be type:any for now

just to clarify this one: TestCaseComponent should declare the property type as TestCaseFixture, but in the TestCasePage in cursorless-org you should leave it as type any. Make sense?

@trillium
Copy link
Contributor Author

trillium commented Apr 9, 2024

Yes that makes sense

  • Page should import the yaml but not care about the type
    • pass to Component as props
  • Component should care about the type to prevent errors

@trillium trillium force-pushed the generate-examples branch 2 times, most recently from 660d2a1 to bb4e62b Compare April 9, 2024 19:16
trillium and others added 27 commits October 2, 2024 22:41
fix: Resolve warning on lockfile
"Ignoring broken lockfile at /Users/trilliumsmith/code/cursorless-dev/cursorless: Lockfile /Users/trilliumsmith/code/cursorless-dev/cursorless/pnpm-lock.yaml not compatible with current pnpm"
@trillium
Copy link
Contributor Author

trillium commented Oct 3, 2024

Hey all, picking this issue back up again. I rebased changes onto main and fixed merge conflicts.

Last I was here @pokey suggested using the upgrade function to make sure that the test files are always in the latest version. that's not working with getStaticProps:

image

I don't know what to do about this, but the test-files are still loading even if they're in the version one previous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants