-
Notifications
You must be signed in to change notification settings - Fork 235
Add powershellcontext #1005
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
Merged
TylerLeonhardt
merged 3 commits into
PowerShell:omnisharp-lsp
from
TylerLeonhardt:add-powershellcontext
Aug 9, 2019
Merged
Add powershellcontext #1005
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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
84 changes: 84 additions & 0 deletions
84
...owerShellEditorServices.Engine/Services/PowerShellContext/Components/ComponentRegistry.cs
This file contains hidden or 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,84 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.PowerShell.EditorServices.Components | ||
{ | ||
/// <summary> | ||
/// Provides a default implementation for the IComponentRegistry | ||
/// interface. | ||
/// </summary> | ||
public class ComponentRegistry : IComponentRegistry | ||
{ | ||
private Dictionary<Type, object> componentRegistry = | ||
new Dictionary<Type, object>(); | ||
|
||
/// <summary> | ||
/// Registers an instance of the specified component type | ||
/// or throws an ArgumentException if an instance has | ||
/// already been registered. | ||
/// </summary> | ||
/// <param name="componentType"> | ||
/// The component type that the instance represents. | ||
/// </param> | ||
/// <param name="componentInstance"> | ||
/// The instance of the component to be registered. | ||
/// </param> | ||
/// <returns> | ||
/// The provided component instance for convenience in assignment | ||
/// statements. | ||
/// </returns> | ||
public object Register(Type componentType, object componentInstance) | ||
{ | ||
this.componentRegistry.Add(componentType, componentInstance); | ||
return componentInstance; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Gets the registered instance of the specified | ||
/// component type or throws a KeyNotFoundException if | ||
/// no instance has been registered. | ||
/// </summary> | ||
/// <param name="componentType"> | ||
/// The component type for which an instance will be retrieved. | ||
/// </param> | ||
/// <returns>The implementation of the specified type.</returns> | ||
public object Get(Type componentType) | ||
{ | ||
return this.componentRegistry[componentType]; | ||
} | ||
|
||
/// <summary> | ||
/// Attempts to retrieve the instance of the specified | ||
/// component type and, if found, stores it in the | ||
/// componentInstance parameter. | ||
/// </summary> | ||
/// <param name="componentInstance"> | ||
/// The out parameter in which the found instance will be stored. | ||
/// </param> | ||
/// <param name="componentType"> | ||
/// The component type for which an instance will be retrieved. | ||
/// </param> | ||
/// <returns> | ||
/// True if a registered instance was found, false otherwise. | ||
/// </returns> | ||
public bool TryGet(Type componentType, out object componentInstance) | ||
{ | ||
componentInstance = null; | ||
|
||
if (this.componentRegistry.TryGetValue(componentType, out componentInstance)) | ||
{ | ||
return componentInstance != null; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...werShellEditorServices.Engine/Services/PowerShellContext/Components/IComponentRegistry.cs
This file contains hidden or 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,61 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System; | ||
|
||
namespace Microsoft.PowerShell.EditorServices.Components | ||
{ | ||
/// <summary> | ||
/// Specifies the contract for a registry of component interfaces. | ||
/// </summary> | ||
public interface IComponentRegistry | ||
{ | ||
/// <summary> | ||
/// Registers an instance of the specified component type | ||
/// or throws an ArgumentException if an instance has | ||
/// already been registered. | ||
/// </summary> | ||
/// <param name="componentType"> | ||
/// The component type that the instance represents. | ||
/// </param> | ||
/// <param name="componentInstance"> | ||
/// The instance of the component to be registered. | ||
/// </param> | ||
/// <returns> | ||
/// The provided component instance for convenience in assignment | ||
/// statements. | ||
/// </returns> | ||
object Register( | ||
Type componentType, | ||
object componentInstance); | ||
|
||
/// <summary> | ||
/// Gets the registered instance of the specified | ||
/// component type or throws a KeyNotFoundException if | ||
/// no instance has been registered. | ||
/// </summary> | ||
/// <param name="componentType"> | ||
/// The component type for which an instance will be retrieved. | ||
/// </param> | ||
/// <returns>The implementation of the specified type.</returns> | ||
object Get(Type componentType); | ||
|
||
/// <summary> | ||
/// Attempts to retrieve the instance of the specified | ||
/// component type and, if found, stores it in the | ||
/// componentInstance parameter. | ||
/// </summary> | ||
/// <param name="componentType"> | ||
/// The component type for which an instance will be retrieved. | ||
/// </param> | ||
/// <param name="componentInstance"> | ||
/// The out parameter in which the found instance will be stored. | ||
/// </param> | ||
/// <returns> | ||
/// True if a registered instance was found, false otherwise. | ||
/// </returns> | ||
bool TryGet(Type componentType, out object componentInstance); | ||
} | ||
} | ||
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.
Newline