How do developers who don't use Xcode find function definitions, typing, and documentation?

Let's say I'm trying to understand the code in the TypeCheckDeclOverride.cpp file. Around line 550[1] I see a function, diagnose(...), which is frequently called. I suppose it's used to emit errors, warnings, and notes (like fixIts). How do I find the function definition to understand how it works, what's the type of the arguments, etc..? If there are no comments in the code, there won't be additional documentation anywhere else either?

Searching the entire project for diagnose( (or Diags, getASTContext(), etc..) I just get overwhelmed by the results, there must be a better way.

I also spent a lot of time trying to setup the Xcode project, but gave up as I couldn't get it to work and it took me really a lot of time I would have rather spent trying to understand the compiler.

How do people who don't use Xcode find function definitions and typing?

[1] swift/TypeCheckDeclOverride.cpp at 227f0deb5b04ee46f10e6bef5792745a5479e3e6 · apple/swift · GitHub

I've historically had issues with Xcode as well. I currently use CLion which I find is significantly better. I have also used VSCode before (you need some extensions like C/C++ Intellisense). Both of them offer a "go to definition" (or similar) feature you can use to find where a particular method is defined by right clicking on a function call.

If Xcode didn't work for you, I would suggest doing a ninja build and then setting it up in CLion (we have a guide for it). It's paid (and worth it IMO) but you get a 30 day trial so you can try it out. If not, you can also open the swift directory in VSCode (which is totally free) and it should be able to figure it out.

1 Like

There is a server for the Language Server Protocol available with the Swift toolchain, sourcekit-lsp, which many editors and IDEs now support. It lets you have such source editing niceties in any LSP-compliant editor. Here are instructions on using it with venerable Emacs, I have successfully used it with a CLI text editor on Android.

Edit: Oh sorry, I didn't read closely and didn't realize you were asking about the C++ sections of the compiler itself. My answer only applies to Swift packages.

1 Like

Thank you! Using CLion now, great so far :tada:

1 Like

For posterity, if jump to definition is not cooperating with bar in foo.bar in Xcode, usually you can still jump to foo, then jump to the type of foo and search for bar at file scope.

1 Like