Skip to content

Commit 273d62f

Browse files
committed
Make files.eol overridable. Fixes microsoft#49418. Fixes microsoft#34876
1 parent 7972287 commit 273d62f

7 files changed

Lines changed: 23 additions & 49 deletions

File tree

src/vs/editor/contrib/smartSelect/test/smartSelect.test.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,11 @@ import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageCo
1212
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
1313
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
1414
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
15-
import { ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
16-
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
17-
import { isLinux, isMacintosh } from 'vs/base/common/platform';
1815
import { BracketSelectionRangeProvider } from 'vs/editor/contrib/smartSelect/bracketSelections';
1916
import { provideSelectionRanges } from 'vs/editor/contrib/smartSelect/smartSelect';
2017
import { CancellationToken } from 'vs/base/common/cancellation';
2118
import { WordSelectionRangeProvider } from 'vs/editor/contrib/smartSelect/wordSelections';
22-
23-
class TestTextResourcePropertiesService implements ITextResourcePropertiesService {
24-
25-
_serviceBrand: undefined;
26-
27-
constructor(
28-
@IConfigurationService private readonly configurationService: IConfigurationService,
29-
) {
30-
}
31-
32-
getEOL(resource: URI | undefined): string {
33-
const filesConfiguration = this.configurationService.getValue<{ eol: string }>('files');
34-
if (filesConfiguration && filesConfiguration.eol) {
35-
if (filesConfiguration.eol !== 'auto') {
36-
return filesConfiguration.eol;
37-
}
38-
}
39-
return (isLinux || isMacintosh) ? '\n' : '\r\n';
40-
}
41-
}
19+
import { TestTextResourcePropertiesService } from 'vs/editor/test/common/services/modelService.test';
4220

4321
class MockJSMode extends MockMode {
4422

src/vs/editor/standalone/browser/simpleServices.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,10 @@ export class SimpleResourcePropertiesService implements ITextResourcePropertiesS
515515
) {
516516
}
517517

518-
getEOL(resource: URI): string {
519-
const filesConfiguration = this.configurationService.getValue<{ eol: string }>('files');
520-
if (filesConfiguration && filesConfiguration.eol) {
521-
if (filesConfiguration.eol !== 'auto') {
522-
return filesConfiguration.eol;
523-
}
518+
getEOL(resource: URI, language?: string): string {
519+
const eol = this.configurationService.getValue<string>('files.eol', { overrideIdentifier: language, resource });
520+
if (eol && eol !== 'auto') {
521+
return eol;
524522
}
525523
return (isLinux || isMacintosh) ? '\n' : '\r\n';
526524
}

src/vs/editor/test/common/services/modelService.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ assertComputeEdits(file1, file2);
365365
}
366366
}
367367

368-
class TestTextResourcePropertiesService implements ITextResourcePropertiesService {
368+
export class TestTextResourcePropertiesService implements ITextResourcePropertiesService {
369369

370370
_serviceBrand: undefined;
371371

@@ -375,11 +375,9 @@ class TestTextResourcePropertiesService implements ITextResourcePropertiesServic
375375
}
376376

377377
getEOL(resource: URI, language?: string): string {
378-
const filesConfiguration = this.configurationService.getValue<{ eol: string }>('files', { overrideIdentifier: language, resource });
379-
if (filesConfiguration && filesConfiguration.eol) {
380-
if (filesConfiguration.eol !== 'auto') {
381-
return filesConfiguration.eol;
382-
}
378+
const eol = this.configurationService.getValue<string>('files.eol', { overrideIdentifier: language, resource });
379+
if (eol && eol !== 'auto') {
380+
return eol;
383381
}
384382
return (platform.isLinux || platform.isMacintosh) ? '\n' : '\r\n';
385383
}

src/vs/workbench/contrib/files/browser/files.contribution.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ configurationRegistry.registerConfiguration({
253253
},
254254
'files.eol': {
255255
'type': 'string',
256+
'overridable': true,
256257
'enum': [
257258
'\n',
258259
'\r\n',

src/vs/workbench/services/keybinding/test/electron-browser/keybindingEditing.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
1919
import { ITextModelService } from 'vs/editor/common/services/resolverService';
2020
import { ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
2121
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
22-
import { ConfigurationService } from 'vs/platform/configuration/node/configurationService';
2322
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
2423
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
2524
import { IFileService } from 'vs/platform/files/common/files';
@@ -49,6 +48,7 @@ import { FileUserDataProvider } from 'vs/workbench/services/userData/common/file
4948
import { parseArgs, OPTIONS } from 'vs/platform/environment/node/argv';
5049
import { WorkbenchEnvironmentService } from 'vs/workbench/services/environment/node/environmentService';
5150
import { IWindowConfiguration } from 'vs/platform/windows/common/windows';
51+
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
5252

5353
class TestEnvironmentService extends WorkbenchEnvironmentService {
5454

@@ -81,11 +81,12 @@ suite('KeybindingsEditing', () => {
8181
instantiationService = new TestInstantiationService();
8282

8383
const environmentService = new TestEnvironmentService(URI.file(testDir));
84+
85+
const configService = new TestConfigurationService();
86+
configService.setUserConfiguration('files', { 'eol': '\n' });
87+
8488
instantiationService.stub(IEnvironmentService, environmentService);
85-
instantiationService.stub(IConfigurationService, ConfigurationService);
86-
instantiationService.stub(IConfigurationService, 'getValue', { 'eol': '\n' });
87-
instantiationService.stub(IConfigurationService, 'onDidUpdateConfiguration', () => { });
88-
instantiationService.stub(IConfigurationService, 'onDidChangeConfiguration', () => { });
89+
instantiationService.stub(IConfigurationService, configService);
8990
instantiationService.stub(IWorkspaceContextService, new TestContextService());
9091
const lifecycleService = new TestLifecycleService();
9192
instantiationService.stub(ILifecycleService, lifecycleService);

src/vs/workbench/services/textfile/common/textResourcePropertiesService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ export class TextResourcePropertiesService implements ITextResourcePropertiesSer
3030
}
3131

3232
getEOL(resource?: URI, language?: string): string {
33-
const filesConfiguration = this.configurationService.getValue<{ eol: string }>('files', { overrideIdentifier: language, resource });
34-
if (filesConfiguration && filesConfiguration.eol && filesConfiguration.eol !== 'auto') {
35-
return filesConfiguration.eol;
33+
const eol = this.configurationService.getValue<string>('files.eol', { overrideIdentifier: language, resource });
34+
if (eol && eol !== 'auto') {
35+
return eol;
3636
}
3737
const os = this.getOS(resource);
3838
return os === OperatingSystem.Linux || os === OperatingSystem.Macintosh ? '\n' : '\r\n';

src/vs/workbench/test/workbenchTestServices.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,12 +1241,10 @@ export class TestTextResourcePropertiesService implements ITextResourcePropertie
12411241
) {
12421242
}
12431243

1244-
getEOL(resource: URI): string {
1245-
const filesConfiguration = this.configurationService.getValue<{ eol: string }>('files');
1246-
if (filesConfiguration && filesConfiguration.eol) {
1247-
if (filesConfiguration.eol !== 'auto') {
1248-
return filesConfiguration.eol;
1249-
}
1244+
getEOL(resource: URI, language?: string): string {
1245+
const eol = this.configurationService.getValue<string>('files.eol', { overrideIdentifier: language, resource });
1246+
if (eol && eol !== 'auto') {
1247+
return eol;
12501248
}
12511249
return (isLinux || isMacintosh) ? '\n' : '\r\n';
12521250
}

0 commit comments

Comments
 (0)