import * as vscode from 'vscode' ; import { DefaultClient , FormatParams , FormatOnTypeRequest } from '../client' ; import { CppSettings , getEditorConfigSettings } from '../settings' ; export class OnTypeFormattingEditProvider implements vscode . OnTypeFormattingEditProvider { private client : DefaultClient ; constructor ( client ) { this . client = client ; } public async provideOnTypeFormattingEdits ( document , position , ch , options , token ) { await this . client . awaitUntilLanguageClientReady ( ) ; const filePath = document . uri . fsPath ; const settings = new CppSettings ( this . client . RootUri ) ; const useVcFormat = settings . useVcFormat ( document ) ; const configCallBack = async ( editorConfigSettings ) => { const params = { editorConfigSettings : { ... editorConfigSettings } , useVcFormat : useVcFormat , uri : document . uri . toString ( ) , insertSpaces : options . insertSpaces , tabSize : options . tabSize , character : ch , range : { start : { character : position . character , line : position . line } , end : { character : 0 , line : 0 } } } ; const textEdits = await this . client . languageClient . sendRequest ( FormatOnTypeRequest , params ) ; const result = [ ] ; textEdits . forEach ( ( textEdit ) => { result . push ( { range : new vscode . Range ( textEdit . range . start . line , textEdit . range . start . character , textEdit . range . end . line , textEdit . range . end . character ) , newText : textEdit . newText } ) ; } ) ; return result ; } ; if ( ! useVcFormat ) { if ( ch !== ';' ) { const result = [ ] ; return result ; } else { return configCallBack ( undefined ) ; } } else { const editorConfigSettings = getEditorConfigSettings ( filePath ) ; return configCallBack ( editorConfigSettings ) ; } } }