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

Added support for "sync namespace" refactoring #1563

Merged
merged 23 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ee09fa0
updated to Roslyn 3.3.0-beta1-19365-07
filipw Jul 16, 2019
6000957
support sync namespace refactoring
filipw Jul 16, 2019
d10d5e7
do not run into null reference
filipw Jul 16, 2019
8a98588
handle newly created files
filipw Jul 17, 2019
d6c4193
better relative path handling
filipw Jul 17, 2019
0ff05fa
small fixes
filipw Jul 18, 2019
2eb486a
improve tests
filipw Jul 18, 2019
650bbdf
added SyncNamespaceFacts
filipw Jul 18, 2019
942882e
fixed test and added more resiliency
filipw Jul 18, 2019
06111ea
added support for live changing of root namespace
filipw Jul 19, 2019
43e4ba9
added more tests - for live reload of a namespace
filipw Jul 19, 2019
ab56c93
Merge branch 'master' into feature/sync-namespace
filipw Jul 19, 2019
4c09d8b
code review feedback
filipw Jul 19, 2019
3cc7abe
Merge branch 'master' into feature/sync-namespace
filipw Jul 22, 2019
063bf86
Merge branch 'master' into feature/sync-namespace
david-driscoll Jul 24, 2019
005f7de
Merge branch 'master' into feature/sync-namespace
filipw Jul 29, 2019
e94af51
Merge branch 'master' into feature/sync-namespace
filipw Jul 30, 2019
8c611eb
roslyn 3.3.0-beta2-19376-02
filipw Jul 31, 2019
43b30d5
reflection fix due to a method change from public to internal in Symb…
filipw Jul 31, 2019
e365c0b
fixed code action tests
filipw Jul 31, 2019
a550617
address changes to https://github.com/dotnet/roslyn/pull/35822
filipw Jul 31, 2019
e105575
fixed cake test
filipw Jul 31, 2019
cb98914
Merge branch 'master' into feature/sync-namespace
akshita31 Jul 31, 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
2 changes: 1 addition & 1 deletion build/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<MSBuildPackageVersion>16.0.461</MSBuildPackageVersion>
<NuGetPackageVersion>5.0.0</NuGetPackageVersion>
<RoslynPackageVersion>3.2.0-beta4-19326-12</RoslynPackageVersion>
<RoslynPackageVersion>3.3.0-beta1-19365-07</RoslynPackageVersion>
<XunitPackageVersion>2.4.0</XunitPackageVersion>
</PropertyGroup>

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 = "3.2.0.0";
public const string RoslynVersion = "3.3.0.0";
public const string RoslynPublicKeyToken = "31bf3856ad364e35";

public readonly static string RoslynFeatures = GetRoslynAssemblyFullName("Microsoft.CodeAnalysis.Features");
Expand Down
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-3.2.0.0" newVersion="3.2.0.0"/>
<bindingRedirect oldVersion="0.0.0.0-3.3.0.0" newVersion="3.3.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0"/>
<bindingRedirect oldVersion="0.0.0.0-3.3.0.0" newVersion="3.3.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0"/>
<bindingRedirect oldVersion="0.0.0.0-3.3.0.0" newVersion="3.3.0.0"/>
</dependentAssembly>

<dependentAssembly>
Expand Down
12 changes: 9 additions & 3 deletions src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.ProjectData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private class ProjectData
public RuleSet RuleSet { get; }
public ImmutableDictionary<string, string> ReferenceAliases { get; }
public bool TreatWarningsAsErrors { get; }
public string DefaultNamespace { get; }

private ProjectData()
{
Expand Down Expand Up @@ -85,6 +86,7 @@ private ProjectData(
bool signAssembly,
string assemblyOriginatorKeyFile,
bool treatWarningsAsErrors,
string defaultNamespace,
RuleSet ruleset)
: this()
{
Expand Down Expand Up @@ -114,6 +116,7 @@ private ProjectData(
AssemblyOriginatorKeyFile = assemblyOriginatorKeyFile;
TreatWarningsAsErrors = treatWarningsAsErrors;
RuleSet = ruleset;
DefaultNamespace = defaultNamespace;
}

private ProjectData(
Expand All @@ -139,11 +142,12 @@ private ProjectData(
ImmutableArray<string> analyzers,
ImmutableArray<string> additionalFiles,
bool treatWarningsAsErrors,
string defaultNamespace,
RuleSet ruleset,
ImmutableDictionary<string, string> referenceAliases)
: this(guid, name, assemblyName, targetPath, outputPath, intermediateOutputPath, projectAssetsFile,
configuration, platform, targetFramework, targetFrameworks, outputKind, languageVersion, nullableContextOptions, allowUnsafeCode,
documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, signAssembly, assemblyOriginatorKeyFile, treatWarningsAsErrors, ruleset)
documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, signAssembly, assemblyOriginatorKeyFile, treatWarningsAsErrors, defaultNamespace, ruleset)
{
SourceFiles = sourceFiles.EmptyIfDefault();
ProjectReferences = projectReferences.EmptyIfDefault();
Expand All @@ -165,6 +169,7 @@ public static ProjectData Create(MSB.Evaluation.Project project)
var projectAssetsFile = project.GetPropertyValue(PropertyNames.ProjectAssetsFile);
var configuration = project.GetPropertyValue(PropertyNames.Configuration);
var platform = project.GetPropertyValue(PropertyNames.Platform);
var defaultNamespace = project.GetPropertyValue(PropertyNames.RootNamespace);

var targetFramework = new FrameworkName(project.GetPropertyValue(PropertyNames.TargetFrameworkMoniker));

Expand All @@ -190,7 +195,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, nullableContextOptions, allowUnsafeCode,
documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, signAssembly, assemblyOriginatorKeyFile, treatWarningsAsErrors, ruleset: null);
documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, signAssembly, assemblyOriginatorKeyFile, treatWarningsAsErrors, defaultNamespace, ruleset: null);
}

