Skip to content
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

[CLOSED] Adds directory names to the files in working tree, ... #4094

Open
core-ai-bot opened this issue Aug 29, 2021 · 30 comments
Open

[CLOSED] Adds directory names to the files in working tree, ... #4094

core-ai-bot opened this issue Aug 29, 2021 · 30 comments

Comments

@core-ai-bot
Copy link
Member

Issue by zaggino
Thursday Jul 11, 2013 at 00:43 GMT
Originally opened as adobe/brackets#4419


... when multiple files with the same name are opened.

Any comments welcome.

myfix


zaggino included the following code: https://github.com/adobe/brackets/pull/4419/commits

@core-ai-bot
Copy link
Member Author

Comment by pthiess
Thursday Jul 11, 2013 at 17:22 GMT


@larz0 can you please review

@core-ai-bot
Copy link
Member Author

Comment by karllindmark
Friday Jul 12, 2013 at 09:01 GMT


I was literally going to fork the repo and implement this, but it seems like you got it covered@zaggino. :-)

@core-ai-bot
Copy link
Member Author

Comment by larz0
Friday Jul 12, 2013 at 17:46 GMT


Looks good@zaggino, could we use "-" instead of "|", and use 11px font for the the directory class? Like the screenshot below:
screen shot 2013-07-12 at 10 45 28 am

This is great.

@core-ai-bot
Copy link
Member Author

Comment by larz0
Friday Jul 12, 2013 at 17:50 GMT


Actually, use the em dash ("—" instead). Thanks.

@core-ai-bot
Copy link
Member Author

Comment by zaggino
Saturday Jul 13, 2013 at 12:34 GMT


No problem.

capture

@core-ai-bot
Copy link
Member Author

Comment by njx
Monday Jul 15, 2013 at 19:48 GMT


Removing@larz0 as assignee since he's already reviewed it for UI design. We'll assign a reviewer or mark it [OPEN] soon.

@core-ai-bot
Copy link
Member Author

Comment by peterflynn
Thursday Jul 18, 2013 at 00:10 GMT


@larz0 I think we'd want em dash only on Mac -- Windows uses a regular hyphen. See the titlebar, for example...

We should probably hoist up some sort of platform-specific separator constant from the current titlebar code in DocumentCommandHandlers.WINDOW_TITLE_STRING so it can be shared with the new code here.

@core-ai-bot
Copy link
Member Author

Comment by larz0
Thursday Jul 18, 2013 at 01:05 GMT


@peterflynn ok sounds good. #4303 could use that as well then.

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Tuesday Jul 30, 2013 at 14:29 GMT


@peterflynn I agree that not repeating that construct in DocumentCommandHandlers would be a good thing. Any opinion on where a separator constant should go? It's not l10n related, but it could go in strings.

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Tuesday Jul 30, 2013 at 14:51 GMT


@zaggino Sorry for the delay in looking at this. Things got a bit hectic during sprint 28.

The first thing that I noticed in looking at your changes is that they feel like the way an extension would do things: augmenting the working set after the core code has done its work. On the other hand, the other code for presenting items in the working set is concerned with the presentation of single items... adding duplicate tracking code to the existing working set view code would require redrawing previously drawn items in many cases. The approach you took may just be cleaner overall.

WorkingSetView-test has a reasonable collection of tests to build on. Would you be able to add some tests that exercise this functionality. At least one test that adds a duplicate file to the working set, causing two files to be displayed with the directory would be good.

If that test was then extended to remove one of the two duplicate files from the working set, I think you'd spot a bug where the directory name stays displayed for the remaining file. (At least, when I read through the code, that's what it looks like would happen... I haven't tested it yet.)

@core-ai-bot
Copy link
Member Author

Comment by zaggino
Wednesday Jul 31, 2013 at 00:40 GMT


@dangoor Yes, you were right. I added a test for this and then fixed the problem, take a look please.

I also have a question - when I run tests in Brackets for the first time, they run from actual sources, which is fine. When I make some modifications to the tests, I need to restart Brackets before running tests again otherwise they seem to be running from some cached source. Am I doing something wrong? Surely it's not optimal to restart Brackets every time I write something into the tests.

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Wednesday Jul 31, 2013 at 17:29 GMT


@zaggino thanks for adding the test. I'll take a look at the code a bit later.

