Order pandoc format quick-pick by usage frequency#61
Conversation
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>
|
📝 Documentation updates detected! New suggestion: Document format list usage frequency sorting Tip: Sort by Shortest Review in the Dashboard to find quick wins ⚡ |
|
@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>
Done in commit 2e232ed. Added a |
# Conflicts: # package-lock.json # package.json
| // 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
Show autofix suggestion
Hide autofix suggestion
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.
| @@ -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"); |
| /*!**************************!*\ | ||
| !*** ./src/extension.ts ***! | ||
| \**************************/ | ||
| __webpack_require__.r(__webpack_exports__); |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note
Show autofix suggestion
Hide autofix suggestion
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.
| @@ -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__); | ||
|
|
| \**************************/ | ||
| __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
Show autofix suggestion
Hide autofix suggestion
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.
| @@ -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__); | ||
|
|
||
|
|
||
|
|
| 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
Show autofix suggestion
Hide autofix suggestion
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.
| @@ -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"); | ||
| } |
|
📝 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 🐙 |
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.tsdisplayMenuAndRendernow acceptsvscode.ExtensionContextpandoc.formatUsagecount map fromcontext.globalStatebefore each menu displaycontext.globalState.updateafter each selectionpandoc.sortByFrequencyis set tofalsepackage.jsonpandoc.sortByFrequencyboolean setting (default:true) to allow users to opt out of frequency-based orderingREADME.mdpandoc.sortByFrequencysetting under a "Sort formats by frequency" sectiontest/suites/extension.test.tsglobalStatecontains prior countsglobalStateis updated with an incremented count after selectionpandoc.sortByFrequencyisfalseglobalStateis not updated whenpandoc.sortByFrequencyisfalseExample behavior
To disable frequency sorting and always show the default static order, set
pandoc.sortByFrequencytofalsein your settings.Original prompt
💡 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.