-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Miscellaneous Files (#1252)
* Basic of the orphan file system * Initialise the project system * add csproj * Test using MSBuildProjectSystem * Orphan file system using the msbuild system * Remove unnecessary change * csproj temp * Get only syntactic diagnostics for misc files * Logic to delete the document * Edit csproj * Rename to misc files * Order the project systems * Ordering failing * Order project systems based on DisplayName * Remove orphan system * Put inside the partial class * Clean up the miscellanous file system * Tests for the misc project system * Make MEF work * Returns only semantic diagnostics running * Add more failing tests * Clean up * Extension Ordering working for the project systems * Clean the solution * Change the target framework * Add references * Rename project system * Add few tests * Refactor the tests to add a method to the test host * Remove roslyn dependency in abstractions * use only one project for all the miscellanous files * Add project system names class * Modifying the files changed facts to use absolute path instead of relative By adding the misc files support, the file that was being added by the test was being treated as a miscellanous file and being added to the workspace. However since the path being passed was relative, an exception was being thrown. * Add the empty project * Add the IUpdates interface * Add absolute paths for the misc file system * Add dotnet project system for the updates * CR feedback * Remove comment * Add project handling in the workspace * Add assembly info * Deal with race condition between project system updates * add property type * CR feedback * Move the check for the Misc files into the workspace * edit comment * Check for the project id for the document * Dont keep track of the documents in the project system * Add test for multiple files * Add test to handle deletion * Call TryRemoveMiscDocument * Naming consistency * Use the default references same as the script system * CR feedback
- Loading branch information
Showing
31 changed files
with
945 additions
and
248 deletions.
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
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.MiscellaneousFiles/MiscellaneousFilesProjectSystem.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.MiscellaneousFiles/OmniSharp.MiscellaneousFiles.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.