Skip to content

Conversation

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Aug 29, 2017

PR Summary

Attempt to fix #1273

PR Checklist

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd also love to see tests for the order of the completed options. The first one should be the one with a correct casing, if accessible. Otherwise, the UX would be pretty bad in the multiple casing cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We use alphabetical sort with ignoring casing. I don't know how put an object with correct casing on first place. It looks you request creating very complex sorting.
Do anybody really create multiple files/directories with different casing on Unix?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is very common to have both Makefile and makefile.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is only one extra press.
I have no idea how to make this weighted sort by simple way 😕

Copy link
Contributor

Choose a reason for hiding this comment

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

Not exactly simple, but sort insensitive, then compare each element to it's successor in a case sensitive manner, swapping to get case correct first.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sample 1:
wordToComplete = "aB"

Input:
abcd
aBcd
abde
aBde

Result:
aBcd
aBde
abcd
abde

Sample 2:
wordToComplete = "aB*D"

Input:
abcdef
aBCDef
abcdgh
aBcDgh

Result:
aBCDef
aBcDgh
abcdef
abcdgh

-- If we want the results the sort is not simple as seems - we must take into account wildcards.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe:

  1. Get a case-sensitive array and sort it
  2. Get a case-insensitive array and sort it
  3. Remove elements of (1) array remove from (2) array
  4. Add elements of (2) array after end of (1) array

Copy link
Contributor

Choose a reason for hiding this comment

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

I would:

  1. Case-insensitive array sort
  2. For each element, compare case insensitive with the next element, if they are equal (should be rare), do a case sensitive wildcard match with the original word to complete to determine the ordering of these 2 elements, swapping if the first fails to match and the second does.

This should be O(n) with an upper bound of 2n, so it's cheaper than 2 sorts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is my sample 2 right? If so your suggestion don't work for it. We get:

Result:
aBcd
abcd
aBde
abde

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure there is a right and wrong result here - only a least surprising, and I think my suggestion prefers case insensitive over the wildcard match which is less surprising, but still orders with some case sensitivity.

At any rate, real world experience will guide us best - try and keep it simple and handle the Makefile/makefile case nicely, and we'll see if it's sufficient.

Copy link
Contributor

@lzybkr lzybkr left a comment

Choose a reason for hiding this comment

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

I think we'll want this as an option (on by default).

Options are not really documented or formalized, but see uses of

internal bool GetOption(string option, bool @default)
for examples.

Copy link
Contributor

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 call ToCharArray - that will unnecessarily create an array.

In C#, strings are enumerable, so you would just use foreach (var ch in wordToComplete) ....

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

First I made a prototype on PowerShell. :-)
Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can reasonably assume all characters are letters and pass wordToComplete.Length * 4 when constructing the string builder to avoid growing and copying the buffer.

Copy link
Collaborator Author

@iSazonov iSazonov Aug 30, 2017

Choose a reason for hiding this comment

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

Thanks! Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm no expert in Unicode - but I can imagine there are letters that have no upper/lowercase variants, so I would avoid the wildcard if ToUpper == ToLower.

Copy link
Collaborator

@vors vors Aug 29, 2017

Choose a reason for hiding this comment

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

German ß for example doesn't have upper in dotnet. (The correct capitalization is probably SS, but dotnet doesn't seem to do it, same as python 2.)
Also the Turkish I is a classical example: if default locale is used, then lower-cased I will be different. We probably can skip these details as a first implementation.

Note that [aa] is a valid regex.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! Fixed.

@iSazonov iSazonov force-pushed the unix-globbing-case-insensitive branch 5 times, most recently from 526ef53 to bfa1b17 Compare August 30, 2017 14:42
@iSazonov
Copy link
Collaborator Author

Options was added.
Also I had to fix an Issue with brackes in paths (tests failed for "Get-Help '.\My [Path]'").

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove, but it might be worth a comment saying we assume wordToComplete is already a wildcard pattern and do not want to escape anything.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed.
Comment added above in line 4114.

Previous I removed there if useLiteralPath - Please clarify the if - it seems we should
(1) always escape '[' and ']'
(2) escape StarOrQuestion for useLiteralPath but we did not this previous and don't now.

Copy link
Contributor

Choose a reason for hiding this comment

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

