8000 Fix various about topic help issues by adityapatwardhan · Pull Request #4014 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Fix various about topic help issues #4014

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

Merged
merged 8 commits into from
Jun 19, 2017

Conversation

adityapatwardhan
Copy link
Member
@adityapatwardhan adityapatwardhan commented Jun 15, 2017

Fixes #3782 #2565 #4011 #4013

  • Fix double help topic printing issue
  • Fix regressions introduced by change a52adcd
  • Use WildcardPattern to fix tab completion

* Fix double help topic printing issue
* Fix regressions introduced by change a52adcd
* Use wildcardPattern to fix tab completion
@adityapatwardhan
Copy link
Member Author

@powercode I changed some code CompletionCompleters.cs which was modified by you recently. Can you please have a look?

@chunqingchen
Copy link
Contributor

signed off

@adityapatwardhan
Copy link
Member Author

@PowerShell/powershell-maintainers This PR is ready to merge.

//On CoreCLR we use ApplicationBase assembly location. That gives us the directory name.
//Hence we do not need to extract the directory name from returnValue.

#if !CORECLR
if (returnValue != null)
{
returnValue = Path.GetDirectoryName(returnValue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed even for FullCLR if you use Utils.GetApplicationBase(Utils.DefaultPowerShellShellID). It returns the pshome path.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetMshDefaultInstallationPath had only one reference, replaced where it was called with Utils.GetApplicationBase(Utils.DefaultPowerShellShellID); And deleted the function GetMshDefaultInstallationPath

var wordToComplete = context.WordToComplete + "*";
var topicPattern = WildcardPattern.Get("about_*.help.txt", WildcardOptions.IgnoreCase);
string[] files = null;

try
{
files = Directory.GetFiles(dirPath, wordToComplete);
var wildcardPattern = WildcardPattern.Get(wordToComplete, WildcardOptions.IgnoreCase);
files = Directory.GetFiles(dirPath).Where(f => wildcardPattern.IsMatch(Path.GetFileName(f))).ToArray();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's recommended to avoid LINQ in perf-sensitive code path (see pref-considerations). Tab completion is perf sensitive, so could you please replace this with a loop?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

{
// We don't actually need the drive, but the drive must be "mounted" in PowerShell before completion
// can succeed. This call will mount the drive if it wasn't already.
executionContext.SessionState.Drive.GetAtScope(wordToComplete.Substring(0, 1), "global");
context.ExecutionContext.SessionState.Drive.GetAtScope(wordToComplete.Substring(0, 1), "global");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to replace executionContext with context.ExecutionContext at the two spots here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

var wordToComplete = context.WordToComplete + "*";
var topicPattern = WildcardPattern.Get("about_*.help.txt", WildcardOptions.IgnoreCase);
string[] files = null;
ArrayList files = new ArrayList();
Copy link
Member
@daxian-dbw daxian-dbw Jun 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use List<string> here? We prefer to strongly typed generic collection whenever possible, it will avoid a cast from object to string in the foreach (string file in files) loop later. However, the concern here is not about the perf hit of the extra casting, but that people will copy pattern of existing code, so better to let them copy List<string> instead of ArrayList.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@adityapatwardhan
Copy link
Member Author

Opened issue #4037 as discussed for refactoring.

@daxian-dbw
Copy link
Member

@adityapatwardhan If you search new CompletionContext { in CompletionCompleters.cs you will find 5 more instances of it which are not updated in this PR. Do they need to be fixed as well?

@adityapatwardhan
Copy link
Member Author

@daxian-dbw Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get-Help about_* bugs (conceptual help topics)
4 participants
0