function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Scott WellsScott Wells 

Maintaining an up-to-date symbol table using the Tooling API

I'm thinking about putting together a simple plugin for IntelliJ IDEA for Force.com development that uses the Tooling API to provide Apex code completion and symbol navigation.  I've explored the API a bit and understand that you can build a pretty comprehensive symbol table for the code deployed into an using a combination of completions for platform APIs and Apex class symbol tables.  That symbol table represents what's been deployed into the org at that point, but of course in an IDE the user is actively creating/changing code.

Any decent modern IDE provides completion against this work-in-progress code, but I don't see how I can provide this with the Tooling API since the symbol tables are returned as part of the saved ApexClass definition.  Is there a way to get the Tooling API to provide a symbol table for a transient Apex class without actually saving it?  If so, does that work even if the Apex class isn't currently 100% valid?

The documentation for the Tooling API states very clearly that it should be used in place of a custom lexer/parser for Apex, but this seems to be one of a few places I've found where it doesn't seem to provide everything needed to avoid at least a simple understanding of the language locally, another being code formatting.

Any thoughts on this?  I guess that minimally being able to perform completion against the known symbols as of the last successful save is more valuable than absolutely nothing, but this really seems required to provide the expected coding experience.
Best Answer chosen by Scott Wells
Scott WellsScott Wells
Okay, I think I get it now after looking at a few other external sites/slide decks.  ApexClassMember (and ApexPageMember, etc.) are working copies of these things that can get compiled with or without getting deployed based on whether the ContainerAsyncRequest specifies IsCheckOnly=true or false.  It sounds like the state of the symbol table on a failed compile is still questionable, but I think this gives me plenty to go on for now, and I can see what things look like once I can at least perform completion against the deployed and (valid?) working state of the code.

All Answers

Scott WellsScott Wells
I'll give a partial answer to my own question here after digging around a little more.  It appears that ApexClassMember is what I want here since it is documented to be "the working copy of an Apex class for editing, saving or compiling".  However, I'm not sure how to state that I just want the class compiled and not saved, nor is it clear whether I can get a partial symbol table for a class that's not 100% valid yet.  I'll keep digging, and I'll provide whatever information I find here if I don't get an answer before then.
Scott WellsScott Wells
Okay, I think I get it now after looking at a few other external sites/slide decks.  ApexClassMember (and ApexPageMember, etc.) are working copies of these things that can get compiled with or without getting deployed based on whether the ContainerAsyncRequest specifies IsCheckOnly=true or false.  It sounds like the state of the symbol table on a failed compile is still questionable, but I think this gives me plenty to go on for now, and I can see what things look like once I can at least perform completion against the deployed and (valid?) working state of the code.
This was selected as the best answer