-
Notifications
You must be signed in to change notification settings - Fork 236
Add tooltip to completions ParameterValue #1152
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,62 +202,65 @@ private static CompletionItem CreateCompletionItem( | |
string completionText = completionDetails.CompletionText; | ||
InsertTextFormat insertTextFormat = InsertTextFormat.PlainText; | ||
|
||
if ((completionDetails.CompletionType == CompletionType.Variable) || | ||
(completionDetails.CompletionType == CompletionType.ParameterName)) | ||
switch (completionDetails.CompletionType) | ||
{ | ||
// Look for type encoded in the tooltip for parameters and variables. | ||
// Display PowerShell type names in [] to be consistent with PowerShell syntax | ||
// and now the debugger displays type names. | ||
var matches = Regex.Matches(completionDetails.ToolTipText, @"^(\[.+\])"); | ||
if ((matches.Count > 0) && (matches[0].Groups.Count > 1)) | ||
{ | ||
detailString = matches[0].Groups[1].Value; | ||
} | ||
} | ||
else if ((completionDetails.CompletionType == CompletionType.Method) || | ||
(completionDetails.CompletionType == CompletionType.Property)) | ||
{ | ||
// We have a raw signature for .NET members, heck let's display it. It's | ||
// better than nothing. | ||
documentationString = completionDetails.ToolTipText; | ||
} | ||
else if (completionDetails.CompletionType == CompletionType.Command) | ||
{ | ||
// For Commands, let's extract the resolved command or the path for an exe | ||
// from the ToolTipText - if there is any ToolTipText. | ||
if (completionDetails.ToolTipText != null) | ||
{ | ||
// Fix for #240 - notepad++.exe in tooltip text caused regex parser to throw. | ||
string escapedToolTipText = Regex.Escape(completionDetails.ToolTipText); | ||
|
||
// Don't display ToolTipText if it is the same as the ListItemText. | ||
// Reject command syntax ToolTipText - it's too much to display as a detailString. | ||
if (!completionDetails.ListItemText.Equals( | ||
completionDetails.ToolTipText, | ||
StringComparison.OrdinalIgnoreCase) && | ||
!Regex.IsMatch(completionDetails.ToolTipText, | ||
@"^\s*" + escapedToolTipText + @"\s+\[")) | ||
case CompletionType.ParameterValue: | ||
case CompletionType.Method: | ||
case CompletionType.Property: | ||
detailString = completionDetails.ToolTipText; | ||
break; | ||
case CompletionType.Variable: | ||
case CompletionType.ParameterName: | ||
// Look for type encoded in the tooltip for parameters and variables. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variables is on line 207? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh I need to move it down gotcha There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed! |
||
// Display PowerShell type names in [] to be consistent with PowerShell syntax | ||
// and how the debugger displays type names. | ||
var matches = Regex.Matches(completionDetails.ToolTipText, @"^(\[.+\])"); | ||
if ((matches.Count > 0) && (matches[0].Groups.Count > 1)) | ||
{ | ||
detailString = completionDetails.ToolTipText; | ||
detailString = matches[0].Groups[1].Value; | ||
} | ||
} | ||
} | ||
else if (completionDetails.CompletionType == CompletionType.Folder && EndsWithQuote(completionText)) | ||
{ | ||
// Insert a final "tab stop" as identified by $0 in the snippet provided for completion. | ||
// For folder paths, we take the path returned by PowerShell e.g. 'C:\Program Files' and insert | ||
// the tab stop marker before the closing quote char e.g. 'C:\Program Files$0'. | ||
// This causes the editing cursor to be placed *before* the final quote after completion, | ||
// which makes subsequent path completions work. See this part of the LSP spec for details: | ||
// https://microsoft.github.io/language-server-protocol/specification#textDocument_completion | ||
|
||
// Since we want to use a "tab stop" we need to escape a few things for Textmate to render properly. | ||
var sb = new StringBuilder(completionDetails.CompletionText) | ||
.Replace(@"\", @"\\") | ||
.Replace(@"}", @"\}") | ||
.Replace(@"$", @"\$"); | ||
completionText = sb.Insert(sb.Length - 1, "$0").ToString(); | ||
insertTextFormat = InsertTextFormat.Snippet; | ||
break; | ||
case CompletionType.Command: | ||
// For Commands, let's extract the resolved command or the path for an exe | ||
// from the ToolTipText - if there is any ToolTipText. | ||
if (completionDetails.ToolTipText != null) | ||
{ | ||
// Fix for #240 - notepad++.exe in tooltip text caused regex parser to throw. | ||
string escapedToolTipText = Regex.Escape(completionDetails.ToolTipText); | ||
|
||
// Don't display ToolTipText if it is the same as the ListItemText. | ||
// Reject command syntax ToolTipText - it's too much to display as a detailString. | ||
if (!completionDetails.ListItemText.Equals( | ||
completionDetails.ToolTipText, | ||
StringComparison.OrdinalIgnoreCase) && | ||
!Regex.IsMatch(completionDetails.ToolTipText, | ||
@"^\s*" + escapedToolTipText + @"\s+\[")) | ||
{ | ||
detailString = completionDetails.ToolTipText; | ||
} | ||
} | ||
|
||
break; | ||
case CompletionType.Folder: | ||
// Insert a final "tab stop" as identified by $0 in the snippet provided for completion. | ||
// For folder paths, we take the path returned by PowerShell e.g. 'C:\Program Files' and insert | ||
// the tab stop marker before the closing quote char e.g. 'C:\Program Files$0'. | ||
// This causes the editing cursor to be placed *before* the final quote after completion, | ||
// which makes subsequent path completions work. See this part of the LSP spec for details: | ||
// https://microsoft.github.io/language-server-protocol/specification#textDocument_completion | ||
|
||
// Since we want to use a "tab stop" we need to escape a few things for Textmate to render properly. | ||
if (EndsWithQuote(completionText)) | ||
{ | ||
var sb = new StringBuilder(completionDetails.CompletionText) | ||
.Replace(@"\", @"\\") | ||
.Replace(@"}", @"\}") | ||
.Replace(@"$", @"\$"); | ||
completionText = sb.Insert(sb.Length - 1, "$0").ToString(); | ||
insertTextFormat = InsertTextFormat.Snippet; | ||
} | ||
|
||
break; | ||
} | ||
|
||
// Force the client to maintain the sort order in which the | ||
|
Uh oh!
There was an error while loading. Please reload this page.