No description
Find a file
2019-10-29 15:44:55 +08:00
assets Add demonstration gif 2018-11-28 20:32:45 +08:00
extension Minify search index properties (items, paths) to match the latest raw one 2019-10-29 15:44:55 +08:00
.gitignore Add basic travis yaml file 2018-11-29 13:10:55 +08:00
.travis.yml Add basic travis yaml file 2018-11-29 13:10:55 +08:00
CONTRIBUTING.md Create CONTRIBUTING.md 2018-11-26 23:32:18 +08:00
LICENSE-APACHE Create LICENSE-APACHE 2018-11-26 23:28:54 +08:00
LICENSE-MIT Create LICENSE-MIT 2018-11-26 23:29:52 +08:00
README.md Update README.md 2019-09-26 12:22:03 +08:00

Rust Search Extension

Chrome Web Store license-mit license-apache

🦀 A handy browser extension to search crates and docs in address bar (omnibox).

Installation

  • Chrome Web Store

https://chrome.google.com/webstore/detail/rust-search-extension/ennpfpdlaclocpomkiablnmbppdnlhoh

  • Mannually

Git clone to your computer, open chrome://extension page, and enable developer mode, then click load unpakced button, select the extension directory.

Features

  • Search Primitive Types and Modules
  • Search Structs, Traits and Enums
  • Search Functions, Methods and Macros
  • Search crates on https://crates.io
  • Search compiler Error Index
  • Offline mode, search local Rust docs (rustup docs --std)
  • Both Chrome and Firefox are supported

Usages

Input keyword rs in the address bar, press Tab or Space to activate the search bar. Then enter any word you want to search, the extension will response the related search results instantly.

demonstration.gif

How the extension works

1. Build search index

The raw search index was generated by rustc-doc. The most important function is build_index() which located at librustdoc/html/render.rs.

The final search index is an object array like this:

var searchIndex = [
    {
      crate: "std",
      desc: "A hash map implemented with linear probing and Robin Hood bucket stealing.",
      name: "HashMap",
      parent: undefined,
      path: "std::collections",
      ty: 3,
      type: null
    },
    {
      crate: "std",
      desc: "Applies function to the elements of iterator and returns the first non-none result.",
      name: "find_map",
      parent: {ty: 8, name: "Iterator"},
      path: "std::iter",
      ty: 11,
      type: [["self"],["f"]]
    }
    ...
];

2. Build search words array based on search index

The search words array is the list of search words to query against which build from the raw search index. It's just a plain name array of every Rust structs, traits, enums, functions, methods, macros, etc.

var searchWords = [
    "result", 
    "option", 
    "hashmap", 
    "hashset", 
    "clone", 
    "copy", 
    "display", 
    "debug"
    ...
];

3. Search keyword in search words array

Using Levenshtein distance algorithm to search matched words, the max Levenshtein distance is 2.

// Max levenshtein distance.
var MAX_LEV_DISTANCE = 2;

4. Sort search result

Sort search result according to Levenshtein distance, lexicographical and others metrics.

5. Transform search result to suggestion result to show in the address bar

Mapping the search word and search index to generate the search result, build Rust doc link for each result item.

var suggestResults = [
    {
      content: "https://doc.rust-lang.org/std/ops/trait.Deref.html",
      description: "std::ops::<match>Deref</match> - <dim>Used for immutable dereferencing operations, like `*v`.</dim>"
    },
    {
      content: "https://doc.rust-lang.org/std/ops/trait.Deref.html#tymethod.deref",
      description: "std::ops::Deref::<match>deref</match> - <dim>Dereferences the value.</dim>"
    }
    ...
];