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

Roslyn analyzers and code fixes #1076

Merged
merged 245 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from 219 commits
Commits
Show all changes
245 commits
Select commit Hold shift + click to select a range
b42ac37
Moved initial logig to fork.
savpek Dec 25, 2017
d2f872f
Version with 'by project' results.
savpek Dec 25, 2017
d366b61
Now analyzers run for all projects after startup.
savpek Dec 25, 2017
b374a3f
Small refactorings.
savpek Dec 25, 2017
6ce7e66
Small refactoring.
savpek Dec 25, 2017
cc8f251
Refactored analyzers to providers.
savpek Dec 26, 2017
978fbdd
Refactored compilation as single solution bound (review fix).
savpek Jan 5, 2018
80801ed
Undoed accidental change.
savpek Jan 5, 2018
3ec70fd
Merge branch 'master' into roslyn-analyzers
savpek Jan 11, 2018
1bbd78e
Merge branch 'master' into roslyn-analyzers
savpek Jan 13, 2018
e168896
Merge branch 'master' into roslyn-analyzers
savpek Jan 26, 2018
e3ad473
Merge branch 'master' into roslyn-analyzers
savpek Feb 8, 2018
23e47ee
Merge branch 'master' into roslyn-analyzers
savpek Jul 22, 2018
4976660
Before debugging strange type error.
savpek Jul 22, 2018
86d197a
Simple first working version.
savpek Jul 22, 2018
544aec8
Cleanup.
savpek Jul 22, 2018
dc527fb
Implemented loading from project analyzer references.
savpek Jul 22, 2018
68fef87
Cleanup.
savpek Jul 22, 2018
e11d11b
Small lazy invocation tweak.
savpek Jul 22, 2018
9070f09
Updated cacellation token handling and way how invalid analyzer ref i…
savpek Jul 24, 2018
5adf1a1
Tweaked assembly discovery algorithm for analyzers.
savpek Jul 24, 2018
1d79739
Initial tests for analyzers.
savpek Jul 25, 2018
fa2721e
Testfix.
savpek Jul 25, 2018
21c670c
Improved tests.
savpek Jul 25, 2018
7ec5cf0
Throtling to avoid certain issues with error reporting.
savpek Jul 25, 2018
f0b4e2a
Merge branch 'master' into roslyn-analyzers
savpek Jul 25, 2018
a8e388a
Testfix.
savpek Jul 25, 2018
177c41b
Attempt to fix hanging cake tests on travis
savpek Jul 26, 2018
2d0c255
Refactored diagnostic service.
savpek Jul 28, 2018
1e607cc
Tweaks.
savpek Jul 29, 2018
21f91c3
Refactoring and tweaks.
savpek Jul 29, 2018
b60d5b0
Added support for remove unnecessary usings.
savpek Jul 29, 2018
8cc9ad2
Implemented code fixes support by project analyzer references.
savpek Jul 29, 2018
bfe05ad
Made semantic analysis result distinct.
savpek Jul 30, 2018
371271d
Update to distinct algorithm.
savpek Jul 30, 2018
7ed7702
Improved version but still has issues with larger projects.
savpek Jul 30, 2018
b51d8f5
Fixes for larger project (like omnisharp).
savpek Jul 30, 2018
51d0048
Testfixes and grouping support on code check service.
savpek Jul 30, 2018
3989685
Testfixes.
savpek Jul 30, 2018
4986456
Small naming fix.
savpek Jul 31, 2018
8511611
Implemented first version of project rulesets.
savpek Jul 31, 2018
a62fdc0
Implemented test for testrules.
savpek Jul 31, 2018
786cbab
Implemented another test for rulesets.
savpek Jul 31, 2018
bc6c9ef
Tweaks for analyzer responsivity.
savpek Jul 31, 2018
1297a62
Ooppss...
savpek Jul 31, 2018
44f79ab
Improved analysis threading.
savpek Aug 1, 2018
19ee0ea
Cleanup.
savpek Aug 1, 2018
9e83c60
User experience and test tweaks.
savpek Aug 1, 2018
b32b04d
Implemented final tests for rules.
savpek Aug 2, 2018
4844226
Undo for accidentally pushed change.
savpek Aug 2, 2018
7ae79b0
Fixed test.
savpek Aug 2, 2018
a06ddb6
Refactored tests.
savpek Aug 5, 2018
0db9e4f
Merge branch 'master' into roslyn-analyzers
savpek Aug 6, 2018
f10fa7b
Review fixes expect assembly loader from DI.
savpek Aug 8, 2018
910a365
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Aug 8, 2018
f4b829c
Sorted usings.
savpek Aug 8, 2018
00da2a9
DI fixes, theres currently issue during runtime however.
savpek Aug 8, 2018
405b2bd
Merge branch 'master' into roslyn-analyzers
savpek Aug 8, 2018
014865a
Implemented missing method.
savpek Aug 8, 2018
2dc672c
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Aug 8, 2018
b0242ce
Some testfixes, however theres changes from master that require chang…
savpek Aug 8, 2018
bf38248
Fix that is required for cake project system to work with diagnostics.
savpek Aug 9, 2018
9d7e2ae
Removed obsolete hack.
savpek Aug 9, 2018
44949a2
More robust initialization routine.
savpek Aug 10, 2018
b3654d4
Small style tweaks.
savpek Aug 10, 2018
b6210f0
Merge branch 'master' into roslyn-analyzers
savpek Aug 10, 2018
bf9db1c
Removed empty class.
savpek Aug 10, 2018
74b6046
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Aug 10, 2018
636a02f
Merge branch 'master' into roslyn-analyzers
savpek Aug 19, 2018
ee18d0f
Some merge fixes.
savpek Aug 19, 2018
bf89628
Fixed mistake in wait routine.
savpek Aug 21, 2018
8594fe8
Small readibility update.
savpek Aug 21, 2018
6575055
Added todo.
savpek Aug 21, 2018
85d424f
Fixed support with misc files.
savpek Aug 21, 2018
871c1d7
Merge branch 'master' into roslyn-analyzers
savpek Aug 24, 2018
32b0c85
Restored null safety.
savpek Aug 24, 2018
2ec0450
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Aug 24, 2018
39e33ec
Fixed mistake.
savpek Aug 24, 2018
65837a9
Merge branch 'master' into roslyn-analyzers
savpek Aug 28, 2018
fa9f660
Review updates, however theres broken csx diagnostic tests still.
savpek Aug 28, 2018
55cf797
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Aug 28, 2018
4233203
Merge branch 'master' into roslyn-analyzers
savpek Aug 29, 2018
e5ef6b3
Fixed custom code actions.
savpek Aug 31, 2018
c5c92f0
Testfixes.
savpek Aug 31, 2018
3aaf770
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Aug 31, 2018
0e59d1b
Merge branch 'master' into roslyn-analyzers
savpek Sep 6, 2018
5b9b265
Small review fixes and simplified assembly loader algorithm.
savpek Sep 9, 2018
902cfe1
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Sep 9, 2018
3e9ec2a
Merge branch 'master' into roslyn-analyzers
savpek Sep 9, 2018
4989125
Mergefix.
savpek Sep 9, 2018
16ef3bb
Fixed changed MiscFile project name.
savpek Sep 10, 2018
2360ee2
Renamed service with better name and fixed missing language for analy…
savpek Sep 10, 2018
ec0e520
Review fixes for code fix provider.
savpek Sep 10, 2018
28a9118
Small tweaks for linq.
savpek Sep 10, 2018
f32c8e7
Immutablity to csharpdiagnostic service.
savpek Sep 10, 2018
abea526
Merge branch 'master' into roslyn-analyzers
savpek Sep 12, 2018
6ff3af8
Merge branch 'master' into roslyn-analyzers
savpek Sep 13, 2018
b33dd60
Comment to explain non self descriptive initial wait.
savpek Sep 14, 2018
d4e7a6e
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Sep 14, 2018
51359b4
Support for roslyn 'IDE' analyzers.
savpek Sep 16, 2018
862d8de
Testfixes and added test that IDE analyzers are enabled.
savpek Sep 23, 2018
f64738d
Better comment on code based on review.
savpek Sep 23, 2018
e761e87
Merge branch 'master' into roslyn-analyzers
savpek Sep 23, 2018
9c25d64
Testfix for signed project.
savpek Sep 23, 2018
24f08b1
Testfix.
savpek Sep 23, 2018
1c3c989
Small test tweak.
savpek Sep 23, 2018
a0f5258
Buildfix.
savpek Sep 23, 2018
0f41ea5
Merge branch 'master' into roslyn-analyzers
savpek Oct 2, 2018
e25d686
Merge branch 'master' into roslyn-analyzers
savpek Oct 3, 2018
bf154f9
Tweaks for issue where workspace updates comes after request.
savpek Oct 5, 2018
2e10c35
Added assert to protect possibly internal changes of roslyn.
savpek Oct 5, 2018
9028a01
Increased timeout and added comment about asserting.
savpek Oct 5, 2018
41ccefc
Further tweaked timeouts on event mechanism asserts.
savpek Oct 5, 2018
164bae4
Increased another 'assert' timeout.
savpek Oct 5, 2018
02ca6cb
Fix for threading issue in test utility.
savpek Oct 5, 2018
39e3bdc
Trigger to test build stability
savpek Oct 5, 2018
f635588
Trigger to test build stability.
savpek Oct 5, 2018
a6f825b
Trigger to test build stability.
savpek Oct 5, 2018
f210d14
Yet another attempt to get build execute.
savpek Oct 5, 2018
f8cce2d
Trigger build
savpek Oct 5, 2018
dbab30c
Added original caller name tracking for OmnisharpTestHostDisposing.
savpek Oct 5, 2018
be8f23e
Attempt to improve robustness of tests.
savpek Oct 7, 2018
9cca424
Moved tool to test utilities.
savpek Oct 7, 2018
9f64935
Added missing file.
savpek Oct 7, 2018
ffe8e8a
Test build robustnes
savpek Oct 7, 2018
ed82a59
Test build robustnes
savpek Oct 7, 2018
ed29a61
Merge branch 'master' into roslyn-analyzers
savpek Oct 13, 2018
e25e934
Merge branch 'master' into roslyn-analyzers
savpek Oct 17, 2018
c4dfc19
Merge branch 'master' into roslyn-analyzers
savpek Oct 29, 2018
21018b9
Merge branch 'master' into roslyn-analyzers
savpek Nov 2, 2018
c322d46
Fix for possible null ref issue.
savpek Nov 2, 2018
336a799
Fixed mistake on exception handling when using WhenAll.
savpek Nov 2, 2018
acb954f
Trigger build
savpek Nov 2, 2018
a734c16
Merge branch 'master' into roslyn-analyzers
savpek Nov 3, 2018
6aea8d1
Merge branch 'master' into roslyn-analyzers
savpek Nov 3, 2018
eba7ca5
Merge branch 'master' into roslyn-analyzers
savpek Nov 7, 2018
bb93520
Merge branch 'master' into roslyn-analyzers
savpek Nov 9, 2018
c33d8f3
Added fallback code to CodeCheckService, next need to figure out how …
savpek Nov 10, 2018
c34f554
Removed duplicate code.
savpek Nov 10, 2018
c9548f6
Added flag to options.
savpek Nov 10, 2018
42a939a
Use expiremental analysis as default during testing.
savpek Nov 10, 2018
7c7d85a
Disabled CsharpDiagnosticService workers if not enabled.
savpek Nov 10, 2018
3cab565
Buildfix.
savpek Nov 10, 2018
8b538a2
Fix for codefix support when analyzers are disabled.
savpek Nov 10, 2018
de7426e
Updated flag name.
savpek Nov 10, 2018
633555b
Fixed default.
savpek Nov 10, 2018
5295e9b
Merge branch 'master' into roslyn-analyzers
savpek Nov 13, 2018
81d743a
Renamed flag.
savpek Nov 13, 2018
baa2113
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Nov 13, 2018
ffce204
Merge branch 'master' into roslyn-analyzers
savpek Nov 14, 2018
08276f1
Merge branch 'master' into roslyn-analyzers
savpek Nov 15, 2018
b4a656d
Initial structure divide for testability.
savpek Nov 19, 2018
e69334e
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Nov 19, 2018
ee55e0d
Few tests.
savpek Nov 21, 2018
ea54463
More tests for queue functionality.
savpek Nov 25, 2018
047d5ed
Improved functionality to match exceptations.
savpek Nov 25, 2018
6528518
Move towards diagnosis which can be switched by common interface.
savpek Nov 25, 2018
180b979
Refactored ugly if switching of diagnostics behind common class.
savpek Nov 25, 2018
7ad625c
Implementation of api in worker with analyzers.
savpek Nov 26, 2018
8b1b499
Small refactoring.
savpek Nov 26, 2018
5e1ab8c
Added logging when codefix provider cannot be created.
savpek Nov 26, 2018
c8a59ba
Merge branch 'master' into roslyn-analyzers
savpek Dec 4, 2018
4e21965
Merge branch 'master' into roslyn-analyzers
savpek Dec 6, 2018
bb5a896
Moved to more robust time control mechanism.
savpek Dec 6, 2018
b22d717
Throttling period refactoring.
savpek Dec 6, 2018
2d0a7af
Merge branch 'master' into roslyn-analyzers
savpek Dec 13, 2018
6bfb484
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Jan 12, 2019
1f0f347
Merge.
savpek Jan 12, 2019
d8c98fe
Merge branch 'master' into roslyn-analyzers
savpek Jan 17, 2019
d37af46
Small review fix.
savpek Jan 17, 2019
3ebb4fd
Small review update.
savpek Jan 17, 2019
6bd21bb
Typofix.
savpek Jan 17, 2019
4ac48b9
Removed unused member.
savpek Jan 17, 2019
6ce28fc
Testfix.
savpek Jan 18, 2019
eb313dd
Testfix.
savpek Jan 18, 2019
d5b69d2
Restored sdk version to global.json.
savpek Jan 18, 2019
6034988
Added test for multiple thead execution of queue.
savpek Jan 19, 2019
42ec450
Parametrized tests to test both non roslyn analysis and with analysis.
savpek Jan 19, 2019
65c1398
Attempt to remove retry from asserts.
savpek Jan 19, 2019
0384bc7
Removed unused code and restored correct global.json.
savpek Jan 19, 2019
d6b8e8f
File rename.
savpek Jan 22, 2019
f69ffc7
Merge branch 'master' into roslyn-analyzers
savpek Jan 22, 2019
17854f5
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Jan 22, 2019
475bcef
Merge branch 'master' into roslyn-analyzers
savpek Jan 22, 2019
421ef74
Added test to queue facts.
savpek Jan 22, 2019
f074e79
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Jan 22, 2019
80eb9dd
Conditional action facts with and without analyzers.
savpek Jan 27, 2019
afe1ad6
Merge branch 'master' into roslyn-analyzers
savpek Jan 27, 2019
1ee7372
Small refactoring.
savpek Jan 27, 2019
ff9e72b
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Jan 27, 2019
cdb30d0
Merge branch 'master' into roslyn-analyzers
savpek Feb 1, 2019
5e049b1
Merge lsp
savpek Feb 9, 2019
e423278
Fix for lsp merge.
savpek Feb 9, 2019
589512d
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Feb 9, 2019
5e11541
Initial version of single file analysis.
savpek Feb 14, 2019
a3e11d0
Fixes and tweaks for analysis, timeouts and error handling.
savpek Feb 16, 2019
3c8a471
Testfixes.
savpek Feb 16, 2019
242a28b
Testfixes.
savpek Feb 16, 2019
2cd0183
Correct global.json.
savpek Feb 16, 2019
8eeabdf
Reduced clutter from message.
savpek Feb 16, 2019
811cbd9
Build stability testing.
savpek Feb 16, 2019
5dac0aa
Testfix.
savpek Feb 16, 2019
9b4b1f0
Test tweak.
savpek Feb 16, 2019
ad38560
Reattempt with travis builds.
savpek Feb 16, 2019
50f25c5
Threading fix.
savpek Feb 16, 2019
be71dd7
Restored task based version to fix possible deadlock with xunit sched…
savpek Feb 16, 2019
e38e73e
Retest builds.
savpek Feb 17, 2019
b251e24
Added skip to possibly hanging cake tests as test.
savpek Feb 17, 2019
342a140
Skipped more cake tests as test.
savpek Feb 17, 2019
a2f8a63
Restored some cake tests to find correct hanging one.
savpek Feb 17, 2019
5edc6de
Restored tests to see which one is broken one.
savpek Feb 17, 2019
751f3c5
Restored CodeCheckFacts
savpek Feb 17, 2019
856e40e
Skipped code checks again because built was aborted.
savpek Feb 17, 2019
4753e64
CodeCheckFacts from cake tests unignored.
savpek Feb 17, 2019
ce0358c
Restored Can_get_code_actions_from_roslyn to check if it is hanging one.
savpek Feb 17, 2019
f886c8b
Refactored initialization routine for diagnostics and updated test de…
savpek Feb 17, 2019
dd98cfe
Bugfix.
savpek Feb 17, 2019
05c8ed5
Test build stability.
savpek Feb 17, 2019
da6089d
Tiny tweak for logging and comment.
savpek Feb 18, 2019
e0c2590
Merge branch 'master' into roslyn-analyzers
Feb 21, 2019
8afa925
Simplify method
Feb 22, 2019
76cba87
Review fixes.
savpek Feb 22, 2019
1d3965a
Merge branch 'roslyn-analyzers' into pr_feedback
savpek Feb 22, 2019
fd9dc51
Merge pull request #1 from rchande/pr_feedback
savpek Feb 22, 2019
4e4d01c
Small tweak, startup with larger projects.
savpek Feb 24, 2019
01cafcb
Initial fixes for syntax analysis rulesets.
savpek Feb 26, 2019
2a0cb3e
Initial fix for rulesets with syntax analysis.
savpek Feb 26, 2019
0c28cbb
Moved comment to correct location.
savpek Feb 27, 2019
4250f38
Logging improvement.
savpek Feb 27, 2019
2b11dd7
Test for CS rule apply.
savpek Feb 27, 2019
2d81bda
Removed dummy variable.
savpek Feb 27, 2019
1c83919
Fix for document loading.
savpek Feb 27, 2019
cbc81e5
Merge upstream/master.
savpek Feb 27, 2019
ce6ca69
Fixed mistake on document fetching.
savpek Feb 27, 2019
3e7edf8
Merge branch 'master' into roslyn-analyzers
savpek Feb 28, 2019
4c49a96
Merge branch 'master' into roslyn-analyzers
savpek Feb 28, 2019
7e4b77c
Attempt to fix duplicate key error.
savpek Feb 28, 2019
ab42b95
Merge branch 'roslyn-analyzers' of https://github.com/savpek/omnishar…
savpek Feb 28, 2019
583d68a
Small refactoring.
savpek Feb 28, 2019
5abc746
Removed unnecessary semantic model get.
savpek Mar 1, 2019
5ab1836
Merge from upstream.
savpek Mar 14, 2019
d15427c
Fix for null ref error on document removal.
savpek Mar 14, 2019
640a968
Merge remote-tracking branch 'upstream/master' into roslyn-analyzers
savpek Mar 16, 2019
849bf32
Merge branch 'master' into roslyn-analyzers
savpek Mar 17, 2019
9b635c9
Merge branch 'master' into roslyn-analyzers
david-driscoll Mar 19, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class AutoCompleteResponse
/// </summary>
public string CompletionText { get; set; }
public string Description { get; set; }

