Skip to content

Order pandoc format quick-pick by usage frequency#61

Merged
ChrisChinchilla merged 6 commits into
mainfrom
copilot/order-selection-by-frequency
Mar 12, 2026
Merged

Order pandoc format quick-pick by usage frequency#61
ChrisChinchilla merged 6 commits into
mainfrom
copilot/order-selection-by-frequency

Conversation

Copilot AI commented Mar 9, 2026

Copy link
Copy Markdown

The format selection menu always displayed output formats in a fixed static order, ignoring which formats a user actually reaches for most often.

Changes

  • src/extension.ts

    • displayMenuAndRender now accepts vscode.ExtensionContext
    • Reads a pandoc.formatUsage count map from context.globalState before each menu display
    • Sorts quick-pick items by descending use count (stable sort — ties preserve the original default order, so first-run experience is unchanged)
    • Increments and persists the selected format's count via context.globalState.update after each selection
    • Sorting and tracking are skipped when pandoc.sortByFrequency is set to false
  • package.json

    • New pandoc.sortByFrequency boolean setting (default: true) to allow users to opt out of frequency-based ordering
  • README.md

    • Documents the new pandoc.sortByFrequency setting under a "Sort formats by frequency" section
  • test/suites/extension.test.ts

    • Added test asserting items arrive sorted when globalState contains prior counts
    • Added test asserting globalState is updated with an incremented count after selection
    • Added test asserting items remain in default order when pandoc.sortByFrequency is false
    • Added test asserting globalState is not updated when pandoc.sortByFrequency is false

Example behavior

# After selecting "html" 10 times and "epub" 4 times:
[html]     Render as html document      ← most used, floats to top
[epub]     Render as epub document
[pdf]      Render as pdf document
[docx]     Render as word document
...

To disable frequency sorting and always show the default static order, set pandoc.sortByFrequency to false in your settings.

Original prompt

This section details on the original issue you should resolve

<issue_title>Order by frequency?</issue_title>
<issue_description>@ChrisChinchilla still in love with your extension!

One quick request:

Can you please order below selection by frequency of usage?

Would be great if you can get this done any time soon!

Heavily depend on your extension and saves me a couple of clicks every time :)

Thanks!

image
</issue_description>

Comments on the Issue (you are @copilot in this section)

@ChrisChinchilla @orschiro Hmm, I can think about it, but that might take me a while to get to.

Though maybe I am misunderstanding the request? Isn't it the same amount of clicks no matter where the option is on the list?</comment_new>
<comment_new>@ChrisChinchilla
@orschiro OK, you can also click the entry directly in the list… But I will take a look at some point, see how much work it is.</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Track per-format usage counts in context.globalState under the key
'pandoc.formatUsage'. Before showing the quick-pick menu, sort formats
in descending order of use count (stable, so the default alphabetical
order is preserved on first run). After a selection, increment the
count and persist it back to globalState.

Also adds two tests: one that verifies items are ordered by count,
and one that verifies globalState is updated after a selection.

Co-authored-by: ChrisChinchilla <42080+ChrisChinchilla@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ordering of selection by frequency of usage Order pandoc format quick-pick by usage frequency Mar 9, 2026
@ChrisChinchilla
ChrisChinchilla marked this pull request as ready for review March 12, 2026 08:11
@promptless

promptless Bot commented Mar 12, 2026

Copy link
Copy Markdown

📝 Documentation updates detected!

New suggestion: Document format list usage frequency sorting


Tip: Sort by Shortest Review in the Dashboard to find quick wins ⚡

@ChrisChinchilla

Copy link
Copy Markdown
Owner

@copilot This is great, I would liketo make this enabled as part of a setting, which is enabled by default, then add this to the read me

- package.json: new boolean setting pandoc.sortByFrequency (default: true)
- src/extension.ts: read the setting; skip sorting and globalState tracking when false
- README.md: document the new setting under "Sort formats by frequency"
- test/suites/extension.test.ts: stub the setting in existing frequency tests;
  add tests for disabled-setting path (no sort, no globalState update)

Co-authored-by: ChrisChinchilla <42080+ChrisChinchilla@users.noreply.github.com>

Copilot AI commented Mar 12, 2026

Copy link
Copy Markdown
Author

@copilot This is great, I would liketo make this enabled as part of a setting, which is enabled by default, then add this to the read me

Done in commit 2e232ed. Added a pandoc.sortByFrequency boolean setting (default: true) so frequency-based ordering is on by default but can be disabled. The README now documents it under a new "Sort formats by frequency" heading. Tests cover both the enabled and disabled paths.

