Skip to content

Commit 2947c2d

Browse files
committed
fix: directly return jsPromise for writeText instead of creating a new promise
1 parent 8c502ab commit 2947c2d

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

src/extensionsIntegrated/CustomSnippets/snippetsState.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*
1919
*/
2020

21+
/* global jsPromise */
2122
define(function (require, exports, module) {
2223
const Global = require("./global");
2324
const FileSystem = require("filesystem/FileSystem");
@@ -73,26 +74,15 @@ define(function (require, exports, module) {
7374
* @returns {Promise} a promise that resolves when snippets are saved
7475
*/
7576
function saveSnippetsToState() {
76-
return new Promise((resolve, reject) => {
77-
const dataToSave = {
78-
snippets: Global.SnippetHintsList
79-
};
80-
81-
const file = FileSystem.getFileForPath(SNIPPETS_FILE_PATH);
82-
const jsonText = JSON.stringify(dataToSave);
77+
const dataToSave = {
78+
snippets: Global.SnippetHintsList
79+
};
8380

84-
// true is allowBlindWrite to overwrite without checking file contents
85-
const writePromise = FileUtils.writeText(file, jsonText, true);
81+
const file = FileSystem.getFileForPath(SNIPPETS_FILE_PATH);
82+
const jsonText = JSON.stringify(dataToSave);
8683

87-
writePromise
88-
.done(function () {
89-
resolve();
90-
})
91-
.fail(function (error) {
92-
console.error("Unable to save snippets to file storage:", error);
93-
reject(error);
94-
});
95-
});
84+
// true is allowBlindWrite to overwrite without checking file contents
85+
return jsPromise(FileUtils.writeText(file, jsonText, true));
9686
}
9787

9888
exports.loadSnippetsFromState = loadSnippetsFromState;

0 commit comments

Comments
 (0)