/// <summary>
/// The text that should be displayed in the auto-complete UI.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
namespace OmniSharp.Models.Diagnostics
using System.Collections.Generic;

namespace OmniSharp.Models.Diagnostics
{
public class DiagnosticLocation : QuickFix
{
public string LogLevel { get; set; }
public string Id { get; set; }

public override bool Equals(object obj)
{
var location = obj as DiagnosticLocation;
return location != null &&
base.Equals(obj) &&
LogLevel == location.LogLevel &&
Id == location.Id;
}

public override int GetHashCode()
{
var hashCode = -1670479257;
savpek marked this conversation as resolved.
Show resolved Hide resolved
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(LogLevel);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Id);
return hashCode;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ public class DiagnosticResult
{
public string FileName { get; set; }
public IEnumerable<DiagnosticLocation> QuickFixes { get; set; }

public override string ToString()
{
return $"{FileName} -> {string.Join(", ", QuickFixes)}";
}
}
}
}
2 changes: 1 addition & 1 deletion src/OmniSharp.Abstractions/Models/v1/QuickFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override int GetHashCode()
}

public override string ToString()
=> $"({Line}:{Column}) - ({EndLine}:{EndColumn})";
=> $"{Text} ({Line}:{Column}) - ({EndLine}:{EndColumn})";

