@@ -16,10 +16,12 @@ export function activate(context: ExtensionContext) {
1616 extensionContext = context
1717 outputChannel = vscode . window . createOutputChannel ( 'Dotty Language Client' ) ;
1818
19- const artifactFile = `${ vscode . workspace . rootPath } /.dotty-ide-artifact`
20- const defaultArtifact = "ch.epfl.lamp:dotty-language-server_0.8:0.8.0-bin-SNAPSHOT"
21- fs . readFile ( artifactFile , ( err , data ) => {
22- const artifact = err ? defaultArtifact : data . toString ( ) . trim ( )
19+ const sbtArtifact = "org.scala-sbt:sbt-launch:1.1.4"
20+ const languageServerArtifactFile = `${ vscode . workspace . rootPath } /.dotty-ide-artifact`
21+ const languageServerDefaultArtifact = "ch.epfl.lamp:dotty-language-server_0.8:0.8.0-RC1"
22+ const loadPluginArtifact = "ch.epfl.scala:load-plugin_2.12:0.1.0+2-496ac670"
23+ fs . readFile ( languageServerArtifactFile , ( err , data ) => {
24+ const languageServerArtifact = err ? languageServerDefaultArtifact : data . toString ( ) . trim ( )
2325
2426 if ( process . env [ 'DLS_DEV_MODE' ] ) {
2527 const portFile = `${ vscode . workspace . rootPath } /.dotty-ide-dev-port`
@@ -35,93 +37,99 @@ export function activate(context: ExtensionContext) {
3537 } )
3638 } )
3739 } else {
38- fetchAndRun ( artifact )
40+ fetchAndRun ( sbtArtifact , languageServerArtifact , loadPluginArtifact )
3941 }
4042 } )
4143}
4244
43- function fetchAndRun ( artifact : string ) {
45+ function fetchAndRun ( sbtArtifact : string , languageServerArtifact : string , loadPluginArtifact : string ) {
4446 const coursierPath = path . join ( extensionContext . extensionPath , './out/coursier' ) ;
4547
46- vscode . window . withProgress ( {
47- location : vscode . ProgressLocation . Window ,
48- title : 'Fetching the Dotty Language Server'
49- } , ( progress ) => {
48+ const sbtPromise = fetchWithCoursier ( coursierPath , sbtArtifact )
49+ const languageServerPromise = fetchWithCoursier ( coursierPath , languageServerArtifact )
50+ const loadPluginPromise = fetchWithCoursier ( coursierPath , loadPluginArtifact )
51+
52+ Promise . all ( [ sbtPromise , languageServerPromise , loadPluginPromise ] ) . then ( ( results ) => {
53+ const [ sbtClasspath , languageServerClasspath , loadPluginJar ] = results
54+ return configureIDE ( sbtClasspath , languageServerClasspath , loadPluginJar )
55+ } ) . then ( ( languageServerClasspath ) => {
56+ run ( {
57+ command : "java" ,
58+ args : [ "-classpath" , languageServerClasspath , "dotty.tools.languageserver.Main" , "-stdio" ]
59+ } )
60+ } )
5061
51- const coursierPromise =
52- cpp . spawn ( "java" , [
62+ }
63+
64+ function fetchWithCoursier ( coursierPath : string , artifact : string , extra : string [ ] = [ ] ) {
65+ return vscode . window . withProgress ( {
66+ location : vscode . ProgressLocation . Window ,
67+ title : `Fetching ${ artifact } `
68+ } , ( progress ) => {
69+ const args = [
5370 "-jar" , coursierPath ,
5471 "fetch" ,
5572 "-p" ,
5673 artifact
57- ] )
58- const coursierProc = coursierPromise . childProcess
74+ ] . concat ( extra )
5975
60- let classPath = ""
76+ const coursierPromise = cpp . spawn ( "java" , args )
77+ const coursierProc = coursierPromise . childProcess
6178
62- coursierProc . stdout . on ( 'data' , ( data : Buffer ) => {
63- classPath += data . toString ( ) . trim ( )
64- } )
65- coursierProc . stderr . on ( 'data' , ( data : Buffer ) => {
66- let msg = data . toString ( )
67- outputChannel . append ( msg )
68- } )
79+ let classPath = ""
6980
70- coursierProc . on ( 'close' , ( code : number ) => {
71- if ( code != 0 ) {
72- let msg = "Fetching the language server failed."
81+ coursierProc . stdout . on ( 'data' , ( data : Buffer ) => {
82+ classPath += data . toString ( ) . trim ( )
83+ } )
84+ coursierProc . stderr . on ( 'data' , ( data : Buffer ) => {
85+ let msg = data . toString ( )
7386 outputChannel . append ( msg )
74- throw new Error ( msg )
75- }
87+ } )
7688
77- configureIDE ( ) . then ( ( res ) => {
78- run ( {
79- command : "java" ,
80- args : [ "-classpath" , classPath , "dotty.tools.languageserver.Main" , "-stdio" ]
81- } )
89+ coursierProc . on ( 'close' , ( code : number ) => {
90+ if ( code != 0 ) {
91+ let msg = `Couldn't fetch '${ artifact } ' (exit code ${ code } ).`
92+ outputChannel . append ( msg )
93+ throw new Error ( msg )
94+ }
8295 } )
96+ return coursierPromise . then ( ( ) => {
97+ return classPath ;
98+ } ) ;
8399 } )
84- return coursierPromise
85- } )
86100}
87101
88- function configureIDE ( ) {
89- const coursierPath = path . join ( extensionContext . extensionPath , './out/coursier' ) ;
90- const loadPluginPath = path . join ( extensionContext . extensionPath , './out/load-plugin.jar' ) ;
91-
102+ function configureIDE ( sbtClasspath : string , languageServerClasspath : string , loadPluginJar : string ) {
92103 return vscode . window . withProgress ( {
93104 location : vscode . ProgressLocation . Window ,
94105 title : 'Configuring IDE...'
95106 } , ( progress ) => {
96-
97- const applyLoadPlugin = "apply -cp " + loadPluginPath + " ch.epfl.scala.loadplugin.LoadPlugin"
98- const ifAbsentCommands = [
99- "if-absent dotty.tools.sbtplugin.DottyPlugin" ,
100- "\"set every scalaVersion := \\\"0.8.0-bin-SNAPSHOT\\\"\"" ,
101- "\"load-plugin ch.epfl.lamp:sbt-dotty:0.2.0-SNAPSHOT dotty.tools.sbtplugin.DottyPlugin\"" ,
102- "\"load-plugin ch.epfl.lamp:sbt-dotty:0.2.0-SNAPSHOT dotty.tools.sbtplugin.DottyIDEPlugin\""
103- ] . join ( " " )
104-
107+ const applyLoadPlugin = `apply -cp ${ loadPluginJar } ch.epfl.scala.loadplugin.LoadPlugin`
108+ const ifAbsentCommands = [
109+ "if-absent dotty.tools.sbtplugin.DottyPlugin" ,
110+ "\"set every scalaVersion := \\\"0.8.0-RC1\\\"\"" ,
111+ "\"load-plugin ch.epfl.lamp:sbt-dotty:0.2.2 dotty.tools.sbtplugin.DottyPlugin\"" ,
112+ "\"load-plugin ch.epfl.lamp:sbt-dotty:0.2.2 dotty.tools.sbtplugin.DottyIDEPlugin\""
113+ ] . join ( " " )
105114 const sbtPromise =
106115 cpp . spawn ( "java" , [
107- "-jar" , coursierPath ,
108- "launch" ,
109- "org.scala-sbt:sbt-launch:1.1.2" , "--" ,
110- applyLoadPlugin ,
111- ifAbsentCommands ,
112- "configureIDE"
116+ "-classpath" , sbtClasspath ,
117+ "xsbt.boot.Boot" ,
118+ applyLoadPlugin ,
119+ ifAbsentCommands ,
120+ "configureIDE"
113121 ] )
114- const sbtProc = sbtPromise . childProcess
115122
123+ const sbtProc = sbtPromise . childProcess
116124 sbtProc . on ( 'close' , ( code : number ) => {
117125 if ( code != 0 ) {
118- let msg = "Configuring the IDE failed."
126+ const msg = "Configuring the IDE failed."
119127 outputChannel . append ( msg )
120128 throw new Error ( msg )
121129 }
122130 } )
123131
124- return sbtPromise ;
132+ return sbtPromise . then ( ( ) => { return languageServerClasspath } ) ;
125133 } )
126134}
127135
0 commit comments