Skip to content

Commit

Permalink
Fix tree node error
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Oct 21, 2024
1 parent a5d941b commit 7c30d1e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand Down
36 changes: 10 additions & 26 deletions packages/open-collaboration-vscode/src/collaboration-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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<string>();
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 {
Expand All @@ -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,
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
8 changes: 3 additions & 5 deletions packages/open-collaboration-vscode/src/follow-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion packages/open-collaboration-vscode/src/utils/package.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 7c30d1e

Please sign in to comment.