Skip to content

Commit

Permalink
Check workspace folder client capabilities before fetching metafields
Browse files Browse the repository at this point in the history
  • Loading branch information
aswamy committed Jan 16, 2025
1 parent 0de2a0f commit c3d728b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changeset/afraid-singers-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/theme-language-server-common': patch
'@shopify/theme-language-server-node': patch
---

[internal] Check workspace folder client capabilities before fetching metafields
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class ClientCapabilities {
return !!this.capabilities?.workspace?.applyEdit;
}

get hasWorkspaceFoldersSupport() {
return !!this.capabilities?.workspace?.workspaceFolders;
}

get hasDidChangeConfigurationDynamicRegistrationSupport() {
return !!this.capabilities?.workspace?.didChangeConfiguration?.dynamicRegistration;
}
Expand Down
16 changes: 9 additions & 7 deletions packages/theme-language-server-common/src/server/startServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,17 @@ export function startServer(
],
});

connection.workspace.getWorkspaceFolders().then(async (folders) => {
if (!folders) return;
if (clientCapabilities.hasWorkspaceFoldersSupport) {
connection.workspace.getWorkspaceFolders().then(async (folders) => {
if (!folders) return;

fetchMetafieldDefinitionsForWorkspaceFolders(folders);
});
fetchMetafieldDefinitionsForWorkspaceFolders(folders);
});

connection.workspace.onDidChangeWorkspaceFolders(async (params) => {
fetchMetafieldDefinitionsForWorkspaceFolders(params.added);
});
connection.workspace.onDidChangeWorkspaceFolders(async (params) => {
fetchMetafieldDefinitionsForWorkspaceFolders(params.added);
});
}
});

connection.onDidChangeConfiguration((_params) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/theme-language-server-node/src/metafieldDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const isWin = process.platform === 'win32';
const shopifyCliPathPromise = getShopifyCliPath();

export async function fetchMetafieldDefinitionsForURI(uri: string) {
const path = await shopifyCliPathPromise;
try {
const path = await shopifyCliPathPromise;

if (!path) {
return;
}
if (!path) {
return;
}

try {
await exec(`${path} theme metafields pull`, {
cwd: new URL(uri),
timeout: 10_000,
Expand Down

0 comments on commit c3d728b

Please sign in to comment.