Skip to content

Commit

Permalink
Fix single quotes not working on Windows (#40)
Browse files Browse the repository at this point in the history
* Fix single quotes not working on Windows

* Note down what to test before release
  • Loading branch information
gediminasz authored Oct 2, 2023
1 parent f4300b4 commit a19cf08
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## Unreleased

- Execute shell commands under `powershell.exe` on Windows. This addresses Command Prompt not supporting queries wrapped in single quotes.

## 2023.9.0

- Fixed `readtags` command failing when a symbol query contains non-alphanumeric characters.
Expand Down
4 changes: 4 additions & 0 deletions NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
1. `make package`
1. `code --install-extension ctags-companion-2023.9.0-beta.vsix`
1. Manually test the extension on a few projects
1. Rebuild ctags task
1. Go to Symbol in Workspace
1. Go to Symbol in File
1. Go to Definition

## Release checklist

Expand Down
14 changes: 10 additions & 4 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,18 @@ function findField(tags, prefix) {
return tag && tag.substring(prefix.length);
}

function wrapExec(exec) {
function wrapExec(exec, platform = process.platform) {
const outputChannel = vscode.window.createOutputChannel(EXTENSION_NAME);
return async (...args) => {
return async (command, options) => {
try {
outputChannel.appendLine(args[0]);
const { stdout } = await exec(...args);
if (platform === "win32") {
// Use PowerShell on Windows because Command Prompt does not support single quotes
options = {...options, shell: "powershell.exe"}
}

outputChannel.appendLine(`${command} ${JSON.stringify(options)}`);

const { stdout } = await exec(command, options);
const output = stdout.trim();
return output ? output.split('\n') : [];
} catch ({ message }) {
Expand Down
16 changes: 16 additions & 0 deletions src/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,20 @@ describe('wrapExec', () => {
expect(result).toEqual([]);
expect(vscode.window.showErrorMessage).toHaveBeenCalledWith("Ctags Companion: epic fail");
});

it.each([
["win32", "powershell.exe"],
["darwin", undefined],
["linux", undefined]
])('uses powershell in windows', async (platform, expectedShell) => {
let shellUsed = undefined;

const exec = async (_, { shell }) => {
shellUsed = shell;
return { stdout: "OK" };
};

await wrapExec(exec, platform)("fakecommand", {});
expect(shellUsed).toEqual(expectedShell);
});
});

0 comments on commit a19cf08

Please sign in to comment.