From 8073b59e9eb2f5d8752f4d4229cd54c6f62c67fc Mon Sep 17 00:00:00 2001 From: XuanMiaoSama Date: Thu, 25 Dec 2025 15:20:22 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9Asupport=20the=20configuration=20of?= =?UTF-8?q?=20emoji=20lists=20by=20users?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add configuration hot update --- package.json | 29 +++++++ playground/javascript.js | 149 +++++++++++++---------------------- src/extension.ts | 11 ++- src/features/random-emoji.ts | 7 +- 4 files changed, 100 insertions(+), 96 deletions(-) diff --git a/package.json b/package.json index 7bc61f6..e6c2291 100644 --- a/package.json +++ b/package.json @@ -102,6 +102,35 @@ "default": true, "description": "Determine whether to insert an emoji." }, + "debugger-for-console.emojiList": { + "type": "array", + "items": { + "type": "string" + }, + "default": [ + "🚀", + "🛸", + "🛰️", + "👑", + "🔭", + "✨", + "🍀", + "🍻", + "🍿", + "🍉", + "🔥", + "🥑", + "🎡", + "🍙", + "📦", + "📫", + "🍟", + "🍭", + "🍩", + "🌿" + ], + "description": "Customize the list of emojis to randomly select from. You can add or remove emojis as you like." + }, "debugger-for-console.quote": { "type": "string", "enum": [ diff --git a/playground/javascript.js b/playground/javascript.js index e480e70..06c854f 100644 --- a/playground/javascript.js +++ b/playground/javascript.js @@ -7,129 +7,92 @@ const str = 'Hello'; const reg = /abcdefg/; -const arr = ['a', 'b', 'c'] -const multiArr = [ - ...arr, - ...arr, -] +const arr = ['a', 'b', 'c']; +const multiArr = [...arr, ...arr]; -const [...list] = [...arr] +const [...list] = [...arr]; -const arrowFn = (..._args) => {} +const arrowFn = (..._args) => {}; -const stringWithSpacesAndQuotes = `Hello\" \' \` World` +const stringWithSpacesAndQuotes = `Hello\" \' \` World`; const obj = { - name: 'John', - age: 20, -} + name: 'John', + age: 20 +}; const computedStyle = computed(() => { - const styles = { - ...config.style, - }; + const styles = { + ...config.style + }; - return styles; + return styles; }); async function fnScope(length = obj['name'].length) { + const say = 'hello,' + 'world!'; - const say = 'hello,' + 'world!'; - - const obj = { - name: 'John', - age: 20, - value: [ - 1, - 2, - 3, - ] - } - - const is = ( - 1 && - 2 || - 3 - ) - - const arrowFn = (arr) => { - - } + const obj = { + name: 'John', + age: 20, + value: [1, 2, 3] + }; - const sortedEntries = Object.entries(obj).sort( - (a, b) => parseInt(a[1]) - parseInt(b[1]), - ); + const is = (1 && 2) || 3; - obj.value?.[0]?.test(); + const arrowFn = (arr) => {}; - const res = await fetch('https://api.github.com/users/octocat', { - data: fn(data), - }); + const sortedEntries = Object.entries(obj).sort((a, b) => parseInt(a[1]) - parseInt(b[1])); - Promise.resolve() - .then((res) => { + obj.value?.[0]?.test(); - }) - .catch((err) => { + const res = await fetch('https://api.github.com/users/octocat', { + data: fn(data) + }); - }) + Promise.resolve() + .then((res) => {}) + .catch((err) => {}); } watch( - () => preferences.theme.mode, - () => globalThis.updateTheme(getLatestTheme()), + () => preferences.theme.mode, + () => globalThis.updateTheme(getLatestTheme()) ); -const veryLongStatement = window.name.includes('abc'.toUpperCase())[0].toLowerCase().includes('a')?.length - -function initApp( Vue ) { - let app = new Vue({ - router, - store, - i18n, - render: () => h(App), - }) - - const arr = new Array([ - 1, - 2, - 3, - ]) - - setSelectedImage(result.assets[0].uri) - - const METHODS = { - mount({ - aaa, - bbb, - }) { - app = app.$mount('#app') - }, - - unmount() { - app.$destroy() - - } - } -} +const veryLongStatement = window.name.includes('abc'.toUpperCase())[0].toLowerCase().includes('a')?.length; -if (Math.random() > 0.5) { - fnScope( +function initApp(Vue) { + let app = new Vue({ + router, + store, + i18n, + render: () => h(App) + }); + + const arr = new Array([1, 2, 3]); - obj['name'].length, + setSelectedImage(result.assets[0].uri); - ) + const METHODS = { + mount({ aaa, bbb }) { + app = app.$mount('#app'); + }, + unmount() { + app.$destroy(); + } + }; +} + +if (Math.random() > 0.5) { + fnScope(obj['name'].length); } export function getTemplate(colors) { - const { - background, - foreground, - ...theme - } = colors + const { background, foreground, ...theme } = colors; - theme.key ||= theme.css + theme.key ||= theme.css; - return theme + return theme; } diff --git a/src/extension.ts b/src/extension.ts index 79bc388..5d81a4c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,4 +1,4 @@ -import { commands } from 'vscode' +import { commands, workspace } from 'vscode' import type { ExtensionContext, WorkspaceConfiguration } from 'vscode' import { commandsMapping } from './commands/index' @@ -16,6 +16,15 @@ export function activate(context: ExtensionContext): void { // only update user config when extension is activated updateUserConfig() + + // auto update config when configuration changes + const configChangeListener = workspace.onDidChangeConfiguration((e) => { + if (e.affectsConfiguration('debugger-for-console')) { + updateUserConfig() + } + }) + + context.subscriptions.push(configChangeListener) } export function deactivate(): void { diff --git a/src/features/random-emoji.ts b/src/features/random-emoji.ts index 6c6d1ad..29589cd 100644 --- a/src/features/random-emoji.ts +++ b/src/features/random-emoji.ts @@ -1,6 +1,6 @@ import { resolvedConfig } from '../extension' -const EMOJIS = [ +const DEFAULT_EMOJIS = [ '🚀', '🛸', '🛰️', @@ -25,7 +25,10 @@ const EMOJIS = [ export function getRandomEmoji() { if (resolvedConfig.get('emoji')) { - return EMOJIS[Math.floor(Math.random() * EMOJIS.length)] + const customEmojiList = resolvedConfig.get('emojiList', []) + const emojiList = customEmojiList.length > 0 ? customEmojiList : DEFAULT_EMOJIS + + return emojiList[Math.floor(Math.random() * emojiList.length)] } return ''