public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance)
Expand All @@ -204,6 +209,7 @@ public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance)
var projectAssetsFile = projectInstance.GetPropertyValue(PropertyNames.ProjectAssetsFile);
var configuration = projectInstance.GetPropertyValue(PropertyNames.Configuration);
var platform = projectInstance.GetPropertyValue(PropertyNames.Platform);
var defaultNamespace = projectInstance.GetPropertyValue(PropertyNames.RootNamespace);

var targetFramework = new FrameworkName(projectInstance.GetPropertyValue(PropertyNames.TargetFrameworkMoniker));

Expand Down Expand Up @@ -277,7 +283,7 @@ public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance)
configuration, platform, targetFramework, targetFrameworks,
outputKind, languageVersion, nullableContextOptions, allowUnsafeCode, documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds,
signAssembly, assemblyOriginatorKeyFile,
sourceFiles, projectReferences, references.ToImmutable(), packageReferences, analyzers, additionalFiles, treatWarningsAsErrors, ruleset, referenceAliases.ToImmutableDictionary());
sourceFiles, projectReferences, references.ToImmutable(), packageReferences, analyzers, additionalFiles, treatWarningsAsErrors, defaultNamespace, ruleset, referenceAliases.ToImmutableDictionary());
}

private static RuleSet ResolveRulesetIfAny(MSB.Execution.ProjectInstance projectInstance)
Expand Down
2 changes: 2 additions & 0 deletions src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ internal partial class ProjectFileInfo
public ImmutableArray<string> AdditionalFiles => _data.AdditionalFiles;
public ImmutableDictionary<string, string> ReferenceAliases => _data.ReferenceAliases;
public bool TreatWarningsAsErrors => _data.TreatWarningsAsErrors;
public string DefaultNamespace => _data.DefaultNamespace;

public ProjectIdInfo ProjectIdInfo { get; }

private ProjectFileInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public static CSharpCompilationOptions CreateCompilationOptions(this ProjectFile
public static ImmutableDictionary<string, ReportDiagnostic> GetDiagnosticOptions(this ProjectFileInfo projectFileInfo)
{
var defaultSuppressions = CompilationOptionsHelper.GetDefaultSuppressedDiagnosticOptions(projectFileInfo.SuppressedDiagnosticIds);

var specificRules = projectFileInfo.RuleSet?.SpecificDiagnosticOptions ?? ImmutableDictionary<string, ReportDiagnostic>.Empty;

return specificRules.Concat(defaultSuppressions.Where(x => !specificRules.Keys.Contains(x.Key))).ToImmutableDictionary();
Expand All @@ -71,7 +70,7 @@ public static ProjectInfo CreateProjectInfo(this ProjectFileInfo projectFileInfo
filePath: projectFileInfo.FilePath,
outputFilePath: projectFileInfo.TargetPath,
compilationOptions: projectFileInfo.CreateCompilationOptions(),
analyzerReferences: analyzerReferences);
analyzerReferences: analyzerReferences).WithDefaultNamespace(projectFileInfo.DefaultNamespace);
}