public bool Contains(int line, int column)
{
Expand Down
2 changes: 2 additions & 0 deletions src/OmniSharp.Abstractions/Options/RoslynExtensionsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace OmniSharp.Options
{
public class RoslynExtensionsOptions
{
public bool EnableAnalyzersSupport { get; set; }

public string[] LocationPaths { get; set; }

public IEnumerable<string> GetNormalizedLocationPaths(IOmniSharpEnvironment env)
Expand Down
16 changes: 16 additions & 0 deletions src/OmniSharp.Abstractions/Utilities/ReflectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ public static object CreateInstance(this Lazy<Type> lazyType, params object[] ar
return Activator.CreateInstance(lazyType.Value, args);
}

public static T CreateInstance<T>(this Type type) where T : class
{
try
{
var defaultCtor = type.GetConstructor(new Type[] { });

return defaultCtor != null
? (T)Activator.CreateInstance(type)
: null;
}
catch (Exception ex)
{
throw new InvalidOperationException($"Failed to create instrance of {type.FullName} in {type.AssemblyQualifiedName}.", ex);
}
}

public static T Invoke<T>(this MethodInfo methodInfo, object obj, object[] args)
{
if (methodInfo == null)
Expand Down
4 changes: 4 additions & 0 deletions src/OmniSharp.Host/CompositionHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Composition.Hosting.Core;
using System.Linq;
using System.Reflection;
using Microsoft.CodeAnalysis;
savpek marked this conversation as resolved.
Show resolved Hide resolved
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -42,6 +43,7 @@ public CompositionHost Build()
var memoryCache = _serviceProvider.GetRequiredService<IMemoryCache>();
var loggerFactory = _serviceProvider.GetRequiredService<ILoggerFactory>();
var assemblyLoader = _serviceProvider.GetRequiredService<IAssemblyLoader>();
var analyzerAssemblyLoader = _serviceProvider.GetRequiredService<IAnalyzerAssemblyLoader>();
var environment = _serviceProvider.GetRequiredService<IOmniSharpEnvironment>();
var eventEmitter = _serviceProvider.GetRequiredService<IEventEmitter>();
var dotNetCliService = _serviceProvider.GetRequiredService<IDotNetCliService>();
Expand Down Expand Up @@ -73,6 +75,7 @@ public CompositionHost Build()
.WithProvider(MefValueProvider.From(options.CurrentValue))
.WithProvider(MefValueProvider.From(options.CurrentValue.FormattingOptions))
.WithProvider(MefValueProvider.From(assemblyLoader))
.WithProvider(MefValueProvider.From(analyzerAssemblyLoader))
.WithProvider(MefValueProvider.From(dotNetCliService))
.WithProvider(MefValueProvider.From(metadataHelper))
.WithProvider(MefValueProvider.From(msbuildLocator))
Expand Down Expand Up @@ -121,6 +124,7 @@ public static IServiceProvider CreateDefaultServiceProvider(
// Caching
services.AddSingleton<IMemoryCache, MemoryCache>();
services.AddSingleton<IAssemblyLoader, AssemblyLoader>();
services.AddSingleton<IAnalyzerAssemblyLoader, AssemblyLoader>();
services.AddOptions();

services.AddSingleton<IDotNetCliService, DotNetCliService>();
Expand Down
13 changes: 12 additions & 1 deletion src/OmniSharp.Host/Services/AssemblyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
using System.IO;
using System.Reflection;
using Microsoft.Extensions.Logging;
using Microsoft.CodeAnalysis;

namespace OmniSharp.Services
{
internal class AssemblyLoader : IAssemblyLoader
internal class AssemblyLoader : IAssemblyLoader, IAnalyzerAssemblyLoader
{
private static readonly ConcurrentDictionary<string, Assembly> AssemblyCache = new ConcurrentDictionary<string, Assembly>(StringComparer.OrdinalIgnoreCase);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as i understand no, it should have flag enabled for shadow copying, however everything seems to work fine with this version, can @DustinCampbell open how current loader solution works from end to end (lifetime eg)?

private readonly ILogger _logger;
Expand All @@ -18,6 +19,11 @@ public AssemblyLoader(ILoggerFactory loggerFactory)
_logger = loggerFactory.CreateLogger<AssemblyLoader>();
}

public void AddDependencyLocation(string fullPath)
{
LoadFrom(fullPath);
}

public Assembly Load(AssemblyName name)
{
Assembly result = null;
Expand Down Expand Up @@ -90,5 +96,10 @@ public Assembly LoadFrom(string assemblyPath, bool dontLockAssemblyOnDisk = fals
_logger.LogTrace($"Assembly loaded from path: {assemblyPath}");
return assembly;
}

public Assembly LoadFromPath(string fullPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to add this, if it already exists as public Assembly LoadFrom(string assemblyPath, bool dontLockAssemblyOnDisk = false)? I would suggest to not proliferate these methods if they just call each other

{
return LoadFrom(fullPath);
}
}
}
1 change: 0 additions & 1 deletion src/OmniSharp.Http/HttpCommandLineApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public HttpCommandLineApplication() : base()
_serverInterface = Application.Option("-i | --interface", "Server interface address (defaults to 'localhost').", CommandOptionType.SingleValue);
}


public int Port => _port.GetValueOrDefault(2000);
public string Interface => _serverInterface.GetValueOrDefault("localhost");
}
Expand Down
29 changes: 23 additions & 6 deletions src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.ProjectData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
Expand Down Expand Up @@ -45,6 +46,7 @@ private class ProjectData
public ImmutableArray<string> References { get; }
public ImmutableArray<PackageReference> PackageReferences { get; }
public ImmutableArray<string> Analyzers { get; }
public RuleSet RuleSet { get; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the initial implementation might not need it but you probably want to support editorconfig as well since that can change some of built-in roslyn analyzers behavior if you want to have the same experience as in VS.

we are working on to make it automatically picked up by Roslyn, so you could just wait until then for editorconfig work (so that msbuild has editorconfig info in it like Analyzers) and you can build roslyn solution with that info like what you are doing with AnalyzerFileReference and CompilationOptions. and then after that CompilationWithAnalyzer takes care of all the detail once context is setup right.

until then, if you want to support editorconfig, you have to do it yourself. let me know if you want to, it is a bit of work depends on what infrastructure you have on editorconfig.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heejaechang do you know when roslyn integrated solution will be released? Not exact timing but like is it upcoming month or maybe year away?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@savpek can't say for sure. but we are actively working on. we recently checked in changes in compiler layer. and I believe we are working on to make it work on roslyn workspace layer. and then features and etc.


private ProjectData()
{
Expand Down Expand Up @@ -74,7 +76,8 @@ private ProjectData(
ImmutableArray<string> preprocessorSymbolNames,
ImmutableArray<string> suppressedDiagnosticIds,
bool signAssembly,
string assemblyOriginatorKeyFile)
string assemblyOriginatorKeyFile,
RuleSet ruleset)
: this()
{
Guid = guid;
Expand All @@ -100,6 +103,7 @@ private ProjectData(

SignAssembly = signAssembly;
AssemblyOriginatorKeyFile = assemblyOriginatorKeyFile;
RuleSet = ruleset;
}

private ProjectData(
Expand All @@ -121,10 +125,11 @@ private ProjectData(
ImmutableArray<string> projectReferences,
ImmutableArray<string> references,
ImmutableArray<PackageReference> packageReferences,
ImmutableArray<string> analyzers)
ImmutableArray<string> analyzers,
RuleSet ruleset)
: this(guid, name, assemblyName, targetPath, outputPath, intermediateOutputPath, projectAssetsFile,
configuration, platform, targetFramework, targetFrameworks, outputKind, languageVersion, allowUnsafeCode,
documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, signAssembly, assemblyOriginatorKeyFile)
documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, signAssembly, assemblyOriginatorKeyFile, ruleset)
{
SourceFiles = sourceFiles.EmptyIfDefault();
ProjectReferences = projectReferences.EmptyIfDefault();
Expand Down Expand Up @@ -167,7 +172,7 @@ public static ProjectData Create(MSB.Evaluation.Project project)
return new ProjectData(
guid, name, assemblyName, targetPath, outputPath, intermediateOutputPath, projectAssetsFile,
configuration, platform, targetFramework, targetFrameworks, outputKind, languageVersion, allowUnsafeCode,
documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, signAssembly, assemblyOriginatorKeyFile);
documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, signAssembly, assemblyOriginatorKeyFile, ruleset: null);
}

public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance)
Expand Down Expand Up @@ -201,6 +206,8 @@ public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance)
var signAssembly = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.SignAssembly), defaultValue: false);
var assemblyOriginatorKeyFile = projectInstance.GetPropertyValue(PropertyNames.AssemblyOriginatorKeyFile);

