diff --git a/package.json b/package.json index 49b1ca3..84d7efb 100644 --- a/package.json +++ b/package.json @@ -146,9 +146,9 @@ "title": "Twitch Highlighter", "properties": { "twitchHighlighter.channels": { - "type": "array", - "default": [], - "description": "The channel name(s) to connect to on Twitch. Example: ['clarkio'], Another Example: ['clarkio', 'parithon']" + "type": "string", + "default": "", + "description": "A comma seperated list of channel name(s) to connect to on Twitch. Example: 'clarkio', Another Example: 'clarkio, parithon'" }, "twitchHighlighter.nickname": { "type": "string", diff --git a/src/extension.ts b/src/extension.ts index c1fc82b..5c855ba 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -10,6 +10,7 @@ import { HighlighterNode } from './twitchHighlighterTreeView'; import { TwitchChatClient } from './twitchChatClient'; +import { isArray } from 'util'; import { extSuffix, Settings, Commands } from './constants'; let highlightDecorationType: vscode.TextEditorDecorationType; @@ -25,6 +26,8 @@ let twitchHighlighterStatusBar: vscode.StatusBarItem; export function activate(context: vscode.ExtensionContext) { setupDecoratorType(); + updateChannelsSetting(); + twitchChatClient = new TwitchChatClient( context.asAbsolutePath(path.join('out', 'twitchLanguageServer.js')), context.subscriptions @@ -61,12 +64,24 @@ export function activate(context: vscode.ExtensionContext) { registerCommand(context, Commands.highlight, highlightHandler); registerCommand(context, Commands.gotoHighlight, gotoHighlightHandler); registerCommand(context, Commands.removeHighlight, removeHighlightHandler); - registerCommand(context, Commands.unhighlightSpecific, unhighlightSpecificHandler); + registerCommand( + context, + Commands.unhighlightSpecific, + unhighlightSpecificHandler + ); registerCommand(context, Commands.unhighlightAll, unhighlightAllHandler); registerCommand(context, Commands.refreshTreeView, refreshTreeViewHandler); - registerCommand(context, Commands.removeTwitchClientId, removeTwitchClientIdHandler); + registerCommand( + context, + Commands.removeTwitchClientId, + removeTwitchClientIdHandler + ); registerCommand(context, Commands.setTwitchPassword, setTwitchTokenHandler); - registerCommand(context, Commands.removeTwitchPassword, removeTwitchPasswordHandler); + registerCommand( + context, + Commands.removeTwitchPassword, + removeTwitchPasswordHandler + ); registerCommand(context, Commands.startChat, startChatHandler); registerCommand(context, Commands.stopChat, stopChatHandler); registerCommand(context, Commands.toggleChat, toggleChatHandler); @@ -168,7 +183,9 @@ export function activate(context: vscode.ExtensionContext) { function highlightHandler() { vscode.window .showInputBox({ prompt: 'Enter a line number' }) - .then(lineString => highlight('self', +(lineString || 0), +(lineString || 0))); + .then(lineString => + highlight('self', +(lineString || 0), +(lineString || 0)) + ); } function unhighlightAllHandler() { @@ -188,10 +205,7 @@ export function activate(context: vscode.ExtensionContext) { let pickerOptions: Array = new Array(); highlighters.forEach(highlighter => { - pickerOptions = [ - ...pickerOptions, - ...highlighter.getPickerDetails() - ]; + pickerOptions = [...pickerOptions, ...highlighter.getPickerDetails()]; }); vscode.window.showQuickPick(pickerOptions).then(pickedOption => { @@ -211,15 +225,25 @@ export function activate(context: vscode.ExtensionContext) { async function stopChatHandler() { const config = vscode.workspace.getConfiguration(extSuffix); - let unhighlightOnDisconnect = config.get(Settings.unhighlightOnDisconnect); + let unhighlightOnDisconnect = config.get( + Settings.unhighlightOnDisconnect + ); - if (highlighters.length > 0 && highlighters.some(h => h.highlights.length > 0) && !unhighlightOnDisconnect) { - const result = await vscode.window.showInformationMessage('Do you want to keep or remove the existing highlights when disconnecting from chat?', 'Always Remove', 'Remove', 'Keep'); + if ( + highlighters.length > 0 && + highlighters.some(h => h.highlights.length > 0) && + !unhighlightOnDisconnect + ) { + const result = await vscode.window.showInformationMessage( + 'Do you want to keep or remove the existing highlights when disconnecting from chat?', + 'Always Remove', + 'Remove', + 'Keep' + ); if (result && result === 'Remove') { unhighlightOnDisconnect = true; } - if (result && result === 'Always Remove') - { + if (result && result === 'Always Remove') { unhighlightOnDisconnect = true; config.update(Settings.unhighlightOnDisconnect, true, true); } @@ -295,7 +319,13 @@ export function deactivate(): Thenable { return twitchChatClient.dispose(); } -function highlight(twitchUser: string, startLine: number, endLine: number, fileName?: string, comment?: string) { +function highlight( + twitchUser: string, + startLine: number, + endLine: number, + fileName?: string, + comment?: string +) { console.log(`highlight called.`); if (!startLine) { console.warn('A line number was not provided to highlight'); @@ -338,10 +368,19 @@ function highlight(twitchUser: string, startLine: number, endLine: number, fileN const decoration = { range, - hoverMessage: `From @${twitchUser === 'self' ? 'You' : twitchUser}${comment !== undefined ? `: ${comment}` : ''}` + hoverMessage: `From @${twitchUser === 'self' ? 'You' : twitchUser}${ + comment !== undefined ? `: ${comment}` : '' + }` }; - addHighlight(existingHighlighter, decoration, editor, startLine, endLine, twitchUser); + addHighlight( + existingHighlighter, + decoration, + editor, + startLine, + endLine, + twitchUser + ); } function unhighlight(lineNumber: number, fileName?: string) { @@ -464,7 +503,11 @@ function findHighlighter(fileName: string): Highlighter | undefined { }); } -function getHighlightRange(startLine: number, endLine: number, doc: vscode.TextDocument) { +function getHighlightRange( + startLine: number, + endLine: number, + doc: vscode.TextDocument +) { // prefix string with plus (+) to make string a number // well at least that's what codephobia says :P // const zeroIndexedLineNumber = +lineNumber - 1; @@ -497,14 +540,24 @@ function registerCommand( context.subscriptions.push(disposable); } +/** + * Used to upgrade the channels setting from an array of strings ['clarkio','parithon'] + * to a string 'clarkio, parithon'. + */ +function updateChannelsSetting() { + const configuration = vscode.workspace.getConfiguration('twitchHighlighter'); + const channels = configuration.get('channels'); + if (isArray(channels)) { + // Update the global settings + configuration.update('channels', channels.join(', '), true); + } +} + function setupDecoratorType() { - const configuration = vscode.workspace.getConfiguration( - 'twitchHighlighter' - ); + const configuration = vscode.workspace.getConfiguration('twitchHighlighter'); highlightDecorationType = vscode.window.createTextEditorDecorationType({ backgroundColor: configuration.get('highlightColor') || 'green', - border: - configuration.get('highlightBorder') || '2px solid white', + border: configuration.get('highlightBorder') || '2px solid white', color: configuration.get('highlightFontColor') || 'white' }); } diff --git a/src/twitchLanguageServer.ts b/src/twitchLanguageServer.ts index 332d994..63d08a2 100644 --- a/src/twitchLanguageServer.ts +++ b/src/twitchLanguageServer.ts @@ -149,13 +149,13 @@ connection.onShutdown(() => { }); function getTwitchChatOptions(params: { - channels: string[]; + channels: string; username: string; clientId: string; password: string; }): tmi.ClientOptions { return { - channels: params.channels, + channels: params.channels.split(',').map(s => s.trim()), connection: { secure: true, reconnect: true,