# Conflicts:
#	package-lock.json
#	package.json
Comment thread dist/extension.js
// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
(() => {
/*!**************************!*\
!*** ./src/extension.ts ***!

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused variable vscode__WEBPACK_IMPORTED_MODULE_0___default.

Copilot Autofix

AI 4 months ago

In general, to fix an unused import/variable created for a module default export, either remove the unused binding or replace other uses to rely on that binding and drop redundant ones. Here, the code uses vscode__WEBPACK_IMPORTED_MODULE_0__ directly and never uses vscode__WEBPACK_IMPORTED_MODULE_0___default, so the minimal, behavior-preserving change is to delete the declaration/initialization of vscode__WEBPACK_IMPORTED_MODULE_0___default and leave the rest intact.

Concretely, in dist/extension.js, locate the import section for ./src/extension.ts where vscode__WEBPACK_IMPORTED_MODULE_0__ and vscode__WEBPACK_IMPORTED_MODULE_0___default are defined. Remove the line that assigns vscode__WEBPACK_IMPORTED_MODULE_0___default = __webpack_require__.n(vscode__WEBPACK_IMPORTED_MODULE_0__), leaving the vscode import (vscode__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(...)) and the remaining imports (child_process, path) unchanged. No new methods, imports, or definitions are needed.

Suggested changeset 1
dist/extension.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/dist/extension.js b/dist/extension.js
--- a/dist/extension.js
+++ b/dist/extension.js
@@ -117,7 +117,6 @@
 /* harmony export */   activate: () => (/* binding */ activate)
 /* harmony export */ });
 /* harmony import */ var vscode__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! vscode */ "vscode");
-/* harmony import */ var vscode__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(vscode__WEBPACK_IMPORTED_MODULE_0__);
 /* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! child_process */ "child_process");
 /* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_1__);
 /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! path */ "path");
EOF
@@ -117,7 +117,6 @@
/* harmony export */ activate: () => (/* binding */ activate)
/* harmony export */ });
/* harmony import */ var vscode__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! vscode */ "vscode");
/* harmony import */ var vscode__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(vscode__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! child_process */ "child_process");
/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! path */ "path");
Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread dist/extension.js
/*!**************************!*\
!*** ./src/extension.ts ***!
\**************************/
__webpack_require__.r(__webpack_exports__);

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused variable child_process__WEBPACK_IMPORTED_MODULE_1___default.

Copilot Autofix

AI 4 months ago

In general, to fix an unused variable or import, either remove it entirely or start using it if it was meant to be used. Here, the unused symbol is the default-import helper child_process__WEBPACK_IMPORTED_MODULE_1___default, not the child_process module itself. The child_process module is still required via child_process__WEBPACK_IMPORTED_MODULE_1__, so we should keep that but remove only the unused alias assignment.

The best minimal fix is to delete the line that defines child_process__WEBPACK_IMPORTED_MODULE_1___default while leaving the rest of the imports intact. That preserves all existing behavior and only removes the dead variable. Concretely, in dist/extension.js around lines 119–124, keep the require("child_process") import but remove the line:

/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_1__);

No additional imports, methods, or definitions are needed.

Suggested changeset 1
dist/extension.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/dist/extension.js b/dist/extension.js
--- a/dist/extension.js
+++ b/dist/extension.js
@@ -119,7 +119,6 @@
 /* harmony import */ var vscode__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! vscode */ "vscode");
 /* harmony import */ var vscode__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(vscode__WEBPACK_IMPORTED_MODULE_0__);
 /* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! child_process */ "child_process");
-/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_1__);
 /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! path */ "path");
 /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_2__);
 
EOF
@@ -119,7 +119,6 @@
/* harmony import */ var vscode__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! vscode */ "vscode");
/* harmony import */ var vscode__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(vscode__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! child_process */ "child_process");
/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! path */ "path");
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_2__);

Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread dist/extension.js
\**************************/
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ activate: () => (/* binding */ activate)

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused variable path__WEBPACK_IMPORTED_MODULE_2___default.

Copilot Autofix

AI 4 months ago

In general, to fix an unused variable, you either remove its declaration (and any associated initialization) or, if the variable was intended to be used, update the code to actually reference it. Here, the path module itself is imported via path__WEBPACK_IMPORTED_MODULE_2__, and only the default-wrapper alias path__WEBPACK_IMPORTED_MODULE_2___default is unused. The best fix that does not change functionality is to remove the creation of this unused alias while preserving the required path__WEBPACK_IMPORTED_MODULE_2__ import.

