bevyengine / bevyengine/bevy

Helper function to find nearest matching registered type name

Open
#9,972 0 comments 0 reactions 0 assignees View on GitHub
A-Reflection A-Utils C-Feature
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?

We are about to enter an era of manually-authored scene files driven by reflection. One pain point is spelling errors - either the programmer mistyped the name, or (more likely) got the package path wrong.

Compilers such as clang and TypeScript have a feature where they display the nearest matching name: "Did you mean 'XXX'?". This is done by computing the "edit distance" using the Levenshtein or Hamming algorithm, which take two strings and return a number indicating the number of edits needed to transform one into another. You can use this to iterate through all of the names and return the one with the smallest score.

## What solution would you like?

I am not suggesting making any changes to the reflection system itself. Spelling errors will most likely be handled by the asset loaders - basically any asset loader that uses reflection to construct an object from its type name.

What I'm suggesting is a small utility function that, given a type registry and a name, finds the "closest" registered name to the one given.

I recognize that Bevy would like to minimize dependencies on external crates. Although the "edit distance" algorithm is implemented in a number of crates (https://crates.io/crates/strsim for example), the actual function is relatively small, and is available in standard textbooks - you could just fork it.

## What alternative(s) have you considered?

Well, each asset loader can do their own edit distance calculation. However, most people writing asset loaders probably aren't going to bother with error suggestions unless it involves very little work. Doing this centrally in one place raises the quality bar for all asset loaders that use reflection.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.