-
Notifications
You must be signed in to change notification settings - Fork 19
Indexer
OcaIDE needs a better representation of the O’Caml AST than the current tree of definitions (represented by a single “Def” class) it uses for the outline, which was originally designed only for the outline, but then used for many other things (completion, hyperlinks, etc.) which would benefit from a better representation.
The current representation is hampering further progress on IDE services, and makes some current bugs and limitations hard to fix.
The code indexer is an O’Caml program that uses Camlp4 to parse O’Caml code, and works as a server that has all the knowledge on the O’Caml program, and can be queried by clients.
The main client is the Eclipse plug-in, which starts the server and gets the needed information from it.
The server indexes O’Caml files asked by the client, by creating symbol tables with bindings from symbol uses to symbol definitions among other things.
The server is stateful, and provides a number of services, both for updating its state and for querying it.
The indexer can be useful for the following (existing of future) features of OcaIDE :
- camlp4 extensions handled natively
- completion
- expected parameters assistance
- outline and quick outline
- tooltip descriptions
- hyperlinks (open declaration)
- find uses of an identifier
- call hierarchy
- refactoring
- formatter that works with other syntaxes than the default one
- semantic hightlighting
- mark occurrences
- module browser
- code folding
Each command consists of a keyword (in bold here) terminated by a newline, followed by a number of arguments (in italic here), each terminated by a newline:
- end, exit, or quit : terminate the indexer process
- xmlAstFromFile filepath : parse the given file and output its AST in XML format
- xmlAstFromInput nLines, line1, line2, etc. : parse the given input and output its AST in XML format
- …
The indexer is stateful, so that the whole project is not re-analyzed each time some information is needed.
This state consists of :
- a list of analyzed modules, each containing
- a recursive list of definitions in this module
- a list of references in this module to definitions possibly in another module
A definition has the following associated information :
- a unique identifier, that can be used to refer to this definition in some indexer commands, when more information is needed about the identifier than initially returned by the indexer
- the start and end offsets of the definition
- the name associated to the definition
- the start and end offsets of the name associated to this definition (the name would be add in
let add a b = a + b
) - the kind of definition (let, type, module, exception, class, etc.)
- the type inferred by the OCaml compiler for this definition (from the .annot file)
- the child definitions contained recursively (ex: module A contains module B, which contains type t1)
- the parent definition if any
- the ocamldoc comment associated with this definition, if any
- the ocamldoc section containing this definition, if any
- the source text corresponding to the definition
Some definitions have additional information :
- module
- the path of the file containing the module definition
- let
- is this in the “and” part of a definition
- is it recursive
- record
- is it mutable
- a type constructor
- the type definition in which it is defined
- …
For performance reasons, a version of the indexer compiled to native code would be preferable. But this binary would be platform-specific.
So, OcaIDE could come packaged with a few binaries, one for each major platform, and a bytecode version for platforms for which a native executable is not packaged.
Maybe the user would be able to compile the code themselves and set the binary path in OcaIDE.
OcaIDE could also propose an automatic compilation of the indexer using the tools defined in the preferences.
- The indexer project on GitHub : https://github.com/nbros/OcamlPDB
- The Camlp4 AST : http://brion.inria.fr/gallium/index.php/Abstract_Syntax_Tree
- The Camlp4 AST code with comments : https://github.com/nbros/OcamlPDB/blob/master/Camlp4Ast.partial.ml
- A related forum discussion : http://ocaml.eclipse.free.fr/forum/viewtopic.php?f=1&t=226