Repository: vscode
Issue: Merge Editor: Allow Diff Adjustments To Auto-Solve Conflict
Labels: feature-request,merge-editor

If both deletion changes align, the conflict can be auto-solved.

This conflict is tricky, and Smart-Git also screws it up (=> bug).
The git conflict markers are not very helpful.

![image](https://user-images.githubusercontent.com/2931520/222919168-a6bcff53-41ce-4af6-b72f-214510ff8247.png)

Related: https://github.com/microsoft/vscode/issues/155938

```json
{
    "languageId": "typescript",
    "base": "/*---------------------------------------------------------------------------------------------\n *  Copyright (c) Microsoft Corporation. All rights reserved.\n *  Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { commands, CompletionItem, CompletionItemKind, ExtensionContext, languages, Position, Range, SnippetString, TextEdit, window, TextDocument, CompletionContext, CancellationToken, ProviderResult, CompletionList } from 'vscode';\nimport { Disposable, LanguageClientOptions, ProvideCompletionItemsSignature, NotificationType, CommonLanguageClient } from 'vscode-languageclient';\nimport * as nls from 'vscode-nls';\nimport { getCustomDataSource } from './customData';\nimport { RequestService, serveFileSystemRequests } from './requests';\n\nnamespace CustomDataChangedNotification {\n\texport const type: NotificationType<string[]> = new NotificationType('css/customDataChanged');\n}\n\nconst localize = nls.loadMessageBundle();\n\nexport type LanguageClientConstructor = (name: string, description: string, clientOptions: LanguageClientOptions) => CommonLanguageClient;\n\nexport interface Runtime {\n\tTextDecoder: { new(encoding?: string): { decode(buffer: ArrayBuffer): string; } };\n\tfs?: RequestService;\n}\n\nexport function startClient(context: ExtensionContext, newLanguageClient: LanguageClientConstructor, runtime: Runtime) {\n\n\tconst customDataSource = getCustomDataSource(context.subscriptions);\n\n\tlet documentSelector = ['css', 'scss', 'less'];\n\n\t// Options to control the language client\n\tlet clientOptions: LanguageClientOptions = {\n\t\tdocumentSelector,\n\t\tsynchronize: {\n\t\t\tconfigurationSection: ['css', 'scss', 'less']\n\t\t},\n\t\tinitializationOptions: {\n\t\t\thandledSchemas: ['file']\n\t\t},\n\t\tmiddleware: {\n\t\t\tprovideCompletionItem(document: TextDocument, position: Position, context: CompletionContext, token: CancellationToken, next: ProvideCompletionItemsSignature): ProviderResult<CompletionItem[] | CompletionList> {\n\t\t\t\t// testing the replace / insert mode\n\t\t\t\tfunction updateRanges(item: CompletionItem) {\n\t\t\t\t\tconst range = item.range;\n\t\t\t\t\tif (range instanceof Range && range.end.isAfter(position) && range.start.isBeforeOrEqual(position)) {\n\t\t\t\t\t\titem.range = { inserting: new Range(range.start, position), replacing: range };\n\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfunction updateLabel(item: CompletionItem) {\n\t\t\t\t\tif (item.kind === CompletionItemKind.Color) {\n\t\t\t\t\t\titem.label2 = {\n\t\t\t\t\t\t\tname: item.label,\n\t\t\t\t\t\t\ttype: (item.documentation as string)\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// testing the new completion\n\t\t\t\tfunction updateProposals(r: CompletionItem[] | CompletionList | null | undefined): CompletionItem[] | CompletionList | null | undefined {\n\t\t\t\t\tif (r) {\n\t\t\t\t\t\t(Array.isArray(r) ? r : r.items).forEach(updateRanges);\n\t\t\t\t\t\t(Array.isArray(r) ? r : r.items).forEach(updateLabel);\n\t\t\t\t\t}\n\t\t\t\t\treturn r;\n\t\t\t\t}\n\t\t\t\tconst isThenable = <T>(obj: ProviderResult<T>): obj is Thenable<T> => obj && (<any>obj)['then'];\n\n\t\t\t\tconst r = next(document, position, context, token);\n\t\t\t\tif (isThenable<CompletionItem[] | CompletionList | null | undefined>(r)) {\n\t\t\t\t\treturn r.then(updateProposals);\n\t\t\t\t}\n\t\t\t\treturn updateProposals(r);\n\t\t\t}\n\t\t}\n\t};\n\n\t// Create the language client and start the client.\n\tlet client = newLanguageClient('css', localize('cssserver.name', 'CSS Language Server'), clientOptions);\n\tclient.registerProposedFeatures();\n\tclient.onReady().then(() => {\n\n\t\tclient.sendNotification(CustomDataChangedNotification.type, customDataSource.uris);\n\t\tcustomDataSource.onDidChange(() => {\n\t\t\tclient.sendNotification(CustomDataChangedNotification.type, customDataSource.uris);\n\t\t});\n\n\t\tserveFileSystemRequests(client, runtime);\n\t});\n\n\tlet disposable = client.start();\n\t// Push the disposable to the context's subscriptions so that the\n\t// client can be deactivated on extension deactivation\n\tcontext.subscriptions.push(disposable);\n\n\tlet indentationRules = {\n\t\tincreaseIndentPattern: /(^.*\\{[^}]*$)/,\n\t\tdecreaseIndentPattern: /^\\s*\\}/\n\t};\n\n\tlanguages.setLanguageConfiguration('css', {\n\t\twordPattern: /(#?-?\\d*\\.\\d\\w*%?)|(::?[\\w-]*(?=[^,{;]*[,{]))|(([@#.!])?[\\w-?]+%?|[@#!.])/g,\n\t\tindentationRules: indentationRules\n\t});\n\n\tlanguages.setLanguageConfiguration('less', {\n\t\twordPattern: /(#?-?\\d*\\.\\d\\w*%?)|(::?[\\w-]+(?=[^,{;]*[,{]))|(([@#.!])?[\\w-?]+%?|[@#!.])/g,\n\t\tindentationRules: indentationRules\n\t});\n\n\tlanguages.setLanguageConfiguration('scss', {\n\t\twordPattern: /(#?-?\\d*\\.\\d\\w*%?)|(::?[\\w-]*(?=[^,{;]*[,{]))|(([@$#.!])?[\\w-?]+%?|[@#!$.])/g,\n\t\tindentationRules: indentationRules\n\t});\n\n\tclient.onReady().then(() => {\n\t\tcontext.subscriptions.push(initCompletionProvider());\n\t});\n\n\tfunction initCompletionProvider(): Disposable {\n\t\tconst regionCompletionRegExpr = /^(\\s*)(\\/(\\*\\s*(#\\w*)?)?)?$/;\n\n\t\treturn languages.registerCompletionItemProvider(documentSelector, {\n\t\t\tprovideCompletionItems(doc: TextDocument, pos: Position) {\n\t\t\t\tlet lineUntilPos = doc.getText(new Range(new Position(pos.line, 0), pos));\n\t\t\t\tlet match = lineUntilPos.match(regionCompletionRegExpr);\n\t\t\t\tif (match) {\n\t\t\t\t\tlet range = new Range(new Position(pos.line, match[1].length), pos);\n\t\t\t\t\tlet beginProposal = new CompletionItem('#region', CompletionItemKind.Snippet);\n\t\t\t\t\tbeginProposal.range = range; TextEdit.replace(range, '/* #region */');\n\t\t\t\t\tbeginProposal.insertText = new SnippetString('/* #region $1*/');\n\t\t\t\t\tbeginProposal.documentation = localize('folding.start', 'Folding Region Start');\n\t\t\t\t\tbeginProposal.filterText = match[2];\n\t\t\t\t\tbeginProposal.sortText = 'za';\n\t\t\t\t\tlet endProposal = new CompletionItem('#endregion', CompletionItemKind.Snippet);\n\t\t\t\t\tendProposal.range = range;\n\t\t\t\t\tendProposal.insertText = '/* #endregion */';\n\t\t\t\t\tendProposal.documentation = localize('folding.end', 'Folding Region End');\n\t\t\t\t\tendProposal.sortText = 'zb';\n\t\t\t\t\tendProposal.filterText = match[2];\n\t\t\t\t\treturn [beginProposal, endProposal];\n\t\t\t\t}\n\t\t\t\treturn null;\n\t\t\t}\n\t\t});\n\t}\n\n\tcommands.registerCommand('_css.applyCodeAction', applyCodeAction);\n\n\tfunction applyCodeAction(uri: string, documentVersion: number, edits: TextEdit[]) {\n\t\tlet textEditor = window.activeTextEditor;\n\t\tif (textEditor && textEditor.document.uri.toString() === uri) {\n\t\t\tif (textEditor.document.version !== documentVersion) {\n\t\t\t\twindow.showInformationMessage(`CSS fix is outdated and can't be applied to the document.`);\n\t\t\t}\n\t\t\ttextEditor.edit(mutator => {\n\t\t\t\tfor (let edit of edits) {\n\t\t\t\t\tmutator.replace(client.protocol2CodeConverter.asRange(edit.range), edit.newText);\n\t\t\t\t}\n\t\t\t}).then(success => {\n\t\t\t\tif (!success) {\n\t\t\t\t\twindow.showErrorMessage('Failed to apply CSS fix to the document. Please consider opening an issue with steps to reproduce.');\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n}\n",
    "input1": "/*---------------------------------------------------------------------------------------------\n *  Copyright (c) Microsoft Corporation. All rights reserved.\n *  Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { commands, CompletionItem, CompletionItemKind, ExtensionContext, languages, Position, Range, SnippetString, TextEdit, window, TextDocument, CompletionContext, CancellationToken, ProviderResult, CompletionList } from 'vscode';\nimport { Disposable, LanguageClientOptions, ProvideCompletionItemsSignature, NotificationType, CommonLanguageClient } from 'vscode-languageclient';\nimport * as nls from 'vscode-nls';\nimport { getCustomDataSource } from './customData';\nimport { RequestService, serveFileSystemRequests } from './requests';\n\nnamespace CustomDataChangedNotification {\n\texport const type: NotificationType<string[]> = new NotificationType('css/customDataChanged');\n}\n\nconst localize = nls.loadMessageBundle();\n\nexport type LanguageClientConstructor = (name: string, description: string, clientOptions: LanguageClientOptions) => CommonLanguageClient;\n\nexport interface Runtime {\n\tTextDecoder: { new(encoding?: string): { decode(buffer: ArrayBuffer): string; } };\n\tfs?: RequestService;\n}\n\nexport function startClient(context: ExtensionContext, newLanguageClient: LanguageClientConstructor, runtime: Runtime) {\n\n\tconst customDataSource = getCustomDataSource(context.subscriptions);\n\n\tlet documentSelector = ['css', 'scss', 'less'];\n\n\t// Options to control the language client\n\tlet clientOptions: LanguageClientOptions = {\n\t\tdocumentSelector,\n\t\tsynchronize: {\n\t\t\tconfigurationSection: ['css', 'scss', 'less']\n\t\t},\n\t\tinitializationOptions: {\n\t\t\thandledSchemas: ['file']\n\t\t},\n\t\tmiddleware: {\n\t\t\tprovideCompletionItem(document: TextDocument, position: Position, context: CompletionContext, token: CancellationToken, next: ProvideCompletionItemsSignature): ProviderResult<CompletionItem[] | CompletionList> {\n\t\t\t\t// testing the replace / insert mode\n\t\t\t\tfunction updateRanges(item: CompletionItem) {\n\t\t\t\t\tconst range = item.range;\n\t\t\t\t\tif (range instanceof Range && range.end.isAfter(position) && range.start.isBeforeOrEqual(position)) {\n\t\t\t\t\t\titem.range = { inserting: new Range(range.start, position), replacing: range };\n\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfunction updateLabel(item: CompletionItem) {\n\t\t\t\t\tif (item.kind === CompletionItemKind.Color) {\n\t\t\t\t\t\titem.label2 = {\n\t\t\t\t\t\t\tname: item.label,\n\t\t\t\t\t\t\ttype: (item.documentation as string)\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// testing the new completion\n\t\t\t\tfunction updateProposals(r: CompletionItem[] | CompletionList | null | undefined): CompletionItem[] | CompletionList | null | undefined {\n\t\t\t\t\tif (r) {\n\t\t\t\t\t\t(Array.isArray(r) ? r : r.items).forEach(updateRanges);\n\t\t\t\t\t\t(Array.isArray(r) ? r : r.items).forEach(updateLabel);\n\t\t\t\t\t}\n\t\t\t\t\treturn r;\n\t\t\t\t}\n\t\t\t\tconst isThenable = <T>(obj: ProviderResult<T>): obj is Thenable<T> => obj && (<any>obj)['then'];\n\n\t\t\t\tconst r = next(document, position, context, token);\n\t\t\t\tif (isThenable<CompletionItem[] | CompletionList | null | undefined>(r)) {\n\t\t\t\t\treturn r.then(updateProposals);\n\t\t\t\t}\n\t\t\t\treturn updateProposals(r);\n\t\t\t}\n\t\t}\n\t};\n\n\t// Create the language client and start the client.\n\tlet client = newLanguageClient('css', localize('cssserver.name', 'CSS Language Server'), clientOptions);\n\tclient.registerProposedFeatures();\n\tclient.onReady().then(() => {\n\n\t\tclient.sendNotification(CustomDataChangedNotification.type, customDataSource.uris);\n\t\tcustomDataSource.onDidChange(() => {\n\t\t\tclient.sendNotification(CustomDataChangedNotification.type, customDataSource.uris);\n\t\t});\n\n\t\tserveFileSystemRequests(client, runtime);\n\t});\n\n\tlet disposable = client.start();\n\t// Push the disposable to the context's subscriptions so that the\n\t// client can be deactivated on extension deactivation\n\tcontext.subscriptions.push(disposable);\n\n\tclient.onReady().then(() => {\n\t\tcontext.subscriptions.push(initCompletionProvider());\n\t});\n\n\tfunction initCompletionProvider(): Disposable {\n\t\tconst regionCompletionRegExpr = /^(\\s*)(\\/(\\*\\s*(#\\w*)?)?)?$/;\n\n\t\treturn languages.registerCompletionItemProvider(documentSelector, {\n\t\t\tprovideCompletionItems(doc: TextDocument, pos: Position) {\n\t\t\t\tlet lineUntilPos = doc.getText(new Range(new Position(pos.line, 0), pos));\n\t\t\t\tlet match = lineUntilPos.match(regionCompletionRegExpr);\n\t\t\t\tif (match) {\n\t\t\t\t\tlet range = new Range(new Position(pos.line, match[1].length), pos);\n\t\t\t\t\tlet beginProposal = new CompletionItem('#region', CompletionItemKind.Snippet);\n\t\t\t\t\tbeginProposal.range = range; TextEdit.replace(range, '/* #region */');\n\t\t\t\t\tbeginProposal.insertText = new SnippetString('/* #region $1*/');\n\t\t\t\t\tbeginProposal.documentation = localize('folding.start', 'Folding Region Start');\n\t\t\t\t\tbeginProposal.filterText = match[2];\n\t\t\t\t\tbeginProposal.sortText = 'za';\n\t\t\t\t\tlet endProposal = new CompletionItem('#endregion', CompletionItemKind.Snippet);\n\t\t\t\t\tendProposal.range = range;\n\t\t\t\t\tendProposal.insertText = '/* #endregion */';\n\t\t\t\t\tendProposal.documentation = localize('folding.end', 'Folding Region End');\n\t\t\t\t\tendProposal.sortText = 'zb';\n\t\t\t\t\tendProposal.filterText = match[2];\n\t\t\t\t\treturn [beginProposal, endProposal];\n\t\t\t\t}\n\t\t\t\treturn null;\n\t\t\t}\n\t\t});\n\t}\n\n\tcommands.registerCommand('_css.applyCodeAction', applyCodeAction);\n\n\tfunction applyCodeAction(uri: string, documentVersion: number, edits: TextEdit[]) {\n\t\tlet textEditor = window.activeTextEditor;\n\t\tif (textEditor && textEditor.document.uri.toString() === uri) {\n\t\t\tif (textEditor.document.version !== documentVersion) {\n\t\t\t\twindow.showInformationMessage(`CSS fix is outdated and can't be applied to the document.`);\n\t\t\t}\n\t\t\ttextEditor.edit(mutator => {\n\t\t\t\tfor (let edit of edits) {\n\t\t\t\t\tmutator.replace(client.protocol2CodeConverter.asRange(edit.range), edit.newText);\n\t\t\t\t}\n\t\t\t}).then(success => {\n\t\t\t\tif (!success) {\n\t\t\t\t\twindow.showErrorMessage('Failed to apply CSS fix to the document. Please consider opening an issue with steps to reproduce.');\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n}\n",
    "input2": "/*---------------------------------------------------------------------------------------------\n *  Copyright (c) Microsoft Corporation. All rights reserved.\n *  Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { commands, CompletionItem, CompletionItemKind, ExtensionContext, languages, Position, Range, SnippetString, TextEdit, window, TextDocument, CompletionContext, CancellationToken, ProviderResult, CompletionList, FormattingOptions, workspace, l10n } from 'vscode';\nimport { Disposable, LanguageClientOptions, ProvideCompletionItemsSignature, NotificationType, BaseLanguageClient, DocumentRangeFormattingParams, DocumentRangeFormattingRequest } from 'vscode-languageclient';\nimport { getCustomDataSource } from './customData';\nimport { RequestService, serveFileSystemRequests } from './requests';\n\nnamespace CustomDataChangedNotification {\n\texport const type: NotificationType<string[]> = new NotificationType('css/customDataChanged');\n}\n\nexport type LanguageClientConstructor = (name: string, description: string, clientOptions: LanguageClientOptions) => BaseLanguageClient;\n\nexport interface Runtime {\n\tTextDecoder: { new(encoding?: string): { decode(buffer: ArrayBuffer): string } };\n\tfs?: RequestService;\n}\n\ninterface FormatterRegistration {\n\treadonly languageId: string;\n\treadonly settingId: string;\n\tprovider: Disposable | undefined;\n}\n\ninterface CSSFormatSettings {\n\tnewlineBetweenSelectors?: boolean;\n\tnewlineBetweenRules?: boolean;\n\tspaceAroundSelectorSeparator?: boolean;\n\tbraceStyle?: 'collapse' | 'expand';\n\tpreserveNewLines?: boolean;\n\tmaxPreserveNewLines?: number | null;\n}\n\nconst cssFormatSettingKeys: (keyof CSSFormatSettings)[] = ['newlineBetweenSelectors', 'newlineBetweenRules', 'spaceAroundSelectorSeparator', 'braceStyle', 'preserveNewLines', 'maxPreserveNewLines'];\n\nexport async function startClient(context: ExtensionContext, newLanguageClient: LanguageClientConstructor, runtime: Runtime): Promise<BaseLanguageClient> {\n\n\tconst customDataSource = getCustomDataSource(context.subscriptions);\n\n\tconst documentSelector = ['css', 'scss', 'less'];\n\n\tconst formatterRegistrations: FormatterRegistration[] = documentSelector.map(languageId => ({\n\t\tlanguageId, settingId: `${languageId}.format.enable`, provider: undefined\n\t}));\n\n\t// Options to control the language client\n\tconst clientOptions: LanguageClientOptions = {\n\t\tdocumentSelector,\n\t\tsynchronize: {\n\t\t\tconfigurationSection: ['css', 'scss', 'less']\n\t\t},\n\t\tinitializationOptions: {\n\t\t\thandledSchemas: ['file'],\n\t\t\tprovideFormatter: false, // tell the server to not provide formatting capability\n\t\t\tcustomCapabilities: { rangeFormatting: { editLimit: 10000 } }\n\t\t},\n\t\tmiddleware: {\n\t\t\tprovideCompletionItem(document: TextDocument, position: Position, context: CompletionContext, token: CancellationToken, next: ProvideCompletionItemsSignature): ProviderResult<CompletionItem[] | CompletionList> {\n\t\t\t\t// testing the replace / insert mode\n\t\t\t\tfunction updateRanges(item: CompletionItem) {\n\t\t\t\t\tconst range = item.range;\n\t\t\t\t\tif (range instanceof Range && range.end.isAfter(position) && range.start.isBeforeOrEqual(position)) {\n\t\t\t\t\t\titem.range = { inserting: new Range(range.start, position), replacing: range };\n\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfunction updateLabel(item: CompletionItem) {\n\t\t\t\t\tif (item.kind === CompletionItemKind.Color) {\n\t\t\t\t\t\titem.label = {\n\t\t\t\t\t\t\tlabel: item.label as string,\n\t\t\t\t\t\t\tdescription: (item.documentation as string)\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// testing the new completion\n\t\t\t\tfunction updateProposals(r: CompletionItem[] | CompletionList | null | undefined): CompletionItem[] | CompletionList | null | undefined {\n\t\t\t\t\tif (r) {\n\t\t\t\t\t\t(Array.isArray(r) ? r : r.items).forEach(updateRanges);\n\t\t\t\t\t\t(Array.isArray(r) ? r : r.items).forEach(updateLabel);\n\t\t\t\t\t}\n\t\t\t\t\treturn r;\n\t\t\t\t}\n\t\t\t\tconst isThenable = <T>(obj: ProviderResult<T>): obj is Thenable<T> => obj && (<any>obj)['then'];\n\n\t\t\t\tconst r = next(document, position, context, token);\n\t\t\t\tif (isThenable<CompletionItem[] | CompletionList | null | undefined>(r)) {\n\t\t\t\t\treturn r.then(updateProposals);\n\t\t\t\t}\n\t\t\t\treturn updateProposals(r);\n\t\t\t}\n\t\t}\n\t};\n\n\t// Create the language client and start the client.\n\tconst client = newLanguageClient('css', l10n.t('CSS Language Server'), clientOptions);\n\tclient.registerProposedFeatures();\n\n\tawait client.start();\n\n\tclient.sendNotification(CustomDataChangedNotification.type, customDataSource.uris);\n\tcustomDataSource.onDidChange(() => {\n\t\tclient.sendNotification(CustomDataChangedNotification.type, customDataSource.uris);\n\t});\n\n\t// manually register / deregister format provider based on the `css/less/scss.format.enable` setting avoiding issues with late registration. See #71652.\n\tfor (const registration of formatterRegistrations) {\n\t\tupdateFormatterRegistration(registration);\n\t\tcontext.subscriptions.push({ dispose: () => registration.provider?.dispose() });\n\t\tcontext.subscriptions.push(workspace.onDidChangeConfiguration(e => e.affectsConfiguration(registration.settingId) && updateFormatterRegistration(registration)));\n\t}\n\n\tserveFileSystemRequests(client, runtime);\n\n\n\tcontext.subscriptions.push(initCompletionProvider());\n\n\tfunction initCompletionProvider(): Disposable {\n\t\tconst regionCompletionRegExpr = /^(\\s*)(\\/(\\*\\s*(#\\w*)?)?)?$/;\n\n\t\treturn languages.registerCompletionItemProvider(documentSelector, {\n\t\t\tprovideCompletionItems(doc: TextDocument, pos: Position) {\n\t\t\t\tconst lineUntilPos = doc.getText(new Range(new Position(pos.line, 0), pos));\n\t\t\t\tconst match = lineUntilPos.match(regionCompletionRegExpr);\n\t\t\t\tif (match) {\n\t\t\t\t\tconst range = new Range(new Position(pos.line, match[1].length), pos);\n\t\t\t\t\tconst beginProposal = new CompletionItem('#region', CompletionItemKind.Snippet);\n\t\t\t\t\tbeginProposal.range = range; TextEdit.replace(range, '/* #region */');\n\t\t\t\t\tbeginProposal.insertText = new SnippetString('/* #region $1*/');\n\t\t\t\t\tbeginProposal.documentation = l10n.t('Folding Region Start');\n\t\t\t\t\tbeginProposal.filterText = match[2];\n\t\t\t\t\tbeginProposal.sortText = 'za';\n\t\t\t\t\tconst endProposal = new CompletionItem('#endregion', CompletionItemKind.Snippet);\n\t\t\t\t\tendProposal.range = range;\n\t\t\t\t\tendProposal.insertText = '/* #endregion */';\n\t\t\t\t\tendProposal.documentation = l10n.t('Folding Region End');\n\t\t\t\t\tendProposal.sortText = 'zb';\n\t\t\t\t\tendProposal.filterText = match[2];\n\t\t\t\t\treturn [beginProposal, endProposal];\n\t\t\t\t}\n\t\t\t\treturn null;\n\t\t\t}\n\t\t});\n\t}\n\n\tcommands.registerCommand('_css.applyCodeAction', applyCodeAction);\n\n\tfunction applyCodeAction(uri: string, documentVersion: number, edits: TextEdit[]) {\n\t\tconst textEditor = window.activeTextEditor;\n\t\tif (textEditor && textEditor.document.uri.toString() === uri) {\n\t\t\tif (textEditor.document.version !== documentVersion) {\n\t\t\t\twindow.showInformationMessage(l10n.t('CSS fix is outdated and can\\'t be applied to the document.'));\n\t\t\t}\n\t\t\ttextEditor.edit(mutator => {\n\t\t\t\tfor (const edit of edits) {\n\t\t\t\t\tmutator.replace(client.protocol2CodeConverter.asRange(edit.range), edit.newText);\n\t\t\t\t}\n\t\t\t}).then(success => {\n\t\t\t\tif (!success) {\n\t\t\t\t\twindow.showErrorMessage(l10n.t('Failed to apply CSS fix to the document. Please consider opening an issue with steps to reproduce.'));\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tfunction updateFormatterRegistration(registration: FormatterRegistration) {\n\t\tconst formatEnabled = workspace.getConfiguration().get(registration.settingId);\n\t\tif (!formatEnabled && registration.provider) {\n\t\t\tregistration.provider.dispose();\n\t\t\tregistration.provider = undefined;\n\t\t} else if (formatEnabled && !registration.provider) {\n\t\t\tregistration.provider = languages.registerDocumentRangeFormattingEditProvider(registration.languageId, {\n\t\t\t\tprovideDocumentRangeFormattingEdits(document: TextDocument, range: Range, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]> {\n\t\t\t\t\tconst filesConfig = workspace.getConfiguration('files', document);\n\n\t\t\t\t\tconst fileFormattingOptions = {\n\t\t\t\t\t\ttrimTrailingWhitespace: filesConfig.get<boolean>('trimTrailingWhitespace'),\n\t\t\t\t\t\ttrimFinalNewlines: filesConfig.get<boolean>('trimFinalNewlines'),\n\t\t\t\t\t\tinsertFinalNewline: filesConfig.get<boolean>('insertFinalNewline'),\n\t\t\t\t\t};\n\t\t\t\t\tconst params: DocumentRangeFormattingParams = {\n\t\t\t\t\t\ttextDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document),\n\t\t\t\t\t\trange: client.code2ProtocolConverter.asRange(range),\n\t\t\t\t\t\toptions: client.code2ProtocolConverter.asFormattingOptions(options, fileFormattingOptions)\n\t\t\t\t\t};\n\t\t\t\t\t// add the css formatter options from the settings\n\t\t\t\t\tconst formatterSettings = workspace.getConfiguration(registration.languageId, document).get<CSSFormatSettings>('format');\n\t\t\t\t\tif (formatterSettings) {\n\t\t\t\t\t\tfor (const key of cssFormatSettingKeys) {\n\t\t\t\t\t\t\tconst val = formatterSettings[key];\n\t\t\t\t\t\t\tif (val !== undefined && val !== null) {\n\t\t\t\t\t\t\t\tparams.options[key] = val;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn client.sendRequest(DocumentRangeFormattingRequest.type, params, token).then(\n\t\t\t\t\t\tclient.protocol2CodeConverter.asTextEdits,\n\t\t\t\t\t\t(error) => {\n\t\t\t\t\t\t\tclient.handleFailedRequest(DocumentRangeFormattingRequest.type, undefined, error, []);\n\t\t\t\t\t\t\treturn Promise.resolve([]);\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\treturn client;\n}\n",
    "result": "/*---------------------------------------------------------------------------------------------\r\n *  Copyright (c) Microsoft Corporation. All rights reserved.\r\n *  Licensed under the MIT License. See License.txt in the project root for license information.\r\n *--------------------------------------------------------------------------------------------*/\r\n\r\nimport { commands, CompletionItem, CompletionItemKind, ExtensionContext, languages, Position, Range, SnippetString, TextEdit, window, TextDocument, CompletionContext, CancellationToken, ProviderResult, CompletionList, FormattingOptions, workspace, l10n } from 'vscode';\r\nimport { Disposable, LanguageClientOptions, ProvideCompletionItemsSignature, NotificationType, BaseLanguageClient, DocumentRangeFormattingParams, DocumentRangeFormattingRequest } from 'vscode-languageclient';\r\nimport { getCustomDataSource } from './customData';\r\nimport { RequestService, serveFileSystemRequests } from './requests';\r\n\r\nnamespace CustomDataChangedNotification {\r\n\texport const type: NotificationType<string[]> = new NotificationType('css/customDataChanged');\r\n}\r\n\r\nexport type LanguageClientConstructor = (name: string, description: string, clientOptions: LanguageClientOptions) => BaseLanguageClient;\r\n\r\nexport interface Runtime {\r\n\tTextDecoder: { new(encoding?: string): { decode(buffer: ArrayBuffer): string } };\r\n\tfs?: RequestService;\r\n}\r\n\r\ninterface FormatterRegistration {\r\n\treadonly languageId: string;\r\n\treadonly settingId: string;\r\n\tprovider: Disposable | undefined;\r\n}\r\n\r\ninterface CSSFormatSettings {\r\n\tnewlineBetweenSelectors?: boolean;\r\n\tnewlineBetweenRules?: boolean;\r\n\tspaceAroundSelectorSeparator?: boolean;\r\n\tbraceStyle?: 'collapse' | 'expand';\r\n\tpreserveNewLines?: boolean;\r\n\tmaxPreserveNewLines?: number | null;\r\n}\r\n\r\nconst cssFormatSettingKeys: (keyof CSSFormatSettings)[] = ['newlineBetweenSelectors', 'newlineBetweenRules', 'spaceAroundSelectorSeparator', 'braceStyle', 'preserveNewLines', 'maxPreserveNewLines'];\r\n\r\nexport async function startClient(context: ExtensionContext, newLanguageClient: LanguageClientConstructor, runtime: Runtime): Promise<BaseLanguageClient> {\r\n\r\n\tconst customDataSource = getCustomDataSource(context.subscriptions);\r\n\r\n\tconst documentSelector = ['css', 'scss', 'less'];\r\n\r\n\tconst formatterRegistrations: FormatterRegistration[] = documentSelector.map(languageId => ({\r\n\t\tlanguageId, settingId: `${languageId}.format.enable`, provider: undefined\r\n\t}));\r\n\r\n\t// Options to control the language client\r\n\tconst clientOptions: LanguageClientOptions = {\r\n\t\tdocumentSelector,\r\n\t\tsynchronize: {\r\n\t\t\tconfigurationSection: ['css', 'scss', 'less']\r\n\t\t},\r\n\t\tinitializationOptions: {\r\n\t\t\thandledSchemas: ['file'],\r\n\t\t\tprovideFormatter: false, // tell the server to not provide formatting capability\r\n\t\t\tcustomCapabilities: { rangeFormatting: { editLimit: 10000 } }\r\n\t\t},\r\n\t\tmiddleware: {\r\n\t\t\tprovideCompletionItem(document: TextDocument, position: Position, context: CompletionContext, token: CancellationToken, next: ProvideCompletionItemsSignature): ProviderResult<CompletionItem[] | CompletionList> {\r\n\t\t\t\t// testing the replace / insert mode\r\n\t\t\t\tfunction updateRanges(item: CompletionItem) {\r\n\t\t\t\t\tconst range = item.range;\r\n\t\t\t\t\tif (range instanceof Range && range.end.isAfter(position) && range.start.isBeforeOrEqual(position)) {\r\n\t\t\t\t\t\titem.range = { inserting: new Range(range.start, position), replacing: range };\r\n\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfunction updateLabel(item: CompletionItem) {\r\n\t\t\t\t\tif (item.kind === CompletionItemKind.Color) {\r\n\t\t\t\t\t\titem.label = {\r\n\t\t\t\t\t\t\tlabel: item.label as string,\r\n\t\t\t\t\t\t\tdescription: (item.documentation as string)\r\n\t\t\t\t\t\t};\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// testing the new completion\r\n\t\t\t\tfunction updateProposals(r: CompletionItem[] | CompletionList | null | undefined): CompletionItem[] | CompletionList | null | undefined {\r\n\t\t\t\t\tif (r) {\r\n\t\t\t\t\t\t(Array.isArray(r) ? r : r.items).forEach(updateRanges);\r\n\t\t\t\t\t\t(Array.isArray(r) ? r : r.items).forEach(updateLabel);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn r;\r\n\t\t\t\t}\r\n\t\t\t\tconst isThenable = <T>(obj: ProviderResult<T>): obj is Thenable<T> => obj && (<any>obj)['then'];\r\n\r\n\t\t\t\tconst r = next(document, position, context, token);\r\n\t\t\t\tif (isThenable<CompletionItem[] | CompletionList | null | undefined>(r)) {\r\n\t\t\t\t\treturn r.then(updateProposals);\r\n\t\t\t\t}\r\n\t\t\t\treturn updateProposals(r);\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\r\n\t// Create the language client and start the client.\r\n\tconst client = newLanguageClient('css', l10n.t('CSS Language Server'), clientOptions);\r\n\tclient.registerProposedFeatures();\r\n\r\n\tawait client.start();\r\n\r\n\tclient.sendNotification(CustomDataChangedNotification.type, customDataSource.uris);\r\n\tcustomDataSource.onDidChange(() => {\r\n\t\tclient.sendNotification(CustomDataChangedNotification.type, customDataSource.uris);\r\n\t});\r\n\r\n\t// manually register / deregister format provider based on the `css/less/scss.format.enable` setting avoiding issues with late registration. See #71652.\r\n\tfor (const registration of formatterRegistrations) {\r\n\t\tupdateFormatterRegistration(registration);\r\n\t\tcontext.subscriptions.push({ dispose: () => registration.provider?.dispose() });\r\n\t\tcontext.subscriptions.push(workspace.onDidChangeConfiguration(e => e.affectsConfiguration(registration.settingId) && updateFormatterRegistration(registration)));\r\n\t}\r\n\r\n\t\tserveFileSystemRequests(client, runtime);\r\n\t});\r\n\r\n\tlet disposable = client.start();\r\n\t// Push the disposable to the context's subscriptions so that the\r\n\t// client can be deactivated on extension deactivation\r\n\tcontext.subscriptions.push(disposable);\r\n\r\n\tlet indentationRules = {\r\n\t\tincreaseIndentPattern: /(^.*\\{[^}]*$)/,\r\n\t\tdecreaseIndentPattern: /^\\s*\\}/\r\n\t};\r\n\r\n\tlanguages.setLanguageConfiguration('css', {\r\n\t\twordPattern: /(#?-?\\d*\\.\\d\\w*%?)|(::?[\\w-]*(?=[^,{;]*[,{]))|(([@#.!])?[\\w-?]+%?|[@#!.])/g,\r\n\t\tindentationRules: indentationRules\r\n\t});\r\n\r\n\tlanguages.setLanguageConfiguration('less', {\r\n\t\twordPattern: /(#?-?\\d*\\.\\d\\w*%?)|(::?[\\w-]+(?=[^,{;]*[,{]))|(([@#.!])?[\\w-?]+%?|[@#!.])/g,\r\n\t\tindentationRules: indentationRules\r\n\t});\r\n\r\n\tlanguages.setLanguageConfiguration('scss', {\r\n\t\twordPattern: /(#?-?\\d*\\.\\d\\w*%?)|(::?[\\w-]*(?=[^,{;]*[,{]))|(([@$#.!])?[\\w-?]+%?|[@#!$.])/g,\r\n\t\tindentationRules: indentationRules\r\n\t});\r\n\r\n\tcontext.subscriptions.push(initCompletionProvider());\r\n\r\n\tfunction initCompletionProvider(): Disposable {\r\n\t\tconst regionCompletionRegExpr = /^(\\s*)(\\/(\\*\\s*(#\\w*)?)?)?$/;\r\n\r\n\t\treturn languages.registerCompletionItemProvider(documentSelector, {\r\n\t\t\tprovideCompletionItems(doc: TextDocument, pos: Position) {\r\n\t\t\t\tconst lineUntilPos = doc.getText(new Range(new Position(pos.line, 0), pos));\r\n\t\t\t\tconst match = lineUntilPos.match(regionCompletionRegExpr);\r\n\t\t\t\tif (match) {\r\n\t\t\t\t\tconst range = new Range(new Position(pos.line, match[1].length), pos);\r\n\t\t\t\t\tconst beginProposal = new CompletionItem('#region', CompletionItemKind.Snippet);\r\n\t\t\t\t\tbeginProposal.range = range; TextEdit.replace(range, '/* #region */');\r\n\t\t\t\t\tbeginProposal.insertText = new SnippetString('/* #region $1*/');\r\n\t\t\t\t\tbeginProposal.documentation = l10n.t('Folding Region Start');\r\n\t\t\t\t\tbeginProposal.filterText = match[2];\r\n\t\t\t\t\tbeginProposal.sortText = 'za';\r\n\t\t\t\t\tconst endProposal = new CompletionItem('#endregion', CompletionItemKind.Snippet);\r\n\t\t\t\t\tendProposal.range = range;\r\n\t\t\t\t\tendProposal.insertText = '/* #endregion */';\r\n\t\t\t\t\tendProposal.documentation = l10n.t('Folding Region End');\r\n\t\t\t\t\tendProposal.sortText = 'zb';\r\n\t\t\t\t\tendProposal.filterText = match[2];\r\n\t\t\t\t\treturn [beginProposal, endProposal];\r\n\t\t\t\t}\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n\r\n\tcommands.registerCommand('_css.applyCodeAction', applyCodeAction);\r\n\r\n\tfunction applyCodeAction(uri: string, documentVersion: number, edits: TextEdit[]) {\r\n\t\tconst textEditor = window.activeTextEditor;\r\n\t\tif (textEditor && textEditor.document.uri.toString() === uri) {\r\n\t\t\tif (textEditor.document.version !== documentVersion) {\r\n\t\t\t\twindow.showInformationMessage(l10n.t('CSS fix is outdated and can\\'t be applied to the document.'));\r\n\t\t\t}\r\n\t\t\ttextEditor.edit(mutator => {\r\n\t\t\t\tfor (const edit of edits) {\r\n\t\t\t\t\tmutator.replace(client.protocol2CodeConverter.asRange(edit.range), edit.newText);\r\n\t\t\t\t}\r\n\t\t\t}).then(success => {\r\n\t\t\t\tif (!success) {\r\n\t\t\t\t\twindow.showErrorMessage(l10n.t('Failed to apply CSS fix to the document. Please consider opening an issue with steps to reproduce.'));\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\tfunction updateFormatterRegistration(registration: FormatterRegistration) {\r\n\t\tconst formatEnabled = workspace.getConfiguration().get(registration.settingId);\r\n\t\tif (!formatEnabled && registration.provider) {\r\n\t\t\tregistration.provider.dispose();\r\n\t\t\tregistration.provider = undefined;\r\n\t\t} else if (formatEnabled && !registration.provider) {\r\n\t\t\tregistration.provider = languages.registerDocumentRangeFormattingEditProvider(registration.languageId, {\r\n\t\t\t\tprovideDocumentRangeFormattingEdits(document: TextDocument, range: Range, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]> {\r\n\t\t\t\t\tconst filesConfig = workspace.getConfiguration('files', document);\r\n\r\n\t\t\t\t\tconst fileFormattingOptions = {\r\n\t\t\t\t\t\ttrimTrailingWhitespace: filesConfig.get<boolean>('trimTrailingWhitespace'),\r\n\t\t\t\t\t\ttrimFinalNewlines: filesConfig.get<boolean>('trimFinalNewlines'),\r\n\t\t\t\t\t\tinsertFinalNewline: filesConfig.get<boolean>('insertFinalNewline'),\r\n\t\t\t\t\t};\r\n\t\t\t\t\tconst params: DocumentRangeFormattingParams = {\r\n\t\t\t\t\t\ttextDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document),\r\n\t\t\t\t\t\trange: client.code2ProtocolConverter.asRange(range),\r\n\t\t\t\t\t\toptions: client.code2ProtocolConverter.asFormattingOptions(options, fileFormattingOptions)\r\n\t\t\t\t\t};\r\n\t\t\t\t\t// add the css formatter options from the settings\r\n\t\t\t\t\tconst formatterSettings = workspace.getConfiguration(registration.languageId, document).get<CSSFormatSettings>('format');\r\n\t\t\t\t\tif (formatterSettings) {\r\n\t\t\t\t\t\tfor (const key of cssFormatSettingKeys) {\r\n\t\t\t\t\t\t\tconst val = formatterSettings[key];\r\n\t\t\t\t\t\t\tif (val !== undefined && val !== null) {\r\n\t\t\t\t\t\t\t\tparams.options[key] = val;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn client.sendRequest(DocumentRangeFormattingRequest.type, params, token).then(\r\n\t\t\t\t\t\tclient.protocol2CodeConverter.asTextEdits,\r\n\t\t\t\t\t\t(error) => {\r\n\t\t\t\t\t\t\tclient.handleFailedRequest(DocumentRangeFormattingRequest.type, undefined, error, []);\r\n\t\t\t\t\t\t\treturn Promise.resolve([]);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\treturn client;\r\n}\r\n",
    "initialResult": "/*---------------------------------------------------------------------------------------------\r\n *  Copyright (c) Microsoft Corporation. All rights reserved.\r\n *  Licensed under the MIT License. See License.txt in the project root for license information.\r\n *--------------------------------------------------------------------------------------------*/\r\n\r\nimport { commands, CompletionItem, CompletionItemKind, ExtensionContext, languages, Position, Range, SnippetString, TextEdit, window, TextDocument, CompletionContext, CancellationToken, ProviderResult, CompletionList, FormattingOptions, workspace, l10n } from 'vscode';\r\nimport { Disposable, LanguageClientOptions, ProvideCompletionItemsSignature, NotificationType, BaseLanguageClient, DocumentRangeFormattingParams, DocumentRangeFormattingRequest } from 'vscode-languageclient';\r\nimport { getCustomDataSource } from './customData';\r\nimport { RequestService, serveFileSystemRequests } from './requests';\r\n\r\nnamespace CustomDataChangedNotification {\r\n\texport const type: NotificationType<string[]> = new NotificationType('css/customDataChanged');\r\n}\r\n\r\nexport type LanguageClientConstructor = (name: string, description: string, clientOptions: LanguageClientOptions) => BaseLanguageClient;\r\n\r\nexport interface Runtime {\r\n\tTextDecoder: { new(encoding?: string): { decode(buffer: ArrayBuffer): string } };\r\n\tfs?: RequestService;\r\n}\r\n\r\ninterface FormatterRegistration {\r\n\treadonly languageId: string;\r\n\treadonly settingId: string;\r\n\tprovider: Disposable | undefined;\r\n}\r\n\r\ninterface CSSFormatSettings {\r\n\tnewlineBetweenSelectors?: boolean;\r\n\tnewlineBetweenRules?: boolean;\r\n\tspaceAroundSelectorSeparator?: boolean;\r\n\tbraceStyle?: 'collapse' | 'expand';\r\n\tpreserveNewLines?: boolean;\r\n\tmaxPreserveNewLines?: number | null;\r\n}\r\n\r\nconst cssFormatSettingKeys: (keyof CSSFormatSettings)[] = ['newlineBetweenSelectors', 'newlineBetweenRules', 'spaceAroundSelectorSeparator', 'braceStyle', 'preserveNewLines', 'maxPreserveNewLines'];\r\n\r\nexport async function startClient(context: ExtensionContext, newLanguageClient: LanguageClientConstructor, runtime: Runtime): Promise<BaseLanguageClient> {\r\n\r\n\tconst customDataSource = getCustomDataSource(context.subscriptions);\r\n\r\n\tconst documentSelector = ['css', 'scss', 'less'];\r\n\r\n\tconst formatterRegistrations: FormatterRegistration[] = documentSelector.map(languageId => ({\r\n\t\tlanguageId, settingId: `${languageId}.format.enable`, provider: undefined\r\n\t}));\r\n\r\n\t// Options to control the language client\r\n\tconst clientOptions: LanguageClientOptions = {\r\n\t\tdocumentSelector,\r\n\t\tsynchronize: {\r\n\t\t\tconfigurationSection: ['css', 'scss', 'less']\r\n\t\t},\r\n\t\tinitializationOptions: {\r\n\t\t\thandledSchemas: ['file'],\r\n\t\t\tprovideFormatter: false, // tell the server to not provide formatting capability\r\n\t\t\tcustomCapabilities: { rangeFormatting: { editLimit: 10000 } }\r\n\t\t},\r\n\t\tmiddleware: {\r\n\t\t\tprovideCompletionItem(document: TextDocument, position: Position, context: CompletionContext, token: CancellationToken, next: ProvideCompletionItemsSignature): ProviderResult<CompletionItem[] | CompletionList> {\r\n\t\t\t\t// testing the replace / insert mode\r\n\t\t\t\tfunction updateRanges(item: CompletionItem) {\r\n\t\t\t\t\tconst range = item.range;\r\n\t\t\t\t\tif (range instanceof Range && range.end.isAfter(position) && range.start.isBeforeOrEqual(position)) {\r\n\t\t\t\t\t\titem.range = { inserting: new Range(range.start, position), replacing: range };\r\n\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfunction updateLabel(item: CompletionItem) {\r\n\t\t\t\t\tif (item.kind === CompletionItemKind.Color) {\r\n\t\t\t\t\t\titem.label = {\r\n\t\t\t\t\t\t\tlabel: item.label as string,\r\n\t\t\t\t\t\t\tdescription: (item.documentation as string)\r\n\t\t\t\t\t\t};\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// testing the new completion\r\n\t\t\t\tfunction updateProposals(r: CompletionItem[] | CompletionList | null | undefined): CompletionItem[] | CompletionList | null | undefined {\r\n\t\t\t\t\tif (r) {\r\n\t\t\t\t\t\t(Array.isArray(r) ? r : r.items).forEach(updateRanges);\r\n\t\t\t\t\t\t(Array.isArray(r) ? r : r.items).forEach(updateLabel);\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn r;\r\n\t\t\t\t}\r\n\t\t\t\tconst isThenable = <T>(obj: ProviderResult<T>): obj is Thenable<T> => obj && (<any>obj)['then'];\r\n\r\n\t\t\t\tconst r = next(document, position, context, token);\r\n\t\t\t\tif (isThenable<CompletionItem[] | CompletionList | null | undefined>(r)) {\r\n\t\t\t\t\treturn r.then(updateProposals);\r\n\t\t\t\t}\r\n\t\t\t\treturn updateProposals(r);\r\n\t\t\t}\r\n\t\t}\r\n\t};\r\n\r\n\t// Create the language client and start the client.\r\n\tconst client = newLanguageClient('css', l10n.t('CSS Language Server'), clientOptions);\r\n\tclient.registerProposedFeatures();\r\n\r\n\tawait client.start();\r\n\r\n\tclient.sendNotification(CustomDataChangedNotification.type, customDataSource.uris);\r\n\tcustomDataSource.onDidChange(() => {\r\n\t\tclient.sendNotification(CustomDataChangedNotification.type, customDataSource.uris);\r\n\t});\r\n\r\n<<<<<<< Updated upstream\r\n\t// manually register / deregister format provider based on the `css/less/scss.format.enable` setting avoiding issues with late registration. See #71652.\r\n\tfor (const registration of formatterRegistrations) {\r\n\t\tupdateFormatterRegistration(registration);\r\n\t\tcontext.subscriptions.push({ dispose: () => registration.provider?.dispose() });\r\n\t\tcontext.subscriptions.push(workspace.onDidChangeConfiguration(e => e.affectsConfiguration(registration.settingId) && updateFormatterRegistration(registration)));\r\n\t}\r\n\r\n\tserveFileSystemRequests(client, runtime);\r\n\r\n\r\n\tcontext.subscriptions.push(initCompletionProvider());\r\n=======\r\n\tlet disposable = client.start();\r\n\t// Push the disposable to the context's subscriptions so that the\r\n\t// client can be deactivated on extension deactivation\r\n\tcontext.subscriptions.push(disposable);\r\n\r\n\tclient.onReady().then(() => {\r\n\t\tcontext.subscriptions.push(initCompletionProvider());\r\n\t});\r\n>>>>>>> Stashed changes\r\n\r\n\tfunction initCompletionProvider(): Disposable {\r\n\t\tconst regionCompletionRegExpr = /^(\\s*)(\\/(\\*\\s*(#\\w*)?)?)?$/;\r\n\r\n\t\treturn languages.registerCompletionItemProvider(documentSelector, {\r\n\t\t\tprovideCompletionItems(doc: TextDocument, pos: Position) {\r\n\t\t\t\tconst lineUntilPos = doc.getText(new Range(new Position(pos.line, 0), pos));\r\n\t\t\t\tconst match = lineUntilPos.match(regionCompletionRegExpr);\r\n\t\t\t\tif (match) {\r\n\t\t\t\t\tconst range = new Range(new Position(pos.line, match[1].length), pos);\r\n\t\t\t\t\tconst beginProposal = new CompletionItem('#region', CompletionItemKind.Snippet);\r\n\t\t\t\t\tbeginProposal.range = range; TextEdit.replace(range, '/* #region */');\r\n\t\t\t\t\tbeginProposal.insertText = new SnippetString('/* #region $1*/');\r\n\t\t\t\t\tbeginProposal.documentation = l10n.t('Folding Region Start');\r\n\t\t\t\t\tbeginProposal.filterText = match[2];\r\n\t\t\t\t\tbeginProposal.sortText = 'za';\r\n\t\t\t\t\tconst endProposal = new CompletionItem('#endregion', CompletionItemKind.Snippet);\r\n\t\t\t\t\tendProposal.range = range;\r\n\t\t\t\t\tendProposal.insertText = '/* #endregion */';\r\n\t\t\t\t\tendProposal.documentation = l10n.t('Folding Region End');\r\n\t\t\t\t\tendProposal.sortText = 'zb';\r\n\t\t\t\t\tendProposal.filterText = match[2];\r\n\t\t\t\t\treturn [beginProposal, endProposal];\r\n\t\t\t\t}\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n\r\n\tcommands.registerCommand('_css.applyCodeAction', applyCodeAction);\r\n\r\n\tfunction applyCodeAction(uri: string, documentVersion: number, edits: TextEdit[]) {\r\n\t\tconst textEditor = window.activeTextEditor;\r\n\t\tif (textEditor && textEditor.document.uri.toString() === uri) {\r\n\t\t\tif (textEditor.document.version !== documentVersion) {\r\n\t\t\t\twindow.showInformationMessage(l10n.t('CSS fix is outdated and can\\'t be applied to the document.'));\r\n\t\t\t}\r\n\t\t\ttextEditor.edit(mutator => {\r\n\t\t\t\tfor (const edit of edits) {\r\n\t\t\t\t\tmutator.replace(client.protocol2CodeConverter.asRange(edit.range), edit.newText);\r\n\t\t\t\t}\r\n\t\t\t}).then(success => {\r\n\t\t\t\tif (!success) {\r\n\t\t\t\t\twindow.showErrorMessage(l10n.t('Failed to apply CSS fix to the document. Please consider opening an issue with steps to reproduce.'));\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\tfunction updateFormatterRegistration(registration: FormatterRegistration) {\r\n\t\tconst formatEnabled = workspace.getConfiguration().get(registration.settingId);\r\n\t\tif (!formatEnabled && registration.provider) {\r\n\t\t\tregistration.provider.dispose();\r\n\t\t\tregistration.provider = undefined;\r\n\t\t} else if (formatEnabled && !registration.provider) {\r\n\t\t\tregistration.provider = languages.registerDocumentRangeFormattingEditProvider(registration.languageId, {\r\n\t\t\t\tprovideDocumentRangeFormattingEdits(document: TextDocument, range: Range, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]> {\r\n\t\t\t\t\tconst filesConfig = workspace.getConfiguration('files', document);\r\n\r\n\t\t\t\t\tconst fileFormattingOptions = {\r\n\t\t\t\t\t\ttrimTrailingWhitespace: filesConfig.get<boolean>('trimTrailingWhitespace'),\r\n\t\t\t\t\t\ttrimFinalNewlines: filesConfig.get<boolean>('trimFinalNewlines'),\r\n\t\t\t\t\t\tinsertFinalNewline: filesConfig.get<boolean>('insertFinalNewline'),\r\n\t\t\t\t\t};\r\n\t\t\t\t\tconst params: DocumentRangeFormattingParams = {\r\n\t\t\t\t\t\ttextDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document),\r\n\t\t\t\t\t\trange: client.code2ProtocolConverter.asRange(range),\r\n\t\t\t\t\t\toptions: client.code2ProtocolConverter.asFormattingOptions(options, fileFormattingOptions)\r\n\t\t\t\t\t};\r\n\t\t\t\t\t// add the css formatter options from the settings\r\n\t\t\t\t\tconst formatterSettings = workspace.getConfiguration(registration.languageId, document).get<CSSFormatSettings>('format');\r\n\t\t\t\t\tif (formatterSettings) {\r\n\t\t\t\t\t\tfor (const key of cssFormatSettingKeys) {\r\n\t\t\t\t\t\t\tconst val = formatterSettings[key];\r\n\t\t\t\t\t\t\tif (val !== undefined && val !== null) {\r\n\t\t\t\t\t\t\t\tparams.options[key] = val;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn client.sendRequest(DocumentRangeFormattingRequest.type, params, token).then(\r\n\t\t\t\t\t\tclient.protocol2CodeConverter.asTextEdits,\r\n\t\t\t\t\t\t(error) => {\r\n\t\t\t\t\t\t\tclient.handleFailedRequest(DocumentRangeFormattingRequest.type, undefined, error, []);\r\n\t\t\t\t\t\t\treturn Promise.resolve([]);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t);\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\treturn client;\r\n}\r\n"
}
```