-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement new interfaces for adding files
Implement a new interface to allow csproj/msvbprj to add files. The existing `ICSharpProjecSite.OnSourceFileAdded` and `IVbCompilerProject.AddFile` had to go back to the hierarchy to check if the file had any `<Link>` metadata on it, effectively requiring that these methods only be called on the main thread. However, this metadata is readily available to csproj/msvbprj; the new `IProjectSiteEx.AddFilEx` method allow it to be passed in. This should make it possible to call this method on a background thread. Also, the language service supports batching up project changes before pushing them to the workspace, but does not currently expose a way for csproj/msvbprj to tell it when a batch of changes is starting or ending. The `StartBatch` and `EndBatch` methods on `IProjectSiteEx` fill this need.
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/VisualStudio/Core/Def/Implementation/ProjectSystem/Interop/IProjectSiteEx.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 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.Interop | ||
{ | ||
[ComImport] | ||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | ||
[Guid("38B39ADD-D4D6-47E1-B996-7ED16D0295A5")] | ||
internal interface IProjectSiteEx | ||
{ | ||
void StartBatch(); | ||
void EndBatch(); | ||
|
||
void AddFileEx([MarshalAs(UnmanagedType.LPWStr)] string filePath, [MarshalAs(UnmanagedType.LPWStr)] string linkMetadata); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
...udio/Core/Def/Implementation/ProjectSystem/Legacy/AbstractLegacyProject_IProjectSiteEx.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,36 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.Interop; | ||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.Legacy | ||
{ | ||
internal abstract partial class AbstractLegacyProject : IProjectSiteEx | ||
{ | ||
private readonly Stack<VisualStudioProject.BatchScope> _batchScopes = new Stack<VisualStudioProject.BatchScope>(); | ||
|
||
public void StartBatch() | ||
{ | ||
_batchScopes.Push(VisualStudioProject.CreateBatchScope()); | ||
} | ||
|
||
public void EndBatch() | ||
{ | ||
Contract.ThrowIfFalse(_batchScopes.Count > 0); | ||
var scope = _batchScopes.Pop(); | ||
scope.Dispose(); | ||
} | ||
|
||
public void AddFileEx([MarshalAs(UnmanagedType.LPWStr)] string filePath, [MarshalAs(UnmanagedType.LPWStr)] string linkMetadata) | ||
{ | ||
// TODO: uncomment when fixing https://github.com/dotnet/roslyn/issues/5325 | ||
//var sourceCodeKind = extension.Equals(".csx", StringComparison.OrdinalIgnoreCase) | ||
// ? SourceCodeKind.Script | ||
// : SourceCodeKind.Regular; | ||
AddFile(filePath, linkMetadata, SourceCodeKind.Regular); | ||
} | ||
} | ||
} |