var ruleset = ResolveRulesetIfAny(projectInstance);

var sourceFiles = GetFullPaths(
projectInstance.GetItems(ItemNames.Compile), filter: FileNameIsNotGenerated);

Expand Down Expand Up @@ -234,7 +241,7 @@ public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance)
references.Add(fullPath);
}
}

var packageReferences = GetPackageReferences(projectInstance.GetItems(ItemNames.PackageReference));
var analyzers = GetFullPaths(projectInstance.GetItems(ItemNames.Analyzer));

Expand All @@ -243,7 +250,17 @@ public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance)
configuration, platform, targetFramework, targetFrameworks,
outputKind, languageVersion, allowUnsafeCode, documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds,
signAssembly, assemblyOriginatorKeyFile,
sourceFiles, projectReferences, references.ToImmutable(), packageReferences, analyzers);
sourceFiles, projectReferences, references.ToImmutable(), packageReferences, analyzers, ruleset);
}

private static RuleSet ResolveRulesetIfAny(MSB.Execution.ProjectInstance projectInstance)
{
var rulesetIfAny = projectInstance.Properties.FirstOrDefault(x => x.Name == "ResolvedCodeAnalysisRuleSet");

if (rulesetIfAny != null)
return RuleSet.LoadEffectiveRuleSetFromFile(Path.Combine(projectInstance.Directory, rulesetIfAny.EvaluatedValue));

return null;
}

