fix: use correct target folder for createFolder/uploadFile in Workspace fs#1913
Conversation
…ce FS extension.ts Switches the Workspace FS panel registration from window.registerTreeDataProvider to window.createTreeView so the TreeView handle (which exposes selection) is available. The resulting workspaceFsTreeView is passed to WorkspaceFsCommands and disposed via context.subscriptions. WorkspaceFsCommands.ts - Accepts TreeView<WorkspaceFsEntity> as a new constructor parameter (private readonly treeView). - Tracks the last left-click–selected item in selectedElement via treeView.onDidChangeSelection (cleared to undefined on deselection). - In createFolder and uploadFile, resolves the target folder using a comparison: - If element !== treeView.selection[0] — the command was invoked from a context menu on a different item than the current selection → use element. - Otherwise — title bar button, or context menu on the already-selected item → use selectedElement (which is undefined if the user deselected before clicking, correctly falling back to the workspace root). This fixes two bugs: 1. Title bar click after deselection was targeting the previously selected folder instead of root. 2. Context-menu click on a non-selected item was targeting the selected folder instead of the right-clicked one.
|
Concern: this may not actually fix the reported bug (and the tests don't guard against it) I traced the logic and I think the core change is effectively a no-op. The key helper: private resolveTargetElement(element?) {
return element !== this.treeView.selection[0]
? element
: this.selectedElement;
}
So The tests pass against the original code too. I ran all 13 cases against the pre-PR logic ( Why I don't think the reported bug is addressed. The "title bar after deselection targets the previously selected folder" bug can only occur if, at title-bar-click time, the element/selection VSCode hands the command still points at the stale folder. But in that exact state Possible regression risk. The logic also relies on the assumption (stated in a test comment) that a right-click does not update Suggestion: before merging, could you verify the deselection repro empirically with vs. without this diff? If there's a real difference, it'd be worth pinning down exactly what VSCode passes for title-bar vs. context-menu invocations and adding a test that fails on the old code to prove the fix matters. If the intent is "title bar always creates at root, context menu uses the clicked item," distinguishing the two invocation paths explicitly (separate command IDs/args) would be more robust than reconciling |
When the toolbar button is clicked, VS Code passes the currently-selected tree node as `element`, making it impossible to distinguish toolbar vs context-menu invocations from a single handler. Changes: - Add `databricks.wsfs.uploadFile.toolbar` command bound to `view/title`; the existing `databricks.wsfs.uploadFile` stays on `view/item/context` only. - Both handlers resolve the target folder directly from `element` (toolbar variant via `resolveTargetElementForToolbar`, which gates on `treeView.selection` to detect whether anything is truly selected). - Extract shared upload logic into private `doUploadFile`. - Remove the now-unused `resolveTargetElement` helper. - Update unit tests: rename mislabelled "title bar" cases, add dedicated suites for `createFolderFromToolbar` and `uploadFileFromToolbar` covering the full selection-state matrix.
|
Handling 2 issues in last commit
Separately toolbar and context versions of createFolder and uploadFolder commands. 2 new command IDs |
anton-107
left a comment
There was a problem hiding this comment.
Approving — the redesign addresses my earlier concern directly. Splitting into separate view/title (toolbar) and view/item/context (context-menu) command IDs is the explicit-invocation-path approach I was hoping for: the old resolveTargetElement no-op is gone, the context menu now uses the right-clicked element directly (so right-click B while A is selected correctly targets B — my regression worry), and the toolbar gates on live treeView.selection to ignore the stale element after deselection. 👍
Two minor, non-blocking notes you can pick up whenever (or not):
-
Verify the repro empirically. The unit tests are good, but they exercise a
FakeTreeViewthat encodes the assumed VS Code contract (staleelementarg vs. accuratetreeView.selection, andview/titlepassing the selected node). They can't prove the real VS Code behavior. If you've already run the actual select → deselect → click-toolbar repro against this build and confirmed it now lands at root, a quick note here would fully close the loop for me. -
Toolbar resolver could read selection directly. When
treeView.selection[0]is defined,resolveTargetElementForToolbarreturns the passedelementrather thanthis.treeView.selection[0]. They should be equal in the toolbar path, but returningtreeView.selection[0]directly would be self-evidently correct without depending onelement === selection[0].
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
## packages/databricks-vscode ## (2026-06-18) * fix: use correct target folder for createFolder/uploadFile in Workspace fs (#1913) ([be427e9](be427e9)), closes [#1913](#1913) * Drop the “or greater” addition on the line where extension suggests to activate a Python environment ([13452fb](13452fb)), closes [#1915](#1915) * Gate WSFS and docs panels on extension activation (#1909) ([308f687](308f687)), closes [#1909](#1909) * Pass DATABRICKS_CLI_PATH and resolve the platform-specific CLI binary (#1910) ([6fcb630](6fcb630)), closes [#1910](#1910) [#1903](#1903) ## packages/databricks-vscode-types ## (2026-06-18) Co-authored-by: releasebot <noreply@github.com>
Changes
Fixes title bar click after deselection was targeting the previously selected folder instead of root.
extension.tsSwitches the Workspace FS panel registration from window.registerTreeDataProvider to window.createTreeView so the TreeView handle (which exposes selection) is available. The resulting workspaceFsTreeView is passed to WorkspaceFsCommands and disposed via context.subscriptions.
WorkspaceFsCommands.tsTests
WorkspaceFsCommands.test.ts