Concretely, in dist/extension.js at lines 123–124, we will keep the line that requires the path module (var path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! path */ "path");) and delete the following line that assigns path__WEBPACK_IMPORTED_MODULE_2___default. No other code changes are needed, because nothing refers to path__WEBPACK_IMPORTED_MODULE_2___default. We do not need new methods, imports, or definitions beyond this small removal.

Suggested changeset 1
dist/extension.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/dist/extension.js b/dist/extension.js
--- a/dist/extension.js
+++ b/dist/extension.js
@@ -121,7 +121,6 @@
 /* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! child_process */ "child_process");
 /* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_1__);
 /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! path */ "path");
-/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_2__);
 
 
 
EOF
@@ -121,7 +121,6 @@
/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! child_process */ "child_process");
/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(child_process__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! path */ "path");
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_2__);



Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread dist/extension.js
var dockerImage = pandocConfigurations.get("docker.image");
var targetExec = useDocker
? `docker run --rm -v "${filePath}:/data" ${dockerOptions} ${dockerImage} "${fileName}" -o "${fileNameOnly}.${format}" ${pandocOptions}`
: `"${pandocExecutablePath}" ${inFile} -o ${outFile} ${pandocOptions}`;

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused variable child.

Copilot Autofix

AI 4 months ago

In general, unused local variables should either be removed, or, if the expression has required side effects, the expression should be left in place while dropping the variable binding. Here the call to (0, child_process__WEBPACK_IMPORTED_MODULE_1__.exec)(...) must still occur to run pandoc, but there is no need to store the returned ChildProcess in a variable.

The single best fix is to remove the var child = part on line 305 and leave the exec call as a standalone statement. This preserves all existing behavior (the child process is still spawned, and the callback still handles output) without introducing new functionality. No imports, methods, or additional definitions are needed.

Concretely, in dist/extension.js, locate the line:

305:     var child = (0,child_process__WEBPACK_IMPORTED_MODULE_1__.exec)(targetExec, { cwd: filePath }, function (error, stdout, stderr) {

and change it to:

305:     (0,child_process__WEBPACK_IMPORTED_MODULE_1__.exec)(targetExec, { cwd: filePath }, function (error, stdout, stderr) {

All surrounding lines remain unchanged.

Suggested changeset 1
dist/extension.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/dist/extension.js b/dist/extension.js
--- a/dist/extension.js
+++ b/dist/extension.js
@@ -302,7 +302,7 @@
     var targetExec = useDocker
         ? `docker run --rm -v "${filePath}:/data" ${dockerOptions} ${dockerImage} "${fileName}" -o "${fileNameOnly}.${format}" ${pandocOptions}`
         : `"${pandocExecutablePath}" ${inFile} -o ${outFile} ${pandocOptions}`;
-    var child = (0,child_process__WEBPACK_IMPORTED_MODULE_1__.exec)(targetExec, { cwd: filePath }, function (error, stdout, stderr) {
+    (0,child_process__WEBPACK_IMPORTED_MODULE_1__.exec)(targetExec, { cwd: filePath }, function (error, stdout, stderr) {
         if (stdout !== null) {
             pandocOutputChannel.append(stdout.toString() + "\n");
         }
EOF
@@ -302,7 +302,7 @@
var targetExec = useDocker
? `docker run --rm -v "${filePath}:/data" ${dockerOptions} ${dockerImage} "${fileName}" -o "${fileNameOnly}.${format}" ${pandocOptions}`
: `"${pandocExecutablePath}" ${inFile} -o ${outFile} ${pandocOptions}`;
var child = (0,child_process__WEBPACK_IMPORTED_MODULE_1__.exec)(targetExec, { cwd: filePath }, function (error, stdout, stderr) {
(0,child_process__WEBPACK_IMPORTED_MODULE_1__.exec)(targetExec, { cwd: filePath }, function (error, stdout, stderr) {
if (stdout !== null) {
pandocOutputChannel.append(stdout.toString() + "\n");
}
Copilot is powered by AI and may make mistakes. Always verify output.
@ChrisChinchilla
ChrisChinchilla merged commit 98d9dd9 into main Mar 12, 2026
4 of 14 checks passed
@promptless

promptless Bot commented Mar 12, 2026

Copy link
Copy Markdown

📝 Documentation updates detected!

Updated existing suggestion: Document format list usage frequency sorting


Tip: Tag @Promptless in GitHub PR comments to guide documentation changes during code review 🐙

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Order by frequency?

3 participants