The word to complete is usually a wildcard pattern (unless the filename specifies -LiteralPath, but I don't think we do that today).

So I think it's probably best to not escape anything. It is probably uncommon to use tab completion and square brackets together, but I'm sure I've done it before, so it might feel broken.

This does mean you need to detect letters inside square brackets and ignore those.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So we leave as is now and add escape StarOrQuestion for useLiteralPath when we'll need?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, except I missed the code above that already does that, except you changed it.


In reply to: 136893930 [](ancestors = 136893930)

Copy link
Contributor

Choose a reason for hiding this comment

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

Not used now, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed.

@iSazonov
Copy link
Collaborator Author

iSazonov commented Aug 31, 2017

One MacOs test failed - I have no opportunity to debug 😕 @vors could you help?

Update: MacOs have /usr and /Users - I have to replace the test string and use /sbin.

@iSazonov iSazonov force-pushed the unix-globbing-case-insensitive branch from c1b300c to 352f380 Compare September 4, 2017 13:10
@lzybkr lzybkr changed the title Make TabCompletion case-insensivite for file names on Unix Make TabCompletion case-insensitive for file names on Unix Sep 4, 2017
@iSazonov iSazonov force-pushed the unix-globbing-case-insensitive branch from 7012631 to 6f3b842 Compare September 5, 2017 03:31
Copy link
Collaborator

@vors vors left a comment

Choose a reason for hiding this comment

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

  • prefer exact case match in the completion order.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like the code was correct before - only when we know we have -LiteralPath.

@iSazonov iSazonov force-pushed the unix-globbing-case-insensitive branch from 0465ccb to 10abc8f Compare September 11, 2017 04:08
@iSazonov
Copy link
Collaborator Author

@vors Could you please build and check that we have case match.

@iSazonov iSazonov force-pushed the unix-globbing-case-insensitive branch 2 times, most recently from 3c69681 to 801af60 Compare September 11, 2017 04:43
@vors
Copy link
Collaborator

vors commented Sep 11, 2017

@iSazonov order doesn't prefer the original casing from my experiments on macOS

@iSazonov iSazonov force-pushed the unix-globbing-case-insensitive branch 2 times, most recently from 985e11c to 3e60212 Compare September 11, 2017 10:38
@iSazonov iSazonov force-pushed the unix-globbing-case-insensitive branch from 3e60212 to 801af60 Compare September 11, 2017 12:47
@iSazonov
Copy link
Collaborator Author

@vors @lzybkr
Today I make some tests and now I suggest either close the PR or remove last commit (remove case-sensivire sorting for Unix) because I don't see a solution - we resolve wordToComplete to absolute filesystem paths then we should case-sensitively compare the paths with wordToComplete (as regex pattern) but in common case the wordToComplete can be relative "path" with wildcards or absolute "path" with wildcards. Ex.: /usr/*/*nn*/M*file and ./*/*nn*/M*file. Also we should convert (escape) wordToComplete to regex pattern. I have no ideas how make that in short code and I have no Unix development environment to create large solition.

@vors
Copy link
Collaborator

vors commented Sep 11, 2017

couple thoughts: order really matters only for a common case (no wildcards). If that is still hard, we can merge it without reordering and improve it later, if this behavior is guarded by an option flag.

@iSazonov iSazonov force-pushed the unix-globbing-case-insensitive branch from 801af60 to fb1eb1b Compare December 19, 2017 18:05
@iSazonov
Copy link
Collaborator Author

iSazonov commented Jan 19, 2018

I wonder can we use Resolve-Path -CaseInsensitive? It seems the new -CaseInsensitive could be useful.

@stale
Copy link

stale bot commented Apr 13, 2018

This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days.
Thank you for your contributions.
Community members are welcome to grab these works.

@stale stale bot added the Stale label Apr 13, 2018
@stale
Copy link

stale bot commented Apr 23, 2018

This PR has be automatically close because it is stale. If you wish to continue working on the PR, please first update the PR, then reopen it.
Thanks again for your contribution.
Community members are welcome to grab these works.

@stale stale bot closed this Apr 23, 2018
@iSazonov iSazonov deleted the unix-globbing-case-insensitive branch April 17, 2020 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Location completion should be case-insensitive

5 participants