Skip to content

Commit

Permalink
Use common uuid generator everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Jan 11, 2024
1 parent 6a7bd87 commit 8ed78e6
Show file tree
Hide file tree
Showing 33 changed files with 55 additions and 64 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"typedoc": "^0.22.11",
"typedoc-plugin-external-module-map": "1.3.2",
"typescript": "~4.5.5",
"uuid": "^8.0.0",
"yargs": "^15.3.1"
},
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"safer-buffer": "^2.1.2",
"socket.io": "^4.5.3",
"socket.io-client": "^4.5.3",
"uuid": "^8.3.2",
"vscode-languageserver-protocol": "^3.17.2",
"vscode-uri": "^2.1.1",
"ws": "^8.14.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/browser/tooltip-service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as React from 'react';
import ReactTooltip from 'react-tooltip';
import { ReactRenderer, RendererHost } from './widgets/react-renderer';
import { CorePreferences } from './core-preferences';
import { v4 } from 'uuid';
import { generateUuid } from '../common/uuid';

export const TooltipService = Symbol('TooltipService');

Expand Down Expand Up @@ -59,7 +59,7 @@ export class TooltipServiceImpl extends ReactRenderer implements TooltipService
@inject(RendererHost) @optional() host?: RendererHost
) {
super(host);
this.tooltipId = v4();
this.tooltipId = generateUuid();
}

@postConstruct()
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ export * from './strings';
export * from './telemetry';
export * from './types';
export { default as URI } from './uri';
export * from './uuid';
export * from './view-column';
export * from './version';
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// *****************************************************************************

import { ContainerModule } from 'inversify';
import { v4 } from 'uuid';
import { generateUuid } from '../common/uuid';
import { bindContributionProvider } from '../common/contribution-provider';
import { RpcConnectionHandler } from '../common/messaging/proxy-factory';
import { ElectronSecurityToken } from '../electron-common/electron-token';
Expand All @@ -29,7 +29,7 @@ import { ElectronSecurityTokenService } from './electron-security-token-service'
import { ElectronMessagingService } from './messaging/electron-messaging-service';
import { ElectronConnectionHandler } from './messaging/electron-connection-handler';

const electronSecurityToken: ElectronSecurityToken = { value: v4() };
const electronSecurityToken: ElectronSecurityToken = { value: generateUuid() };
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any)[ElectronSecurityToken] = electronSecurityToken;

