@@ -32,6 +32,8 @@ internal static class AstOperations
32
32
33
33
private static readonly SemaphoreSlim s_completionHandle = AsyncUtils . CreateSimpleLockingSemaphore ( ) ;
34
34
35
+ private static PowerShell pwsh = PowerShell . Create ( ) ;
36
+
35
37
/// <summary>
36
38
/// Gets completions for the symbol found in the Ast at
37
39
/// the given file offset.
@@ -69,6 +71,11 @@ static public async Task<CommandCompletion> GetCompletionsAsync(
69
71
return null ;
70
72
}
71
73
74
+ if ( ! RunspaceSynchronizer . IsReadyForEvents )
75
+ {
76
+ RunspaceSynchronizer . InitializeRunspaces ( powerShellContext . CurrentRunspace . Runspace , pwsh . Runspace ) ;
77
+ }
78
+
72
79
try
73
80
{
74
81
IScriptPosition cursorPosition = ( IScriptPosition ) s_extentCloneWithNewOffset . Invoke (
@@ -90,49 +97,65 @@ static public async Task<CommandCompletion> GetCompletionsAsync(
90
97
91
98
var stopwatch = new Stopwatch ( ) ;
92
99
100
+ stopwatch . Start ( ) ;
101
+
102
+ try
103
+ {
104
+ return CommandCompletion . CompleteInput (
105
+ scriptAst ,
106
+ currentTokens ,
107
+ cursorPosition ,
108
+ options : null ,
109
+ powershell : pwsh ) ;
110
+ }
111
+ finally
112
+ {
113
+ stopwatch . Stop ( ) ;
114
+ logger . Write ( LogLevel . Verbose , $ "IntelliSense completed in { stopwatch . ElapsedMilliseconds } ms.") ;
115
+ }
93
116
// If the current runspace is out of process we can use
94
117
// CommandCompletion.CompleteInput because PSReadLine won't be taking up the
95
118
// main runspace.
96
- if ( powerShellContext . IsCurrentRunspaceOutOfProcess ( ) )
97
- {
98
- using ( RunspaceHandle runspaceHandle = await powerShellContext . GetRunspaceHandleAsync ( cancellationToken ) )
99
- using ( PowerShell powerShell = PowerShell . Create ( ) )
100
- {
101
- powerShell . Runspace = runspaceHandle . Runspace ;
102
- stopwatch . Start ( ) ;
103
- try
104
- {
105
- return CommandCompletion . CompleteInput (
106
- scriptAst ,
107
- currentTokens ,
108
- cursorPosition ,
109
- options : null ,
110
- powershell : powerShell ) ;
111
- }
112
- finally
113
- {
114
- stopwatch . Stop ( ) ;
115
- logger . Write ( LogLevel . Verbose , $ "IntelliSense completed in { stopwatch . ElapsedMilliseconds } ms.") ;
116
- }
117
- }
118
- }
119
-
120
- CommandCompletion commandCompletion = null ;
121
- await powerShellContext . InvokeOnPipelineThreadAsync (
122
- pwsh =>
123
- {
124
- stopwatch . Start ( ) ;
125
- commandCompletion = CommandCompletion . CompleteInput (
126
- scriptAst ,
127
- currentTokens ,
128
- cursorPosition ,
129
- options : null ,
130
- powershell : pwsh ) ;
131
- } ) ;
132
- stopwatch . Stop ( ) ;
133
- logger . Write ( LogLevel . Verbose , $ "IntelliSense completed in { stopwatch . ElapsedMilliseconds } ms.") ;
134
-
135
- return commandCompletion ;
119
+ // if (powerShellContext.IsCurrentRunspaceOutOfProcess())
120
+ // {
121
+ // using (RunspaceHandle runspaceHandle = await powerShellContext.GetRunspaceHandleAsync(cancellationToken))
122
+ // using (PowerShell powerShell = PowerShell.Create())
123
+ // {
124
+ // powerShell.Runspace = runspaceHandle.Runspace;
125
+ // stopwatch.Start();
126
+ // try
127
+ // {
128
+ // return CommandCompletion.CompleteInput(
129
+ // scriptAst,
130
+ // currentTokens,
131
+ // cursorPosition,
132
+ // options: null,
133
+ // powershell: powerShell);
134
+ // }
135
+ // finally
136
+ // {
137
+ // stopwatch.Stop();
138
+ // logger.Write(LogLevel.Verbose, $"IntelliSense completed in {stopwatch.ElapsedMilliseconds}ms.");
139
+ // }
140
+ // }
141
+ // }
142
+
143
+ // CommandCompletion commandCompletion = null;
144
+ // await powerShellContext.InvokeOnPipelineThreadAsync(
145
+ // pwsh =>
146
+ // {
147
+ // stopwatch.Start();
148
+ // commandCompletion = CommandCompletion.CompleteInput(
149
+ // scriptAst,
150
+ // currentTokens,
151
+ // cursorPosition,
152
+ // options: null,
153
+ // powershell: pwsh);
154
+ // });
155
+ // stopwatch.Stop();
156
+ // logger.Write(LogLevel.Verbose, $"IntelliSense completed in {stopwatch.ElapsedMilliseconds}ms.");
157
+
158
+ // return commandCompletion;
136
159
}
137
160
finally
138
161
{
0 commit comments