diff --git a/packages/vscode-pv-handlebars-language-server/server/src/completionProvider.ts b/packages/vscode-pv-handlebars-language-server/server/src/completionProvider.ts index 9735aca..9317833 100644 --- a/packages/vscode-pv-handlebars-language-server/server/src/completionProvider.ts +++ b/packages/vscode-pv-handlebars-language-server/server/src/completionProvider.ts @@ -204,7 +204,7 @@ export async function completionProvider( if (/^\n*---[^---]*layout:\s*(\w|\d)*$/.test(text)) { const isPageTemplate = filePath.includes("/frontend/src/pages"); const layouts = await getLayoutFiles(componentsRootPath); - const relevantLayouts = layouts?.[isPageTemplate ? "pages" : "lsg"]; + const relevantLayouts = isPageTemplate ? layouts?.normal : {...layouts?.normal , ...layouts?.lsg}; if (relevantLayouts) return Object.keys(relevantLayouts) diff --git a/packages/vscode-pv-handlebars-language-server/server/src/definitionProvider.ts b/packages/vscode-pv-handlebars-language-server/server/src/definitionProvider.ts index 6b17075..e7e82b3 100644 --- a/packages/vscode-pv-handlebars-language-server/server/src/definitionProvider.ts +++ b/packages/vscode-pv-handlebars-language-server/server/src/definitionProvider.ts @@ -58,8 +58,8 @@ export async function definitionProvider( const componentsRootPath = filePath.includes("src/components/") ? `${filePath.split("/frontend/src/components")[0]}/frontend/src/components` : filePath.includes("src/pages/") - ? `${filePath.split("/frontend/src/pages")[0]}/frontend/src/components` - : `${filePath.split("/frontend/src/layouts")[0]}/frontend/src/components`; + ? `${filePath.split("/frontend/src/pages")[0]}/frontend/src/components` + : `${filePath.split("/frontend/src/layouts")[0]}/frontend/src/components`; // e.g. {{> partial if (isPartial(textBefore)) { @@ -149,12 +149,23 @@ export async function definitionProvider( --- */ else if (/^\n*---[^---]*layout:\s*(\w|\d)+$/.test(textBefore)) { - // templates inside /page/ directory use different layouts than the open under /components/ + // templates inside /components/ directory in the older assemble/stylemark were rendered with the layout hbs files *and a second time* with the `lsgTemplatesSrc` layouts + // these option doesn't need to be shown for /pages/ const isPageTemplate = filePath.includes("/frontend/src/pages"); - const layouts = await getLayoutFiles(componentsRootPath); - const layoutFilePath = layouts?.[isPageTemplate ? "pages" : "lsg"]?.[symbolName]; + const allLayouts = await getLayoutFiles(componentsRootPath); + if (!allLayouts) return null; + + const normalLayouts = allLayouts.normal; + const lsgLayouts = allLayouts.lsg; + + const layouts = []; + if (normalLayouts) layouts.push(...Object.entries(normalLayouts)); + if (lsgLayouts && !isPageTemplate) layouts.push(...Object.entries(lsgLayouts)); + const results = []; + + for (const [name, layoutFilePath] of layouts) { + if (name !== symbolName) continue; - if (layoutFilePath) { const fileContent = await getFileContent(layoutFilePath); // placeholder assemble-lite uses to place content in the layout const BODY_PLACEHOLDER = "{% body%}"; @@ -164,14 +175,18 @@ export async function definitionProvider( if (placeholderStart !== -1) { const before = fileContent.slice(0, placeholderStart); const lineNumber = (before.match(/\n/g) || []).length; - return Location.create(URI.file(layoutFilePath).toString(), Range.create(lineNumber, 0, lineNumber, 1000)); + results.push( + Location.create(URI.file(layoutFilePath).toString(), Range.create(lineNumber, 0, lineNumber, 1000)), + ); } // whole file else { - return Location.create(URI.file(layoutFilePath).toString(), Range.create(0, 0, 0, 0)); + results.push(Location.create(URI.file(layoutFilePath).toString(), Range.create(0, 0, 0, 0))); } - } + + return results; } + return null; } diff --git a/packages/vscode-pv-handlebars-language-server/server/src/helpers.ts b/packages/vscode-pv-handlebars-language-server/server/src/helpers.ts index 99841ea..c6c5da0 100644 --- a/packages/vscode-pv-handlebars-language-server/server/src/helpers.ts +++ b/packages/vscode-pv-handlebars-language-server/server/src/helpers.ts @@ -11,6 +11,10 @@ import rgx from "./rgx"; interface PVConfig { hbsHelperSrc?: string; namespace?: string; + /** + * @deprecated + * was removed in pv-stylemark v4. + */ lsgTemplatesSrc?: string; cdTemplatesSrc?: string; } @@ -161,8 +165,13 @@ export async function getCustomHelperFiles(componentsRootPath: string): Promise< } interface LayoutFiles { - lsg?: { [name: string]: string }; - pages?: { [name: string]: string }; + // list of layouts only used to generate lsg_components + lsg?: { + // e.g. default: "/lsg/layouts/default.hbs" + [name: string]: string; + }; + // layouts to generate pages/ and components/ + normal?: { [name: string]: string }; } // list of hbs files which are used in assemble-lite as layouts for lsg components or pages @@ -172,13 +181,14 @@ export async function getLayoutFiles(componentsRootPath: string): Promise = [ + const layouts: Array<{ name: "lsg" | "normal"; dir: string | undefined }> = [ + // still provide backwards compatibility for projects not yet migrated to the new pv-stylemark { name: "lsg", dir: pvConfig.lsgTemplatesSrc, }, { - name: "pages", + name: "normal", dir: pvConfig.cdTemplatesSrc, }, ];