@@ -21,14 +21,12 @@ namespace Microsoft.CodeAnalysis.LanguageServer.FileBasedPrograms;
2121[ Export ( typeof ( VirtualProjectXmlProvider ) ) , Shared ]
2222[ method: ImportingConstructor ]
2323[ method: Obsolete ( MefConstruction . ImportingConstructorMessage , error : true ) ]
24- internal class VirtualProjectXmlProvider ( DotnetCliHelper dotnetCliHelper , ILoggerFactory loggerFactory )
24+ internal class VirtualProjectXmlProvider ( DotnetCliHelper dotnetCliHelper )
2525{
26- private readonly ILogger < VirtualProjectXmlProvider > _logger = loggerFactory . CreateLogger < VirtualProjectXmlProvider > ( ) ;
27-
28- internal async Task < ( string VirtualProjectXml , ImmutableArray < SimpleDiagnostic > Diagnostics ) ? > GetVirtualProjectContentAsync ( string documentFilePath , CancellationToken cancellationToken )
26+ internal async Task < ( string VirtualProjectXml , ImmutableArray < SimpleDiagnostic > Diagnostics ) ? > GetVirtualProjectContentAsync ( string documentFilePath , ILogger logger , CancellationToken cancellationToken )
2927 {
3028 var workingDirectory = Path . GetDirectoryName ( documentFilePath ) ;
31- var process = dotnetCliHelper . Run ( [ "run-api" ] , workingDirectory , shouldLocalizeOutput : true , redirectStandardInput : true ) ;
29+ var process = dotnetCliHelper . Run ( [ "run-api" ] , workingDirectory , shouldLocalizeOutput : true ) ;
3230
3331 cancellationToken . Register ( ( ) =>
3432 {
@@ -42,21 +40,21 @@ internal class VirtualProjectXmlProvider(DotnetCliHelper dotnetCliHelper, ILogge
4240
4341 // Debug severity is used for these because we think it will be common for the user environment to have too old of an SDK for the call to work.
4442 // Rather than representing a hard error condition, it represents a condition where we need to gracefully downgrade the experience.
45- process . ErrorDataReceived += ( sender , args ) => _logger . LogDebug ( $ "dotnet run-api: { args . Data } ") ;
43+ process . ErrorDataReceived += ( sender , args ) => logger . LogDebug ( $ "[stderr] dotnet run-api: { args . Data } ") ;
4644 process . BeginErrorReadLine ( ) ;
4745
4846 var responseJson = await process . StandardOutput . ReadLineAsync ( cancellationToken ) ;
4947 await process . WaitForExitAsync ( cancellationToken ) ;
5048
5149 if ( process . ExitCode != 0 )
5250 {
53- _logger . LogDebug ( $ "dotnet run-api exited with exit code '{ process . ExitCode } '.") ;
51+ logger . LogDebug ( $ "dotnet run-api exited with exit code '{ process . ExitCode } '.") ;
5452 return null ;
5553 }
5654
5755 if ( string . IsNullOrWhiteSpace ( responseJson ) )
5856 {
59- _logger . LogError ( $ "dotnet run-api exited with exit code 0, but did not return any response.") ;
57+ logger . LogError ( $ "dotnet run-api exited with exit code 0, but did not return any response.") ;
6058 return null ;
6159 }
6260
@@ -65,17 +63,13 @@ internal class VirtualProjectXmlProvider(DotnetCliHelper dotnetCliHelper, ILogge
6563 var response = JsonSerializer . Deserialize ( responseJson , RunFileApiJsonSerializerContext . Default . RunApiOutput ) ;
6664 if ( response is RunApiOutput . Error error )
6765 {
68- _logger . LogError ( $ "dotnet run-api version: { error . Version } . Latest known version: { RunApiOutput . LatestKnownVersion } ") ;
69- _logger . LogError ( $ "dotnet run-api returned error: '{ error . Message } '") ;
66+ logger . LogError ( $ "dotnet run-api version: { error . Version } . Latest known version: { RunApiOutput . LatestKnownVersion } ") ;
67+ logger . LogError ( $ "dotnet run-api returned error: '{ error . Message } '") ;
7068 return null ;
7169 }
7270
7371 if ( response is RunApiOutput . Project project )
7472 {
75- if ( project . Version > RunApiOutput . LatestKnownVersion )
76- {
77- _logger . LogWarning ( $ "'dotnet run-api' version '{ project . Version } ' is newer than latest known version { RunApiOutput . LatestKnownVersion } ") ;
78- }
7973
8074 return ( project . Content , project . Diagnostics ) ;
8175 }
@@ -85,7 +79,11 @@ internal class VirtualProjectXmlProvider(DotnetCliHelper dotnetCliHelper, ILogge
8579 catch ( JsonException ex )
8680 {
8781 // In this case, run-api returned 0 exit code, but gave us back JSON that we don't know how to parse.
88- _logger . LogError ( ex , "Could not deserialize run-api response." ) ;
82+ logger . LogError ( ex , "Could not deserialize run-api response." ) ;
83+ logger . LogTrace ( $ """
84+ Full run-api response:
85+ { responseJson }
86+ """ ) ;
8987 return null ;
9088 }
9189 }
@@ -99,7 +97,7 @@ internal static string GetVirtualProjectPath(string documentFilePath)
9997
10098 internal static bool IsFileBasedProgram ( string documentFilePath , SourceText text )
10199 {
102- // TODO : this needs to be adjusted to be more sustainable.
100+ // https://github.com/dotnet/roslyn/issues/78878 : this needs to be adjusted to be more sustainable.
103101 // When we adopt the dotnet run-api, we need to get rid of this or adjust it to be more sustainable (e.g. using the appropriate document to get a syntax tree)
104102 var tree = CSharpSyntaxTree . ParseText ( text , options : CSharpParseOptions . Default . WithLanguageVersion ( LanguageVersion . Preview ) , path : documentFilePath ) ;
105103 var root = tree . GetRoot ( ) ;
0 commit comments