11
11
using System . Diagnostics ;
12
12
using System . IO ;
13
13
using System . Text ;
14
+ using System . Threading ;
14
15
using System . Threading . Tasks ;
15
16
16
17
namespace Microsoft . PowerShell . EditorServices . Test . Host
@@ -35,12 +36,15 @@ protected async Task<Tuple<int, int>> LaunchService(
35
36
string scriptPath = Path . Combine ( modulePath , "Start-EditorServices.ps1" ) ;
36
37
37
38
#if CoreCLR
39
+ string assemblyPath = this . GetType ( ) . GetTypeInfo ( ) . Assembly . Location ;
38
40
FileVersionInfo fileVersionInfo =
39
- FileVersionInfo . GetVersionInfo ( this . GetType ( ) . GetTypeInfo ( ) . Assembly . Location ) ;
41
+ FileVersionInfo . GetVersionInfo ( assemblyPath ) ;
40
42
#else
43
+ string assemblyPath = this . GetType ( ) . Assembly . Location ;
41
44
FileVersionInfo fileVersionInfo =
42
- FileVersionInfo . GetVersionInfo ( this . GetType ( ) . Assembly . Location ) ;
45
+ FileVersionInfo . GetVersionInfo ( assemblyPath ) ;
43
46
#endif
47
+ string sessionPath = Path . Combine ( Path . GetDirectoryName ( assemblyPath ) , "session.json" ) ;
44
48
45
49
string editorServicesModuleVersion =
46
50
string . Format (
@@ -59,7 +63,7 @@ protected async Task<Tuple<int, int>> LaunchService(
59
63
"-BundledModulesPath \\ \" " + modulePath + "\\ \" " +
60
64
"-LogLevel \" Verbose\" " +
61
65
"-LogPath \" " + logPath + "\" " +
62
- "-SessionDetailsPath \" . \\ sessionDetails \" " +
66
+ "-SessionDetailsPath \" " + sessionPath + " \" " +
63
67
"-FeatureFlags @() " +
64
68
"-AdditionalModules @() " ,
65
69
editorServicesModuleVersion ) ;
@@ -98,40 +102,20 @@ protected async Task<Tuple<int, int>> LaunchService(
98
102
this . serviceProcess . Start ( ) ;
99
103
100
104
// Wait for the server to finish initializing
101
- Task < string > stdoutTask = this . serviceProcess . StandardOutput . ReadLineAsync ( ) ;
102
- Task < string > stderrTask = this . serviceProcess . StandardError . ReadLineAsync ( ) ;
103
- Task < string > completedRead = await Task . WhenAny < string > ( stdoutTask , stderrTask ) ;
104
-
105
- if ( completedRead == stdoutTask )
105
+ while ( ! File . Exists ( sessionPath ) )
106
106
{
107
- JObject result = JObject . Parse ( completedRead . Result ) ;
108
- if ( result [ "status" ] . Value < string > ( ) == "started" )
109
- {
110
- return new Tuple < int , int > (
111
- result [ "languageServicePort" ] . Value < int > ( ) ,
112
- result [ "debugServicePort" ] . Value < int > ( ) ) ;
113
- }
114
-
115
- return null ;
107
+ Thread . Sleep ( 100 ) ;
116
108
}
117
- else
118
- {
119
- // Must have read an error? Keep reading from error stream
120
- string errorString = completedRead . Result ;
121
- Task < string > errorRead = this . serviceProcess . StandardError . ReadToEndAsync ( ) ;
122
109
123
- // Lets give the read operation 5 seconds to complete. Ideally, it shouldn't
124
- // take that long at all, but just in case...
125
- if ( errorRead . Wait ( 5000 ) )
126
- {
127
- if ( ! string . IsNullOrEmpty ( errorRead . Result ) )
128
- {
129
- errorString += errorRead . Result + Environment . NewLine ;
130
- }
131
- }
132
-
133
- throw new Exception ( "Could not launch powershell.exe:\r \n \r \n " + errorString ) ;
110
+ JObject result = JObject . Parse ( File . ReadAllText ( sessionPath ) ) ;
111
+ if ( result [ "status" ] . Value < string > ( ) == "started" )
112
+ {
113
+ return new Tuple < int , int > (
114
+ result [ "languageServicePort" ] . Value < int > ( ) ,
115
+ result [ "debugServicePort" ] . Value < int > ( ) ) ;
134
116
}
117
+
118
+ return null ;
135
119
}
136
120
137
121
protected void KillService ( )
0 commit comments