Shopify / Shopify/theme-tools

Extract snippet from file `refactor.extract` CodeAction

Open
#433 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:theme-check enhancement
Dominant language
TypeScript
Stars
234
Forks
92
Avg merge
1d 3h
Merged PRs (30d)
6

Description

The LSP defines some CodeActionKinds that have special meanings in some Language Clients. One of those is the RefactorExtract action kind.

We could probably offer a RefactorExtract action when you highlight a large range of text inside a section|template|snippet.

When executed, we could do something like this:

  • For range Y in input file X:
    1. Find all non-global variables in Y
    2. Create a file snippets/Z.liquid with the contents of Y
    3. Replace Y in X by the following:
      {%
        render '#{Z}',
        #{all_the_non_global_variables_as_arguments}
      %}
    

To be answered:

  • Can we prompt for a filename during that process?
Resources
  1. https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#textDocument_codeAction

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the proposed behavior in this issue and read the linked LSP CodeAction specification. Identify the language-server entry point for CodeActions and determine how range variables, snippet creation, replacement text, and filename prompting should work. Done means a RefactorExtract action can perform the described extraction with a clear filename flow.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.