'use strict' ; import * as path from 'path' ; import { Middleware } from 'vscode-languageclient' ; import { ClientCollection } from './clientCollection' ; import { Client } from './client' ; import * as vscode from 'vscode' ; import { CppSettings , OtherSettings } from './settings' ; import { onDidChangeActiveTextEditor , processDelayedDidOpen } from './extension' ; export function createProtocolFilter ( clients ) { const defaultHandler = ( data , callback ) => { clients . ActiveClient . notifyWhenLanguageClientReady ( ( ) => callback ( data ) ) ; } ; const invoke2 = ( a , b , callback ) => clients . ActiveClient . requestWhenReady < any > ( ( ) => callback ( a , b ) ) ; const invoke3 = ( a , b , c , callback ) => clients . ActiveClient . requestWhenReady < any > ( ( ) => callback ( a , b , c ) ) ; const invoke4 = ( a , b , c , d , callback ) => clients . ActiveClient . requestWhenReady < any > ( ( ) => callback ( a , b , c , d ) ) ; const invoke5 = ( a , b , c , d , e , callback ) => clients . ActiveClient . requestWhenReady < any > ( ( ) => callback ( a , b , c , d , e ) ) ; return { didOpen : ( document , sendMessage ) => { const editor = vscode . window . visibleTextEditors . find ( e => e . document === document ) ; if ( editor ) { const me = clients . getClientFor ( document . uri ) ; if ( ! me . TrackedDocuments . has ( document ) ) { clients . timeTelemetryCollector . setDidOpenTime ( document . uri ) ; if ( clients . checkOwnership ( me , document ) ) { me . TrackedDocuments . add ( document ) ; const finishDidOpen = ( doc ) => { me . provideCustomConfiguration ( doc . uri , undefined ) ; me . notifyWhenLanguageClientReady ( ( ) => { sendMessage ( doc ) ; me . onDidOpenTextDocument ( doc ) ; if ( editor && editor === vscode . window . activeTextEditor ) { onDidChangeActiveTextEditor ( editor ) ; } } ) ; } ; let languageChanged = false ; if ( ( document . uri . path . endsWith ( ".C" ) || document . uri . path . endsWith ( ".H" ) ) && document . languageId === "c" ) { const cppSettings = new CppSettings ( ) ; if ( cppSettings . autoAddFileAssociations ) { const fileName = path . basename ( document . uri . fsPath ) ; const mappingString = fileName + "@" + document . uri . fsPath ; me . addFileAssociations ( mappingString , "cpp" ) ; me . sendDidChangeSettings ( { files : { associations : new OtherSettings ( ) . filesAssociations } } ) ; vscode . languages . setTextDocumentLanguage ( document , "cpp" ) . then ( ( newDoc ) => { finishDidOpen ( newDoc ) ; } ) ; languageChanged = true ; } } if ( ! languageChanged ) { finishDidOpen ( document ) ; } } } } else { } } , didChange : ( textDocumentChangeEvent , sendMessage ) => { const me = clients . getClientFor ( textDocumentChangeEvent . document . uri ) ; if ( ! me . TrackedDocuments . has ( textDocumentChangeEvent . document ) ) { processDelayedDidOpen ( textDocumentChangeEvent . document ) ; } me . onDidChangeTextDocument ( textDocumentChangeEvent ) ; me . notifyWhenLanguageClientReady ( ( ) => sendMessage ( textDocumentChangeEvent ) ) ; } , willSave : defaultHandler , willSaveWaitUntil : ( event , sendMessage ) => { const me = clients . getClientFor ( event . document . uri ) ; if ( me . TrackedDocuments . has ( event . document ) ) { return sendMessage ( event ) ; } return Promise . resolve ( [ ] ) ; } , didSave : defaultHandler , didClose : ( document , sendMessage ) => { const me = clients . getClientFor ( document . uri ) ; if ( me . TrackedDocuments . has ( document ) ) { me . onDidCloseTextDocument ( document ) ; me . TrackedDocuments . delete ( document ) ; me . notifyWhenLanguageClientReady ( ( ) => sendMessage ( document ) ) ; } } , provideCompletionItem : invoke4 , resolveCompletionItem : invoke2 , provideHover : ( document , position , token , next ) => { const me = clients . getClientFor ( document . uri ) ; if ( clients . checkOwnership ( me , document ) ) { return clients . ActiveClient . requestWhenReady ( ( ) => next ( document , position , token ) ) ; } return null ; } , provideSignatureHelp : invoke3 , provideDefinition : invoke3 , provideReferences : invoke4 , provideDocumentHighlights : invoke3 , provideDocumentSymbols : invoke2 , provideWorkspaceSymbols : invoke2 , provideCodeActions : invoke4 , provideCodeLenses : invoke2 , resolveCodeLens : invoke2 , provideDocumentFormattingEdits : invoke3 , provideDocumentRangeFormattingEdits : invoke4 , provideOnTypeFormattingEdits : invoke5 , provideRenameEdits : invoke4 , provideDocumentLinks : invoke2 , resolveDocumentLink : invoke2 , provideDeclaration : invoke3 } ; }