private static bool IsCSharpProject(string filePath)
Expand Down
1 change: 1 addition & 0 deletions src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ internal partial class ProjectFileInfo

public bool SignAssembly => _data.SignAssembly;
public string AssemblyOriginatorKeyFile => _data.AssemblyOriginatorKeyFile;
public RuleSet RuleSet => _data.RuleSet;

public ImmutableArray<string> SourceFiles => _data.SourceFiles;
public ImmutableArray<string> References => _data.References;
Expand Down
23 changes: 20 additions & 3 deletions src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfoExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
using OmniSharp.Helpers;

namespace OmniSharp.MSBuild.ProjectFile
Expand Down Expand Up @@ -35,8 +39,10 @@ public static CSharpCompilationOptions CreateCompilationOptions(this ProjectFile
return result;
}

public static ProjectInfo CreateProjectInfo(this ProjectFileInfo projectFileInfo)
public static ProjectInfo CreateProjectInfo(this ProjectFileInfo projectFileInfo, IAnalyzerAssemblyLoader analyzerAssemblyLoader)
{
var analyzerReferences = ResolveAnalyzerReferencesForProject(projectFileInfo, analyzerAssemblyLoader);

return ProjectInfo.Create(
id: projectFileInfo.Id,
version: VersionStamp.Create(),
Expand All @@ -45,7 +51,18 @@ public static ProjectInfo CreateProjectInfo(this ProjectFileInfo projectFileInfo
language: LanguageNames.CSharp,
filePath: projectFileInfo.FilePath,
outputFilePath: projectFileInfo.TargetPath,
compilationOptions: projectFileInfo.CreateCompilationOptions());
compilationOptions: projectFileInfo.CreateCompilationOptions(),
analyzerReferences: analyzerReferences);
}

