Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/git/src/emoji.ts
3314 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
'use strict';
7
import { workspace, Uri } from 'vscode';
8
import { getExtensionContext } from './main';
9
import { TextDecoder } from 'util';
10
11
const emojiRegex = /:([-+_a-z0-9]+):/g;
12
13
let emojiMap: Record<string, string> | undefined;
14
let emojiMapPromise: Promise<void> | undefined;
15
16
export async function ensureEmojis() {
17
if (emojiMap === undefined) {
18
if (emojiMapPromise === undefined) {
19
emojiMapPromise = loadEmojiMap();
20
}
21
await emojiMapPromise;
22
}
23
}
24
25
async function loadEmojiMap() {
26
const context = getExtensionContext();
27
const uri = (Uri as any).joinPath(context.extensionUri, 'resources', 'emojis.json');
28
emojiMap = JSON.parse(new TextDecoder('utf8').decode(await workspace.fs.readFile(uri)));
29
}
30
31
export function emojify(message: string) {
32
if (emojiMap === undefined) {
33
return message;
34
}
35
36
return message.replace(emojiRegex, (s, code) => {
37
return emojiMap?.[code] || s;
38
});
39
}
40
41