Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align OmniSharp.Script with Dotnet.Script.DependencyModel 0.3.0 #1035

Merged
merged 4 commits into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

<PropertyGroup>
<CakeScriptinTransportVersion>0.1.0</CakeScriptinTransportVersion>
<DotnetScriptDependencyModelVersion>0.2.0</DotnetScriptDependencyModelVersion>
<DotnetScriptDependencyModelNuGetVersion>0.2.0</DotnetScriptDependencyModelNuGetVersion>
<DotnetScriptDependencyModelVersion>0.3.0</DotnetScriptDependencyModelVersion>
<DotnetScriptDependencyModelNuGetVersion>0.3.0</DotnetScriptDependencyModelNuGetVersion>
<MicrosoftAspNetCoreDiagnosticsVersion>1.1.0</MicrosoftAspNetCoreDiagnosticsVersion>
<MicrosoftAspNetCoreHostingVersion>1.1.0</MicrosoftAspNetCoreHostingVersion>
<MicrosoftAspNetCoreHttpFeaturesVersion>1.1.0</MicrosoftAspNetCoreHttpFeaturesVersion>
Expand Down
23 changes: 17 additions & 6 deletions src/OmniSharp.Script/ScriptProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Dotnet.Script.DependencyModel.Compilation;
using Dotnet.Script.DependencyModel.NuGet;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Scripting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyModel;
using Microsoft.Extensions.Logging;
using OmniSharp.Models.WorkspaceInformation;
using OmniSharp.Services;
using OmniSharp.Roslyn.Utilities;
using Dotnet.Script.DependencyModel.Compilation;
using LogLevel = Dotnet.Script.DependencyModel.Logging.LogLevel;

namespace OmniSharp.Script
Expand Down Expand Up @@ -105,12 +107,12 @@ public void Initalize(IConfiguration configuration)
// same applies for having a context that is not a .NET Core app
if (!compilationDependencies.Any())
{
_logger.LogInformation("Unable to find dependency context for CSX files. Will default to non-context usage (Destkop CLR scripts).");
_logger.LogInformation("Unable to find dependency context for CSX files. Will default to non-context usage (Desktop CLR scripts).");
AddDefaultClrMetadataReferences(commonReferences);
}
else
{
foreach (var compilationAssembly in compilationDependencies)
foreach (var compilationAssembly in compilationDependencies.SelectMany(cd => cd.AssemblyPaths).Distinct())
{
_logger.LogDebug("Discovered script compilation assembly reference: " + compilationAssembly);
AddMetadataReference(commonReferences, compilationAssembly);
Expand All @@ -133,6 +135,15 @@ public void Initalize(IConfiguration configuration)
var csxFileName = Path.GetFileName(csxPath);
var project = scriptHelper.CreateProject(csxFileName, commonReferences);

if (enableScriptNuGetReferences)
{
var scriptMap = compilationDependencies.ToDictionary(rdt => rdt.Name, rdt => rdt.Scripts);
var options = project.CompilationOptions.WithSourceReferenceResolver(
new NuGetSourceReferenceResolver(ScriptSourceResolver.Default,
scriptMap));
project = project.WithCompilationOptions(options);
}

// add CSX project to workspace
_workspace.AddProject(project);
_workspace.AddDocument(project.Id, csxPath, SourceCodeKind.Script);
Expand All @@ -146,7 +157,7 @@ public void Initalize(IConfiguration configuration)
}
}

private string[] TryGetCompilationDependencies(bool enableScriptNuGetReferences)
private CompilationDependency[] TryGetCompilationDependencies(bool enableScriptNuGetReferences)
{
try
{
Expand All @@ -155,8 +166,8 @@ private string[] TryGetCompilationDependencies(bool enableScriptNuGetReferences)
catch (Exception e)
{
_logger.LogError("Failed to resolve compilation dependencies", e);
return Array.Empty<string>();
}
return Array.Empty<CompilationDependency>();
}
}

private void AddDefaultClrMetadataReferences(HashSet<MetadataReference> commonReferences)
Expand Down