forked from scalameta/metals
/
ScalaPresentationCompiler.scala
245 lines (203 loc) Β· 7.37 KB
/
ScalaPresentationCompiler.scala
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package scala.meta.internal.pc
import java.net.URI
import java.nio.file.Path
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
import java.util.concurrent.ScheduledExecutorService
import java.{util => ju}
import scala.concurrent.ExecutionContext
import scala.concurrent.ExecutionContextExecutor
import scala.jdk.CollectionConverters._
import scala.meta.internal.metals.ReportLevel
import scala.meta.pc.AutoImportsResult
import scala.meta.pc.DefinitionResult
import scala.meta.pc.HoverSignature
import scala.meta.pc.InlayHintsParams
import scala.meta.pc.Node
import scala.meta.pc.OffsetParams
import scala.meta.pc.PresentationCompiler
import scala.meta.pc.PresentationCompilerConfig
import scala.meta.pc.RangeParams
import scala.meta.pc.SymbolSearch
import scala.meta.pc.VirtualFileParams
import dotty.tools.pc.{ScalaPresentationCompiler => DottyPresentationCompiler}
import org.eclipse.lsp4j.CompletionItem
import org.eclipse.lsp4j.CompletionList
import org.eclipse.lsp4j.Diagnostic
import org.eclipse.lsp4j.DocumentHighlight
import org.eclipse.lsp4j.InlayHint
import org.eclipse.lsp4j.SelectionRange
import org.eclipse.lsp4j.SignatureHelp
import org.eclipse.lsp4j.TextEdit
/**
* This is a wrapper around the DottyPresentationCompiler
* The main purpose is to allow metals developers to iterate
* faster on new features.
*
* All bugfixes should happen directly in dotty repository.
* https://github.com/lampepfl/dotty/tree/main/presentation-compiler
*
* New features can be developed here, and then later moved to dotty.
*/
case class ScalaPresentationCompiler(
buildTargetIdentifier: String = "",
buildTargetName: Option[String] = None,
classpath: Seq[Path] = Nil,
options: List[String] = Nil,
search: SymbolSearch = EmptySymbolSearch,
ec: ExecutionContextExecutor = ExecutionContext.global,
sh: Option[ScheduledExecutorService] = None,
config: PresentationCompilerConfig = PresentationCompilerConfigImpl(),
folderPath: Option[Path] = None,
reportsLevel: ReportLevel = ReportLevel.Info,
) extends PresentationCompiler:
val underlying: DottyPresentationCompiler = new DottyPresentationCompiler(
buildTargetIdentifier = buildTargetIdentifier,
buildTargetName = buildTargetName,
classpath = classpath,
options = options,
search = search,
ec = ec,
sh = sh,
config = config,
folderPath = folderPath,
reportsLevel = reportsLevel,
)
def this() = this("", None, Nil, Nil)
override def inlayHints(
params: InlayHintsParams
): CompletableFuture[ju.List[InlayHint]] =
underlying.inlayHints(params)
override def didClose(uri: URI): Unit =
underlying.didClose(uri)
override def isLoaded(): Boolean =
underlying.isLoaded()
override def autoImports(
name: String,
params: OffsetParams,
isExtension: java.lang.Boolean,
): CompletableFuture[ju.List[AutoImportsResult]] =
underlying.autoImports(name, params, isExtension)
override def newInstance(
buildTargetIdentifier: String,
classpath: ju.List[Path],
options: ju.List[String],
): PresentationCompiler =
copy(
buildTargetIdentifier = buildTargetIdentifier,
classpath = classpath.asScala.toSeq,
options = options.asScala.toList,
)
override def withScheduledExecutorService(
scheduledExecutorService: ScheduledExecutorService
): PresentationCompiler =
copy(sh = Some(scheduledExecutorService))
override def hover(
params: OffsetParams
): CompletableFuture[ju.Optional[HoverSignature]] =
underlying.hover(params)
override def convertToNamedArguments(
params: OffsetParams,
argIndices: ju.List[Integer],
): CompletableFuture[ju.List[TextEdit]] =
underlying.convertToNamedArguments(params, argIndices)
override def shutdown(): Unit =
underlying.shutdown()
override def withWorkspace(workspace: Path): PresentationCompiler =
copy(folderPath = Some(workspace))
override def complete(
params: OffsetParams
): CompletableFuture[CompletionList] =
underlying.complete(params)
override def withConfiguration(
config: PresentationCompilerConfig
): PresentationCompiler =
copy(config = config)
override def insertInferredType(
params: OffsetParams
): CompletableFuture[ju.List[TextEdit]] =
underlying.insertInferredType(params)
override def typeDefinition(
params: OffsetParams
): CompletableFuture[DefinitionResult] =
underlying.typeDefinition(params)
override def completionItemResolve(
item: CompletionItem,
symbol: String,
): CompletableFuture[CompletionItem] =
underlying.completionItemResolve(item, symbol)
override def prepareRename(
params: OffsetParams
): CompletableFuture[ju.Optional[org.eclipse.lsp4j.Range]] =
underlying.prepareRename(params)
override def diagnosticsForDebuggingPurposes(): ju.List[String] =
underlying.diagnosticsForDebuggingPurposes()
override def withSearch(search: SymbolSearch): PresentationCompiler =
copy(search = search)
override def scalaVersion(): String =
underlying.scalaVersion()
override def definition(
params: OffsetParams
): CompletableFuture[DefinitionResult] =
underlying.definition(params)
override def documentHighlight(
params: OffsetParams
): CompletableFuture[ju.List[DocumentHighlight]] =
underlying.documentHighlight(params)
override def rename(
params: OffsetParams,
name: String,
): CompletableFuture[ju.List[TextEdit]] =
underlying.rename(params, name)
override def implementAbstractMembers(
params: OffsetParams
): CompletableFuture[ju.List[TextEdit]] =
underlying.implementAbstractMembers(params)
override def didChange(
params: VirtualFileParams
): CompletableFuture[ju.List[Diagnostic]] =
underlying.didChange(params)
override def semanticdbTextDocument(
filename: URI,
code: String,
): CompletableFuture[Array[Byte]] =
underlying.semanticdbTextDocument(filename, code)
override def signatureHelp(
params: OffsetParams
): CompletableFuture[SignatureHelp] =
underlying.signatureHelp(params)
override def selectionRange(
params: ju.List[OffsetParams]
): CompletableFuture[ju.List[SelectionRange]] =
underlying.selectionRange(params)
override def extractMethod(
range: RangeParams,
extractionPos: OffsetParams,
): CompletableFuture[ju.List[TextEdit]] =
underlying.extractMethod(range, extractionPos)
override def getTasty(
targetUri: URI,
isHttpEnabled: Boolean,
): CompletableFuture[String] =
underlying.getTasty(targetUri, isHttpEnabled)
override def restart(): Unit =
underlying.restart()
override def withExecutorService(
executorService: ExecutorService
): PresentationCompiler =
copy(ec = ExecutionContext.fromExecutorService(executorService))
override def withBuildTargetName(
buildTargetName: String
): PresentationCompiler =
copy(buildTargetIdentifier = buildTargetName)
override def semanticTokens(
params: VirtualFileParams
): CompletableFuture[ju.List[Node]] =
underlying.semanticTokens(params)
override def withReportsLoggerLevel(level: String): PresentationCompiler =
copy(reportsLevel = ReportLevel.fromString(level))
override def inlineValue(
params: OffsetParams
): CompletableFuture[ju.List[TextEdit]] =
underlying.inlineValue(params)
end ScalaPresentationCompiler