@@ -46,7 +46,7 @@ public PsesCompletionHandler(
46
46
// TODO: What do we do with the arguments?
47
47
DocumentSelector = LspUtils . PowerShellDocumentSelector ,
48
48
ResolveProvider = true ,
49
- TriggerCharacters = new [ ] { "." , "-" , ":" , "\\ " , "$" }
49
+ TriggerCharacters = new [ ] { "." , "-" , ":" , "\\ " , "$" , " " }
50
50
} ;
51
51
52
52
public override async Task < CompletionList > Handle ( CompletionParams request , CancellationToken cancellationToken )
@@ -55,13 +55,16 @@ public override async Task<CompletionList> Handle(CompletionParams request, Canc
55
55
int cursorColumn = request . Position . Character + 1 ;
56
56
57
57
ScriptFile scriptFile = _workspaceService . GetFile ( request . TextDocument . Uri ) ;
58
- IEnumerable < CompletionItem > completionResults = await GetCompletionsInFileAsync (
58
+ ( bool isIncomplete , IReadOnlyList < CompletionItem > completionResults ) = await GetCompletionsInFileAsync (
59
59
scriptFile ,
60
60
cursorLine ,
61
61
cursorColumn ,
62
62
cancellationToken ) . ConfigureAwait ( false ) ;
63
63
64
- return new CompletionList ( completionResults ) ;
64
+ // Treat completions trigged by space as incomplete so that `gci `
65
+ // and then typing `-` doesn't just filter the list of parameter values
66
+ // (typically files) returned by the space completion
67
+ return new CompletionList ( completionResults , isIncomplete || request . Context . TriggerCharacter is " " ) ;
65
68
}
66
69
67
70
// Handler for "completionItem/resolve". In VSCode this is fired when a completion item is highlighted in the completion list.
@@ -113,7 +116,7 @@ public override async Task<CompletionItem> Handle(CompletionItem request, Cancel
113
116
/// <returns>
114
117
/// A CommandCompletion instance completions for the identified statement.
115
118
/// </returns>
116
- internal async Task < IEnumerable < CompletionItem > > GetCompletionsInFileAsync (
119
+ internal async Task < ( bool isIncomplete , IReadOnlyList < CompletionItem > matches ) > GetCompletionsInFileAsync (
117
120
ScriptFile scriptFile ,
118
121
int lineNumber ,
119
122
int columnNumber ,
@@ -131,21 +134,32 @@ internal async Task<IEnumerable<CompletionItem>> GetCompletionsInFileAsync(
131
134
132
135
if ( result . CompletionMatches . Count == 0 )
133
136
{
134
- return Array . Empty < CompletionItem > ( ) ;
137
+ return ( true , Array . Empty < CompletionItem > ( ) ) ;
135
138
}
136
139
137
140
BufferRange replacedRange = scriptFile . GetRangeBetweenOffsets (
138
141
result . ReplacementIndex ,
139
142
result . ReplacementIndex + result . ReplacementLength ) ;
140
143
144
+ bool isIncomplete = false ;
141
145
// Create OmniSharp CompletionItems from PowerShell CompletionResults. We use a for loop
142
146
// because the index is used for sorting.
143
147
CompletionItem [ ] completionItems = new CompletionItem [ result . CompletionMatches . Count ] ;
144
148
for ( int i = 0 ; i < result . CompletionMatches . Count ; i ++ )
145
149
{
150
+ CompletionResult completionMatch = result . CompletionMatches [ i ] ;
151
+
152
+ // If a completion result is a variable scope like `$script:` we want to
153
+ // mark as incomplete so on typing `:` completion changes.
154
+ if ( completionMatch . ResultType is CompletionResultType . Variable
155
+ && completionMatch . CompletionText . EndsWith ( ":" ) )
156
+ {
157
+ isIncomplete = true ;
158
+ }
159
+
146
160
completionItems [ i ] = CreateCompletionItem ( result . CompletionMatches [ i ] , replacedRange , i + 1 ) ;
147
161
}
148
- return completionItems ;
162
+ return ( isIncomplete , completionItems ) ;
149
163
}
150
164
151
165
internal static CompletionItem CreateCompletionItem (
0 commit comments