-
Notifications
You must be signed in to change notification settings - Fork 416
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
Add support for Miscellaneous Files #1252
Merged
Merged
Changes from 55 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
a784769
Basic of the orphan file system
akshita31 f0cc59e
Initialise the project system
akshita31 b26552b
add csproj
akshita31 48548a7
Test using MSBuildProjectSystem
akshita31 774cc9b
Orphan file system using the msbuild system
akshita31 2d46149
Remove unnecessary change
akshita31 27266dd
csproj temp
akshita31 6f972d0
Get only syntactic diagnostics for misc files
akshita31 7bb4708
Logic to delete the document
akshita31 bf59f02
Edit csproj
akshita31 0db4d70
Rename to misc files
akshita31 8e6baec
Order the project systems
akshita31 439e9ad
Ordering failing
akshita31 2bbfe5b
Order project systems based on DisplayName
akshita31 35e2630
Remove orphan system
akshita31 999bf3f
Put inside the partial class
akshita31 81321cd
Clean up the miscellanous file system
akshita31 7e6ba33
Tests for the misc project system
akshita31 eba6ae2
Make MEF work
af435a6
Merge pull request #1 from rchande/MEFfix
akshita31 895cf5b
Returns only semantic diagnostics running
akshita31 c422035
Add more failing tests
akshita31 57bfbc5
Clean up
akshita31 48b4c26
Extension Ordering working for the project systems
akshita31 9a9cfa9
Merge master
akshita31 36af94b
Clean the solution
akshita31 11251b0
Change the target framework
akshita31 dd73d39
Add references
akshita31 2b599a6
Rename project system
akshita31 42c9049
Add few tests
akshita31 d0574cb
Refactor the tests to add a method to the test host
akshita31 6d8201a
Remove roslyn dependency in abstractions
akshita31 7a419ed
use only one project for all the miscellanous files
akshita31 def58ec
Add project system names class
akshita31 5788c37
Modifying the files changed facts to use absolute path instead of rel…
akshita31 9a8d447
Add the empty project
akshita31 c7158ba
Add the IUpdates interface
akshita31 c243202
Add absolute paths for the misc file system
akshita31 3cf76e6
Merge remote-tracking branch 'upstream/master' into orphan_system
akshita31 98e4de3
Add dotnet project system for the updates
akshita31 6228db3
CR feedback
akshita31 069d6f0
Remove comment
akshita31 2e5e7fc
Add project handling in the workspace
akshita31 850f3fd
Merge remote-tracking branch 'origin/orphan_system' into orphan_system
akshita31 f89946d
Add assembly info
akshita31 20bf194
Deal with race condition between project system updates
akshita31 4163f3f
add property type
akshita31 9e2e0b9
CR feedback
akshita31 6dfca92
Move the check for the Misc files into the workspace
akshita31 c5db9c9
edit comment
akshita31 2a3666a
Merge branch 'master' into orphan_system
akshita31 7a70a07
Check for the project id for the document
akshita31 ce3a437
Dont keep track of the documents in the project system
akshita31 2355ded
Add test for multiple files
akshita31 b8d11e2
Add test to handle deletion
akshita31 67003aa
Call TryRemoveMiscDocument
akshita31 4d3e853
Naming consistency
akshita31 f0d3255
Use the default references same as the script system
akshita31 cdecdad
CR feedback
akshita31 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
18 changes: 18 additions & 0 deletions
18
src/OmniSharp.Abstractions/Mef/ExportProjectSystemAttribute.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,18 @@ | ||
using System; | ||
using System.Composition; | ||
using OmniSharp.Services; | ||
|
||
namespace OmniSharp.Mef | ||
{ | ||
[MetadataAttribute] | ||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] | ||
public class ExportProjectSystemAttribute: ExportAttribute | ||
{ | ||
public string Name { get; } | ||
|
||
public ExportProjectSystemAttribute(string name) : base(typeof(IProjectSystem)) | ||
{ | ||
Name = name; | ||
} | ||
} | ||
} |
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,7 @@ | ||
namespace OmniSharp.Mef | ||
{ | ||
public class ProjectSystemMetadata | ||
{ | ||
public string Name { get; set; } | ||
} | ||
} |
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,11 @@ | ||
namespace OmniSharp | ||
{ | ||
public static class ProjectSystemNames | ||
{ | ||
public const string MSBuildProjectSystem = "MSBuildProjectSystem"; | ||
public const string CakeProjectSystem = "CakeProjectSystem"; | ||
public const string DotNetProjectSystem = "DotNetProjectSystem"; | ||
public const string ScriptProjectSystem = "ScriptProjectSystem"; | ||
public const string MiscellaneousFilesProjectSystem = "MiscellaneousFilesProjectSystem"; | ||
} | ||
} |
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,9 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace OmniSharp.Services | ||
{ | ||
public interface IWaitableProjectSystem: IProjectSystem | ||
{ | ||
Task WaitForUpdatesAsync(); | ||
} | ||
} |
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
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 | ||
---|---|---|---|---|
@@ -1,13 +1,16 @@ | ||||
using System; | ||||
using System.Composition.Hosting; | ||||
using System.Linq; | ||||
using Microsoft.Extensions.Configuration; | ||||
using Microsoft.Extensions.DependencyInjection; | ||||
using Microsoft.Extensions.Logging; | ||||
using Microsoft.Extensions.Options; | ||||
using OmniSharp.Mef; | ||||
using OmniSharp.Options; | ||||
using OmniSharp.Roslyn; | ||||
using OmniSharp.Roslyn.Options; | ||||
using OmniSharp.Services; | ||||
using OmniSharp.Utilities; | ||||
|
||||
namespace OmniSharp | ||||
{ | ||||
|
@@ -24,9 +27,11 @@ public static void Initialize( | |||
|
||||
var projectEventForwarder = compositionHost.GetExport<ProjectEventForwarder>(); | ||||
projectEventForwarder.Initialize(); | ||||
var projectSystems = compositionHost.GetExports<Lazy<IProjectSystem, ProjectSystemMetadata>>(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we should hide that logic in some generic extension method? this way it could be reused in the future against other potentially ordered look ups like i.e.
|
||||
var ps = projectSystems.Select(n => n.Value); | ||||
var orderedProjectSystems = ExtensionOrderer.GetOrderedOrUnorderedList<IProjectSystem, ExportProjectSystemAttribute>(ps, eps => eps.Name); | ||||
|
||||
// Initialize all the project systems | ||||
foreach (var projectSystem in compositionHost.GetExports<IProjectSystem>()) | ||||
foreach (var projectSystem in orderedProjectSystems) | ||||
{ | ||||
try | ||||
{ | ||||
|
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
111 changes: 111 additions & 0 deletions
111
src/OmniSharp.MiscellaneousFile/MiscellaneousFileProjectSystem.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,111 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Composition; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
using OmniSharp.FileSystem; | ||
using OmniSharp.FileWatching; | ||
using OmniSharp.Mef; | ||
using OmniSharp.Models.WorkspaceInformation; | ||
using OmniSharp.Services; | ||
|
||
namespace OmniSharp.MiscellaneousFile | ||
{ | ||
[ExtensionOrder(After = ProjectSystemNames.MSBuildProjectSystem)] | ||
[ExtensionOrder(After = ProjectSystemNames.DotNetProjectSystem)] | ||
[ExportProjectSystem(ProjectSystemNames.MiscellaneousFilesProjectSystem), Shared] | ||
public class MiscellaneousFilesProjectSystem : IProjectSystem | ||
{ | ||
private const string miscFileExtension = ".cs"; | ||
public string Key => ProjectSystemNames.MiscellaneousFilesProjectSystem; | ||
public string Language => LanguageNames.CSharp; | ||
IEnumerable<string> IProjectSystem.Extensions => new[] { miscFileExtension }; | ||
public bool EnabledByDefault { get; } = true; | ||
|
||
private readonly OmniSharpWorkspace _workspace; | ||
private readonly IFileSystemWatcher _fileSystemWatcher; | ||
private readonly FileSystemHelper _fileSystemHelper; | ||
private readonly List<IWaitableProjectSystem> _projectSystems; | ||
private readonly ILogger _logger; | ||
|
||
[ImportingConstructor] | ||
public MiscellaneousFilesProjectSystem(OmniSharpWorkspace workspace, IFileSystemWatcher fileSystemWatcher, FileSystemHelper fileSystemHelper, | ||
ILoggerFactory loggerFactory, [ImportMany] IEnumerable<Lazy<IProjectSystem, ProjectSystemMetadata>> projectSystems) | ||
{ | ||
_workspace = workspace; | ||
_fileSystemWatcher = fileSystemWatcher; | ||
_fileSystemHelper = fileSystemHelper; | ||
_logger = loggerFactory.CreateLogger<MiscellaneousFilesProjectSystem>(); | ||
_projectSystems = projectSystems | ||
.Where(ps => ps.Metadata.Name == ProjectSystemNames.MSBuildProjectSystem || | ||
ps.Metadata.Name == ProjectSystemNames.DotNetProjectSystem) | ||
.Select(ps => ps.Value) | ||
.Cast<IWaitableProjectSystem>() | ||
.ToList(); | ||
} | ||
|
||
Task<object> IProjectSystem.GetProjectModelAsync(string filePath) | ||
{ | ||
return Task.FromResult<object>(null); | ||
} | ||
|
||
Task<object> IProjectSystem.GetWorkspaceModelAsync(WorkspaceInformationRequest request) | ||
{ | ||
return Task.FromResult<object>(null); | ||
} | ||
|
||
void IProjectSystem.Initalize(IConfiguration configuration) | ||
{ | ||
var allFiles = _fileSystemHelper.GetFiles("**/*.cs"); | ||
foreach (var filePath in allFiles) | ||
TryAddMiscellaneousFile(filePath); | ||
|
||
_fileSystemWatcher.Watch(miscFileExtension, OnMiscellaneousFileChanged); | ||
} | ||
|
||
private async void TryAddMiscellaneousFile(string filePath) | ||
{ | ||
//wait for the project systems to finish processing the updates | ||
foreach (var projectSystem in _projectSystems) | ||
{ | ||
await projectSystem.WaitForUpdatesAsync(); | ||
} | ||
|
||
var absoluteFilePath = new FileInfo(filePath).FullName; | ||
if (!File.Exists(absoluteFilePath)) | ||
return; | ||
|
||
if (_workspace.TryAddMiscellaneousDocument(absoluteFilePath, Language) != null) | ||
{ | ||
_logger.LogInformation($"Successfully added file '{absoluteFilePath}' to workspace"); | ||
} | ||
} | ||
|
||
private void OnMiscellaneousFileChanged(string filePath, FileChangeType changeType) | ||
{ | ||
if (changeType == FileChangeType.Unspecified && File.Exists(filePath) || | ||
changeType == FileChangeType.Create) | ||
{ | ||
TryAddMiscellaneousFile(filePath); | ||
} | ||
|
||
else if (changeType == FileChangeType.Unspecified && !File.Exists(filePath) || | ||
changeType == FileChangeType.Delete) | ||
{ | ||
RemoveFromWorkspace(filePath); | ||
} | ||
} | ||
|
||
private void RemoveFromWorkspace(string filePath) | ||
{ | ||
if (_workspace.TryRemoveMiscellaneousDocument(filePath)) | ||
{ | ||
_logger.LogDebug($"Removed file '{filePath}' from the workspace."); | ||
} | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/OmniSharp.MiscellaneousFile/OmniSharp.MiscellaneousFile.csproj
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,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net461</TargetFramework> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.8.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\OmniSharp.Abstractions\OmniSharp.Abstractions.csproj" /> | ||
<ProjectReference Include="..\OmniSharp.Roslyn\OmniSharp.Roslyn.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are the project + folder + namespace called
OmniSharp.MiscellaneousFile
(singular) but everywhere we refer toMiscellaneousFiles
(plural)? I believe for consistency, the project and folder and namespace should be renamed toOmniSharp.MiscellaneousFiles
too