Skip to content

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.

#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

{
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