import { QueryValidationFeature , RequestTypes } from '@salesforce/soql-language-server' ; import { LanguageClient } from 'vscode-languageclient' ; import { QueryRunner } from '../editor/queryRunner' ; import { withSFConnection } from '../sfdx' ; import { workspace } from 'vscode' ; import { SOQL_CONFIGURATION_NAME , SOQL_VALIDATION_CONFIG } from '../constants' ; export function init ( client ) { client . registerFeature ( new QueryValidationFeature ( ) ) ; return client ; } const emptyQueryResults = { done : true , totalSize : 0 , records : [ ] } ; export function afterStart ( client ) { client . onRequest ( RequestTypes . RunQuery , async ( queryText ) => { const enabled = workspace . getConfiguration ( SOQL_CONFIGURATION_NAME ) . get < boolean > ( SOQL_VALIDATION_CONFIG ) ; try { return enabled ? await withSFConnection ( async ( conn ) => { const queryData = await new QueryRunner ( conn ) . runQuery ( queryText , { showErrors : false } ) ; return { result : queryData } ; } ) : emptyQueryResults ; } catch ( e ) { return { error : { name : e . name , errorCode : e . errorCode , message : e . message } } ; } } ) ; return client ; }