Skip to content

Commit 64d55c5

Browse files
committed
Simple file dialog missing drive letter on windows local (fix microsoft#90116)
1 parent ea8d1b7 commit 64d55c5

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

src/vs/workbench/services/textfile/browser/textFileService.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { coalesce } from 'vs/base/common/arrays';
3535
import { suggestFilename } from 'vs/base/common/mime';
3636
import { INotificationService } from 'vs/platform/notification/common/notification';
3737
import { toErrorMessage } from 'vs/base/common/errorMessage';
38-
import { resolve } from 'vs/base/common/path';
38+
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
3939

4040
/**
4141
* The workbench file service implementation implements the raw file service spec and adds additional methods on top.
@@ -85,7 +85,8 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
8585
@IFilesConfigurationService protected readonly filesConfigurationService: IFilesConfigurationService,
8686
@ITextModelService private readonly textModelService: ITextModelService,
8787
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
88-
@INotificationService private readonly notificationService: INotificationService
88+
@INotificationService private readonly notificationService: INotificationService,
89+
@IRemotePathService private readonly remotePathService: IRemotePathService
8990
) {
9091
super();
9192

@@ -321,12 +322,12 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
321322

322323
// Untitled with associated file path don't need to prompt
323324
if (model.hasAssociatedFilePath) {
324-
targetUri = this.suggestSavePath(resource);
325+
targetUri = await this.suggestSavePath(resource);
325326
}
326327

327328
// Otherwise ask user
328329
else {
329-
targetUri = await this.fileDialogService.pickFileToSave(this.suggestSavePath(resource), options?.availableFileSystems);
330+
targetUri = await this.fileDialogService.pickFileToSave(await this.suggestSavePath(resource), options?.availableFileSystems);
330331
}
331332

332333
// Save as if target provided
@@ -367,7 +368,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
367368

368369
// Get to target resource
369370
if (!target) {
370-
target = await this.fileDialogService.pickFileToSave(this.suggestSavePath(source), options?.availableFileSystems);
371+
target = await this.fileDialogService.pickFileToSave(await this.suggestSavePath(source), options?.availableFileSystems);
371372
}
372373

373374
if (!target) {
@@ -546,7 +547,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
546547
return (await this.dialogService.confirm(confirm)).confirmed;
547548
}
548549

549-
private suggestSavePath(resource: URI): URI {
550+
private async suggestSavePath(resource: URI): Promise<URI> {
550551

551552
// Just take the resource as is if the file service can handle it
552553
if (this.fileService.canHandleResource(resource)) {
@@ -582,16 +583,8 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
582583
}
583584

584585
// Try to place where last active file was if any
585-
const defaultFilePath = this.fileDialogService.defaultFilePath();
586-
if (defaultFilePath) {
587-
return joinPath(defaultFilePath, suggestedFilename);
588-
}
589-
590-
// Finally fallback to suggest just the file name
591-
// Since we do not have a default file path to
592-
// put, we use path.resolve() to make sure the path
593-
// is absolute.
594-
return toLocalResource(resource.with({ path: resolve(suggestedFilename) }), remoteAuthority);
586+
// Otherwise fallback to user home
587+
return joinPath(this.fileDialogService.defaultFilePath() || (await this.remotePathService.userHome), suggestedFilename);
595588
}
596589

597590
//#endregion

src/vs/workbench/services/textfile/electron-browser/nativeTextFileService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { IFilesConfigurationService } from 'vs/workbench/services/filesConfigura
3838
import { ITextModelService } from 'vs/editor/common/services/resolverService';
3939
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
4040
import { INotificationService } from 'vs/platform/notification/common/notification';
41+
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
4142

4243
export class NativeTextFileService extends AbstractTextFileService {
4344

@@ -55,9 +56,10 @@ export class NativeTextFileService extends AbstractTextFileService {
5556
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService,
5657
@ITextModelService textModelService: ITextModelService,
5758
@ICodeEditorService codeEditorService: ICodeEditorService,
58-
@INotificationService notificationService: INotificationService
59+
@INotificationService notificationService: INotificationService,
60+
@IRemotePathService remotePathService: IRemotePathService
5961
) {
60-
super(fileService, untitledTextEditorService, lifecycleService, instantiationService, modelService, environmentService, dialogService, fileDialogService, textResourceConfigurationService, filesConfigurationService, textModelService, codeEditorService, notificationService);
62+
super(fileService, untitledTextEditorService, lifecycleService, instantiationService, modelService, environmentService, dialogService, fileDialogService, textResourceConfigurationService, filesConfigurationService, textModelService, codeEditorService, notificationService, remotePathService);
6163
}
6264

6365
private _encoding: EncodingOracle | undefined;

src/vs/workbench/test/browser/workbenchTestServices.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export import TestTextResourcePropertiesService = CommonWorkbenchTestServices.Te
9292
export import TestContextService = CommonWorkbenchTestServices.TestContextService;
9393
export import TestStorageService = CommonWorkbenchTestServices.TestStorageService;
9494
export import TestWorkingCopyService = CommonWorkbenchTestServices.TestWorkingCopyService;
95+
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
9596

9697
export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
9798
return instantiationService.createInstance(FileEditorInput, resource, undefined, undefined);
@@ -118,7 +119,8 @@ export class TestTextFileService extends BrowserTextFileService {
118119
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService,
119120
@ITextModelService textModelService: ITextModelService,
120121
@ICodeEditorService codeEditorService: ICodeEditorService,
121-
@INotificationService notificationService: INotificationService
122+
@INotificationService notificationService: INotificationService,
123+
@IRemotePathService remotePathService: IRemotePathService
122124
) {
123125
super(
124126
fileService,
@@ -133,7 +135,8 @@ export class TestTextFileService extends BrowserTextFileService {
133135
filesConfigurationService,
134136
textModelService,
135137
codeEditorService,
136-
notificationService
138+
notificationService,
139+
remotePathService
137140
);
138141
}
139142

src/vs/workbench/test/electron-browser/workbenchTestServices.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { createTextBufferFactoryFromStream } from 'vs/editor/common/model/textMo
2929
import { IOpenedWindow, IOpenEmptyWindowOptions, IWindowOpenable, IOpenWindowOptions, IWindowConfiguration } from 'vs/platform/windows/common/windows';
3030
import { parseArgs, OPTIONS } from 'vs/platform/environment/node/argv';
3131
import { LogLevel } from 'vs/platform/log/common/log';
32+
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
3233

3334
export const TestWindowConfiguration: IWindowConfiguration = {
3435
windowId: 0,
@@ -61,7 +62,8 @@ export class TestTextFileService extends NativeTextFileService {
6162
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService,
6263
@ITextModelService textModelService: ITextModelService,
6364
@ICodeEditorService codeEditorService: ICodeEditorService,
64-
@INotificationService notificationService: INotificationService
65+
@INotificationService notificationService: INotificationService,
66+
@IRemotePathService remotePathService: IRemotePathService
6567
) {
6668
super(
6769
fileService,
@@ -77,7 +79,8 @@ export class TestTextFileService extends NativeTextFileService {
7779
filesConfigurationService,
7880
textModelService,
7981
codeEditorService,
80-
notificationService
82+
notificationService,
83+
remotePathService
8184
);
8285
}
8386

0 commit comments

Comments
 (0)