Expand Down
1 change: 0 additions & 1 deletion packages/filesystem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"stat-mode": "^1.0.0",
"tar-fs": "^1.16.2",
"trash": "^7.2.0",
"uuid": "^8.0.0",
"vscode-languageserver-textdocument": "^1.0.1"
},
"publishConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { equal, fail } from 'assert';
import { promises as fs } from 'fs';
import { join } from 'path';
import * as temp from 'temp';
import { v4 } from 'uuid';
import { generateUuid } from '@theia/core/lib/common/uuid';
import { FilePermission, FileSystemProviderError, FileSystemProviderErrorCode } from '../common/files';
import { DiskFileSystemProvider } from './disk-file-system-provider';
import { bindFileSystemWatcherServer } from './filesystem-backend-module';
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('disk-file-system-provider', () => {
describe('stat', () => {
it("should omit the 'permissions' property of the stat if the file can be both read and write", async () => {
const tempDirPath = tracked.mkdirSync();
const tempFilePath = join(tempDirPath, `${v4()}.txt`);
const tempFilePath = join(tempDirPath, `${generateUuid()}.txt`);
await fs.writeFile(tempFilePath, 'some content', { encoding: 'utf8' });

let content = await fs.readFile(tempFilePath, { encoding: 'utf8' });
Expand All @@ -70,7 +70,7 @@ describe('disk-file-system-provider', () => {

it("should set the 'permissions' property to `Readonly` if the file can be read but not write", async () => {
const tempDirPath = tracked.mkdirSync();
const tempFilePath = join(tempDirPath, `${v4()}.txt`);
const tempFilePath = join(tempDirPath, `${generateUuid()}.txt`);
await fs.writeFile(tempFilePath, 'readonly content', {
encoding: 'utf8',
});
Expand Down
4 changes: 2 additions & 2 deletions packages/filesystem/src/node/disk-file-system-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
import { basename, dirname, normalize, join } from 'path';
import { v4 } from 'uuid';
import { generateUuid } from '@theia/core/lib/common/uuid';
import * as os from 'os';
import * as fs from 'fs';
import {
Expand Down Expand Up @@ -525,7 +525,7 @@ export class DiskFileSystemProvider implements Disposable,

protected async rimrafMove(path: string): Promise<void> {
try {
const pathInTemp = join(os.tmpdir(), v4());
const pathInTemp = join(os.tmpdir(), generateUuid());
try {
await promisify(rename)(path, pathInTemp);
} catch (error) {
Expand Down
10 changes: 5 additions & 5 deletions packages/filesystem/src/node/download/file-download-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as os from 'os';
import * as fs from '@theia/core/shared/fs-extra';
import * as path from 'path';
import { v4 } from 'uuid';
import { generateUuid } from '@theia/core/lib/common/uuid';
import { Request, Response } from '@theia/core/shared/express';
import { inject, injectable } from '@theia/core/shared/inversify';
import { OK, BAD_REQUEST, METHOD_NOT_ALLOWED, NOT_FOUND, INTERNAL_SERVER_ERROR, REQUESTED_RANGE_NOT_SATISFIABLE, PARTIAL_CONTENT } from 'http-status-codes';
Expand Down Expand Up @@ -135,12 +135,12 @@ export abstract class FileDownloadHandler {
end: (isNaN(end) || end > statSize - 1) ? (statSize - 1) : end
};
}
protected async archive(inputPath: string, outputPath: string = path.join(os.tmpdir(), v4()), entries?: string[]): Promise<string> {
protected async archive(inputPath: string, outputPath: string = path.join(os.tmpdir(), generateUuid()), entries?: string[]): Promise<string> {
await this.directoryArchiver.archive(inputPath, outputPath, entries);
return outputPath;
}

protected async createTempDir(downloadId: string = v4()): Promise<string> {
protected async createTempDir(downloadId: string = generateUuid()): Promise<string> {
const outputPath = path.join(os.tmpdir(), downloadId);
await fs.mkdir(outputPath);
return outputPath;
Expand Down Expand Up @@ -221,7 +221,7 @@ export class SingleFileDownloadHandler extends FileDownloadHandler {
return;
}
try {
const downloadId = v4();
const downloadId = generateUuid();
const options: PrepareDownloadOptions = { filePath, downloadId, remove: false };
if (!stat.isDirectory()) {
await this.prepareDownload(request, response, options);
Expand Down Expand Up @@ -271,7 +271,7 @@ export class MultiFileDownloadHandler extends FileDownloadHandler {
}
}
try {
const downloadId = v4();
const downloadId = generateUuid();
const outputRootPath = await this.createTempDir(downloadId);
const distinctUris = Array.from(new Set(body.uris.map(uri => new URI(uri))));
const tarPaths = [];
Expand Down
1 change: 0 additions & 1 deletion packages/mini-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"@types/mime-types": "^2.1.0",
"mime-types": "^2.1.18",
"pdfobject": "^2.0.201604172",
"uuid": "^8.0.0",
"vhost": "^3.0.2"
},
"publishConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Endpoint, FrontendApplicationContribution } from '@theia/core/lib/brows
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { environment } from '@theia/core/shared/@theia/application-package/lib/environment';
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import { v4 } from 'uuid';
import { generateUuid } from '@theia/core/lib/common/uuid';
import { MiniBrowserEndpoint } from '../../common/mini-browser-endpoint';

/**
Expand Down Expand Up @@ -71,7 +71,7 @@ export class MiniBrowserEnvironment implements FrontendApplicationContribution {
* Throws if `hostPatternPromise` is not yet resolved.
*/
getRandomEndpoint(): Endpoint {
return this.getEndpoint(v4());
return this.getEndpoint(generateUuid());
}

protected async getHostPattern(): Promise<string> {
Expand Down
3 changes: 1 addition & 2 deletions packages/notebook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"@theia/core": "1.45.0",
"@theia/editor": "1.45.0",
"@theia/filesystem": "1.45.0",
"@theia/monaco": "1.45.0",
"uuid": "^8.3.2"
"@theia/monaco": "1.45.0"
},
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Disposable, DisposableCollection, Emitter, URI } from '@theia/core';
import { Disposable, DisposableCollection, Emitter, URI, generateUuid } from '@theia/core';
import { inject, injectable } from '@theia/core/shared/inversify';
import { NotebookService } from './notebook-service';
import {
Expand All @@ -27,7 +27,6 @@ import {
} from '../../common';
import { CellPartialInternalMetadataEditByHandle, CellEditOperation } from '../notebook-types';
import { NotebookModel } from '../view-model/notebook-model';
import { v4 } from 'uuid';

export type CellExecuteUpdate = CellExecuteOutputEdit | CellExecuteOutputItemEdit | CellExecutionStateUpdate;

Expand Down Expand Up @@ -178,7 +177,7 @@ export class CellExecution implements Disposable {
editType: CellEditType.PartialInternalMetadata,
handle: this.cellHandle,
internalMetadata: {
executionId: v4(),
executionId: generateUuid(),
runStartTime: undefined,
runEndTime: undefined,
lastRunSuccess: undefined,
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"mime": "^2.4.4",
"ps-tree": "^1.2.0",
"semver": "^7.5.4",
"uuid": "^8.0.0",
"vhost": "^3.0.2",
"vscode-textmate": "^9.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { URI } from '@theia/core/shared/vscode-uri';
import { CancellationToken } from '@theia/core/lib/common';
import { RPCProtocol } from '../../../common/rpc-protocol';
import { interfaces } from '@theia/core/shared/inversify';
import { v4 as uuidv4 } from 'uuid';
import { generateUuid } from '@theia/core/lib/common/uuid';
import { CommentsContribution } from './comments-contribution';

/*---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -392,7 +392,7 @@ export class CommentsMainImp implements CommentsMain {
}

$registerCommentController(handle: number, id: string, label: string): void {
const providerId = uuidv4();
const providerId = generateUuid();
this.handlers.set(handle, providerId);

const provider = new CommentController(this.proxy, this.commentService, handle, providerId, id, label, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import URI from '@theia/core/lib/common/uri';
import { ApplicationShell, OpenHandler, Widget, WidgetManager, WidgetOpenerOptions } from '@theia/core/lib/browser';
import { CustomEditor, CustomEditorPriority, CustomEditorSelector } from '../../../common';
import { CustomEditorWidget } from './custom-editor-widget';
import { v4 } from 'uuid';
import { generateUuid } from '@theia/core/lib/common/uuid';
import { Emitter } from '@theia/core';
import { match } from '@theia/core/lib/common/glob';

Expand Down Expand Up @@ -77,7 +77,7 @@ export class CustomEditorOpener implements OpenHandler {
const uriString = uri.toString();
let widgetPromise = this.pendingWidgetPromises.get(uriString);
if (!widgetPromise) {
const id = v4();
const id = generateUuid();
widgetPromise = this.widgetManager.getOrCreateWidget<CustomEditorWidget>(CustomEditorWidget.FACTORY_ID, { id });
this.pendingWidgetPromises.set(uriString, widgetPromise);
widget = await widgetPromise;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import * as React from '@theia/core/shared/react';
import { inject, injectable, interfaces, postConstruct } from '@theia/core/shared/inversify';
import { NotebookRendererMessagingService, CellOutputWebview, NotebookRendererRegistry, NotebookEditorWidgetService, NotebookCellOutputsSplice } from '@theia/notebook/lib/browser';
import { v4 } from 'uuid';
import { generateUuid } from '@theia/core/lib/common/uuid';
import { NotebookCellModel } from '@theia/notebook/lib/browser/view-model/notebook-cell-model';
import { WebviewWidget } from '../../webview/webview';
import { Message, WidgetManager } from '@theia/core/lib/browser';
Expand Down Expand Up @@ -65,7 +65,7 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
@inject(QuickPickService)
protected readonly quickPickService: QuickPickService;

readonly id = v4();
readonly id = generateUuid();

protected readonly elementRef = React.createRef<HTMLDivElement>();
protected outputPresentationListeners: DisposableCollection = new DisposableCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { ThemeIcon } from '@theia/monaco-editor-core/esm/vs/platform/theme/commo
import { WebviewView, WebviewViewResolver } from '../webview-views/webview-views';
import { WebviewWidget, WebviewWidgetIdentifier } from '../webview/webview';
import { CancellationToken } from '@theia/core/lib/common/cancellation';
import { v4 } from 'uuid';
import { generateUuid } from '@theia/core/lib/common/uuid';
import { nls } from '@theia/core';
import { TheiaDockPanel } from '@theia/core/lib/browser/shell/theia-dock-panel';
import { Deferred } from '@theia/core/lib/common/promise-util';
Expand Down Expand Up @@ -425,7 +425,7 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
protected async createNewWebviewView(viewId: string): Promise<WebviewView> {
const webview = await this.widgetManager.getOrCreateWidget<WebviewWidget>(
WebviewWidget.FACTORY_ID, <WebviewWidgetIdentifier>{
id: v4(),
id: generateUuid(),
viewId,
});
webview.setContentOptions({ allowScripts: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { interfaces } from '@theia/core/shared/inversify';
import { WebviewWidget, WebviewWidgetIdentifier, WebviewWidgetExternalEndpoint } from './webview';
import { WebviewEnvironment } from './webview-environment';
import { StorageService } from '@theia/core/lib/browser';
import { v4 } from 'uuid';
import { generateUuid } from '@theia/core/lib/common/uuid';

export class WebviewWidgetFactory {

Expand Down Expand Up @@ -46,7 +46,7 @@ export class WebviewWidgetFactory {
const key = 'plugin-view-registry.origin.' + viewId;
const origin = await storageService.getData<string>(key);
if (!origin) {
const newOrigin = v4();
const newOrigin = generateUuid();
storageService.setData(key, newOrigin);
return newOrigin;
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-ext/src/main/node/errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import { rejects } from 'assert';
import { strictEqual } from 'assert/strict';
import { promises as fs } from 'fs';
import { v4 } from 'uuid';
import { generateUuid } from '@theia/core/lib/common/uuid';
import { isENOENT } from '../../common/errors';

describe('errors', () => {
describe('errno-exception', () => {
it('should be ENOENT error', async () => {
await rejects(fs.readFile(v4()), reason => isENOENT(reason));
await rejects(fs.readFile(generateUuid()), reason => isENOENT(reason));
});

it('should not be ENOENT error (no code)', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-ext/src/plugin/debug/debug-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { DEBUG_SCHEME, SCHEME_PATTERN } from '@theia/debug/lib/common/debug-uri-
import { Disposable, Breakpoint as BreakpointExt, SourceBreakpoint, FunctionBreakpoint, Location, Range, URI as URIImpl } from '../types-impl';
import { PluginDebugAdapterSession } from './plugin-debug-adapter-session';
import { PluginDebugAdapterTracker } from './plugin-debug-adapter-tracker';
import uuid = require('uuid');
import { generateUuid } from '@theia/core/lib/common/uuid';
import { DebugAdapter } from '@theia/debug/lib/common/debug-model';
import { PluginDebugAdapterCreator } from './plugin-debug-adapter-creator';
import { NodeDebugAdapterCreator } from '../node/debug/plugin-node-debug-adapter-creator';
Expand Down Expand Up @@ -336,7 +336,7 @@ export class DebugExtImpl implements DebugExt {
}

async $createDebugSession(debugConfiguration: DebugConfiguration, workspaceFolderUri: string | undefined): Promise<string> {
const sessionId = uuid.v4();
const sessionId = generateUuid();

const parentSession = debugConfiguration.parentSessionId ? this.sessions.get(debugConfiguration.parentSessionId) : undefined;
const theiaSession: theia.DebugSession = {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-ext/src/plugin/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as theia from '@theia/plugin';
import { RPCProtocol } from '../common/rpc-protocol';
import { EnvMain, PLUGIN_RPC_CONTEXT } from '../common/plugin-api-rpc';
import { QueryParameters } from '../common/env';
import { v4 } from 'uuid';
import { generateUuid } from '@theia/core/lib/common/uuid';

export abstract class EnvExtImpl {
private proxy: EnvMain;
Expand All @@ -33,8 +33,8 @@ export abstract class EnvExtImpl {

constructor(rpc: RPCProtocol) {
this.proxy = rpc.getProxy(PLUGIN_RPC_CONTEXT.ENV_MAIN);
this.envSessionId = v4();
this.envMachineId = v4();
this.envSessionId = generateUuid();
this.envMachineId = generateUuid();
this._remoteName = undefined;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-ext/src/plugin/languages/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { MarkerData } from '../../common/plugin-api-rpc-model';
import { RPCProtocol } from '../../common/rpc-protocol';
import { PLUGIN_RPC_CONTEXT, LanguagesMain } from '../../common/plugin-api-rpc';
import { URI } from '@theia/core/shared/vscode-uri';
import { v4 } from 'uuid';
import { generateUuid } from '@theia/core/lib/common/uuid';

export class DiagnosticCollection implements theia.DiagnosticCollection {
private static DIAGNOSTICS_PRIORITY = [
Expand Down Expand Up @@ -288,7 +288,7 @@ export class Diagnostics {
}

private getNextId(): string {
return v4();
return generateUuid();
}

private getAllDiagnosticsForResource(uri: URI): theia.Diagnostic[] {
Expand Down
Loading

0 comments on commit 8ed78e6

Please sign in to comment.