Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for searching by tag, description #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/EmojiCompletionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export default class EmojiCompletionProvider implements vscode.CompletionItemPro
return this.getMarkupEmojiCompletions(document, replacementSpan);
}

return this.getUnicodeEmojiCompletions(document, replacementSpan)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change prevented duplicate suggestions, like:

:wink:
::wink::

It still seems to work with either : or :: prefixes. Is there anything else I'm missing here?

.concat(this.getMarkupEmojiCompletions(document, replacementSpan));
return this.getUnicodeEmojiCompletions(document, replacementSpan);
}

private getUnicodeEmojiCompletions(
Expand All @@ -54,9 +53,15 @@ export default class EmojiCompletionProvider implements vscode.CompletionItemPro

const kind = vscode.CompletionItemKind.Text;
return this.emojiProvider.emojis.map((x) => {
const item = new vscode.CompletionItem(`:${x.name}: ${x.emoji}`, kind);
item.filterText = `:${x.name}:`;
item.documentation = new vscode.MarkdownString(`# ${x.emoji}`);
const item = new vscode.CompletionItem({
label: `:${x.name}: ${x.emoji}`,
description: x.tags.join(', '),
}, kind);
item.filterText = `:${x.name} ${x.tags.join(' ')} ${x.description} ${x.category}:`;
item.documentation = new vscode.MarkdownString([
`# ${x.emoji}`,
`_${x.category}: ${x.tags.concat(x.description).join(', ')}_`,
].join('\n'));
item.insertText = x.emoji;
item.range = replacementSpan;
return item;
Expand All @@ -73,9 +78,15 @@ export default class EmojiCompletionProvider implements vscode.CompletionItemPro

const kind = vscode.CompletionItemKind.Text;
return this.emojiProvider.emojis.map((x) => {
const item = new vscode.CompletionItem(`::${x.name} ${x.emoji}`, kind);
item.filterText = `::${x.name}`;
item.documentation = new vscode.MarkdownString(`# ${x.emoji}`);
const item = new vscode.CompletionItem({
label: `::${x.name} ${x.emoji}`,
description: x.tags.join(', ')
}, kind);
item.filterText = `::${x.name} ${x.tags.join(' ')} ${x.description} ${x.category}`;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think category should be included in the filter text as it is shared between too many emoji

Also I don't think description should be included because it will also match in some unexpected cases

item.documentation = new vscode.MarkdownString([
`# ${x.emoji}`,
`_${x.category}: ${x.tags.concat(x.description).join(', ')}_`,
].join('\n'));
item.insertText = `:${x.name}:`;
item.range = replacementSpan;
return item;
Expand Down
11 changes: 10 additions & 1 deletion src/emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { gemoji } from 'gemoji';
export interface Emoji {
readonly name: string;
readonly emoji: string;
readonly tags: string[];
readonly description: string;
readonly category: string;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Category is useful to search for something like animal

}

export class EmojiProvider {
Expand All @@ -26,7 +29,13 @@ export class EmojiProvider {
for (const g of gemoji) {
for (const name of g.names) {
if (!this._emojiMap.has(name)) {
this._emojiMap.set(name, { name, emoji: g.emoji });
this._emojiMap.set(name, {
name,
emoji: g.emoji,
tags: g.tags,
description: g.description,
category: g.category
});
}
}
}
Expand Down