|
5 | 5 |
|
6 | 6 | using Microsoft.PowerShell.EditorServices.Utility;
|
7 | 7 | using System;
|
| 8 | +using System.Diagnostics; |
8 | 9 | using System.Collections.Generic;
|
9 | 10 | using System.Linq;
|
10 | 11 | using System.Reflection;
|
11 | 12 | using System.Threading;
|
12 | 13 | using System.Threading.Tasks;
|
| 14 | +using System.Management.Automation.Language; |
| 15 | +using System.Management.Automation.Runspaces; |
13 | 16 |
|
14 | 17 | namespace Microsoft.PowerShell.EditorServices
|
15 | 18 | {
|
16 |
| - using System.Diagnostics; |
17 | 19 | using System.Management.Automation;
|
18 |
| - using System.Management.Automation.Language; |
19 |
| - using System.Management.Automation.Runspaces; |
20 | 20 |
|
21 | 21 | /// <summary>
|
22 | 22 | /// Provides common operations for the syntax tree of a parsed script.
|
23 | 23 | /// </summary>
|
24 | 24 | internal static class AstOperations
|
25 | 25 | {
|
| 26 | + // TODO: When netstandard is upgraded to 2.0, see if |
| 27 | + // Delegate.CreateDelegate can be used here instead |
| 28 | + private static readonly MethodInfo s_extentCloneWithNewOffset = typeof(PSObject).GetTypeInfo().Assembly |
| 29 | + .GetType("System.Management.Automation.Language.InternalScriptPosition") |
| 30 | + .GetMethod("CloneWithNewOffset", BindingFlags.Instance | BindingFlags.NonPublic); |
| 31 | + |
26 | 32 | /// <summary>
|
27 | 33 | /// Gets completions for the symbol found in the Ast at
|
28 | 34 | /// the given file offset.
|
@@ -55,24 +61,10 @@ static public async Task<CommandCompletion> GetCompletions(
|
55 | 61 | ILogger logger,
|
56 | 62 | CancellationToken cancellationToken)
|
57 | 63 | {
|
58 |
| - var type = scriptAst.Extent.StartScriptPosition.GetType(); |
59 |
| - var method = |
60 |
| -#if CoreCLR |
61 |
| - type.GetMethod( |
62 |
| - "CloneWithNewOffset", |
63 |
| - BindingFlags.Instance | BindingFlags.NonPublic); |
64 |
| -#else |
65 |
| - type.GetMethod( |
66 |
| - "CloneWithNewOffset", |
67 |
| - BindingFlags.Instance | BindingFlags.NonPublic, |
68 |
| - null, |
69 |
| - new[] { typeof(int) }, null); |
70 |
| -#endif |
71 |
| - |
72 |
| - IScriptPosition cursorPosition = |
73 |
| - (IScriptPosition)method.Invoke( |
74 |
| - scriptAst.Extent.StartScriptPosition, |
75 |
| - new object[] { fileOffset }); |
| 64 | + |
| 65 | + IScriptPosition cursorPosition = (IScriptPosition)s_extentCloneWithNewOffset.Invoke( |
| 66 | + scriptAst.Extent.StartScriptPosition, |
| 67 | + new object[] { fileOffset }); |
76 | 68 |
|
77 | 69 | logger.Write(
|
78 | 70 | LogLevel.Verbose,
|
|
0 commit comments