Skip to content

Creating cross file autocompletion

Patrick Scheibe edited this page Nov 26, 2016 · 2 revisions

A logic that lets you autocomplete symbols that were defined in a different file/package than the one you are currently editing. Since analyzing files and extracting symbols that are exported is a time-consuming task, this cannot be done on each invocation of an autocompletion. Therefore, files are indexed with a so-called FileBasedIndex. The index is stored in an optimized way and as long as files are not touched can be retrieved without re-indexing the files again.

Several things need to be clarified to build a consistent set-up:

  • In the files you are currently editing
    1. What should be suggested for completion? Only symbols that are exported from other packages?
    2. Do you need to import a package in the second argument of BeginPackage to make the symbols from this file available in your code?
    3. How do one consistently extracts which packages are imported in the current file and how is the file determined in which the package code can be found?
  • In the files that are indexed
    1. How exactly are exported symbols and their Context determined? Usually, one starts a package and after BeginPackage all exported symbols are given with their ::usage before the implementation follows after the Private` context is opened. Unfortunately, many different other forms are possible. What do we support?
    2. What are we doing with files that don't use the usual BeginPackage, Begin template?
    3. How do we define which files are indexed? So far all *.m files are searched but a more sophisticated search scope is required.

Current state

I have implemented an indexer and simple logic that goes through the top-level of the file extracting all symbols with an ::usage message. Furthermore, an action exists that can be activated through the menu to show all found exported symbols in all files that can be used to test which symbols are found.