UNPKG

@shopify/theme-language-server-common

Version:

<h1 align="center" style="position: relative;" > <br> <img src="https://github.com/Shopify/theme-check-vscode/blob/main/images/shopify_glyph.png?raw=true" alt="logo" width="141" height="160"> <br> Theme Language Server </h1>

66 lines 3.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BlockSettingsHoverProvider = void 0; const theme_check_common_1 = require("@shopify/theme-check-common"); const translations_1 = require("../../../translations"); const RequestContext_1 = require("../../RequestContext"); const utils_1 = require("../../utils"); const BlockTypeCompletionProvider_1 = require("../../completions/providers/BlockTypeCompletionProvider"); class BlockSettingsHoverProvider { constructor(getDefaultSchemaTranslations, getThemeBlockSchema) { this.getDefaultSchemaTranslations = getDefaultSchemaTranslations; this.getThemeBlockSchema = getThemeBlockSchema; } canHover(context, path) { return ((0, utils_1.isSectionOrBlockFile)(context.doc.uri) && (0, RequestContext_1.isLiquidRequestContext)(context) && path.length !== 0 && isBlocksSettingsPath(path)); } async hover(context, path) { var _a; if (!this.canHover(context, path)) return []; const { doc } = context; const schema = await doc.getSchema(); if (!isValidSchema(schema)) return []; const blockType = (0, theme_check_common_1.deepGet)(schema.parsed, [...path.slice(0, -2), 'type']); if (!blockType) return []; const themeBlockSchema = await this.getThemeBlockSchema(doc.uri, blockType); if (!isValidSchema(themeBlockSchema)) return []; if (!hasValidSchemaSettings(themeBlockSchema)) return []; const label = (_a = themeBlockSchema.parsed.settings.find((setting) => (setting === null || setting === void 0 ? void 0 : setting.id) === path.at(-1))) === null || _a === void 0 ? void 0 : _a.label; if (!label) return []; if (!label.startsWith('t:')) { return [label]; } return this.getDefaultSchemaTranslations(doc.uri).then((translations) => { const path = label.substring(2); const value = (0, translations_1.translationValue)(path, translations); if (!value) return undefined; return [(0, translations_1.renderTranslation)(value)]; }); } } exports.BlockSettingsHoverProvider = BlockSettingsHoverProvider; function isBlocksSettingsPath(path) { return ((path.at(0) === 'presets' || path.at(0) === 'default') && path.at(-4) === 'blocks' && path.at(-2) === 'settings' && path.at(-1) !== undefined && typeof path.at(-1) === 'string'); } function isValidSchema(schema) { return !!schema && !(0, theme_check_common_1.isError)(schema.parsed) && (0, BlockTypeCompletionProvider_1.isSectionOrBlockSchema)(schema); } function hasValidSchemaSettings(schema) { var _a; return ((_a = schema.parsed) === null || _a === void 0 ? void 0 : _a.settings) !== undefined && Array.isArray(schema.parsed.settings); } //# sourceMappingURL=BlockSettingsHoverProvider.js.map