forked from scalameta/metals
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement hover, completions and signature help.
This is a large commit that adds new infrastructure to use the Scala presentation compiler for interactive features like completions and "show type". This commit implements several features together because we could have used a simpler architecture if we for example only implemented hover first. That architecture would then need to be redesigned as we implemented more features. Instead, by implmenting several features together we reach the final design faster. Features -------- The presentation compiler provides decent APIs to implement hover and completions. We make a few customizations: - signature help is implemented from scratch using a custom tree traverser to track the active argument tree, including named arguments. - scope completions perform a workspace/symbol search for symbols that are not in scope. - we use our own fuzzy string matcher so for example `uService<TAB>` matches `userDatabaseService`. - Java and Scala docstrings are extracted from library dependency sources. - we have a custom signature printer that implements several niceties: - fully qualified types are shortened so they are easier to read, take up less space. - Java parameter names are extracted from library source code to avoid method signatures with parameters named `x$1`. A lot of Java code (including the JDK) is not compiled with -parameter so the only way to recover the parameter names is from source code. - Scala parameter default values are extracted from source when possible, for example `Iterator.sliding(size: Int, step: Int = 1)` instead of `Iterator.sliding(size: Int, step: Int = {})`. Performance ----------- It costs around 150-250ms to start a new presentation compiler, which happens every time a build target has finished compilation. Benchmarks show that a warmed up presentation compiler responds comfortably within 100ms even for large source files with 7k lines of code. I suspect the performance is slower for macro-heavy code, but I was nevertheless impressed by the performance in the cases I tried. Build changes ------------- The following projects have been added to the sbt build: - `pc-interfaces` module that is a pure Java API enabling Metals to communicate with the 2.11/2.12 compiler via reflection. - `pc` module that is cross-built against exact Scala compiler versions and implements the `pc-interfaces` Java APIs, support both Scala 2.11 and 2.12. - internal `cross` module that is used for testing 2.11/2.12 cross-built modules like `pc`. - internal `mtest` module that is used for sharing testing infrastructure between 2.11 and 2.12. The implementation for workspace/symbol has moved from the `metals` project into the `pc` project to facilitate testing on 2.11.
- Loading branch information
Showing
112 changed files
with
8,191 additions
and
453 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.