- Get formatting options using text model

- Send only bindings to resolve
This commit is contained in:
Sandeep Somavarapu
2019-12-02 11:15:31 +01:00
parent 46d8590621
commit 4b0a066b83
11 changed files with 408 additions and 380 deletions

View File

@@ -1,32 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { parse } from 'vs/base/common/json';
import { IUserFriendlyKeybinding, IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IUserKeybindingsResolverService } from 'vs/platform/userDataSync/common/userDataSync';
import { IStringDictionary } from 'vs/base/common/collections';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
export class UserKeybindingsResolverService implements IUserKeybindingsResolverService {
_serviceBrand: undefined;
constructor(
@IKeybindingService private readonly keybindingsService: IKeybindingService
) { }
public async resolveUserKeybindings(localContent: string, remoteContent: string, baseContent: string | null): Promise<IStringDictionary<string>> {
const local = <IUserFriendlyKeybinding[]>parse(localContent);
const remote = <IUserFriendlyKeybinding[]>parse(remoteContent);
const base = baseContent ? <IUserFriendlyKeybinding[]>parse(baseContent) : null;
const keys: IStringDictionary<string> = {};
for (const keybinding of [...local, ...remote, ...(base || [])]) {
keys[keybinding.key] = this.keybindingsService.resolveUserBinding(keybinding.key).map(part => part.getUserSettingsLabel()).join(' ');
}
return keys;
}
}
registerSingleton(IUserKeybindingsResolverService, UserKeybindingsResolverService);

View File

@@ -0,0 +1,40 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IUserDataSyncUtilService } from 'vs/platform/userDataSync/common/userDataSync';
import { IStringDictionary } from 'vs/base/common/collections';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { FormattingOptions } from 'vs/base/common/jsonFormatter';
import { URI } from 'vs/base/common/uri';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
class UserDataSyncUtilService implements IUserDataSyncUtilService {
_serviceBrand: undefined;
constructor(
@IKeybindingService private readonly keybindingsService: IKeybindingService,
@ITextModelService private readonly textModelService: ITextModelService,
) { }
public async resolveUserBindings(userBindings: string[]): Promise<IStringDictionary<string>> {
const keys: IStringDictionary<string> = {};
for (const userbinding of userBindings) {
keys[userbinding] = this.keybindingsService.resolveUserBinding(userbinding).map(part => part.getUserSettingsLabel()).join(' ');
}
return keys;
}
async resolveFormattingOptions(resource: URI): Promise<FormattingOptions> {
const modelReference = await this.textModelService.createModelReference(resource);
const { insertSpaces, tabSize } = modelReference.object.textEditorModel.getOptions();
const eol = modelReference.object.textEditorModel.getEOL();
modelReference.dispose();
return { eol, insertSpaces, tabSize };
}
}
registerSingleton(IUserDataSyncUtilService, UserDataSyncUtilService);