Skip to content

Commit

Permalink
Merge branch 'master' into fix/1340
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyasantoss authored Jan 22, 2019
2 parents cb9f8d2 + 8caf8de commit 6e32721
Show file tree
Hide file tree
Showing 35 changed files with 504 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mono: latest
os:
- linux
- osx
osx_image: xcode9.2
osx_image: xcode9.4
script:
- git fetch --unshallow
- git fetch origin '+refs/heads/*:refs/heads/*'
Expand Down Expand Up @@ -48,6 +48,7 @@ install:
sudo ldconfig
elif [ "$TRAVIS_OS_NAME" == "osx" ]; then
# On OSX, we install libuv via Homebrew
brew update
brew install libuv
fi
- export PATH="$PWD/.dotnet:$PATH"
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
All changes to the project will be documented in this file.

## [1.32.9] - not yet released
* Updated to Roslyn 2.10.0 (PR: [#1344](https://github.com/OmniSharp/omnisharp-roslyn/pull/1344))
* Updated to Roslyn `2.11.0-beta1-final` and initial support for C# 8 (PR: [#1365](https://github.com/OmniSharp/omnisharp-roslyn/pull/1365))
* Incorporate *IndentSwitchCaseSectionWhenBlock* into OmniSharp's formatting options. This fixes the default formatting behavior, as the setting is set to *true* by default, and still allows users to disable it if needed. ([#1351](https://github.com/OmniSharp/omnisharp-roslyn/issues/1351), PR: [#1353](https://github.com/OmniSharp/omnisharp-roslyn/pull/1353))
* Removed unused `-stdio` flag from the `StdioCommandLineApplication` (PR: [#1362](https://github.com/OmniSharp/omnisharp-roslyn/pull/1362))

This comment has been minimized.

Copy link
@dmgonch

dmgonch Jan 27, 2019

Contributor

@johnnyasantoss Hi! I just wanted to bring to your attention issue #1392 caused by this change since C# extension is still being passed the argument to OmniSharp (https://github.com/OmniSharp/omnisharp-vscode/blob/b2581f68d8f754287640ec2050e1ada53a5594e6/src/omnisharp/server.ts#L297).

This comment has been minimized.

Copy link
@johnnyasantoss

johnnyasantoss Jan 29, 2019

Author Contributor

Hello :)
I think that this is not related to my PR 😅

What it does is change the way that OmniSharp selects a MSBuild instance.

* Fixed finding references to operator overloads _(Contributed by [@SirIntruder](https://github.com/SirIntruder))_ (PR: [#1371](https://github.com/OmniSharp/omnisharp-roslyn/pull/1371))

## [1.32.8] - 2018-11-14
* Fixed MSBuild discovery path (1.32.7 regression) (PR: [#1337](https://github.com/OmniSharp/omnisharp-roslyn/pull/1337))
Expand Down
33 changes: 33 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,12 @@ void CopyMonoBuild(BuildEnvironment env, string sourceFolder, string outputFolde
DeleteUnnecessaryAssemblies(outputFolder);
}

void CopyExtraDependencies(BuildEnvironment env, string outputFolder)
{
// copy license
FileHelper.Copy(CombinePaths(env.WorkingDirectory, "license.md"), CombinePaths(outputFolder, "license.md"), overwrite: true);
}

string PublishMonoBuild(string project, BuildEnvironment env, BuildPlan plan, string configuration)
{
Information($"Publishing Mono build for {project}...");
Expand All @@ -695,8 +701,31 @@ string PublishMonoBuild(string project, BuildEnvironment env, BuildPlan plan, st

CopyMonoBuild(env, buildFolder, outputFolder);

CopyExtraDependencies(env, outputFolder);

Package(project, "mono", outputFolder, env.Folders.ArtifactsPackage, env.Folders.DeploymentPackage);

// Copy dependencies of Mono build
FileHelper.Copy(
source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.core", "lib", "net45", "SQLitePCLRaw.core.dll"),
destination: CombinePaths(outputFolder, "SQLitePCLRaw.core.dll"),
overwrite: true);

FileHelper.Copy(
source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.provider.e_sqlite3.net45", "lib", "net45", "SQLitePCLRaw.provider.e_sqlite3.dll"),
destination: CombinePaths(outputFolder, "SQLitePCLRaw.provider.e_sqlite3.dll"),
overwrite: true);

FileHelper.Copy(
source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.bundle_green", "lib", "net45", "SQLitePCLRaw.batteries_v2.dll"),
destination: CombinePaths(outputFolder, "SQLitePCLRaw.batteries_v2.dll"),
overwrite: true);

FileHelper.Copy(
source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.bundle_green", "lib", "net45", "SQLitePCLRaw.batteries_green.dll"),
destination: CombinePaths(outputFolder, "SQLitePCLRaw.batteries_green.dll"),
overwrite: true);

return outputFolder;
}

Expand All @@ -716,6 +745,8 @@ string PublishMonoBuildForPlatform(string project, MonoRuntime monoRuntime, Buil

CopyMonoBuild(env, sourceFolder, omnisharpFolder);

CopyExtraDependencies(env, outputFolder);

Package(project, monoRuntime.PlatformName, outputFolder, env.Folders.ArtifactsPackage, env.Folders.DeploymentPackage);

return outputFolder;
Expand Down Expand Up @@ -776,6 +807,8 @@ string PublishWindowsBuild(string project, BuildEnvironment env, BuildPlan plan,
// Copy MSBuild to output
DirectoryHelper.Copy($"{env.Folders.MSBuild}", CombinePaths(outputFolder, "msbuild"));

CopyExtraDependencies(env, outputFolder);

Package(project, rid, outputFolder, env.Folders.ArtifactsPackage, env.Folders.DeploymentPackage);

return outputFolder;
Expand Down
4 changes: 3 additions & 1 deletion build/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<MSBuildPackageVersion>15.8.166</MSBuildPackageVersion>
<NuGetPackageVersion>4.8.0</NuGetPackageVersion>
<RoslynPackageVersion>2.10.0</RoslynPackageVersion>
<RoslynPackageVersion>2.11.0-beta1-final</RoslynPackageVersion>
<XunitPackageVersion>2.4.0</XunitPackageVersion>
</PropertyGroup>

Expand Down Expand Up @@ -60,7 +60,9 @@
<PackageReference Update="Nuget.ProjectModel" Version="$(NuGetPackageVersion)" />
<PackageReference Update="Nuget.Versioning" Version="$(NuGetPackageVersion)" />

<PackageReference Update="SQLitePCLRaw.bundle_green" Version="1.1.2" />
<PackageReference Update="System.Collections.Immutable" Version="1.4.0" />
<PackageReference Update="System.ComponentModel.Composition" Version="4.5.0" />
<PackageReference Update="System.Composition" Version="1.0.31" />
<PackageReference Update="System.Reflection.Metadata" Version="1.4.2" />
<PackageReference Update="System.Threading.Tasks.Dataflow" Version="4.5.24" />
Expand Down
2 changes: 1 addition & 1 deletion src/OmniSharp.Abstractions/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ internal static class Configuration
{
public static bool ZeroBasedIndices = false;

public const string RoslynVersion = "2.10.0.0";
public const string RoslynVersion = "2.11.0.0";
public const string RoslynPublicKeyToken = "31bf3856ad364e35";

public readonly static string RoslynFeatures = GetRoslynAssemblyFullName("Microsoft.CodeAnalysis.Features");
Expand Down
1 change: 1 addition & 0 deletions src/OmniSharp.Host/OmniSharp.Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.SDK.EmbedInteropTypes" PrivateAssets="all" />
<PackageReference Include="SQLitePCLRaw.bundle_green" PrivateAssets="all" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions src/OmniSharp.Http.Driver/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.10.0.0" newVersion="2.10.0.0"/>
<bindingRedirect oldVersion="0.0.0.0-2.11.0.0" newVersion="2.11.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.10.0.0" newVersion="2.10.0.0"/>
<bindingRedirect oldVersion="0.0.0.0-2.11.0.0" newVersion="2.11.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.10.0.0" newVersion="2.10.0.0"/>
<bindingRedirect oldVersion="0.0.0.0-2.11.0.0" newVersion="2.11.0.0"/>
</dependentAssembly>

<dependentAssembly>
Expand Down
6 changes: 6 additions & 0 deletions src/OmniSharp.MSBuild/Options/MSBuildOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ internal class MSBuildOptions
public string Platform { get; set; }
public bool EnablePackageAutoRestore { get; set; }

/// <summary>
/// If true, MSBuild project system will only be loading projects for files that were opened in the editor
/// as well as referenced projects, recursively.
/// </summary>
public bool LoadProjectsOnDemand { get; set; }

/// <summary>
/// When set to true, the MSBuild project system will attempt to resolve the path to the MSBuild
/// SDKs for a project by running 'dotnet --info' and retrieving the path. This is only needed
Expand Down
1 change: 1 addition & 0 deletions src/OmniSharp.MSBuild/ProjectFile/PropertyConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static LanguageVersion ToLanguageVersion(string propertyValue)
case "7.1": return LanguageVersion.CSharp7_1;
case "7.2": return LanguageVersion.CSharp7_2;
case "7.3": return LanguageVersion.CSharp7_3;
case "8.0": return LanguageVersion.CSharp8;
default: return LanguageVersion.Default;
}
}
Expand Down
60 changes: 57 additions & 3 deletions src/OmniSharp.MSBuild/ProjectManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
Expand All @@ -17,6 +18,7 @@
using OmniSharp.MSBuild.Models.Events;
using OmniSharp.MSBuild.Notification;
using OmniSharp.MSBuild.ProjectFile;
using OmniSharp.Options;
using OmniSharp.Roslyn.Utilities;
using OmniSharp.Services;
using OmniSharp.Utilities;
Expand All @@ -39,12 +41,14 @@ public ProjectToUpdate(string filePath, bool allowAutoRestore)
}

private readonly ILogger _logger;
private readonly MSBuildOptions _options;
private readonly IEventEmitter _eventEmitter;
private readonly IFileSystemWatcher _fileSystemWatcher;
private readonly MetadataFileReferenceCache _metadataFileReferenceCache;
private readonly PackageDependencyChecker _packageDependencyChecker;
private readonly ProjectFileInfoCollection _projectFiles;
private readonly HashSet<string> _failedToLoadProjectFiles;
private readonly ConcurrentDictionary<string, int/*unused*/> _projectsRequestedOnDemand;
private readonly ProjectLoader _projectLoader;
private readonly OmniSharpWorkspace _workspace;
private readonly ImmutableArray<IMSBuildEventSink> _eventSinks;
Expand All @@ -57,15 +61,25 @@ public ProjectToUpdate(string filePath, bool allowAutoRestore)

private readonly FileSystemNotificationCallback _onDirectoryFileChanged;

public ProjectManager(ILoggerFactory loggerFactory, IEventEmitter eventEmitter, IFileSystemWatcher fileSystemWatcher, MetadataFileReferenceCache metadataFileReferenceCache, PackageDependencyChecker packageDependencyChecker, ProjectLoader projectLoader, OmniSharpWorkspace workspace, ImmutableArray<IMSBuildEventSink> eventSinks)
public ProjectManager(ILoggerFactory loggerFactory,
MSBuildOptions options,
IEventEmitter eventEmitter,
IFileSystemWatcher fileSystemWatcher,
MetadataFileReferenceCache metadataFileReferenceCache,
PackageDependencyChecker packageDependencyChecker,
ProjectLoader projectLoader,
OmniSharpWorkspace workspace,
ImmutableArray<IMSBuildEventSink> eventSinks)
{
_logger = loggerFactory.CreateLogger<ProjectManager>();
_options = options ?? new MSBuildOptions();
_eventEmitter = eventEmitter;
_fileSystemWatcher = fileSystemWatcher;
_metadataFileReferenceCache = metadataFileReferenceCache;
_packageDependencyChecker = packageDependencyChecker;
_projectFiles = new ProjectFileInfoCollection();
_failedToLoadProjectFiles = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
_projectsRequestedOnDemand = new ConcurrentDictionary<string, int>(StringComparer.OrdinalIgnoreCase);
_projectLoader = projectLoader;
_workspace = workspace;
_eventSinks = eventSinks;
Expand All @@ -75,6 +89,46 @@ public ProjectManager(ILoggerFactory loggerFactory, IEventEmitter eventEmitter,
_processLoopTask = Task.Run(() => ProcessLoopAsync(_processLoopCancellation.Token));

_onDirectoryFileChanged = OnDirectoryFileChanged;

if (_options.LoadProjectsOnDemand)
{
_workspace.AddWaitForProjectModelReadyHandler(WaitForProjectModelReadyAsync);
}
}

private async Task WaitForProjectModelReadyAsync(string documentPath)
{
// Search and queue for loading C# projects that are likely to reference the requested file.
// C# source files are located pretty much always in the same folder with their project file or in a subfolder below.
// Search up the root folder to enable on-demand project load in additional scenarios like the following:
// - A subfolder in a big codebase was opened in VSCode and then a document was opened that is located outside of the subfoler.
// - A workspace was opened in VSCode that includes multiple subfolders from a big codebase.
// - Documents from different codebases are opened in the same VSCode workspace.
string projectDir = Path.GetDirectoryName(documentPath);
do
{
var csProjFiles = Directory.EnumerateFiles(projectDir, "*.csproj", SearchOption.TopDirectoryOnly).ToList();
if (csProjFiles.Count > 0)
{
foreach(string csProjFile in csProjFiles)
{
if (_projectsRequestedOnDemand.TryAdd(csProjFile, 0 /*unused*/))
{
QueueProjectUpdate(csProjFile, allowAutoRestore:true);
}
}

break;
}

projectDir = Path.GetDirectoryName(projectDir);
} while(projectDir != null);

// Wait for all queued projects to load to ensure that workspace is fully up to date before this method completes.
// If the project for the document was loaded before and there are no other projects to load at the moment, the call below will be no-op.
_logger.LogTrace($"Started waiting for projects queue to be empty when requested '{documentPath}'");
await WaitForQueueEmptyAsync();
_logger.LogTrace($"Stopped waiting for projects queue to be empty when requested '{documentPath}'");
}

protected override void DisposeCore(bool disposing)
Expand Down Expand Up @@ -221,6 +275,8 @@ private void ProcessQueue(CancellationToken cancellationToken)
{
_processingQueue = false;
}

_fileSystemWatcher.Watch(".cs", _onDirectoryFileChanged);
}

private (ProjectFileInfo, ProjectLoadedEventArgs) LoadProject(string projectFilePath)
Expand Down Expand Up @@ -367,8 +423,6 @@ private void UpdateSourceFiles(Project project, IList<string> sourceFiles)
// Add source files to the project.
foreach (var sourceFile in sourceFiles)
{
_fileSystemWatcher.Watch(Path.GetDirectoryName(sourceFile), _onDirectoryFileChanged);

// If a document for this source file already exists in the project, carry on.
if (currentDocuments.Remove(sourceFile))
{
Expand Down
9 changes: 8 additions & 1 deletion src/OmniSharp.MSBuild/ProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ public void Initalize(IConfiguration configuration)

_packageDependencyChecker = new PackageDependencyChecker(_loggerFactory, _eventEmitter, _dotNetCli, _options);
_loader = new ProjectLoader(_options, _environment.TargetDirectory, _propertyOverrides, _loggerFactory, _sdksPathResolver);
_manager = new ProjectManager(_loggerFactory, _eventEmitter, _fileSystemWatcher, _metadataFileReferenceCache, _packageDependencyChecker, _loader, _workspace, _eventSinks);
_manager = new ProjectManager(_loggerFactory, _options, _eventEmitter, _fileSystemWatcher, _metadataFileReferenceCache, _packageDependencyChecker,
_loader, _workspace, _eventSinks);

if (_options.LoadProjectsOnDemand)
{
_logger.LogInformation($"Skip loading projects listed in solution file or under target directory because {Key}:{nameof(MSBuildOptions.LoadProjectsOnDemand)} is true.");
return;
}

var initialProjectPaths = GetInitialProjectPaths();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public CodeCheckService(OmniSharpWorkspace workspace)
public async Task<QuickFixResponse> Handle(CodeCheckRequest request)
{
var documents = request.FileName != null
? _workspace.GetDocuments(request.FileName)
// To properly handle the request wait until all projects are loaded.
? await _workspace.GetDocumentsFromFullProjectModelAsync(request.FileName)
: _workspace.CurrentSolution.Projects.SelectMany(project => project.Documents);

var quickFixes = await documents.FindDiagnosticLocationsAsync(_workspace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public FindUsagesService(OmniSharpWorkspace workspace)

public async Task<QuickFixResponse> Handle(FindUsagesRequest request)
{
var document = _workspace.GetDocument(request.FileName);
// To produce complete list of usages for symbols in the document wait until all projects are loaded.
var document = await _workspace.GetDocumentFromFullProjectModelAsync(request.FileName);
var response = new QuickFixResponse();
if (document != null)
{
Expand All @@ -39,8 +40,10 @@ public async Task<QuickFixResponse> Handle(FindUsagesRequest request)
var usages = request.OnlyThisFile
? await SymbolFinder.FindReferencesAsync(definition ?? symbol, _workspace.CurrentSolution, ImmutableHashSet.Create(document))
: await SymbolFinder.FindReferencesAsync(definition ?? symbol, _workspace.CurrentSolution);
var dontRequireReferenceByName = symbol is IMethodSymbol method &&
(method.MethodKind == MethodKind.Constructor || method.MethodKind == MethodKind.UserDefinedOperator);

foreach (var usage in usages.Where(u => u.Definition.CanBeReferencedByName || (symbol as IMethodSymbol)?.MethodKind == MethodKind.Constructor))
foreach (var usage in usages.Where(u => u.Definition.CanBeReferencedByName || dontRequireReferenceByName))
{
foreach (var location in usage.Locations)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ protected BaseCodeActionService(OmniSharpWorkspace workspace, CodeActionHelper h

protected async Task<IEnumerable<AvailableCodeAction>> GetAvailableCodeActions(ICodeActionRequest request)
{
var document = this.Workspace.GetDocument(request.FileName);
// To produce a complete list of code actions for the document wait until all projects are loaded.
var document = await this.Workspace.GetDocumentFromFullProjectModelAsync(request.FileName);
if (document == null)
{
return Array.Empty<AvailableCodeAction>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ public BlockStructureService(IAssemblyLoader loader, OmniSharpWorkspace workspac

public async Task<BlockStructureResponse> Handle(BlockStructureRequest request)
{
var document = _workspace.GetDocument(request.FileName);
// To provide complete code structure for the document wait until all projects are loaded.
var document = await _workspace.GetDocumentFromFullProjectModelAsync(request.FileName);
if (document == null)
{
return null;
}

var text = await document.GetTextAsync();

var service = _blockStructureService.LazyGetMethod("GetService").InvokeStatic(new[] { document });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public CodeStructureService(

public async Task<CodeStructureResponse> Handle(CodeStructureRequest request)
{
var document = _workspace.GetDocument(request.FileName);
// To provide complete code structure for the document wait until all projects are loaded.
var document = await _workspace.GetDocumentFromFullProjectModelAsync(request.FileName);
if (document == null)
{
return null;
Expand Down
Loading

0 comments on commit 6e32721

Please sign in to comment.