Skip to content
This repository was archived by the owner on Apr 1, 2020. It is now read-only.

Conversation

feltech
Copy link
Contributor

@feltech feltech commented Jul 15, 2018

Add command palette option "Explorer: Locate Current Buffer" that will
expand directories down to the current buffer, then select the
corresponding file/directory.

Add command palette option "Explorer: Locate Current Buffer" that will
expand directories down to the current buffer, then select the
corresponding file/directory.
@feltech
Copy link
Contributor Author

feltech commented Jul 15, 2018

As I'm entirely new to the Oni codebase I thought I would submit this before I tackle writing tests, in the hopes someone can take a look and let me know if my approach is reasonable.

@feltech feltech changed the title Command to find current buffer in Explorer and select it (#1567) Explorer: Locate Current Buffer (#1567) Jul 15, 2018
@akinsho
Copy link
Member

akinsho commented Jul 15, 2018

I just tried this out @feltech 😍 very cool 👍, I think the approach is good although there are couple of things I noted whilst trying it.

The speed with which you can navigate the explorer seems much slower, checking the logs it seems a SELECT_FILE_SUCCESS action is fired for each movement so not sure if this is triggering the epic each time a user tries to move between nodes and there is maybe no guard to distinguish between a location action and a simple navigation.

This is more cosmetic-ish but if the explorer/sidebar is closed and you use this command it remains closed but I found that on opening it the correct file is selected, so I think the functionality did work but it was initially a bit confusing, I think a good check would be to see if the sidebar is closed and if so open it, you might be able to achieve this be using Commands.executeCommand("explorer.toggle") or something

@codecov
Copy link

codecov bot commented Jul 15, 2018

Codecov Report

Merging #2429 into master will increase coverage by 1.07%.
The diff coverage is 94%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2429      +/-   ##
=========================================
+ Coverage   42.62%   43.7%   +1.07%     
=========================================
  Files         332     343      +11     
  Lines       13212   13664     +452     
  Branches     1736    1799      +63     
=========================================
+ Hits         5632    5972     +340     
- Misses       7302    7454     +152     
+ Partials      278     238      -40
Impacted Files Coverage Δ
browser/src/Services/Sidebar/SidebarStore.ts 45.28% <0%> (-0.44%) ⬇️
...rowser/src/Services/Explorer/ExplorerFileSystem.ts 90.74% <100%> (+5.83%) ⬆️
browser/src/Services/Explorer/ExplorerView.tsx 60% <100%> (+8.14%) ⬆️
browser/src/Services/Explorer/ExplorerStore.ts 80.21% <100%> (+11.83%) ⬆️
browser/src/Services/Explorer/ExplorerSplit.tsx 25.16% <85.71%> (ø)
browser/src/UI/components/VimNavigator.tsx 72.91% <85.71%> (+10.69%) ⬆️
...src/Services/VersionControl/VersionControlStore.ts 68% <0%> (-8.93%) ⬇️
...src/Services/VersionControl/VersionControlView.tsx 72.58% <0%> (-6.59%) ⬇️
...src/Services/VersionControl/VersionControlPane.tsx 47.89% <0%> (-5.17%) ⬇️
browser/src/Services/EditorManager.ts 55.69% <0%> (-2.88%) ⬇️
... and 39 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e7fe16...dc045ab. Read the comment docs.

Prevent sending pointless `SELECT_FILE_SUCCESS` actions if we're not
actually in the process of selecting a file (or haven't selected the
file we expect yet).
@feltech
Copy link
Contributor Author

feltech commented Jul 15, 2018

@akin909 Thanks for the quick feedback!

I've changed the SUCCESS action logic so that it doesn't trigger unnecessarily. It seems odd that dispatching such a simple action (which isn't part of the epic) would slow things down. When I tried I could maybe feel some slight lag, but not particularly noticeable. Perhaps my machine is just able to absorb the extra effort.

I do find the Explorer pane is a bit buggy when scrolling down beyond the last visible file. The pane seems to scroll jump up and down. That bug is present in the current stable release, which I'm using for development, so I'm not concerned that my changes broke it. I'll try to remember to check if there's an existing bug report and if not I'll make one.

Activating the Explorer if it's closed is a nice idea, I'll add that asap.

@@ -50,6 +50,20 @@ export const isPathExpanded = (state: IExplorerState, pathToCheck: string): bool
return !!state.expandedFolders[pathToCheck]
}

/**
Copy link
Member

@akinsho akinsho Jul 15, 2018

Choose a reason for hiding this comment

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

@feltech a version of this same functionality already exists in ExplorerStore.ts maybe you could import that and use it instead

* Keep `registerCommand` calls together in the `index.tsx` and unify
their style.
* Use the `SidebarManager` to first ensure the Explorer is shown, before
then locating the file in the `ExplorerSplit`.
@akinsho
Copy link
Member

akinsho commented Jul 15, 2018

I think re. the slowness it might have been that the epic was triggered by the select action so the whole function runs each time i will re-try it later I'm working on a laptop but a fairly well spec'ed one but everything is slower in development due to all the logging etc.

Re. the flicker in the explorer that isn't because of your changes its a known bug i've opened #2182 in order to fix that

feltech added 3 commits July 15, 2018 22:13
* Strangely, `SidebarManager.setActiveEntry` will close the sidebar if
the Explorer is already open and you try to open it again.
* So only trigger opening the Explorer if it's not already visible.
@feltech
Copy link
Contributor Author

feltech commented Jul 15, 2018

@akin909 - well spotted on the duplicated nodePath function, thanks for that.

Now the Explorer will open if it was closed when locating a file.

@akinsho
Copy link
Member

akinsho commented Jul 16, 2018

@feltech just tried it again works really well and now opens the explorer, thanks for adding that 👍. re. testing I don't think you need too many here my recommendation would be just testing the reducer and epic, the other tests are here in terms of examples of how those work

feltech added 2 commits July 17, 2018 23:11
* `epicMiddleware.replaceEpic` internally dispatches a
`@@redux-observable/EPIC_END` action, which gets saved to the
`mockStore`'s
actions list. Every test case's `afterEach` thus adds an additional
action to this actions list. This pollutes all subsequent stores created
via the `mockStore` factory, which is odd.
* This was accounted for in the YANK_AND_PASTE_EPICS test by assuming
"an init action is sent first", which is not the case.
* So move the setup that is only for the SET_ROOT_DIRECTORY test inside
it's own `describe` block, remove the unnecessary `replaceEpic` call,
and fix the test for expected number of actions.
@feltech
Copy link
Contributor Author

feltech commented Jul 17, 2018

Still more tests to write. That weird redux-mock-store bug was an odd one.

@akinsho
Copy link
Member

akinsho commented Jul 20, 2018

@feltech thanks for adding so all those tests 🎉

@akinsho
Copy link
Member

akinsho commented Jul 20, 2018

@feltech is this complete?

@feltech
Copy link
Contributor Author

feltech commented Jul 20, 2018

Nearly, working on the final test now (though it's late here so might take another day).

@feltech
Copy link
Contributor Author

feltech commented Jul 24, 2018

That's a good plan. My one concern is that the OSX integration test for this feature did highlight a genuine issue to do with symlinks, so it would be good to include the fix for that. I suppose that could be part of a separate PR to improve the feature (along with the fixes to the CI tests).

@feltech
Copy link
Contributor Author

feltech commented Jul 24, 2018

I've now split at the last successful build as #2456. However, I had to merge in master so the tests are going to run again...

I still hold out some hope of fixing all this up. So it would be good to keep this PR around so I can abuse Travis a bit longer.

@feltech feltech changed the title Explorer: Locate Current Buffer (#1567) [WIP] Explorer: Locate Current Buffer (minor bugfix + additional tests) Jul 24, 2018
@feltech
Copy link
Contributor Author

feltech commented Jul 24, 2018

Hmm so the split-off PR looks good as far as CI goes. Very strange. I might have to rewind and cherry pick bit by bit to isolate what causes the breakage.

@feltech
Copy link
Contributor Author

feltech commented Jul 24, 2018

No freaking way. Finally Travis stops complaining! There's a bunch of debug logs to remove and other tidying. Hopefully the build still passes after that.

@feltech
Copy link
Contributor Author

feltech commented Jul 25, 2018

OK then, pending review I think this is good to go.

package.json Outdated
@@ -628,7 +628,7 @@
"test:setup":
"yarn run build:test:integration && mocha -t 120000 --recursive lib_test/test/setup",
"test:integration":
"yarn run build:test:integration && mocha -t 120000 lib_test/test/CiTests.js --bail",
"yarn run build:test:integration && mocha -t 120000 lib_test/test/CiTests.js --bail --runInBand --no-cache",
Copy link
Member

Choose a reason for hiding this comment

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

Just for my info what does this change runInBand

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, apparently I got my wires crossed. Looks like it has no effect. It should ensure that all tests run in the same process. But that looks to be a jest config option, not mocha. From the jest docs

Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm pushing a commit to remove those pointless flags. Fingers crossed the tests still pass!

@akinsho
Copy link
Member

akinsho commented Jul 25, 2018

@feltech 🎉 glad you managed to get the CI tests working 👍 looks good to me.

Re. the CI test changes tbh I havent spent a great deal of time looking at how its all setup what do the changes you've made do? also might be worth if (hes available getting @bryphe or) @CrossR to review

akinsho
akinsho previously approved these changes Jul 25, 2018
@CrossR
Copy link
Member

CrossR commented Jul 25, 2018

From a quick look, it looks like the main changes are swapping to using a temporary workspace in some tests, since currently they run in the full Oni repo. That should help a few of the tests, but we may want to revert it if in the future we do some performance tests since the Oni repo is nice to test against as its a decent size.

The other changes seem to be removing the "before" and "after" parts of the CI tests, and collapsing it down into the test itself. It doesn't look to change the tests themselves, but if it helps reliability then sounds good! Only part I wasn't quite sure on was the catching and then doing nothing with the error in the final try-finally of runInProcTest.

As for the runInBand and no-cache, from a quick Google they looked like jest flags not mocha flags, but I could be wrong.

@feltech
Copy link
Contributor Author

feltech commented Jul 25, 2018

Ah good point. A summary of the changes:

  • A few integration tests now use a temporary workspace, rather than relying on whatever default workspace Oni opens.
  • The PrettierPluginTest now checks for the presence of the statusbar icon in a waitFor. Looking at the flux actions in the log output there were a lot of STATUSBAR_SHOW (or some such) around the same time as the assertion, so I concluded it was a race condition.
  • I removed the beforeEach and afterEach in the main runInProcTest, and instead put their logic inside the (single) it, with an appropriate try/catch clause. This means if the setup/teardown fails, the configured retries will still take place. I.e. if there is an error in a before/afterEach then the test does not retry, which was annoying.
  • During teardown of Oni, I noticed that it would sometimes hang trying to get the windowCount, which only appears to be used for logging, so I made that time out non-fatally.
  • In package.json I added a couple of switches to the test:integration call.... OK just read your comment @CrossR - I may well have been mistaken there and those switches are pointless.

@feltech
Copy link
Contributor Author

feltech commented Jul 25, 2018

@CrossR

Only part I wasn't quite sure on was the catching and then doing nothing with the error in the final try-finally of runInProcTest.

My thinking was that if Oni had failed to start or was in some other bad state, then presumably we could get an exception trying to stop it, which we don't really care about.

I suppose the downside is that if Oni fails to shut down, then that specific test won't fail (should it?).

However, I suspect in that case subsequent tests will fail, because there would be two instances of Oni running, which is bad news for these integration tests.

@feltech
Copy link
Contributor Author

feltech commented Jul 25, 2018

@CrossR Re. swapping to use a temporary workspace in some tests:

I did this originally in the integration test for this feature, so that I wasn't relying on a specific workspace and some arbitrary file existing in it.

Then I found that subsequent tests will run in that same temporary workspace, and at least one of those tests does rely on an arbitrary file in the Oni repo. I judged that to be bad practice, so went with refactoring that test to also use a temporary workspace.

I do get your point about monitoring performance. Though integration tests that break because of a side-effect of a previous integration test are a pain to debug.

I'm happy to change the test I wrote to rely on running in the Oni repo as it's workspace, if that's the standard.

@CrossR
Copy link
Member

CrossR commented Jul 25, 2018

I'm happy to change the test I wrote to rely on running in the Oni repo as it's workspace, if that's the standard.

Nah, its fine! Your new implementation is great, its better to setup a proper workspace rather than depend on a file which could maybe move etc. It was more just a mental note that if in the future we swap to checking performance, we'd want to update it so we are running in a bigger repo for more realistic performance.

@CrossR
Copy link
Member

CrossR commented Jul 26, 2018

Just wanted to check this PR can be merged, since its got WIP in the title still! Otherwise looks good.

I assume the split-off PR can be closed?

@feltech feltech changed the title [WIP] Explorer: Locate Current Buffer (minor bugfix + additional tests) Explorer: Locate Current Buffer (minor bugfix + additional tests) Jul 26, 2018
@feltech
Copy link
Contributor Author

feltech commented Jul 26, 2018

Hey, yep it's ready to go. I'll close the other PR.

@feltech feltech changed the title Explorer: Locate Current Buffer (minor bugfix + additional tests) Explorer: Locate Current Buffer Jul 26, 2018
@CrossR CrossR merged commit b6bdb4b into onivim:master Jul 26, 2018
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.

3 participants