@@ -26,11 +26,13 @@ import reporting._, reporting.diagnostic.{Message, MessageContainer, messages}
2626import typer .Typer
2727import util .{Set => _ , _ }
2828import interactive ._ , interactive .InteractiveDriver ._
29+ import decompiler .IDEDecompilerDriver
2930import Interactive .Include
3031import config .Printers .interactiv
3132
3233import languageserver .config .ProjectConfig
33- import languageserver .worksheet .{Worksheet , WorksheetClient , WorksheetService }
34+ import languageserver .worksheet .{Worksheet , WorksheetService }
35+ import languageserver .decompiler .{TastyDecompilerService }
3436
3537import lsp4j .services ._
3638
@@ -43,7 +45,7 @@ import lsp4j.services._
4345 * - This implementation is based on the LSP4J library: https://github.com/eclipse/lsp4j
4446 */
4547class DottyLanguageServer extends LanguageServer
46- with TextDocumentService with WorkspaceService with WorksheetService { thisServer =>
48+ with TextDocumentService with WorkspaceService with WorksheetService with TastyDecompilerService { thisServer =>
4749 import ast .tpd ._
4850
4951 import DottyLanguageServer ._
@@ -128,6 +130,25 @@ class DottyLanguageServer extends LanguageServer
128130 drivers(configFor(uri))
129131 }
130132
133+ /** The driver instance responsible for decompiling `uri` in `classPath` */
134+ def decompilerDriverFor (uri : URI , classPath : String ): IDEDecompilerDriver = thisServer.synchronized {
135+ val config = configFor(uri)
136+ val defaultFlags = List (" -color:never" )
137+
138+ implicit class updateDeco (ss : List [String ]) {
139+ def update (pathKind : String , pathInfo : String ) = {
140+ val idx = ss.indexOf(pathKind)
141+ val ss1 = if (idx >= 0 ) ss.take(idx) ++ ss.drop(idx + 2 ) else ss
142+ ss1 ++ List (pathKind, pathInfo)
143+ }
144+ }
145+ val settings =
146+ defaultFlags ++
147+ config.compilerArguments.toList
148+ .update(" -classpath" , (classPath +: config.dependencyClasspath).mkString(File .pathSeparator))
149+ new IDEDecompilerDriver (settings)
150+ }
151+
131152 /** A mapping from project `p` to the set of projects that transitively depend on `p`. */
132153 def dependentProjects : Map [ProjectConfig , Set [ProjectConfig ]] = thisServer.synchronized {
133154 if (myDependentProjects == null ) {
@@ -184,7 +205,8 @@ class DottyLanguageServer extends LanguageServer
184205 rootUri = params.getRootUri
185206 assert(rootUri != null )
186207
187- class DottyServerCapabilities (val worksheetRunProvider : Boolean = true ) extends lsp4j.ServerCapabilities
208+ class DottyServerCapabilities (val worksheetRunProvider : Boolean = true ,
209+ val tastyDecompiler : Boolean = true ) extends lsp4j.ServerCapabilities
188210
189211 val c = new DottyServerCapabilities
190212 c.setTextDocumentSync(TextDocumentSyncKind .Full )
0 commit comments