/
PresentationCompiler.java
139 lines (115 loc) Β· 5.26 KB
/
PresentationCompiler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package scala.meta.pc;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.CompletionList;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.SignatureHelp;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
/**
* The public API of the presentation compiler.
*
* This API should remain
*/
public abstract class PresentationCompiler {
// ==============================
// Language Server Protocol APIs.
// ==============================
/**
* Returns code completions for the given source position.
*
* The returned completion items are incomplete meaning they may not contain available
* information such as documentation or the detail signature may have `x$1` parameter
* names for Java methods. It's recommended to call
* {@link #completionItemResolve(CompletionItem, String)}
* before displaying the `detail` and `documentation` fields to the user.
*
* @implNote supports cancellation.
*/
public abstract CompletionList complete(OffsetParams params);
/**
* Returns a fully resolved completion item with defined fields such as `documentation` and `details` populated.
*
* @implNote does not support cancellation.
*/
public abstract CompletionItem completionItemResolve(CompletionItem item, String symbol);
/**
* Returns the parameter hints at the given source position.
*
* @implNote supports cancellation.
*/
public abstract SignatureHelp signatureHelp(OffsetParams params);
/**
* Returns the type of the expression at the given position along with the symbol of the referenced symbol.
*/
public abstract Optional<Hover> hover(OffsetParams params);
/**
* Returns the definition of the symbol at the given position.
*/
public abstract List<Location> definition(OffsetParams params);
/**
* Returns the Protobuf byte array representation of a SemanticDB <code>TextDocument</code> for the given source.
*/
public abstract byte[] semanticdbTextDocument(String filename, String code);
// =================================
// Configuration and lifecycle APIs.
// =================================
/**
* Clean up resources and shutdown the presentation compiler.
*
* It is necessary to call this method in order to for example stop the presentation compiler thread.
* If this method is not called, then the JVM may not shut exit cleanly.
*
* This presentation compiler instance should no longer be used after calling this method.
*/
public abstract void shutdown();
/**
* Clean the symbol table and other mutable state in the compiler.
*/
public abstract void restart();
/**
* Provide a SymbolSearch to extract docstrings, java parameter names and Scala default parameter values.
*/
public abstract PresentationCompiler withSearch(SymbolSearch search);
/**
* Provide a custom executor service to run asynchronous cancellation or requests.
*/
public abstract PresentationCompiler withExecutorService(ExecutorService executorService);
/**
* Provide a custom scheduled executor service to schedule `Thread.stop()` for unresponsive compiler instances.
*/
public abstract PresentationCompiler withScheduledExecutorService(ScheduledExecutorService scheduledExecutorService);
/**
* Provide custom configuration for features like signature help and completions.
*/
public abstract PresentationCompiler withConfiguration(PresentationCompilerConfig config);
/**
* Construct a new presentation compiler with the given parameters.
*
* @param buildTargetIdentifier the build target containing this source file. This is needed for
* {@link #completionItemResolve(CompletionItem, String)}.
* @param classpath the classpath of this build target.
* @param options the compiler flags for the new compiler. Important, it is recommended to disable
* all compiler plugins excluding org.scalamacros:paradise, kind-projector and better-monadic-for.
*/
public abstract PresentationCompiler newInstance(String buildTargetIdentifier, List<Path> classpath, List<String> options);
// =============================
// Intentionally missing methods
// =============================
// Metals uses diagnostics from the build. It is not on the roadmap to publish diagnostics
// from the presentation compiler because they are unreliable, especially for long-running
// compiler instances.
// def diagnostics(): List[Diagnostics]
// The presentation compiler does not have enough information to implement it standalone.
// def definition(params: OffsetParams): List[Location]
// The presentation compiler does not have enough information to implement it standalone.
// def references(params: OffsetParams): List[Location]
// ==============================================
// Internal methods - not intended for public use
// ==============================================
public abstract List<String> diagnosticsForDebuggingPurposes();
}