Skip to content

Commit fef9498

Browse files
committed
Merge remote-tracking branch 'origin/master' into pr/LadyCailin/77762
2 parents 8283819 + eec46fc commit fef9498

5 files changed

Lines changed: 49 additions & 47 deletions

File tree

src/vs/editor/test/common/model/textModelWithTokens.test.ts

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,10 @@ suite('TextModelWithTokens regression tests', () => {
572572
});
573573

574574
suite('TextModel.getLineIndentGuide', () => {
575-
function assertIndentGuides(lines: [number, number, number, number, string][]): void {
575+
function assertIndentGuides(lines: [number, number, number, number, string][], tabSize: number): void {
576576
let text = lines.map(l => l[4]).join('\n');
577577
let model = TextModel.createFromString(text);
578+
model.updateOptions({ tabSize: tabSize });
578579

579580
let actualIndents = model.getLinesIndentGuides(1, model.getLineCount());
580581

@@ -589,59 +590,59 @@ suite('TextModel.getLineIndentGuide', () => {
589590
model.dispose();
590591
}
591592

592-
test('getLineIndentGuide one level', () => {
593+
test('getLineIndentGuide one level 2', () => {
593594
assertIndentGuides([
594595
[0, 1, 1, 0, 'A'],
595596
[1, 2, 4, 1, ' A'],
596597
[1, 2, 4, 1, ' A'],
597598
[1, 2, 4, 1, ' A'],
598-
]);
599+
], 2);
599600
});
600601

601602
test('getLineIndentGuide two levels', () => {
602603
assertIndentGuides([
603604
[0, 1, 1, 0, 'A'],
604605
[1, 2, 5, 1, ' A'],
605606
[1, 2, 5, 1, ' A'],
606-
[1, 2, 5, 1, ' A'],
607-
[1, 2, 5, 1, ' A'],
608-
]);
607+
[2, 4, 5, 2, ' A'],
608+
[2, 4, 5, 2, ' A'],
609+
], 2);
609610
});
610611

611612
test('getLineIndentGuide three levels', () => {
612613
assertIndentGuides([
613614
[0, 1, 1, 0, 'A'],
614615
[1, 2, 4, 1, ' A'],
615-
[1, 2, 4, 1, ' A'],
616-
[2, 4, 4, 2, ' A'],
616+
[2, 3, 4, 2, ' A'],
617+
[3, 4, 4, 3, ' A'],
617618
[0, 5, 5, 0, 'A'],
618-
]);
619+
], 2);
619620
});
620621

621622
test('getLineIndentGuide decreasing indent', () => {
622623
assertIndentGuides([
623-
[1, 1, 2, 1, ' A'],
624+
[2, 1, 1, 2, ' A'],
624625
[1, 1, 2, 1, ' A'],
625626
[0, 3, 3, 0, 'A'],
626-
]);
627+
], 2);
627628
});
628629

629630
test('getLineIndentGuide Java', () => {
630631
assertIndentGuides([
631632
/* 1*/[0, 1, 1, 0, 'class A {'],
632633
/* 2*/[1, 2, 9, 1, ' void foo() {'],
633-
/* 3*/[1, 2, 9, 1, ' console.log(1);'],
634-
/* 4*/[1, 2, 9, 1, ' console.log(2);'],
634+
/* 3*/[2, 3, 4, 2, ' console.log(1);'],
635+
/* 4*/[2, 3, 4, 2, ' console.log(2);'],
635636
/* 5*/[1, 2, 9, 1, ' }'],
636637
/* 6*/[1, 2, 9, 1, ''],
637638
/* 7*/[1, 2, 9, 1, ' void bar() {'],
638-
/* 8*/[1, 2, 9, 1, ' console.log(3);'],
639+
/* 8*/[2, 8, 8, 2, ' console.log(3);'],
639640
/* 9*/[1, 2, 9, 1, ' }'],
640641
/*10*/[0, 10, 10, 0, '}'],
641642
/*11*/[0, 11, 11, 0, 'interface B {'],
642643
/*12*/[1, 12, 12, 1, ' void bar();'],
643644
/*13*/[0, 13, 13, 0, '}'],
644-
]);
645+
], 2);
645646
});
646647

647648
test('getLineIndentGuide Javadoc', () => {
@@ -653,20 +654,20 @@ suite('TextModel.getLineIndentGuide', () => {
653654
[1, 5, 6, 1, ' void foo() {'],
654655
[1, 5, 6, 1, ' }'],
655656
[0, 7, 7, 0, '}'],
656-
]);
657+
], 2);
657658
});
658659

659660
test('getLineIndentGuide Whitespace', () => {
660661
assertIndentGuides([
661662
[0, 1, 1, 0, 'class A {'],
662663
[1, 2, 7, 1, ''],
663664
[1, 2, 7, 1, ' void foo() {'],
664-
[1, 2, 7, 1, ' '],
665-
[2, 5, 5, 2, ' return 1;'],
665+
[2, 4, 5, 2, ' '],
666+
[3, 5, 5, 3, ' return 1;'],
666667
[1, 2, 7, 1, ' }'],
667668
[1, 2, 7, 1, ' '],
668669
[0, 8, 8, 0, '}']
669-
]);
670+
], 2);
670671
});
671672

672673
test('getLineIndentGuide Tabs', () => {
@@ -679,7 +680,7 @@ suite('TextModel.getLineIndentGuide', () => {
679680
[1, 2, 7, 1, ' \t}'],
680681
[1, 2, 7, 1, ' '],
681682
[0, 8, 8, 0, '}']
682-
]);
683+
], 4);
683684
});
684685

685686
test('getLineIndentGuide checker.ts', () => {
@@ -701,7 +702,7 @@ suite('TextModel.getLineIndentGuide', () => {
701702
/*15*/[2, 11, 15, 2, ' return node.id;'],
702703
/*16*/[1, 5, 16, 1, ' }'],
703704
/*17*/[0, 17, 17, 0, '}']
704-
]);
705+
], 4);
705706
});
706707

707708
test('issue #8425 - Missing indentation lines for first level indentation', () => {
@@ -710,7 +711,7 @@ suite('TextModel.getLineIndentGuide', () => {
710711
[2, 2, 3, 2, '\t\tindent2'],
711712
[2, 2, 3, 2, '\t\tindent2'],
712713
[1, 1, 4, 1, '\tindent1']
713-
]);
714+
], 4);
714715
});
715716

716717
test('issue #8952 - Indentation guide lines going through text on .yml file', () => {
@@ -721,7 +722,7 @@ suite('TextModel.getLineIndentGuide', () => {
721722
[2, 3, 5, 2, ' - length:'],
722723
[3, 5, 5, 3, ' max: 255'],
723724
[0, 6, 6, 0, 'getters:']
724-
]);
725+
], 4);
725726
});
726727

727728
test('issue #11892 - Indent guides look funny', () => {
@@ -734,15 +735,15 @@ suite('TextModel.getLineIndentGuide', () => {
734735
[3, 6, 6, 3, '\t\t\treturn 2;'],
735736
[1, 2, 7, 1, '\t}'],
736737
[0, 8, 8, 0, '}']
737-
]);
738+
], 4);
738739
});
739740

740741
test('issue #12398 - Problem in indent guidelines', () => {
741742
assertIndentGuides([
742743
[2, 1, 2, 2, '\t\t.bla'],
743744
[3, 2, 2, 3, '\t\t\tlabel(for)'],
744745
[0, 3, 3, 0, 'include script']
745-
]);
746+
], 4);
746747
});
747748

748749
test('issue #49173', () => {

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)