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

Automatic renaming of snippet and assets on file rename #541

Merged
merged 6 commits into from
Oct 31, 2024

Conversation

charlespwd
Copy link
Contributor

@charlespwd charlespwd commented Oct 25, 2024

What are you adding in this PR?

automatic-rename-refactor.mp4
  • When snippets/*.liquid files are renamed, we ask the client to do the following:
    • update all the {% render 'oldName' %} calls to {% render 'newName' %}
  • When assets/*(.liquid)? files are renamed, we ask the client to do the following:
    • update all the {{ 'oldName.ext' | asset_url }} calls to {{ 'newName.ext' | asset_url }}
  • Add a preload method to the DocumentManager
    • this makes it possible for files that are not open to be parsed and be accesible
    • we won't reparse files that are already parsed
    • files from disk are cached in the DocumentManager with a version of undefined
  • Add an optional second argument to DocumentManager#theme
    • includeFilesFromDisk will make it so the theme method returns all the files in the theme
    • the default is still to only return all the open files
    • that way theme check keeps running on the open files only.

How it works

sequenceDiagram
    participant C as Client
    participant S as Server
    C->>S: Notification "workspace/didRenameFiles"
    activate S
    S->>S: Find relevant changes
    S->>+C: Request "workspace/applyEdit"
    activate C
    C->>-S: Response "applied!"
    deactivate S
Loading

What's next? Any followup issues?

Before you deploy

  • I included a minor bump changeset

@charlespwd charlespwd force-pushed the feature/412-snippet-rename-smart-replace branch from 2cfba99 to 48f9255 Compare October 29, 2024 14:02
@charlespwd charlespwd marked this pull request as ready for review October 29, 2024 14:12
@charlespwd charlespwd changed the title Add OnSnippetRename theme refactor Update section and asset references when they are renamed Oct 29, 2024
@charlespwd charlespwd changed the title Update section and asset references when they are renamed Automatic renaming of snippet and assets on file rename Oct 29, 2024
@charlespwd charlespwd linked an issue Oct 29, 2024 that may be closed by this pull request
@charlespwd charlespwd added #gsd:43130 Liquid DX and removed #gsd:43130 Liquid DX labels Oct 29, 2024
Copy link
Contributor

@aswamy aswamy left a comment

Choose a reason for hiding this comment

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

🎩 complete (we already discussed about the limitations on auto-saving after renaming files on Node)

minor comments, but nothing blocking


it('returns a needConfirmation: false workspace edit for renaming an asset', async () => {
await handler.onDidRenameFiles({
files: [
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't tophat this, but could we also attempt to rename two files at once in both handler's test cases? From the code, it appears as if that's possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tbh, I put that in to satisfy typescript. You'd get an array when you rename folders, but if you did then the condition isSnippet() for both the old and new uri would never be true.

I'm not 100% sure how else you could get multiple snippet renames in one UI operation.

packages/theme-check-common/src/path.ts Show resolved Hide resolved
}
});

it('handles .js.liquid files', async (ext) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it('handles .js.liquid files', async (ext) => {
it('handles when asset file is renamed and has added a `.liquid` extension to it', async (ext) => {

}
});

it('handles .css.liquid files', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it('handles .css.liquid files', async () => {
it('handles when asset file with `.liquid` extension is renamed', async () => {

- {{ 'oldName.js' | asset_url }} -> {{ 'newName.js' | asset_url }}
- {{ 'oldName.css' | asset_url }} -> {{ 'newName.css' | asset_url }}
- {% echo 'oldName.css' | asset_url %} -> {% echo 'newName.css' | asset_url %}
- etc.
@charlespwd charlespwd force-pushed the feature/412-snippet-rename-smart-replace branch from 23f980e to 70cb630 Compare October 31, 2024 12:18
@charlespwd charlespwd merged commit 5fab0e9 into main Oct 31, 2024
6 checks passed
@charlespwd charlespwd deleted the feature/412-snippet-rename-smart-replace branch October 31, 2024 12:23
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.

Update links when files are renamed
3 participants