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

Pass snippets as argument to engine #2478

Merged
merged 7 commits into from
Jul 11, 2024
Merged

Pass snippets as argument to engine #2478

merged 7 commits into from
Jul 11, 2024

Conversation

AndreasArvidsson
Copy link
Member

Makes it so that Cursorless everywhere editors doesn't have to provide a snippet implementation

Checklist

  • [/] I have added tests
  • [/] I have updated the docs and cheatsheet
  • [/] I have not broken the cheatsheet

@AndreasArvidsson AndreasArvidsson requested a review from pokey as a code owner July 9, 2024 20:27
Copy link
Member

@pokey pokey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't read in detail, but my first two reactions are as follows:

Moving snippets from engine to vscode feels like a lateral at best. We went through the effort to abstract vscode out of the snippets component, so I would prefer if we didn't reverse that. Ie this makes it harder for us to use snippets in neovim or other node contexts

Second issue is that it doesn't really make the core much leaner if we still have a bunch of references to snippets in the engine. They're only used in two actions right? I'd be tempted to think the right abstraction is to allow passing in custom actions. Then snippets are never even mentioned

But I didn't read super closely so maybe missing something

@AndreasArvidsson
Copy link
Member Author

AndreasArvidsson commented Jul 9, 2024

I was thinking that since snippets is probably going to be deprecated this was a reasonable decision. When we make the next version we can do it more properly. But right now I'm blocked on this and I don't think any other editor is going to want to implement our json based snippets in the coming few weeks?

This is just about getting rid of node references in engine. A much better interface for snippets could definitely be designed.

With that said let me have another look at it tomorrow and I might come up with a solution you like better :)

@AndreasArvidsson
Copy link
Member Author

I've had another look and started a more more abstracted implementation and bailed. Basically most of what is in Snippets.ts that I here reamed to VscodeSnippets.ts is vscode specific. The fact that we are polling the file system. The handling of directory error message. The fact that you can a register third party snippets to some extent. If I remove everything that isn't vscode and make an abstraction it basically becomes more code for no good reason. I stand by my original assessment that this should probably live in vscode until we make a refactor where we used the new snippet format and don't poll.

@AndreasArvidsson
Copy link
Member Author

AndreasArvidsson commented Jul 10, 2024

Implementations like this also makes it a bit hard to abstract snippets. We are explicitly creating a file in the file system and then opening in the editor. To open the file we need a filepath so we are still stuck in the file system with snippets. Here my inclination is just to drill the file system instance through and add touch to that. We can later on revamp the entire snippet system and make its smarter, but for now I can a just need to be unblocked. Sounds reasonable?

@pokey
Copy link
Member

pokey commented Jul 10, 2024

Implementations like this also makes it a bit hard to abstract snippets. We are explicitly creating a file in the file system and then opening in the editor. To open the file we need a filepath so we are still stuck in the file system with snippets. Here my inclination is just to drill the file system instance through and add touch to that. We can later on revamp the entire snippet system and make its smarter, but for now I can a just need to be unblocked. Sounds reasonable?

Wouldn't my second suggestion above solve this problem? Ie generate snippet, insert snippet and wrap with snippet are just custom actions passed into the engine. If this isn't making sense let's discuss tomorrow alongside vscode vs engine thing

@AndreasArvidsson
Copy link
Member Author

AndreasArvidsson commented Jul 10, 2024

That sounds like a reasonable solution, but to be fair I don't really have the energy for that right now. This was only moving a single file that will unblock me. And we can then later make a more flexible approach. Happy to discuss it tomorrow.

@pokey
Copy link
Member

pokey commented Jul 10, 2024

Let's discuss tomorrow

@AndreasArvidsson AndreasArvidsson added the to discuss Plan to discuss at meet-up label Jul 11, 2024
@pokey pokey removed the to discuss Plan to discuss at meet-up label Jul 11, 2024
@pokey
Copy link
Member

pokey commented Jul 11, 2024

update from meet-up: pokey caved

Copy link
Member

@pokey pokey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one thing I think we discussed changing here is creating a DisabledSnippets class so that we can confine null checks to createEngine. Otherwise looks good; see also #2353 (comment)

@AndreasArvidsson
Copy link
Member Author

Done

Copy link
Member

@pokey pokey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with minor nit

packages/cursorless-engine/src/cursorlessEngine.ts Outdated Show resolved Hide resolved
@AndreasArvidsson AndreasArvidsson added this pull request to the merge queue Jul 11, 2024
@AndreasArvidsson AndreasArvidsson removed this pull request from the merge queue due to a manual request Jul 11, 2024
@AndreasArvidsson AndreasArvidsson added this pull request to the merge queue Jul 11, 2024
Merged via the queue into main with commit 00651ad Jul 11, 2024
15 checks passed
@AndreasArvidsson AndreasArvidsson deleted the refactorSnippets branch July 11, 2024 14:46
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.

2 participants