-
Notifications
You must be signed in to change notification settings - Fork 62
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
feat(playground): add leaf connection icons inside playground VSCODE-650 #885
Changes from 6 commits
86d25b7
6feac32
b1adb2a
474beb3
e915b3f
e17008f
27f0aad
a8bcf84
bce4de9
99128f5
b7f9618
a9c2836
b0ca543
c870786
145af8d
692dc1c
1d1f0a3
42cdd92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import webfont from 'webfont'; | ||
import fs from 'fs/promises'; | ||
import { GlyphData } from 'webfont/dist/src/types'; | ||
|
||
/** Icons to include in the generated icon font */ | ||
const INCLUDED_ICONS = ['connection-active', 'connection-inactive']; | ||
|
||
/** | ||
* Generates an icon font from the included icons and outputs package.json | ||
* configuration field for those icons as specified in | ||
* https://code.visualstudio.com/api/references/icons-in-labels | ||
*/ | ||
async function main(): Promise<void> { | ||
const font = await webfont({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's worth it to have a external dev dependency / script for this. We can potentially utilize Vscode's support for icons fonts for i.e. easily having different color versions of the same icons and, as in this case, easily including icons in different places. Open to discussing this if there are other ideas though; at least for codelenses the need for an icon font is unavoidable so we could either ask design to make it or generate it from this script as done here. |
||
files: INCLUDED_ICONS.map((icon) => `./images/light/${icon}.svg`), | ||
fontName: 'MongoDB Icons', | ||
formats: ['woff'], | ||
normalize: true, | ||
centerHorizontally: true, | ||
}); | ||
|
||
if (!font.woff) { | ||
throw new Error('Error occurred generating template'); | ||
} | ||
|
||
await fs.writeFile('./fonts/mongodb-icons.woff', font.woff); | ||
|
||
const iconsConfig = {}; | ||
font.glyphsData?.forEach((glyph) => { | ||
if (!glyph.metadata?.name) { | ||
throw new Error('There is a glyph without a name'); | ||
} | ||
iconsConfig[glyph.metadata.name] = { | ||
description: 'MongoDB Icon', | ||
default: { | ||
fontPath: './fonts/mongodb-icons.woff', | ||
fontCharacter: getUnicodeHex(glyph), | ||
}, | ||
}; | ||
}); | ||
|
||
// Prints out the VSCode configuration package.json | ||
console.info( | ||
JSON.stringify( | ||
{ | ||
icons: iconsConfig, | ||
}, | ||
undefined, | ||
2 | ||
) | ||
); | ||
} | ||
|
||
function getUnicodeHex(glyph: GlyphData): string { | ||
if (glyph.metadata?.unicode == undefined) { | ||
throw new Error('No unicode defined'); | ||
} | ||
const hex = glyph.metadata?.unicode[0].codePointAt(0)!.toString(16); | ||
|
||
return `\\${hex}`; | ||
} | ||
|
||
main(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as vscode from 'vscode'; | ||
import EXTENSION_COMMANDS from '../commands'; | ||
import type { SendMessageToParticipantFromInputOptions } from '../participant/participantTypes'; | ||
import { isPlayground } from '../utils/playground'; | ||
|
||
const COPILOT_CHAT_EXTENSION_ID = 'GitHub.copilot-chat'; | ||
|
||
export class QueryWithCopilotCodeLensProvider | ||
implements vscode.CodeLensProvider | ||
{ | ||
constructor() {} | ||
|
||
readonly onDidChangeCodeLenses: vscode.Event<void> = | ||
vscode.extensions.onDidChange; | ||
|
||
provideCodeLenses(document: vscode.TextDocument): vscode.CodeLens[] { | ||
if (!isPlayground(document.uri)) { | ||
return []; | ||
} | ||
|
||
// We can only detect whether a user has the Copilot extension active | ||
// but not whether it has an active subscription. | ||
const hasCopilotChatActive = | ||
vscode.extensions.getExtension(COPILOT_CHAT_EXTENSION_ID)?.isActive === | ||
true; | ||
|
||
if (!hasCopilotChatActive) { | ||
return []; | ||
} | ||
|
||
const options: SendMessageToParticipantFromInputOptions = { | ||
prompt: 'Describe the query you would like to generate.', | ||
placeHolder: | ||
'e.g. Find the document in sample_mflix.users with the name of Kayden Washington', | ||
messagePrefix: '/query', | ||
isNewChat: true, | ||
}; | ||
|
||
return [ | ||
new vscode.CodeLens(new vscode.Range(0, 0, 0, 0), { | ||
title: '✨ Generate query with MongoDB Copilot', | ||
command: EXTENSION_COMMANDS.SEND_MESSAGE_TO_PARTICIPANT_FROM_INPUT, | ||
arguments: [options], | ||
}), | ||
]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can either have this font generated in CI or just do it ourselves at changes? I feel like this is a small enough file and one we will likely not touch often (and would also require
package.json
updates) so perhaps it's fine just having this as part of repo files?