From 7c30d1e5436ef32dc5a7b3a70503203ffeb843e1 Mon Sep 17 00:00:00 2001 From: Mark Sujew Date: Mon, 21 Oct 2024 14:31:15 +0200 Subject: [PATCH] Fix tree node error --- .../src/collaboration-connection-provider.ts | 4 +-- .../src/collaboration-instance.ts | 36 ++++++------------- .../src/collaboration-status-view.ts | 3 +- .../src/follow-service.ts | 8 ++--- .../src/utils/package.ts | 10 +++++- 5 files changed, 25 insertions(+), 36 deletions(-) diff --git a/packages/open-collaboration-vscode/src/collaboration-connection-provider.ts b/packages/open-collaboration-vscode/src/collaboration-connection-provider.ts index d4a2127..14aeb34 100644 --- a/packages/open-collaboration-vscode/src/collaboration-connection-provider.ts +++ b/packages/open-collaboration-vscode/src/collaboration-connection-provider.ts @@ -8,7 +8,7 @@ import * as vscode from 'vscode'; import { inject, injectable } from 'inversify'; import { ConnectionProvider, SocketIoTransportProvider } from 'open-collaboration-protocol'; import { ExtensionContext } from './inversify'; -import { version } from '../package.json'; +import { packageVersion } from './utils/package'; export const OCT_USER_TOKEN = 'oct.userToken'; @@ -30,7 +30,7 @@ export class CollaborationConnectionProvider { if (serverUrl) { return new ConnectionProvider({ url: serverUrl, - client: 'OCT-VSCode@' + packageVersion, + client: `OCT_CODE_${vscode.env.appName.replace(/\s+/, '_')}@${packageVersion}`, opener: (url) => vscode.env.openExternal(vscode.Uri.parse(url)), transports: [SocketIoTransportProvider], userToken, diff --git a/packages/open-collaboration-vscode/src/collaboration-instance.ts b/packages/open-collaboration-vscode/src/collaboration-instance.ts index 7c52432..909cc47 100644 --- a/packages/open-collaboration-vscode/src/collaboration-instance.ts +++ b/packages/open-collaboration-vscode/src/collaboration-instance.ts @@ -17,10 +17,10 @@ import { inject, injectable, postConstruct } from 'inversify'; import { removeWorkspaceFolders } from './utils/workspace'; import { Mutex } from 'async-mutex'; import { CollaborationUri } from './utils/uri'; -import { userColors } from "./utils/package"; +import { userColors } from './utils/package'; export interface PeerWithColor extends types.Peer { - color?: [number, number, number] | string; + color?: string; } export class DisposablePeer implements vscode.Disposable { @@ -60,8 +60,8 @@ export class DisposablePeer implements vscode.Disposable { } private createDecorationType(): ClientTextEditorDecorationType { - const color = createColor(); - const colorCss = typeof color === 'string' ? `var(--vscode-${color.replaceAll('.', '-')})` : `rgb(${color[0]}, ${color[1]}, ${color[2]})`; + const color = nextColor(); + const colorCss = `var(--vscode-${color.replaceAll('.', '-')})`; const selection: vscode.DecorationRenderOptions = { backgroundColor: `color-mix(in srgb, ${colorCss} 25%, transparent)`, borderRadius: '0.1em' @@ -115,26 +115,10 @@ export class DisposablePeer implements vscode.Disposable { } let colorIndex = 0; -const defaultColors: ([number, number, number] | string)[] = [ - ...userColors, - [92, 45, 145], // Purple - [0, 178, 148], // Light teal - [255, 241, 0], // Light yellow - [180, 160, 255] // Light purple -]; - -const knownColors = new Set(); -function createColor(): [number, number, number] | string { - if (colorIndex < defaultColors.length) { - return defaultColors[colorIndex++]; - } - const o = Math.round, r = Math.random, s = 255; - let color: [number, number, number]; - do { - color = [o(r() * s), o(r() * s), o(r() * s)]; - } while (knownColors.has(JSON.stringify(color))); - knownColors.add(JSON.stringify(color)); - return color; + +function nextColor(): string { + colorIndex %= userColors.length; + return userColors[colorIndex++]; } export class ClientTextEditorDecorationType implements vscode.Disposable { @@ -146,7 +130,7 @@ export class ClientTextEditorDecorationType implements vscode.Disposable { default: vscode.TextEditorDecorationType, inverted: vscode.TextEditorDecorationType }, - readonly color: [number, number, number] | string + readonly color: string ) { this.toDispose = vscode.Disposable.from( before, after, @@ -160,7 +144,7 @@ export class ClientTextEditorDecorationType implements vscode.Disposable { } getThemeColor(): vscode.ThemeColor | undefined { - return typeof this.color === 'string' ? new vscode.ThemeColor(this.color) : undefined; + return new vscode.ThemeColor(this.color); } } diff --git a/packages/open-collaboration-vscode/src/collaboration-status-view.ts b/packages/open-collaboration-vscode/src/collaboration-status-view.ts index 9a1559c..01f3bb0 100644 --- a/packages/open-collaboration-vscode/src/collaboration-status-view.ts +++ b/packages/open-collaboration-vscode/src/collaboration-status-view.ts @@ -39,10 +39,9 @@ export class CollaborationStatusViewDataProvider implements vscode.TreeDataProvi tags.push(vscode.l10n.t('Host')); } treeItem.description = tags.length ? ('(' + tags.join(' • ') + ')') : undefined; - treeItem.id = peer.id; treeItem.contextValue = 'self'; if (self?.id !== peer.id) { - const themeColor = typeof peer.color === 'string' ? new vscode.ThemeColor(peer.color) : undefined; + const themeColor = peer.color ? new vscode.ThemeColor(peer.color) : undefined; treeItem.iconPath = new vscode.ThemeIcon('circle-filled', themeColor); treeItem.contextValue = this.instance?.following === peer.id ? 'followedPeer' : 'peer'; } diff --git a/packages/open-collaboration-vscode/src/follow-service.ts b/packages/open-collaboration-vscode/src/follow-service.ts index 1b236ab..510c3f5 100644 --- a/packages/open-collaboration-vscode/src/follow-service.ts +++ b/packages/open-collaboration-vscode/src/follow-service.ts @@ -4,9 +4,8 @@ // terms of the MIT License, which is available in the project root. // ****************************************************************************** -import * as vscode from 'vscode'; import { inject, injectable } from 'inversify'; -import { CollaborationInstance, DisposablePeer } from './collaboration-instance'; +import { CollaborationInstance } from './collaboration-instance'; import { showQuickPick } from './utils/quick-pick'; import { CollaborationStatusViewDataProvider } from './collaboration-status-view'; import { ContextKeyService } from './context-key-service'; @@ -26,10 +25,9 @@ export class FollowService { } if (!peer) { - const quickPick = vscode.window.createQuickPick(); const users = await CollaborationInstance.Current.connectedUsers; - quickPick.items = users.map(user => ({ label: user.name, detail: user.id })); - peer = users[(await showQuickPick(quickPick))]?.id; + const items = users.map(user => ({ label: user.name, detail: user.id, key: user.id })); + peer = await showQuickPick(items); } if (!peer) { diff --git a/packages/open-collaboration-vscode/src/utils/package.ts b/packages/open-collaboration-vscode/src/utils/package.ts index ee91a7c..cc0b63d 100644 --- a/packages/open-collaboration-vscode/src/utils/package.ts +++ b/packages/open-collaboration-vscode/src/utils/package.ts @@ -1,4 +1,12 @@ -export const packageJson = require('../../package.json'); +// ****************************************************************************** +// Copyright 2024 TypeFox GmbH +// This program and the accompanying materials are made available under the +// terms of the MIT License, which is available in the project root. +// ****************************************************************************** + +import * as packageJson from '../../package.json'; + +export { packageJson }; export const packageVersion: string = packageJson.version; export const userColors: string[] = packageJson.contributes.colors .map((color: any) => color.id)