Skip to content

Commit

Permalink
Merge branch 'master' into dmgonch/PluginsConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
dmgonch authored Oct 5, 2019
2 parents 9bbcfa8 + b010270 commit 79d7cdc
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 29 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog
All changes to the project will be documented in this file.

## [1.34.5] - not yet released
* Fixed 1.34.4 regression that caused "go to metadata" to not work ([#1624](https://github.com/OmniSharp/omnisharp-roslyn/issues/1624), PR: [#1625](https://github.com/OmniSharp/omnisharp-roslyn/pull/1625))

## [1.34.4] - 2019-09-30
* Upgraded to MSBuild 16.3 and Mono MSBuild 16.3 (from Mono 6.4.0) to support .NET Core 3.0 RTM (PR: [#1616](https://github.com/OmniSharp/omnisharp-roslyn/pull/1616), [#1612](https://github.com/OmniSharp/omnisharp-roslyn/pull/1612), [#1606](https://github.com/OmniSharp/omnisharp-roslyn/pull/1606))
* Fixed behavior when there are multiple handlers are defined for a language for a given request (PR: [#1582](https://github.com/OmniSharp/omnisharp-roslyn/pull/1582))

## [1.34.3] - 2019-09-11
* Added support for `CheckForOverflowUnderflow ` in csproj files (PR: [#1587](https://github.com/OmniSharp/omnisharp-roslyn/pull/1587))
* Updated LSP libraries to 0.13 which fixes problems with clients not supporting dynamic registrations. ([#1505](https://github.com/OmniSharp/omnisharp-roslyn/issues/1505), [#1525](https://github.com/OmniSharp/omnisharp-roslyn/issues/1525), PR: [#1562](https://github.com/OmniSharp/omnisharp-roslyn/pull/1562))
Expand Down
17 changes: 16 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@

trigger:
batch: true
branches:
include:
- master
- refs/tags/*

pr:
autoCancel: true
branches:
include:
- master

resources:
repositories:
- repository: rsg
Expand Down Expand Up @@ -76,9 +90,10 @@ jobs:
- script: |
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
sudo apt install apt-transport-https ca-certificates
echo "deb https://download.mono-project.com/repo/ubuntu stable-xenial/snapshots/6.4.0.198 main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
echo "deb https://download.mono-project.com/repo/ubuntu vs-xenial/snapshots/6.4.0.198 main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update
sudo apt install mono-devel
sudo apt install msbuild
displayName: Use Mono $(MONO_VERSION)
- script: |
chmod 755 ./build.sh
Expand Down
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Task("CreateMSBuildFolder")
var libraryFileName = library + ".dll";

// copy MSBuild from current Mono (should be 6.4.0+)
var librarySourcePath = CombinePaths(Platform.Current.IsMacOS ? "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/msbuild/15.0/bin" : "/usr/lib/mono/msbuild/15.0/bin", libraryFileName);
var librarySourcePath = CombinePaths(Platform.Current.IsMacOS ? "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/msbuild/15.0/bin" : "/usr/lib/mono/msbuild/Current/bin", libraryFileName);
var libraryTargetPath = CombinePaths(msbuildCurrentBinTargetFolder, libraryFileName);
if (FileHelper.Exists(librarySourcePath))
{
Expand Down
9 changes: 5 additions & 4 deletions build/Packages.props
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="14.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<MSBuildPackageVersion>16.3.0-preview-19426-01</MSBuildPackageVersion>
<NuGetPackageVersion>5.0.0</NuGetPackageVersion>
<NuGetPackageVersion>5.2.0</NuGetPackageVersion>
<RoslynPackageVersion>3.4.0-beta1-19460-02</RoslynPackageVersion>
<XunitPackageVersion>2.4.0</XunitPackageVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Update="Cake.Scripting.Transport" Version="0.3.0" />

<PackageReference Update="Dotnet.Script.DependencyModel" Version="0.6.1" />
<PackageReference Update="Dotnet.Script.DependencyModel.NuGet" Version="0.6.2" />
<PackageReference Update="Dotnet.Script.DependencyModel" Version="0.50.0" />
<PackageReference Update="Dotnet.Script.DependencyModel.NuGet" Version="0.50.0" />

<PackageReference Update="Humanizer" Version="2.2.0" />
<PackageReference Update="McMaster.Extensions.CommandLineUtils" Version="2.2.4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public class GotoDefinitionResponse : ICanBeEmptyResponse
[JsonConverter(typeof(ZeroBasedIndexConverter))]
public int Column { get; set; }
public MetadataSource MetadataSource { get; set; }
public bool IsEmpty => FileName == null || FileName == string.Empty;
public bool IsEmpty => string.IsNullOrWhiteSpace(FileName) && MetadataSource == null;
}
}
3 changes: 1 addition & 2 deletions src/OmniSharp.Script/ScriptContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Dotnet.Script.DependencyModel.Compilation;
using Microsoft.CodeAnalysis;

namespace OmniSharp.Script
Expand All @@ -21,6 +20,6 @@ public ScriptContext(ScriptProjectProvider scriptProjectProvider, HashSet<Metada

public CompilationDependency[] CompilationDependencies { get; }

public Type GlobalsType { get; }
public Type GlobalsType { get; }
}
}
35 changes: 30 additions & 5 deletions src/OmniSharp.Script/ScriptContextProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Scripting.Hosting;
using Microsoft.Extensions.Logging;
using OmniSharp.FileSystem;
using OmniSharp.Roslyn.Utilities;
using OmniSharp.Services;
using LogLevel = Dotnet.Script.DependencyModel.Logging.LogLevel;
Expand All @@ -23,22 +24,28 @@ public class ScriptContextProvider
private readonly CompilationDependencyResolver _compilationDependencyResolver;
private readonly IOmniSharpEnvironment _env;
private readonly MetadataFileReferenceCache _metadataFileReferenceCache;
private readonly FileSystemHelper _fileSystemHelper;
private readonly ILogger _logger;

[ImportingConstructor]
public ScriptContextProvider(ILoggerFactory loggerFactory, IOmniSharpEnvironment env, MetadataFileReferenceCache metadataFileReferenceCache)
public ScriptContextProvider(ILoggerFactory loggerFactory, IOmniSharpEnvironment env, MetadataFileReferenceCache metadataFileReferenceCache, FileSystemHelper fileSystemHelper)
{
_loggerFactory = loggerFactory;
_env = env;
_metadataFileReferenceCache = metadataFileReferenceCache;
_fileSystemHelper = fileSystemHelper;
_logger = loggerFactory.CreateLogger<ScriptContextProvider>();
_compilationDependencyResolver = new CompilationDependencyResolver(type =>
{
// Prefix with "OmniSharp" so that we make it through the log filter.
var categoryName = $"OmniSharp.Script.{type.FullName}";
var dependencyResolverLogger = loggerFactory.CreateLogger(categoryName);
return ((level, message) =>
return ((level, message, exception) =>
{
if (level == LogLevel.Trace)
{
dependencyResolverLogger.LogTrace(message);
}
if (level == LogLevel.Debug)
{
dependencyResolverLogger.LogDebug(message);
Expand All @@ -47,11 +54,23 @@ public ScriptContextProvider(ILoggerFactory loggerFactory, IOmniSharpEnvironment
{
dependencyResolverLogger.LogInformation(message);
}
if (level == LogLevel.Warning)
{
dependencyResolverLogger.LogWarning(message);
}
if (level == LogLevel.Error)
{
dependencyResolverLogger.LogError(exception, message);
}
if (level == LogLevel.Critical)
{
dependencyResolverLogger.LogCritical(exception, message);
}
});
});
}

public ScriptContext CreateScriptContext(ScriptOptions scriptOptions)
public ScriptContext CreateScriptContext(ScriptOptions scriptOptions, string[] allCsxFiles)
{
var currentDomainAssemblies = AppDomain.CurrentDomain.GetAssemblies();

Expand All @@ -67,7 +86,7 @@ public ScriptContext CreateScriptContext(ScriptOptions scriptOptions)
try
{
_logger.LogInformation($"Searching for compilation dependencies with the fallback framework of '{scriptOptions.DefaultTargetFramework}'.");
compilationDependencies = _compilationDependencyResolver.GetDependencies(_env.TargetDirectory, scriptOptions.IsNugetEnabled(), scriptOptions.DefaultTargetFramework).ToArray();
compilationDependencies = _compilationDependencyResolver.GetDependencies(_env.TargetDirectory, allCsxFiles, scriptOptions.IsNugetEnabled(), scriptOptions.DefaultTargetFramework).ToArray();
}
catch (Exception e)
{
Expand All @@ -92,7 +111,13 @@ public ScriptContext CreateScriptContext(ScriptOptions scriptOptions)
isDesktopClr = false;
HashSet<string> loadedFiles = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

foreach (var compilationAssembly in compilationDependencies.SelectMany(cd => cd.AssemblyPaths).Distinct())
// Pick the highest version
var resolvedAssemblyPaths = compilationDependencies.SelectMany(cd => cd.AssemblyPaths)
.Select(path => new { AssemblyName = AssemblyName.GetAssemblyName(path), Path = path }).Distinct()
.GroupBy(nameAndPath => nameAndPath.AssemblyName.Name, nameAndPath => nameAndPath)
.Select(gr => gr.OrderBy(nameAndPath => nameAndPath.AssemblyName.Version).Last()).Select(nameAndPath => nameAndPath.Path);

foreach (var compilationAssembly in resolvedAssemblyPaths)
{
if (loadedFiles.Add(Path.GetFileName(compilationAssembly)))
{
Expand Down
25 changes: 24 additions & 1 deletion src/OmniSharp.Script/ScriptOptions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
using System.IO;
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.CodeAnalysis;

namespace OmniSharp.Script
{
public class ScriptOptions
{
private Lazy<Dictionary<string, ReportDiagnostic>> _nullableDiagnostics;

public ScriptOptions()
{
_nullableDiagnostics = new Lazy<Dictionary<string, ReportDiagnostic>>(CreateNullableDiagnostics);
}

private Dictionary<string, ReportDiagnostic> CreateNullableDiagnostics()
{
var nullableDiagnostics = new Dictionary<string, ReportDiagnostic>();
for (var i = 8600; i <= 8655; i++)
{
nullableDiagnostics.Add($"CS{i}", ReportDiagnostic.Error);
}

return nullableDiagnostics;
}

public bool EnableScriptNuGetReferences { get; set; }

public string DefaultTargetFramework { get; set; } = "net461";
Expand All @@ -24,5 +45,7 @@ public string GetNormalizedRspFilePath(IOmniSharpEnvironment env)
? RspFilePath
: Path.Combine(env.TargetDirectory, RspFilePath);
}

public Dictionary<string, ReportDiagnostic> NullableDiagnostics => _nullableDiagnostics.Value;
}
}
13 changes: 9 additions & 4 deletions src/OmniSharp.Script/ScriptProjectProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private CSharpCommandLineArguments CreateCommandLineArguments()
_isDesktopClr ? Path.GetDirectoryName(typeof(object).GetTypeInfo().Assembly.ManifestModule.FullyQualifiedName) : null);
}
}

return null;
}

Expand All @@ -100,6 +100,11 @@ private CSharpCompilationOptions CreateCompilationOptions()
.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default)
.WithSpecificDiagnosticOptions(CompilationOptionsHelper.GetDefaultSuppressedDiagnosticOptions());

if (_scriptOptions.IsNugetEnabled())
{
compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(_scriptOptions.NullableDiagnostics);
}

var topLevelBinderFlagsProperty = typeof(CSharpCompilationOptions).GetProperty(TopLevelBinderFlagsProperty, BindingFlags.Instance | BindingFlags.NonPublic);
var binderFlagsType = typeof(CSharpCompilationOptions).GetTypeInfo().Assembly.GetType(BinderFlagsType);

Expand All @@ -124,18 +129,18 @@ private CachingScriptMetadataResolver CreateMetadataReferenceResolver()
InjectXMLDocumentationProviderIntoRuntimeMetadataReferenceResolver(defaultResolver);

var decoratedResolver = _scriptOptions.EnableScriptNuGetReferences
? new CachingScriptMetadataResolver(new NuGetMetadataReferenceResolver(defaultResolver))
? new CachingScriptMetadataResolver(new NuGetMetadataReferenceResolver(defaultResolver))
: new CachingScriptMetadataResolver(defaultResolver);

return decoratedResolver;
}

public ProjectInfo CreateProject(string csxFileName, IEnumerable<MetadataReference> references, string csxFilePath, Type globalsType, IEnumerable<string> namespaces = null)
{
var csharpCommandLineArguments = _commandLineArgs.Value;

// if RSP file was used, include the metadata references from RSP merged with the provided set
// otherwise just use the provided metadata references
// otherwise just use the provided metadata references
if (csharpCommandLineArguments != null && csharpCommandLineArguments.MetadataReferences.Any())
{
var resolvedRspReferences = csharpCommandLineArguments.ResolveMetadataReferences(_compilationOptions.Value.MetadataReferenceResolver);
Expand Down
22 changes: 12 additions & 10 deletions src/OmniSharp.Script/ScriptProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ public void Initalize(IConfiguration configuration)
if (Initialized) return;

_scriptOptions = new ScriptOptions();
ConfigurationBinder.Bind(configuration, _scriptOptions);

_scriptContext = new Lazy<ScriptContext>(() => _scriptContextProvider.CreateScriptContext(_scriptOptions));
ConfigurationBinder.Bind(configuration, _scriptOptions);

_logger.LogInformation($"Detecting CSX files in '{_env.TargetDirectory}'.");

// Nothing to do if there are no CSX files
var allCsxFiles = _fileSystemHelper.GetFiles("**/*.csx").ToArray();

_scriptContext = new Lazy<ScriptContext>(() => _scriptContextProvider.CreateScriptContext(_scriptOptions, allCsxFiles));

if (allCsxFiles.Length == 0)
{
_logger.LogInformation("Could not find any CSX files");
Expand Down Expand Up @@ -110,14 +112,14 @@ private void AddToWorkspace(string csxPath)
var csxFileName = Path.GetFileName(csxPath);
var project = _scriptContext.Value.ScriptProjectProvider.CreateProject(csxFileName, _scriptContext.Value.MetadataReferences, csxPath, _scriptContext.Value.GlobalsType);

if (_scriptOptions.IsNugetEnabled())
{
var scriptMap = _scriptContext.Value.CompilationDependencies.ToDictionary(rdt => rdt.Name, rdt => rdt.Scripts);
var options = project.CompilationOptions.WithSourceReferenceResolver(
new NuGetSourceReferenceResolver(ScriptSourceResolver.Default,
scriptMap));
project = project.WithCompilationOptions(options);
}
if (_scriptOptions.IsNugetEnabled())
{
var scriptMap = _scriptContext.Value.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);
Expand Down
1 change: 1 addition & 0 deletions tests/OmniSharp.Roslyn.CSharp.Tests/GoToDefinitionFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ private async Task TestGoToMetadataAsync(TestFile testFile, string expectedAssem
var response = await GetResponseAsync(new[] { testFile }, wantMetadata: true);

Assert.NotNull(response.MetadataSource);
Assert.False(response.IsEmpty);
Assert.Equal(expectedAssemblyName, response.MetadataSource.AssemblyName);
Assert.Equal(expectedTypeName, response.MetadataSource.TypeName);

Expand Down

0 comments on commit 79d7cdc

Please sign in to comment.