private static IEnumerable<AnalyzerReference> ResolveAnalyzerReferencesForProject(ProjectFileInfo projectFileInfo, IAnalyzerAssemblyLoader analyzerAssemblyLoader)
{
foreach(var analyzerAssemblyPath in projectFileInfo.Analyzers.Distinct())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also have the possibility of loading code refactorings via global configuration https://github.com/OmniSharp/omnisharp-roslyn/blob/master/src/OmniSharp.Abstractions/Options/RoslynExtensionsOptions.cs#L10.

At the moment only refactorings work this way, but not analyzers - it would make sense to include assemblies discovered this way in analyzers

Copy link
Contributor Author

@savpek savpek Nov 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i remember correctly (implemented like 6 months back 🙂 ) it should be in current version:

                var allAnalyzers = _providers
                    .SelectMany(x => x.CodeDiagnosticAnalyzerProviders)
                    .Concat(project.AnalyzerReferences.SelectMany(x => x.GetAnalyzers(project.Language)))
                    .ToImmutableArray();

_providers is implementation of ICodeActionProvider which is extended to support analyzers and code fixes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah you are right, brilliant 👍the PR is difficult to view on github at this point 😄

{
analyzerAssemblyLoader.AddDependencyLocation(analyzerAssemblyPath);
}

return projectFileInfo.Analyzers.Select(analyzerCandicatePath => new AnalyzerFileReference(analyzerCandicatePath, analyzerAssemblyLoader));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this used differently than the logic in CachingCodeFixProvider to load analyzers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code fixes and analyzers can come from same assemblies, but analyzers are given to Project object and CodeFixes are cached elswhere since project doesn't have any information about it's CodeFixes available at model itself. This has same assembly ref part but after that they are different, extension method creates AnalyzerFileReference that are handled by roslyn internally and codeFixes per project are fetched from this cache. I am not 100% sure is there some other way to do this but it seems roslyn doesn't expose means for it at this point. If i remember correctly there are kind of similar mechanism inside of roslyn source code, however this memory goes almost year back so who knows 🙂 I think this is something which can be refactored if better means show up.

}
}
}
Loading