@@ -16,10 +16,12 @@ export function activate(context: ExtensionContext) {
16
16
extensionContext = context
17
17
outputChannel = vscode . window . createOutputChannel ( 'Dotty Language Client' ) ;
18
18
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 ( )
23
25
24
26
if ( process . env [ 'DLS_DEV_MODE' ] ) {
25
27
const portFile = `${ vscode . workspace . rootPath } /.dotty-ide-dev-port`
@@ -35,93 +37,99 @@ export function activate(context: ExtensionContext) {
35
37
} )
36
38
} )
37
39
} else {
38
- fetchAndRun ( artifact )
40
+ fetchAndRun ( sbtArtifact , languageServerArtifact , loadPluginArtifact )
39
41
}
40
42
} )
41
43
}
42
44
43
- function fetchAndRun ( artifact : string ) {
45
+ function fetchAndRun ( sbtArtifact : string , languageServerArtifact : string , loadPluginArtifact : string ) {
44
46
const coursierPath = path . join ( extensionContext . extensionPath , './out/coursier' ) ;
45
47
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
+ } )
50
61
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 = [
53
70
"-jar" , coursierPath ,
54
71
"fetch" ,
55
72
"-p" ,
56
73
artifact
57
- ] )
58
- const coursierProc = coursierPromise . childProcess
74
+ ] . concat ( extra )
59
75
60
- let classPath = ""
76
+ const coursierPromise = cpp . spawn ( "java" , args )
77
+ const coursierProc = coursierPromise . childProcess
61
78
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 = ""
69
80
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 ( )
73
86
outputChannel . append ( msg )
74
- throw new Error ( msg )
75
- }
87
+ } )
76
88
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
+ }
82
95
} )
96
+ return coursierPromise . then ( ( ) => {
97
+ return classPath ;
98
+ } ) ;
83
99
} )
84
- return coursierPromise
85
- } )
86
100
}
87
101
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 ) {
92
103
return vscode . window . withProgress ( {
93
104
location : vscode . ProgressLocation . Window ,
94
105
title : 'Configuring IDE...'
95
106
} , ( 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 ( " " )
105
114
const sbtPromise =
106
115
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"
113
121
] )
114
- const sbtProc = sbtPromise . childProcess
115
122
123
+ const sbtProc = sbtPromise . childProcess
116
124
sbtProc . on ( 'close' , ( code : number ) => {
117
125
if ( code != 0 ) {
118
- let msg = "Configuring the IDE failed."
126
+ const msg = "Configuring the IDE failed."
119
127
outputChannel . append ( msg )
120
128
throw new Error ( msg )
121
129
}
122
130
} )
123
131
124
- return sbtPromise ;
132
+ return sbtPromise . then ( ( ) => { return languageServerClasspath } ) ;
125
133
} )
126
134
}
127
135
0 commit comments