Skip to content

Fix for issue 12040#18279

Merged
bpasero merged 6 commits intomicrosoft:masterfrom
hun1ahpu:fix12040
Jan 13, 2017
Merged

Fix for issue 12040#18279
bpasero merged 6 commits intomicrosoft:masterfrom
hun1ahpu:fix12040

Conversation

@hun1ahpu
Copy link
Contributor

@hun1ahpu hun1ahpu commented Jan 8, 2017

Fix proposal for issue #12040 : Shortening the paths of the duplicate filenames.

Goal

  • Path is shortened by replacing excessive info with ellipsis.
  • Every shortened path has only one match from the original paths. And vice versa for every original path there is only one shortened path that matches it.

Implementation details and assumptions

  • For every path in the list we search for the shortest subpath that is not a subpath in any other path.
  • Last segment of the path is treated differently while checking for match as it's next to the filename.
  • Paths considered as case-sensitive when checking for subpath condition: 'a/b/C' and 'a/b/c' are different. The reason is: in the current implementation the filenames are case-sensitive meaning test.txt and TEST.txt are not duplicates.
  • Algorithm can be optimized later if needed. Usually the number of duplicate filenames is small.

Future updates (if this PR is accepted):

  • Always keep disk drive letter at the beginning of the path, same for schema:// (TODOs in unit tests).
  • Do not replace if path segment is short enough (one letter).

@bpasero bpasero self-assigned this Jan 9, 2017
Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

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

@hun1ahpu this is cool, thanks. I gave some feedback in the code.

Also I ran a test quickly and wonder about this situation:

image

In particular:

  • first loader.js is inside qunit.1/qunit
  • second loader.js is inside qunit.1
  • third loader.js is inside qunit

I find the first and second tab now hard to distinguish, shouldn't the full path be shown in this case?

* Every shorten path matches only one original path and vice versa.
*/
export function shorten(paths: string[]): string[] {
var separator = isWindows ? '\\' : '/';
Copy link
Member

Choose a reason for hiding this comment

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

import { isLinux, isWindows } from 'vs/base/common/platform';
import { fill } from 'vs/base/common/arrays';
import { CharCode } from 'vs/base/common/charCode';
import { endsWith } from 'vs/base/common/strings';
Copy link
Member

Choose a reason for hiding this comment

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

Overall, can you please use const and let instead of var for variables?

*/
export function shorten(paths: string[]): string[] {
var separator = isWindows ? '\\' : '/';
var ellipsis = '...';
Copy link
Member

Choose a reason for hiding this comment

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

@hun1ahpu
Copy link
Contributor Author

hun1ahpu commented Jan 9, 2017

@bpasero Thank you for your comments. I've resolved comments in the code.
Regarding the other comment I thought the distinction between direct and inderect parent was clear enough. But I agree it is probably confusing. I guess we may consider all the paths like 'a', 'a/...', '.../a' as hard to distinguish. Same for a/b/... and .../a/b ?

import { fill } from 'vs/base/common/arrays';
import { rtrim } from 'vs/base/common/strings';
import { CharCode } from 'vs/base/common/charCode';
import { endsWith } from 'vs/base/common/strings';
Copy link
Member

Choose a reason for hiding this comment

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

@hun1ahpu unused import?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

labelDuplicates.forEach(duplicates => {
if (duplicates.length > 1) {
duplicates.forEach(duplicate => {
var shortenedDescriptions = paths.shorten(duplicates.map(duplicate => duplicate.editor.getDescription()));
Copy link
Member

Choose a reason for hiding this comment

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

var => const

@bpasero
Copy link
Member

bpasero commented Jan 10, 2017

@hun1ahpu here is another example I am not sure about:

image

We have:

  • readme.md (top level)
  • qunit/readme.md => qunit
  • lib/readme.md => lib
  • lib/more/readme.md => lib/...
  • qunit/more/readme.md => qunit/...

To me this does not really improve the way I now understand where the files are from. Imho the right fix here is to show as many segments of the path until the description is unique. So I would expect:

lib/more instead of lib/... and qunit/more instead of qunit/...

@hun1ahpu
Copy link
Contributor Author

@bpasero I've resolved your comments. It also works for your example now.z
Thanks.

@bpasero bpasero requested a review from Tyriar January 12, 2017 06:16
@bpasero
Copy link
Member

bpasero commented Jan 12, 2017

@hun1ahpu thanks

@Tyriar I am adding you as reviewer to see if the behaviour is now desired. since you filed #12040.

This is for example how terminalService.ts is looking after this change is applied:

image

@Tyriar
Copy link
Member

Tyriar commented Jan 12, 2017

Really cool stuff!

I found one minor problem/preference in that I think it should say . next to files in the root folder:

image

Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

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

LGTM from a functionality perspective apart from the minor issue above.

@bpasero
Copy link
Member

bpasero commented Jan 12, 2017

@Tyriar "."? like how? Can you give an example how it would look like?

@Tyriar
Copy link
Member

Tyriar commented Jan 12, 2017

@bpasero just a grey . next to gulpfile.js like how it has build. This is a personal preference obviously and would indicate to me, hey you have another gulpfile.js open too (as the tabs may not both be on the screen).

@bpasero
Copy link
Member

bpasero commented Jan 12, 2017

Ah, so the "." would only show if there is a duplicate. Yeah, I dont mind either way.

@bpasero bpasero merged commit 5070ce4 into microsoft:master Jan 13, 2017
@bpasero
Copy link
Member

bpasero commented Jan 13, 2017

Merged, thanks for the fix!

@bpasero bpasero added this to the February 2017 milestone Jan 13, 2017
@bpasero
Copy link
Member

bpasero commented Jan 13, 2017

@hun1ahpu your tests seem to fail on macOS. Can you fix them? I moved the code into labels.ts and labels.test.ts. Thanks.

@hun1ahpu hun1ahpu deleted the fix12040 branch January 13, 2017 16:46
@hun1ahpu
Copy link
Contributor Author

@bpasero I will take a look at them tonight.
Also will try to send a couple of updates later: '.' asked by @Tyriar and other improvements.
Thanks.

@bpasero
Copy link
Member

bpasero commented Jan 13, 2017

@hun1ahpu feel free to open a new PR for this, I was a bit too early to merge this in it seems ;)

@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants