@@ -30,7 +30,7 @@ import { ServerInitializationResult, ServerStatusView } from "./serverStatus";
3030import StatusView from "../views/statusView" ;
3131import * as LanguageServiceContracts from "../models/contracts/languageService" ;
3232import { DownloadType , IConfigUtils } from "./interfaces" ;
33- import { exists } from "../utils/utils" ;
33+ import { exists , getErrorMessage } from "../utils/utils" ;
3434import { env } from "process" ;
3535import {
3636 getAppDataPath ,
@@ -193,75 +193,84 @@ export default class SqlToolsServiceClient {
193193
194194 // initialize the SQL Tools Service Client instance by launching
195195 // out-of-proc server through the LanguageClient
196- public initialize ( context : vscode . ExtensionContext ) : Promise < ServerInitializationResult > {
196+ public async initialize ( context : vscode . ExtensionContext ) : Promise < ServerInitializationResult > {
197197 this . _logger . appendLine ( Constants . serviceInitializing ) ;
198198 this . _logPath = context . logUri . fsPath ;
199- return PlatformInformation . getCurrent ( ) . then ( ( platformInfo ) => {
200- return this . initializeForPlatform ( platformInfo , context ) ;
201- } ) ;
199+ const platformInfo = await PlatformInformation . getCurrent ( ) ;
200+
201+ const result = await this . initializeForPlatform ( platformInfo , context ) ;
202+ this . _logger . appendLine (
203+ `Service ${ result . installedBeforeInitializing ? "downloaded and " : "" } ${ result . isRunning ? "started" : "failed to start" } at ${ result . serverPath } ` ,
204+ ) ;
205+
206+ return result ;
202207 }
203208
204- public initializeForPlatform (
209+ public async initializeForPlatform (
205210 platformInfo : PlatformInformation ,
206211 context : vscode . ExtensionContext ,
207212 ) : Promise < ServerInitializationResult > {
208- return new Promise < ServerInitializationResult > ( ( resolve , reject ) => {
209- this . _logger . appendLine ( Constants . commandsNotAvailableWhileInstallingTheService ) ;
213+ this . _logger . appendLine ( Constants . commandsNotAvailableWhileInstallingTheService ) ;
214+ this . _logger . appendLine ( ) ;
215+ this . _logger . append ( `Platform: ${ platformInfo . toString ( ) } ` ) ;
216+ if ( ! platformInfo . isValidRuntime ) {
217+ Utils . showErrorMsg ( Constants . unsupportedPlatformErrorMessage ) ;
218+ throw new Error ( "Invalid Platform" ) ;
219+ }
220+
221+ if ( platformInfo . runtimeId ) {
222+ this . _logger . appendLine ( ` (${ platformInfo . getRuntimeDisplayName ( ) } )` ) ;
223+ } else {
210224 this . _logger . appendLine ( ) ;
211- this . _logger . append ( `Platform: ${ platformInfo . toString ( ) } ` ) ;
212- if ( ! platformInfo . isValidRuntime ) {
213- Utils . showErrorMsg ( Constants . unsupportedPlatformErrorMessage ) ;
214- reject ( "Invalid Platform" ) ;
215- } else {
216- if ( platformInfo . runtimeId ) {
217- this . _logger . appendLine ( ` (${ platformInfo . getRuntimeDisplayName ( ) } )` ) ;
218- } else {
219- this . _logger . appendLine ( ) ;
225+ }
226+ this . _logger . appendLine ( ) ;
227+
228+ // For macOS we need to ensure the tools service version is set appropriately
229+ this . updateServiceVersion ( platformInfo ) ;
230+
231+ try {
232+ const serverPath = await this . _server . getServerPath ( platformInfo . runtimeId ) ;
233+ if ( serverPath === undefined ) {
234+ // Check if the service already installed and if not open the output channel to show the logs
235+ if ( this . _vscodeWrapper !== undefined ) {
236+ this . _vscodeWrapper . outputChannel . show ( ) ;
220237 }
221- this . _logger . appendLine ( ) ;
222-
223- // For macOS we need to ensure the tools service version is set appropriately
224- this . updateServiceVersion ( platformInfo ) ;
225-
226- this . _server
227- . getServerPath ( platformInfo . runtimeId )
228- . then ( async ( serverPath ) => {
229- if ( serverPath === undefined ) {
230- // Check if the service already installed and if not open the output channel to show the logs
231- if ( this . _vscodeWrapper !== undefined ) {
232- this . _vscodeWrapper . outputChannel . show ( ) ;
233- }
234- let installedServerPath = await this . _server . downloadServerFiles (
235- platformInfo . runtimeId ,
236- ) ;
237- this . _sqlToolsServicePath = path . dirname ( installedServerPath ) ;
238- await this . initializeLanguageClient (
239- installedServerPath ,
240- context ,
241- platformInfo . isWindows ,
242- ) ;
243- await this . _client . onReady ( ) ;
244- resolve (
245- new ServerInitializationResult ( true , true , installedServerPath ) ,
246- ) ;
247- } else {
248- this . _sqlToolsServicePath = path . dirname ( serverPath ) ;
249- await this . initializeLanguageClient (
250- serverPath ,
251- context ,
252- platformInfo . isWindows ,
253- ) ;
254- await this . _client . onReady ( ) ;
255- resolve ( new ServerInitializationResult ( false , true , serverPath ) ) ;
256- }
257- } )
258- . catch ( ( err ) => {
259- this . logger . logDebug ( Constants . serviceLoadingFailed + " " + err ) ;
260- Utils . showErrorMsg ( Constants . serviceLoadingFailed ) ;
261- reject ( err ) ;
262- } ) ;
238+
239+ const installedServerPath = await this . _server . downloadServerFiles (
240+ platformInfo . runtimeId ,
241+ ) ;
242+ this . _sqlToolsServicePath = path . dirname ( installedServerPath ) ;
243+
244+ await this . initializeLanguageClient (
245+ installedServerPath ,
246+ context ,
247+ platformInfo . isWindows ,
248+ ) ;
249+
250+ await this . _client . onReady ( ) ;
251+
252+ return new ServerInitializationResult (
253+ true , // installedBeforeInitializing
254+ true , // isRunning
255+ installedServerPath ,
256+ ) ;
257+ } else {
258+ this . _sqlToolsServicePath = path . dirname ( serverPath ) ;
259+
260+ await this . initializeLanguageClient ( serverPath , context , platformInfo . isWindows ) ;
261+ await this . _client . onReady ( ) ;
262+
263+ return new ServerInitializationResult (
264+ false , // installedBeforeInitializing
265+ true , // isRunning
266+ serverPath ,
267+ ) ;
263268 }
264- } ) ;
269+ } catch ( err ) {
270+ this . logger . logDebug ( Constants . serviceLoadingFailed + " " + getErrorMessage ( err ) ) ;
271+ Utils . showErrorMsg ( Constants . serviceLoadingFailed ) ;
272+ throw err ;
273+ }
265274 }
266275
267276 private updateServiceVersion ( platformInfo : PlatformInformation ) : void {
0 commit comments