Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Add Windows support #35

Merged
merged 2 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ To install the `shopify` CLI, follow these steps:
1. Go to https://shopify.dev/tools/cli/installation
2. Follow the instructions for your operating system

⚠️ **Note:** Windows not yet supported.

## Configuration

- `"shopifyLiquid.shopifyCLIPath": string`, (optional) a path to the `shopify` executable.
Expand Down
23 changes: 13 additions & 10 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { LanguageClient } = require('vscode-languageclient');
class CommandNotFoundError extends Error {}
class IncompatibleVersionError extends Error {}

const isWin = process.platform === 'win32';
const sleep = (ms) => new Promise((res) => setTimeout(res, ms));

let client;
Expand Down Expand Up @@ -47,7 +48,7 @@ async function startServer() {
};

client = new LanguageClient(
'theme-check',
'shopifyLiquid',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this need to change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the configuration. This way you can set

"shopifyLiquid.trace.server": "verbose"

In your VS Code settings.json and see the lsp logs in the Output pane. Leaving it as theme-check meant that it had to be "theme-check.server.logs" which feels out of place with the rest of the configuration options.

'Theme Check Language Server',
serverOptions,
clientOptions,
Expand All @@ -56,7 +57,6 @@ async function startServer() {
client.start();
}


async function stopServer() {
try {
if (client) await Promise.race([client.stop(), sleep(1000)]);
Expand All @@ -71,7 +71,6 @@ async function restartServer() {
if (client) await stopServer();
await startServer();
}
/** */

function onConfigChange(event) {
const didChangeThemeCheck = event.affectsConfiguration(
Expand Down Expand Up @@ -118,21 +117,25 @@ async function getServerOptions() {
}
}

async function which(command) {
const whichCmd = isWin ? 'where' : 'which';
const { stdout } = await exec(`${whichCmd} ${command}`);
return stdout.split('\n')[0].replace('\r', '');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

}

async function getShopifyCLIExecutable() {
try {
const { stdout } = await exec('which shopify');
return shopifyCLIExecutable(stdout.replace('\n', ''));
const path = await which('shopify');
return shopifyCLIExecutable(path);
} catch (e) {
return undefined;
}
}

async function getThemeCheckExecutable() {
try {
const { stdout } = await exec(
'which theme-check-language-server',
);
return themeCheckExecutable(stdout.replace('\n', ''));
const path = await which('theme-check-language-server');
return themeCheckExecutable(path);
} catch (e) {
return undefined;
}
Expand Down Expand Up @@ -173,7 +176,7 @@ async function shopifyCLIIsAtLeastVersion2(command) {

async function themeCheckExecutableExists(command) {
try {
await exec(`[[ -f "${command}" ]]`);
!isWin && (await exec(`[[ -f "${command}" ]]`));
} catch (e) {
throw new CommandNotFoundError(
`${command} not found, are you sure this is the correct path?`,
Expand Down