This repository has been archived by the owner on Oct 4, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6228 from mono/master-issue6061
Fixes issue #6061 Add using writes the wrong reference down for a
- Loading branch information
Showing
16 changed files
with
632 additions
and
22 deletions.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
...re/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/MonoDevelopFrameworkAssemblyPathResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// | ||
// MonoDevelopFrameworkAssemblyPathResolver.cs | ||
// | ||
// Author: | ||
// Mike Krüger <mikkrg@microsoft.com> | ||
// | ||
// Copyright (c) 2018 Microsoft Corporation. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
using System; | ||
using System.Composition; | ||
using System.IO; | ||
using System.Reflection; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Host; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
using MonoDevelop.Core; | ||
using MonoDevelop.Core.Assemblies; | ||
using MonoDevelop.Projects; | ||
|
||
namespace MonoDevelop.Ide.TypeSystem | ||
{ | ||
[ExportWorkspaceServiceFactory (typeof (IFrameworkAssemblyPathResolver), ServiceLayer.Host), Shared] | ||
class MonoDevelopFrameworkAssemblyPathResolverFactory : IWorkspaceServiceFactory | ||
{ | ||
public IWorkspaceService CreateService (HostWorkspaceServices workspaceServices) | ||
{ | ||
return new MonoDevelopFrameworkAssemblyPathResolver (workspaceServices.Workspace as MonoDevelopWorkspace); | ||
} | ||
|
||
class MonoDevelopFrameworkAssemblyPathResolver : IFrameworkAssemblyPathResolver | ||
{ | ||
readonly MonoDevelopWorkspace workspace; | ||
public MonoDevelopFrameworkAssemblyPathResolver (MonoDevelopWorkspace workspace) | ||
{ | ||
this.workspace = workspace; | ||
} | ||
|
||
public string ResolveAssemblyPath (ProjectId projectId, string assemblyName, string fullyQualifiedName = null) | ||
{ | ||
if (workspace == null) | ||
return null; | ||
|
||
if (!(workspace.GetMonoProject (projectId) is DotNetProject monoProject)) | ||
return null; | ||
|
||
string assemblyFile = monoProject.AssemblyContext.GetAssemblyLocation (assemblyName, monoProject.TargetFramework); | ||
if (assemblyFile != null) { | ||
//if (string.IsNullOrEmpty(fullyQualifiedName) || CanResolveType(ResolveAssembly (projectId, assemblyName), fullyQualifiedName)) | ||
return assemblyFile; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
//static bool CanResolveType (Assembly assembly, string fullyQualifiedTypeName) | ||
//{ | ||
// if (fullyQualifiedTypeName == null) { | ||
// // nothing to resolve. | ||
// return true; | ||
// } | ||
|
||
// // We only get a type name without generic indicators. So try to few different | ||
// // generic versions of the type name in case any of those hit. it's highly | ||
// // unlikely we'd find something with more than 4 generic parameters, so only try | ||
// // up that point. | ||
// for (var i = 0; i < 5; i++) { | ||
// var name = i == 0 | ||
// ? fullyQualifiedTypeName | ||
// : fullyQualifiedTypeName + "`" + i; | ||
|
||
// try { | ||
// var type = assembly.GetType (name, throwOnError: false); | ||
// if (type != null) { | ||
// return true; | ||
// } | ||
// } catch (FileNotFoundException) { | ||
// } catch (FileLoadException) { | ||
// } catch (BadImageFormatException) { | ||
// } | ||
// } | ||
// return false; | ||
//} | ||
|
||
//Assembly ResolveAssembly (ProjectId projectId, string assemblyLocation) | ||
//{ | ||
// Runtime.AssertMainThread (); | ||
|
||
// try { | ||
// return Assembly.LoadFrom (assemblyLocation); | ||
// } catch (Exception e) { | ||
// // Something wrong with our TFM. We don't have enough information to | ||
// // properly resolve this assembly name. | ||
// LoggingService.LogError ("Error while resolving assembly assemblyName"); | ||
// return null; | ||
// } | ||
//} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...ts/MonoDevelop.Ide.RoslynServices/MonoDevelopFrameworkAssemblyPathResolverFactoryTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// MonoDevelopFrameworkAssemblyPathResolverFactoryTests.cs | ||
// | ||
// Author: | ||
// Mike Krüger <mikkrg@microsoft.com> | ||
// | ||
// Copyright (c) 2018 Microsoft Corporation. All rights reserved. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Microsoft.CodeAnalysis.Notification; | ||
using Microsoft.CodeAnalysis.Options; | ||
using MonoDevelop.Ide.Composition; | ||
using Microsoft.CodeAnalysis.Host; | ||
|
||
namespace MonoDevelop.Ide.RoslynServices | ||
{ | ||
[TestFixture] | ||
public class MonoDevelopFrameworkAssemblyPathResolverFactoryTests : TextEditorExtensionTestBase | ||
{ | ||
protected override EditorExtensionTestData GetContentData () => EditorExtensionTestData.CSharp; | ||
|
||
[Test] | ||
public async Task ServiceIsRegistered () | ||
{ | ||
using (var testCase = await SetupTestCase ("class MyTest {}")) { | ||
var doc = testCase.Document; | ||
|
||
var service = doc.RoslynWorkspace.Services.GetService<IFrameworkAssemblyPathResolver> (); | ||
Assert.IsNotNull (service); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task TestSimpleCase () | ||
{ | ||
using (var testCase = await SetupTestCase ("class MyTest {}")) { | ||
var doc = testCase.Document; | ||
|
||
var service = doc.RoslynWorkspace.Services.GetService<IFrameworkAssemblyPathResolver> (); | ||
string path = service.ResolveAssemblyPath (doc.AnalysisDocument.Project.Id, "System"); | ||
Assert.IsNotNull (path); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.