theme-tools icon indicating copy to clipboard operation
theme-tools copied to clipboard

Deeplink to open a theme block by its type value specified in the liquid schema

Open albchu opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. It would be good DX to allow theme developers to deeplink through theme block type in blocks and preset nested blocks

Describe the solution you'd like A clear and concise description of what you want to happen. Deeplink click to open the corresponding theme block asset

Checklist

  • [x] I have checked and made sure that the proposal adheres to this plugin's principles

Additional context Add any other context or screenshots about the feature request here. Something like this

// {% schema %}{ "blocks": [{ "type": "█" }] }{% endschema %}
LiquidRawTag(node) {
  if (node.name !== 'schema') return;
  if (!schema || isError(schema.ast) || isError(schema.validSchema)) return;
  const offset = node.blockPositionStart.end;
  const blockDefs = schema.validSchema.blocks;
  if (!blockDefs || hasLocalBlocks(blockDefs)) return;
  return blockDefs.map((def, i) => {
    const type = def.type;
    const typeNode = nodeAtPath(schema.ast, [blocks, i, "type"]);
    return DocumentLink.create(
      Range.create(offset + locStart(typeNode), offset + locEnd(typeNode)),
      Utils.resolvePath(root, 'blocks', type + ".liquid").toString(),
    );
  });
}

albchu avatar Dec 02 '24 16:12 albchu