How to access and query type info?

(This might possibly be off-topic, but since it is about using Swift and, I guess, tools that are included in the Swift repository, I figured this is the best place to ask.)

I'd like to find or write a tool (source editor extension, command line tool or whatever) that enables me to do advanced queries for type info, eg:

  • See what protocols some (stdlib or other) type conforms to, or ideally its place in a type hierarchy. I know I can click "Open In Developer Documentation" (in the Quick Help Inspector) and look at "Relationships". But I'd like a more powerful/programmatic way, and I want to be sure that the info I get is relevant (ie the info should be for the toolchain I'm currently using).

  • Get a list of methods and/or properties of some (stdlib or other) type, filterable by things like return type, arg types, whether they are static or not, deprecated or not, etc, etc. This would be like a more advanced code completion, where the list of completions can be filtered not only by (part of) name.

  • Get a list of all the stuff in a given module, filterable in all sorts of ways (eg only the types that conform to Hashable AND are generic AND where the name contains "ab"). I know I can get a list of completions for eg Foundation., MyModule. or Swift. but I want much more control than that.


Is this the sort of thing that SourceKit should be used for? If so, what are some good introductory material and advice?

Are there other (better/simpler) ways?

1 Like

@Jens , were you able to find something like this since you last posted? I'm myself looking for something like this, some sort of inspector library which we can query all sorts of information like structs, classes, their members, protocols, top level declarations.

Take a look at swift-syntax and sourcery.

Terms of Service

Privacy Policy

Cookie Policy