@@ -202,62 +202,65 @@ private static CompletionItem CreateCompletionItem(
202202 string completionText = completionDetails . CompletionText ;
203203 InsertTextFormat insertTextFormat = InsertTextFormat . PlainText ;
204204
205- if ( ( completionDetails . CompletionType == CompletionType . Variable ) ||
206- ( completionDetails . CompletionType == CompletionType . ParameterName ) )
205+ switch ( completionDetails . CompletionType )
207206 {
208- // Look for type encoded in the tooltip for parameters and variables.
209- // Display PowerShell type names in [] to be consistent with PowerShell syntax
210- // and now the debugger displays type names.
211- var matches = Regex . Matches ( completionDetails . ToolTipText , @"^(\[.+\])" ) ;
212- if ( ( matches . Count > 0 ) && ( matches [ 0 ] . Groups . Count > 1 ) )
213- {
214- detailString = matches [ 0 ] . Groups [ 1 ] . Value ;
215- }
216- }
217- else if ( ( completionDetails . CompletionType == CompletionType . Method ) ||
218- ( completionDetails . CompletionType == CompletionType . Property ) )
219- {
220- // We have a raw signature for .NET members, heck let's display it. It's
221- // better than nothing.
222- documentationString = completionDetails . ToolTipText ;
223- }
224- else if ( completionDetails . CompletionType == CompletionType . Command )
225- {
226- // For Commands, let's extract the resolved command or the path for an exe
227- // from the ToolTipText - if there is any ToolTipText.
228- if ( completionDetails . ToolTipText != null )
229- {
230- // Fix for #240 - notepad++.exe in tooltip text caused regex parser to throw.
231- string escapedToolTipText = Regex . Escape ( completionDetails . ToolTipText ) ;
232-
233- // Don't display ToolTipText if it is the same as the ListItemText.
234- // Reject command syntax ToolTipText - it's too much to display as a detailString.
235- if ( ! completionDetails . ListItemText . Equals (
236- completionDetails . ToolTipText ,
237- StringComparison . OrdinalIgnoreCase ) &&
238- ! Regex . IsMatch ( completionDetails . ToolTipText ,
239- @"^\s*" + escapedToolTipText + @"\s+\[" ) )
207+ case CompletionType . ParameterValue :
208+ case CompletionType . Method :
209+ case CompletionType . Property :
210+ detailString = completionDetails . ToolTipText ;
211+ break ;
212+ case CompletionType . Variable :
213+ case CompletionType . ParameterName :
214+ // Look for type encoded in the tooltip for parameters and variables.
215+ // Display PowerShell type names in [] to be consistent with PowerShell syntax
216+ // and how the debugger displays type names.
217+ var matches = Regex . Matches ( completionDetails . ToolTipText , @"^(\[.+\])" ) ;
218+ if ( ( matches . Count > 0 ) && ( matches [ 0 ] . Groups . Count > 1 ) )
240219 {
241- detailString = completionDetails . ToolTipText ;
220+ detailString = matches [ 0 ] . Groups [ 1 ] . Value ;
242221 }
243- }
244- }
245- else if ( completionDetails . CompletionType == CompletionType . Folder && EndsWithQuote ( completionText ) )
246- {
247- // Insert a final "tab stop" as identified by $0 in the snippet provided for completion.
248- // For folder paths, we take the path returned by PowerShell e.g. 'C:\Program Files' and insert
249- // the tab stop marker before the closing quote char e.g. 'C:\Program Files$0'.
250- // This causes the editing cursor to be placed *before* the final quote after completion,
251- // which makes subsequent path completions work. See this part of the LSP spec for details:
252- // https://microsoft.github.io/language-server-protocol/specification#textDocument_completion
253-
254- // Since we want to use a "tab stop" we need to escape a few things for Textmate to render properly.
255- var sb = new StringBuilder ( completionDetails . CompletionText )
256- . Replace ( @"\" , @"\\" )
257- . Replace ( @"}" , @"\}" )
258- . Replace ( @"$" , @"\$" ) ;
259- completionText = sb . Insert ( sb . Length - 1 , "$0" ) . ToString ( ) ;
260- insertTextFormat = InsertTextFormat . Snippet ;
222+ break ;
223+ case CompletionType . Command :
224+ // For Commands, let's extract the resolved command or the path for an exe
225+ // from the ToolTipText - if there is any ToolTipText.
226+ if ( completionDetails . ToolTipText != null )
227+ {
228+ // Fix for #240 - notepad++.exe in tooltip text caused regex parser to throw.
229+ string escapedToolTipText = Regex . Escape ( completionDetails . ToolTipText ) ;
230+
231+ // Don't display ToolTipText if it is the same as the ListItemText.
232+ // Reject command syntax ToolTipText - it's too much to display as a detailString.
233+ if ( ! completionDetails . ListItemText . Equals (
234+ completionDetails . ToolTipText ,
235+ StringComparison . OrdinalIgnoreCase ) &&
236+ ! Regex . IsMatch ( completionDetails . ToolTipText ,
237+ @"^\s*" + escapedToolTipText + @"\s+\[" ) )
238+ {
239+ detailString = completionDetails . ToolTipText ;
240+ }
241+ }
242+
243+ break ;
244+ case CompletionType . Folder :
245+ // Insert a final "tab stop" as identified by $0 in the snippet provided for completion.
246+ // For folder paths, we take the path returned by PowerShell e.g. 'C:\Program Files' and insert
247+ // the tab stop marker before the closing quote char e.g. 'C:\Program Files$0'.
248+ // This causes the editing cursor to be placed *before* the final quote after completion,
249+ // which makes subsequent path completions work. See this part of the LSP spec for details:
250+ // https://microsoft.github.io/language-server-protocol/specification#textDocument_completion
251+
252+ // Since we want to use a "tab stop" we need to escape a few things for Textmate to render properly.
253+ if ( EndsWithQuote ( completionText ) )
254+ {
255+ var sb = new StringBuilder ( completionDetails . CompletionText )
256+ . Replace ( @"\" , @"\\" )
257+ . Replace ( @"}" , @"\}" )
258+ . Replace ( @"$" , @"\$" ) ;
259+ completionText = sb . Insert ( sb . Length - 1 , "$0" ) . ToString ( ) ;
260+ insertTextFormat = InsertTextFormat . Snippet ;
261+ }
262+
263+ break ;
261264 }
262265
263266 // Force the client to maintain the sort order in which the
0 commit comments