Skip to content

Commit 5f8b69a

Browse files
Scott DoverScott Dover
authored andcommitted
chore: address code review comments
Signed-off-by: Scott Dover <[email protected]>
1 parent d040a77 commit 5f8b69a

File tree

4 files changed

+85
-25
lines changed

4 files changed

+85
-25
lines changed

client/src/components/ContentNavigator/ContentDataProvider.ts

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
FileType,
1515
Position,
1616
ProviderResult,
17+
TabInputNotebook,
18+
TabInputText,
1719
TextDocument,
1820
TextDocumentContentProvider,
1921
ThemeIcon,
@@ -52,7 +54,7 @@ import {
5254
FileManipulationEvent,
5355
} from "./types";
5456
import {
55-
getEditorTabForItem,
57+
getEditorTabsForItem,
5658
getFileStatement,
5759
isContainer as getIsContainer,
5860
} from "./utils";
@@ -285,23 +287,62 @@ class ContentDataProvider
285287
name: string,
286288
): Promise<Uri | undefined> {
287289
const closing = closeFileIfOpen(item);
288-
if (!(await closing)) {
290+
const removedTabUris = await closing;
291+
if (!removedTabUris) {
289292
return;
290293
}
291294

292295
const newItem = await this.model.renameResource(item, name);
293-
if (newItem) {
294-
const newUri = newItem.vscUri;
295-
if (closing !== true) {
296-
// File was open before rename, so re-open it
297-
commands.executeCommand("vscode.open", newUri);
298-
}
296+
if (!newItem) {
297+
return;
298+
}
299+
300+
const newUri = newItem.vscUri;
301+
const oldUriToNewUriMap = [[item.vscUri, newUri]];
302+
const newItemIsContainer = getIsContainer(newItem);
303+
if (closing !== true && !newItemIsContainer) {
304+
commands.executeCommand("vscode.open", newUri);
305+
}
306+
const urisToOpen = getPreviouslyOpenedChildItems(
307+
await this.getChildren(newItem),
308+
);
309+
urisToOpen.forEach(([, newUri]) =>
310+
commands.executeCommand("vscode.open", newUri),
311+
);
312+
oldUriToNewUriMap.push(...urisToOpen);
313+
oldUriToNewUriMap.forEach(([uri, newUri]) =>
299314
this._onDidManipulateFile.fire({
300315
type: "rename",
301-
uri: item.vscUri,
316+
uri,
302317
newUri,
303-
});
304-
return newUri;
318+
}),
319+
);
320+
return newUri;
321+
322+
function getPreviouslyOpenedChildItems(childItems: ContentItem[]) {
323+
const loadChildItems = closing !== true && newItemIsContainer;
324+
if (!Array.isArray(removedTabUris) || !loadChildItems) {
325+
return [];
326+
}
327+
// Here's where things get a little weird. When we rename folders in
328+
// sas content, we _don't_ close those files. It doesn't matter since
329+
// their path isn't hierarchical. In sas file system, the path is hierarchical,
330+
// thus we need to re-open all the closed files. This does that by getting
331+
// children and comparing the removedTabUris
332+
const filteredChildItems = childItems
333+
.map((childItem) => {
334+
const matchingUri = removedTabUris.find((uri) =>
335+
uri.path.endsWith(childItem.name),
336+
);
337+
if (!matchingUri) {
338+
return;
339+
}
340+
341+
return [matchingUri, childItem.vscUri];
342+
})
343+
.filter((exists) => exists);
344+
345+
return filteredChildItems;
305346
}
306347
}
307348

@@ -697,10 +738,26 @@ class ContentDataProvider
697738

698739
export default ContentDataProvider;
699740

700-
const closeFileIfOpen = (item: ContentItem) => {
701-
const tab = getEditorTabForItem(item);
702-
if (tab) {
703-
return window.tabGroups.close(tab);
741+
const closeFileIfOpen = (item: ContentItem): Promise<Uri[]> | boolean => {
742+
const tabs = getEditorTabsForItem(item);
743+
if (tabs.length > 0) {
744+
return new Promise((resolve, reject) => {
745+
Promise.all(tabs.map((tab) => window.tabGroups.close(tab)))
746+
.then(() =>
747+
resolve(
748+
tabs
749+
.map(
750+
(tab) =>
751+
(tab.input instanceof TabInputText ||
752+
tab.input instanceof TabInputNotebook) &&
753+
tab.input.uri,
754+
)
755+
.filter((exists) => exists),
756+
),
757+
)
758+
.catch(reject);
759+
});
704760
}
761+
705762
return true;
706763
};

client/src/components/ContentNavigator/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ const folderValidator = (
6363

6464
class ContentNavigator implements SubscriptionProvider {
6565
private contentDataProvider: ContentDataProvider;
66-
private contentModel: ContentModel;
6766
private sourceType: ContentNavigatorConfig["sourceType"];
6867
private treeIdentifier: ContentNavigatorConfig["treeIdentifier"];
6968

69+
get contentModel() {
70+
return new ContentModel(this.contentAdapterForConnectionType());
71+
}
72+
7073
constructor(context: ExtensionContext, config: ContentNavigatorConfig) {
7174
this.sourceType = config.sourceType;
7275
this.treeIdentifier = config.treeIdentifier;
73-
this.contentModel = new ContentModel(
74-
this.contentAdapterForConnectionType(),
75-
);
7676
this.contentDataProvider = new ContentDataProvider(
7777
this.contentModel,
7878
context.extensionUri,
@@ -400,9 +400,7 @@ class ContentNavigator implements SubscriptionProvider {
400400
if (event.affectsConfiguration("SAS.connectionProfiles")) {
401401
const endpoint = this.viyaEndpoint();
402402
this.collapseAllContent();
403-
this.contentDataProvider.useModel(
404-
new ContentModel(this.contentAdapterForConnectionType()),
405-
);
403+
this.contentDataProvider.useModel(this.contentModel);
406404
if (endpoint) {
407405
await this.contentDataProvider.connect(endpoint);
408406
} else {

client/src/components/ContentNavigator/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ export const createStaticFolder = (
8484
],
8585
});
8686

87-
export const getEditorTabForItem = (item: ContentItem) => {
87+
export const getEditorTabsForItem = (item: ContentItem) => {
8888
const fileUri = item.vscUri;
8989
const tabs: Tab[] = window.tabGroups.all.map((tg) => tg.tabs).flat();
90-
return tabs.find(
90+
return tabs.filter(
9191
(tab) =>
9292
(tab.input instanceof TabInputText ||
9393
tab.input instanceof TabInputNotebook) &&
94-
tab.input.uri.query === fileUri.query, // compare the file id
94+
tab.input.uri.query.includes(fileUri.query), // compare the file id
9595
);
9696
};

client/src/connection/rest/RestSASServerAdapter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ class RestSASServerAdapter implements ContentAdapter {
154154
});
155155

156156
const contentItem = this.filePropertiesToContentItem(response.data);
157+
this.updateFileMetadata(
158+
this.trimComputePrefix(contentItem.uri),
159+
response,
160+
);
157161

158162
if (buffer) {
159163
await this.updateContentOfItemAtPath(
@@ -249,6 +253,7 @@ class RestSASServerAdapter implements ContentAdapter {
249253
}
250254

251255
private async getContentOfItemAtPath(path: string) {
256+
await this.setup();
252257
const response = await this.fileSystemApi.getFileContentFromSystem(
253258
{
254259
sessionId: this.sessionId,

0 commit comments

Comments
 (0)