For running the tests without restarting, open the dev tools from the test runner window and click on the gear icon to pull up the settings. Click on Disable Caches there. (Annoying, I know! But, at least this is something you need only do once).

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Thursday Aug 01, 2013 at 20:02 GMT


I don't want to complicate this too much, but I noticed that if you open test/node/package.json and src/extensibility/node/package.json they both list "node" as the directory. I'd be okay with that for a first go at this feature, but I thought I'd mention it in case you feel like fixing that :)

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Thursday Aug 01, 2013 at 20:02 GMT


Overall, the code looks good, the test looks good. I appreciate the work you've done here!

@core-ai-bot
Copy link
Member Author

Comment by zaggino
Thursday Aug 01, 2013 at 20:28 GMT


That's a valid point and I actually thought of this one when I was first writing the code but wasn't really sure about the proper solution as different editors I have used in the past handle this different way. What do you think would be preferable? Show just first different directory there (this case would be 'extensibility' and 'test', I think eclipse does this) or keep adding parent directory names until strings are different (that would show 'extensibility/node' and 'test/node') ? I personally like the second option more but string could get very long in extreme cases of course. That could be solved that if there were many directories like a/c/d/e and b/c/d/e, middle common thing could be replaced to a/.../e and b/.../e. If I'll have a hint how the final thing should look like I have no problem implementing it.

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Thursday Aug 01, 2013 at 20:32 GMT


Maybe@larz0 has an opinion on this, but I like your suggesting of keep adding directories until the strings are different. (FWIW, Sublime seems to show the different directories starting from the top... src/extensbility/node, test/node)

@core-ai-bot
Copy link
Member Author

Comment by zaggino
Friday Aug 02, 2013 at 00:15 GMT


@dangoor take a look at new commits please. I used old style for cycles in the main algorithm to be as efficient as possible in this. Also been looking if it's possible to get into an infinite loop here, but I think that would require to have one file on the file system opened twice in the working tree, what should not be possible, right?
image

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Friday Aug 02, 2013 at 13:06 GMT


I just pulled the latest code from your branch and noticed three things:

  1. the case above is handled well!
  2. package.json at the top level is shown as "package.json –". I think that either just "package.json" or "package.json – /" would be better (I'm leaning toward "package.json". What do you think?)
  3. the new code seems to be kicking in all the time

For the third one above, I have node_modules/mathjs/package.json, src/extensions/dev/ex1/package.json and src/extensibility/node/package.json open. In this case, it should be able to just say "package.json – mathjs", "package.json – ex1" and "package.json – node".

package.json has been a good stress test for this, given how many of them there are :)

@core-ai-bot
Copy link
Member Author

Comment by zaggino
Friday Aug 02, 2013 at 13:40 GMT


I'll definitely look at that third thing sometime over the weekend.

I don't really know between "package.json" and "package.json – /" ... First one would give me a feeling that the file was excluded from the functionality (and the current tests would fail if there was no .directory element next to it, when counting how many files were affected by this, but that could be of course fixed). Second one would make probably me wonder for a second or two (for the first time), where did the slash come from.

@core-ai-bot
Copy link
Member Author

Comment by zaggino
Friday Aug 02, 2013 at 15:05 GMT


Written a new algorithm for this. Take a look - it's giving slightly different results than the one before.

@core-ai-bot
Copy link
Member Author

Comment by dangoor
Friday Aug 02, 2013 at 15:24 GMT


That's definitely better. There's still one case I'm not as happy about... if you open test/node/package.json and src/extensibility/node/package.json, you get "package.json – node" (for test/node) and "package.json – extensibility/node". I like the fact that it's not src/extensibility/node now, but I think the other one should be "test/node".

Does that seem right to you?

@core-ai-bot
Copy link
Member Author

Comment by TomMalbran
Friday Aug 02, 2013 at 21:55 GMT


You might want to reverse the folder check order. Since the last element in the path array is the top most folder, you could first check the top most folder against all the top most folders of the files with the same filename. If you find a folder with the same name, go down one folder and check again. Do this until you find a unique folder, or get to the last folder in the path. If you got to the last one without finding a unique folder, just use the whole path since the path from another file with the same name will eventually be longer and have a unique folder.

