Skip to content

Commit f63ce90

Browse files
committed
Adding STS initialization logging
1 parent 2bfe915 commit f63ce90

2 files changed

Lines changed: 72 additions & 63 deletions

File tree

extensions/mssql/src/languageservice/serverStatus.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import * as Constants from "../constants/constants";
1212
*/
1313
export class ServerInitializationResult {
1414
public constructor(
15-
public installedBeforeInitializing: Boolean = false,
16-
public isRunning: Boolean = false,
15+
public installedBeforeInitializing: boolean = false,
16+
public isRunning: boolean = false,
1717
public serverPath: string = undefined,
1818
) {}
1919

@@ -25,7 +25,7 @@ export class ServerInitializationResult {
2525
);
2626
}
2727

28-
public withRunning(isRunning: Boolean): ServerInitializationResult {
28+
public withRunning(isRunning: boolean): ServerInitializationResult {
2929
return new ServerInitializationResult(
3030
this.installedBeforeInitializing,
3131
isRunning,

extensions/mssql/src/languageservice/serviceclient.ts

Lines changed: 69 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { ServerInitializationResult, ServerStatusView } from "./serverStatus";
3030
import StatusView from "../views/statusView";
3131
import * as LanguageServiceContracts from "../models/contracts/languageService";
3232
import { DownloadType, IConfigUtils } from "./interfaces";
33-
import { exists } from "../utils/utils";
33+
import { exists, getErrorMessage } from "../utils/utils";
3434
import { env } from "process";
3535
import {
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

Comments
 (0)