Non-ascii char in struct/enum/trait name, also work well with IntelliJ?

rg "struct" | wc -l; rg "enum" | wc -l; rg "trait" | wc -l
1002
426
153

One of my favorite features in IntelliJ is "goto class". Unfortunately, I'm getting a bit too much spam these days. I am wondering if it is possible to embed a non-ascii unicode char in rust struct/enum/trait names (that is also easy to type in IntelliJ goto-class).

The goal is that some important structs/enum/traits have this unicode char, while the "less important" ones do not, so that in goto-class, I can once again easily find the struct/enum/trait I want to jump to.

I'm on Linux, if that matters for unicode input.

Thanks!

Generally you should avoid nonascii identifiers if you're writing English-speaking code. Instead of a nonascii character, you could use a name as part of the identifier to mark "important" symbols.

The easiest way to input nonascii symbols will always be to have a non-US keyboard layout. The way to enable keyboard switching and the chord to trigger it will depend on your distro, but should be fairly to easy to find if you look for it.

1 Like

In theory I agree with you, in practice, the way IntelliJ does pattern matching is really annoying. For example, suppose we pick ABC_ as our 'important prefix', IntelliJ will actually match it with

Actor_Bacon_***** matching the A, B, c, and the _.

Next thought is: no one uses q, but we're CS people, so we use Que everywhere; and this desperation is leading me to look at non-ascii vars. :frowning:

I'm happy to listen to other solutions that does not involved non-ascii chars too. Like if there is a way in IntelliJ to define a goto-class2 that only hits a subset of the structs/enums/traits.

I actually find fuzzy matching useful (e.g. if I want StringBuilder, I can just type StrB), but to each their own, and it's certainly more useful if you already roughly know what the symbol name you're looking for is than if you don't. I believe you can turn this off in the general IDE settings somewhere.

Perhaps a bit more useful, I also think you can do a scoped lookup that will only pull up members below some namespace. Unfortunately it's been too long since I've used the IntelliJ platform to recall.[1]


  1. I mostly use vscode nowadays as it's more commonly used and I jump between setups to help people a lot. I do retain a fondness for IntelliJ, though, and have Alt + Enter bound as my "do assist" action for my IDEA muscle memory in addition to the vscode default CTRL + .. ↩︎

So in IntelliJ, there is a way to jump to a file / line via something like:

idea64.exe [--line <number>] [--column <number>] <path ...>

Something else I have been thinking about is: if there is a way to dump, for every struct/enum/trait in a workspace, a triple of

(name, file_name, line_number)

then I can render this myself in an HTML file, use my own search algos, and have it (via the above) jump to the right file/line in IntelliJ.

Problem is: still not found a nice tool for dumping struct/enum/traits (besides maybe trying a hacky regex).

You can ask rustdoc for json output:

Additionally, powering cargo-semver-checks is a query engine called trustfall which you can use to query rustdoc json more semantically (and shielded some from the rustdoc json's instability), e.g.:

trustfall can produce exactly what it sounds like you want, e.g. the linked query:
# Structs whose names end in "Iter": not all crates have them,
# so try one of these crates: arrayvec, indexmap, itertools
query {
  Crate {
    item {
      ... on Struct {
        name @output @filter(op: "has_suffix", value: ["$suffix"])

        span {
          filename @output
          first_line: begin_line @output
        }
      }
    }
  }
}
[
  {
    "filename": "library/std/src/collections/hash/map.rs",
    "first_line": 1392,
    "name": "Iter"
  },
  {
    "filename": "library/std/src/sync/mpsc/mod.rs",
    "first_line": 302,
    "name": "IntoIter"
  },
  {
    "filename": "library/std/src/collections/hash/set.rs",
    "first_line": 1287,
    "name": "IntoIter"
  },
  {
    "filename": "library/std/src/path.rs",
    "first_line": 624,
    "name": "Iter"
  },
  {
    "filename": "library/std/src/collections/hash/set.rs",
    "first_line": 1266,
    "name": "Iter"
  },
  {
    "filename": "library/std/src/sync/mpsc/mod.rs",
    "first_line": 225,
    "name": "Iter"
  },
  {
    "filename": "library/std/src/collections/hash/map.rs",
    "first_line": 1460,
    "name": "IntoIter"
  },
  {
    "filename": "library/std/src/sync/mpsc/mod.rs",
    "first_line": 268,
    "name": "TryIter"
  }
]
1 Like

cargo doc --workspace --no-deps is a life changer

You'll probably also enjoy having --document-private-items for the "my local code's API" use case