You can optimize this by checking all the paths from the files with the same topmost folders/filename together. Start by creating an array with a pair pairs = Array.<{same, rest}> for each path to check where same starts empty and rest is the path without the file name and a map with a signature similar to Object<same-path, Array.<rest-of-the-path>>, that will start as map = {}.

You then iterate through the array pairs and for each element you grab last = element.rest.pop() unique = element.same +"/"+ last and check if unique is a key in the map. If it isn't add a new entry as map[unique] = [element.rest]. If it is there, add it as map[unique].push(element.rest). After going through all the array, set pairs as [], and iterate through each key in map and check the length of the array value. If is 1, use the key as the unique path. If not, iterate through the elements in the array, if the path is empty use the key in the map as the unique path, if not add it as pairs.push({same: key, rest: map[i]}). You then restart using this recreated pairs array and an empty map, and keep looping until the array pairs is empty.

I hope this can help you with the algorithm.

@core-ai-bot
Copy link
Member Author

Comment by zaggino
Saturday Aug 03, 2013 at 12:26 GMT


... when I started this feature I thought it will be much easier :)

@dangoor@TomMalbran take a look at the last version, it takes the parent directory of every file and keeps adding parent directories, where duplicates still occur. Not quite the thing@TomMalbran wrote but it should be something similar. I went through cases mentioned earlier in this pull requests and all seem fine to me. Or I missed something, again :)

@core-ai-bot
Copy link
Member Author

Comment by TomMalbran
Saturday Aug 03, 2013 at 21:42 GMT


Nice, the implementation looks good. I had 1 comment on it. You should also fix 2 JSLint errors (spaces between function and (), and probably use 3 lines for the if return code (or invert the guard for the rest of the code) and 3 lines for the while. We could have an extra optimization of making a map for the paths and displayed paths to skip the index of function when adding the directories in the DOM, but not sure if that is really needed.

As nice bonus, I like how it shows the project folder when this is the first different folder, instead of showing /. Since I actually forgot that the full paths you are using aren't relative to the project folder. Anyway, unless you open a file outside of the project it shouldn't go past the project folder.

I was opening lots of packages.json files and opened:

  • src/extensibility/node/node_modules/fs-extra/node_modules/rimraf/package.json
  • test/node/node_modules/fs-extra/node_modules/rimraf/package.json

Which correctly showed:

  • package.json - extensibility/node/node_modules/fs-extra/node_modules/rimraf
  • package.json - test/node/node_modules/fs-extra/node_modules/rimraf

Where extensibility and test are the first different directories, but the list is still really long. We might want to think about also using ... when there are 4 or more folders to display.

  • package.json - extensibility/.../rimraf
  • package.json - test/.../rimraf

There is also a conflict issue in this branch, you should merge with master and fix it.

@core-ai-bot
Copy link
Member Author

Comment by zaggino
Saturday Aug 03, 2013 at 23:36 GMT


@TomMalbran I wanted to ask at least three times and always forgot, do you use any code-formatting tool ? I use jsbeautify in my projects before each commit so I don't have weird diffs in git, but that seems to mess-up a code here.

I fixed those JSLint errors and the last mentioned problem:
image

Also did the merge with current master (in two commits because I fucked up submodules in the first sadly).

@core-ai-bot
Copy link
Member Author

Comment by TomMalbran
Saturday Aug 03, 2013 at 23:50 GMT


I use Brackets, with JSLint enabled, and no other formatting tool.

It looks great now.

2 more minor things. We always use " instead of ' and \u2026 instead of ....
Here are the codding conventions: https://github.com/adobe/brackets/wiki/Brackets-Coding-Conventions

@core-ai-bot
Copy link
Member Author

Comment by zaggino
Sunday Aug 04, 2013 at 00:56 GMT


Fixed

@core-ai-bot
Copy link
Member Author

Comment by TomMalbran
Sunday Aug 04, 2013 at 01:26 GMT


Thanks for the fixes. I added a few more comments after going through the final code.

@core-ai-bot
Copy link
Member Author

Comment by TomMalbran
Sunday Aug 04, 2013 at 01:30 GMT


And there are a few more JSLint errors in WorkingSetView-tests.js.

@core-ai-bot
Copy link
Member Author

Comment by zaggino
Sunday Aug 04, 2013 at 01:51 GMT


Comments in the code should be fixed, JSLint errors too.

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

No branches or pull requests

1 participant