private static IEnumerable<AnalyzerReference> ResolveAnalyzerReferencesForProject(ProjectFileInfo projectFileInfo, IAnalyzerAssemblyLoader analyzerAssemblyLoader)
Expand Down
1 change: 1 addition & 0 deletions src/OmniSharp.MSBuild/ProjectFile/PropertyNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal static class PropertyNames
public const string ProjectGuid = nameof(ProjectGuid);
public const string ProjectName = nameof(ProjectName);
public const string _ResolveReferenceDependencies = nameof(_ResolveReferenceDependencies);
public const string RootNamespace = nameof(RootNamespace);
public const string RoslynTargetsPath = nameof(RoslynTargetsPath);
public const string SignAssembly = nameof(SignAssembly);
public const string SkipCompilerExecution = nameof(SkipCompilerExecution);
Expand Down
23 changes: 20 additions & 3 deletions src/OmniSharp.MSBuild/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,14 +434,15 @@ private void UpdateProject(string projectFilePath)
UpdateParseOptions(project, projectFileInfo.LanguageVersion, projectFileInfo.PreprocessorSymbolNames, !string.IsNullOrWhiteSpace(projectFileInfo.DocumentationFile));
UpdateProjectReferences(project, projectFileInfo.ProjectReferences);
UpdateReferences(project, projectFileInfo.ProjectReferences, projectFileInfo.References);
UpdateAnalyzerReferences(projectFileInfo, project);
UpdateAnalyzerReferences(project, projectFileInfo);
UpdateAdditionalFiles(project, projectFileInfo.AdditionalFiles);
UpdateProjectProperties(project, projectFileInfo);

_workspace.TryPromoteMiscellaneousDocumentsToProject(project);
_workspace.UpdateDiagnosticOptionsForProject(project.Id, projectFileInfo.GetDiagnosticOptions());
}

private void UpdateAnalyzerReferences(ProjectFileInfo projectFileInfo, Project project)
private void UpdateAnalyzerReferences(Project project, ProjectFileInfo projectFileInfo)
{
var analyzerFileReferences = projectFileInfo.Analyzers
.Select(analyzerReferencePath => new AnalyzerFileReference(analyzerReferencePath, _analyzerAssemblyLoader))
Expand All @@ -450,6 +451,22 @@ private void UpdateAnalyzerReferences(ProjectFileInfo projectFileInfo, Project p
_workspace.SetAnalyzerReferences(project.Id, analyzerFileReferences);
}

private void UpdateProjectProperties(Project project, ProjectFileInfo projectFileInfo)
{
if (projectFileInfo.DefaultNamespace != project.DefaultNamespace)
{
var newSolution = _workspace.CurrentSolution.WithProjectDefaultNamespace(project.Id, projectFileInfo.DefaultNamespace);
if (_workspace.TryApplyChanges(newSolution))
{
_logger.LogDebug($"Updated default namespace from {project.DefaultNamespace} to {projectFileInfo.DefaultNamespace} on {project.FilePath} project.");
}
else
{
_logger.LogWarning($"Couldn't update default namespace from {project.DefaultNamespace} to {projectFileInfo.DefaultNamespace} on {project.FilePath} project.");
}
}
}

private void UpdateAdditionalFiles(Project project, IList<string> additionalFiles)
{
var currentAdditionalDocuments = project.AdditionalDocuments;
Expand Down Expand Up @@ -490,7 +507,7 @@ private void UpdateSourceFiles(Project project, IList<string> sourceFiles)
continue;
}

_workspace.AddDocument(project.Id, sourceFile);
_workspace.AddDocument(project, sourceFile);
}

// Removing any remaining documents from the project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public override async Task<RunCodeActionResponse> Handle(RunCodeActionRequest re
}
}

this.Workspace.AddDocument(documentId, projectChange.ProjectId, newFilePath, newDocument.SourceCodeKind);
this.Workspace.AddDocument(documentId, projectChange.NewProject, newFilePath, newDocument.SourceCodeKind);
solution = this.Workspace.CurrentSolution;
}
else
Expand Down
19 changes: 8 additions & 11 deletions src/OmniSharp.Roslyn/BufferManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,29 +151,26 @@ private bool TryAddTransientDocument(string fileName, string fileContent)
}
else
{
var projectAndDocumentIds = new List<(ProjectId ProjectId, DocumentId DocumentId)>();
var sourceText = SourceText.From(fileContent);
var documentInfos = new List<DocumentInfo>();

foreach (var project in projects)
{
var id = DocumentId.CreateNewId(project.Id);
var version = VersionStamp.Create();
var documentInfo = DocumentInfo.Create(
id, fileName, filePath: fileName,
loader: TextLoader.From(TextAndVersion.Create(sourceText, version)));

documentInfos.Add(documentInfo);
var documentId = DocumentId.CreateNewId(project.Id);
projectAndDocumentIds.Add((project.Id, documentId));
}

lock (_lock)
{
var documentIds = documentInfos.Select(document => document.Id);
var documentIds = projectAndDocumentIds.Select(x => x.DocumentId);
_transientDocuments[fileName] = documentIds;
_transientDocumentIds.UnionWith(documentIds);
}

foreach (var documentInfo in documentInfos)
foreach (var projectAndDocumentId in projectAndDocumentIds)
{
_workspace.AddDocument(documentInfo);
var version = VersionStamp.Create();
_workspace.AddDocument(projectAndDocumentId.DocumentId, projectAndDocumentId.ProjectId, fileName, TextLoader.From(TextAndVersion.Create(sourceText, version)));
}
}

Expand Down
Loading