Skip to content

Replace custom generateUuid with crypto.randomUUID - #1789

Closed
Remco Haszing (remcohaszing) wants to merge 1 commit into
microsoft:mainfrom
remcohaszing:crypto-random-uuid
Closed

Remco Haszing (remcohaszing) wants to merge 1 commit into
microsoft:mainfrom
remcohaszing:crypto-random-uuid

Conversation

@remcohaszing

Copy link
Copy Markdown
Contributor

This replaces the custom Math.random() based UUID generated with the cryptographically secure builtin crypto.randomUUID().

Other functions from he uuid modules were unused.

This replaces the custom `Math.random()` based UUID generated with the
cryptographically secure builtin `crypto.randomUUID()`.

Other functions from he `uuid` modules were unused.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The common TypeScript projects do not declare the Web Crypto global, causing the new calls to fail compilation.

2 open findings
What changed in this PR

Replaces custom Math.random() UUID generation with native crypto.randomUUID() and removes obsolete UUID utilities.

Changes:

  • Migrates client/server registration and progress tokens.
  • Deletes duplicate UUID utility modules.
  • Introduces unresolved Web Crypto typings in common projects.
File Description
server/​src/​common/​utils/​uuid.ts Removes UUID utility.
server/​src/​common/​server.ts Migrates registration IDs.
server/​src/​common/​progress.ts Migrates progress tokens.
client/​src/​common/​workspaceSymbol.ts Migrates registration ID.
client/​src/​common/​workspaceFolder.ts Migrates registration ID.
client/​src/​common/​utils/​uuid.ts Removes UUID utility.
client/​src/​common/​textSynchronization.ts Migrates synchronization IDs.
client/​src/​common/​textDocumentContent.ts Migrates registration ID.
client/​src/​common/​signatureHelp.ts Migrates registration ID.
client/​src/​common/​rename.ts Migrates registration ID.
client/​src/​common/​reference.ts Migrates registration ID.
client/​src/​common/​notebook.ts Migrates synchronization ID.
client/​src/​common/​inlineCompletion.ts Migrates registration ID.
client/​src/​common/​hover.ts Migrates registration ID.
client/​src/​common/​formatting.ts Migrates formatting IDs.
client/​src/​common/​fileOperations.ts Migrates registration ID.
client/​src/​common/​features.ts Migrates shared feature IDs.
client/​src/​common/​executeCommand.ts Migrates registration ID.
client/​src/​common/​documentSymbol.ts Migrates registration ID.
client/​src/​common/​documentLink.ts Migrates registration ID.
client/​src/​common/​documentHighlight.ts Migrates registration ID.
client/​src/​common/​diagnostic.ts Migrates partial-result token.
client/​src/​common/​definition.ts Migrates registration ID.
client/​src/​common/​configuration.ts Migrates registration ID.
client/​src/​common/​completion.ts Migrates registration ID.
client/​src/​common/​codeLens.ts Migrates registration ID.
client/​src/​common/​codeAction.ts Migrates registration ID.
client/​src/​common/​client.ts Migrates initialization and watcher IDs.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

return [undefined, undefined];
} else if (TextDocumentRegistrationOptions.is(capability)) {
const id = StaticRegistrationOptions.hasId(capability) ? capability.id : UUID.generateUuid();
const id = StaticRegistrationOptions.hasId(capability) ? capability.id : crypto.randomUUID();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true to some extent, but not completely. crypto.randomUUID() is available in both browsers and Node.js, but it requires either the dom lib types or @types/node. This problem affects more than just the global crypto. Also for example console, URL, and URLSearchParams are available in both environments, but require type definitions of at least one of them.

throw new Error(`${method} is already added to this registration`);
}
const id = UUID.generateUuid();
const id = crypto.randomUUID();
@dbaeumer

Copy link
Copy Markdown
Member

Covered by #1893

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants