mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-06 09:35:41 -05:00
Extensions Cleanup (#359)
* clean up extensions * updated copyrights * formatting
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
import * as path from 'path';
|
||||
import {IConfig} from '../languageservice/interfaces';
|
||||
import * as SharedConstants from '../models/constants';
|
||||
import { IConfig } from '../languageservice/interfaces';
|
||||
import { Constants } from '../models/constants';
|
||||
|
||||
/*
|
||||
* Config class handles getting values from config.json.
|
||||
@@ -18,7 +18,7 @@ export default class Config implements IConfig {
|
||||
private _extensionConfigSectionName: string = undefined;
|
||||
private _fromBuild: boolean = undefined;
|
||||
|
||||
constructor(extensionConfigSectionName: string, fromBuild?: boolean) {
|
||||
constructor(extensionConfigSectionName: string, private path: string, fromBuild?: boolean) {
|
||||
this._extensionConfigSectionName = extensionConfigSectionName;
|
||||
this._fromBuild = fromBuild;
|
||||
}
|
||||
@@ -31,24 +31,24 @@ export default class Config implements IConfig {
|
||||
}
|
||||
|
||||
public getDownloadUrl(): string {
|
||||
return this.getConfigValue(SharedConstants.downloadUrlConfigKey);
|
||||
return this.getConfigValue(Constants.downloadUrlConfigKey);
|
||||
}
|
||||
|
||||
public getInstallDirectory(): string {
|
||||
return this.getConfigValue(SharedConstants.installDirConfigKey);
|
||||
return this.getConfigValue(Constants.installDirConfigKey);
|
||||
}
|
||||
|
||||
public getExecutableFiles(): string[] {
|
||||
return this.getConfigValue(SharedConstants.executableFilesConfigKey);
|
||||
return this.getConfigValue(Constants.executableFilesConfigKey);
|
||||
}
|
||||
|
||||
public getPackageVersion(): string {
|
||||
return this.getConfigValue(SharedConstants.versionConfigKey);
|
||||
return this.getConfigValue(Constants.versionConfigKey);
|
||||
}
|
||||
|
||||
public getConfigValue(configKey: string): any {
|
||||
let json = this.configJsonContent;
|
||||
let toolsConfig = json[SharedConstants.serviceConfigKey];
|
||||
let toolsConfig = json[Constants.serviceConfigKey];
|
||||
let configValue: string = undefined;
|
||||
if (toolsConfig !== undefined) {
|
||||
configValue = toolsConfig[configKey];
|
||||
@@ -82,7 +82,7 @@ export default class Config implements IConfig {
|
||||
configContent = fs.readFileSync(path.join(__dirname, remainingPath));
|
||||
}
|
||||
else {
|
||||
configContent = fs.readFileSync(path.join(__dirname, '../../../../client/out/config.json'));
|
||||
configContent = fs.readFileSync(this.path);
|
||||
}
|
||||
return JSON.parse(configContent);
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import Config from './config';
|
||||
import Config from './config';
|
||||
import { workspace, WorkspaceConfiguration } from 'vscode';
|
||||
import {IConfig} from '../languageservice/interfaces';
|
||||
import * as Constants from '../models/constants';
|
||||
import { IConfig } from '../languageservice/interfaces';
|
||||
import { Constants } from '../models/constants';
|
||||
|
||||
/*
|
||||
* ExtConfig class handles getting values from workspace config or config.json.
|
||||
@@ -16,10 +16,11 @@ import * as Constants from '../models/constants';
|
||||
export default class ExtConfig implements IConfig {
|
||||
|
||||
constructor(private _extensionConfigSectionName: string, private _config?: IConfig,
|
||||
path?: string,
|
||||
private _extensionConfig?: WorkspaceConfiguration,
|
||||
private _workspaceConfig?: WorkspaceConfiguration) {
|
||||
if (this._config === undefined) {
|
||||
this._config = new Config(_extensionConfigSectionName);
|
||||
this._config = new Config(_extensionConfigSectionName, path);
|
||||
}
|
||||
if (this._extensionConfig === undefined) {
|
||||
this._extensionConfig = workspace.getConfiguration(_extensionConfigSectionName);
|
||||
|
||||
@@ -4,11 +4,9 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import vscode = require('vscode');
|
||||
import {IExtensionConstants} from '../models/contracts/contracts';
|
||||
import { IExtensionConstants } from '../models/contracts/contracts';
|
||||
|
||||
export import TextEditor = vscode.TextEditor;
|
||||
|
||||
export default class VscodeWrapper {
|
||||
export class VscodeWrapper {
|
||||
private _extensionConstants: IExtensionConstants;
|
||||
/**
|
||||
* Output channel for logging. Shared among all instances.
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import {IDecompressProvider, IPackage} from './interfaces';
|
||||
import {ILogger} from '../models/interfaces';
|
||||
import { IDecompressProvider, IPackage } from './interfaces';
|
||||
import { ILogger } from '../models/interfaces';
|
||||
const decompress = require('decompress');
|
||||
|
||||
export default class DecompressProvider implements IDecompressProvider {
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
import {IPackage, IStatusView, PackageError, IHttpClient} from './interfaces';
|
||||
import {ILogger} from '../models/interfaces';
|
||||
import {parse as parseUrl, Url} from 'url';
|
||||
import { IPackage, IStatusView, PackageError, IHttpClient } from './interfaces';
|
||||
import { ILogger } from '../models/interfaces';
|
||||
import { parse as parseUrl, Url } from 'url';
|
||||
import * as https from 'https';
|
||||
import * as http from 'http';
|
||||
import {getProxyAgent} from './proxy';
|
||||
import { getProxyAgent } from './proxy';
|
||||
|
||||
let fs = require('fs');
|
||||
const fs = require('fs');
|
||||
|
||||
/*
|
||||
* Http client class to handle downloading files using http or https urls
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as tmp from 'tmp';
|
||||
import {ILogger} from '../models/interfaces';
|
||||
import { ILogger } from '../models/interfaces';
|
||||
|
||||
export interface IStatusView {
|
||||
installingService(): void;
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
'use strict';
|
||||
|
||||
import { Url, parse as parseUrl } from 'url';
|
||||
let HttpProxyAgent = require('http-proxy-agent');
|
||||
let HttpsProxyAgent = require('https-proxy-agent');
|
||||
const HttpProxyAgent = require('http-proxy-agent');
|
||||
const HttpsProxyAgent = require('https-proxy-agent');
|
||||
|
||||
function getSystemProxyURL(requestURL: Url): string {
|
||||
if (requestURL.protocol === 'http:') {
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
'use strict';
|
||||
|
||||
import * as path from 'path';
|
||||
import {Runtime} from '../models/platform';
|
||||
import { Runtime } from '../models/platform';
|
||||
import ServiceDownloadProvider from './serviceDownloadProvider';
|
||||
import {IConfig, IStatusView} from './interfaces';
|
||||
let fs = require('fs-extra-promise');
|
||||
import { IConfig, IStatusView } from './interfaces';
|
||||
const fs = require('fs-extra-promise');
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import {IStatusView} from './interfaces';
|
||||
import { IStatusView } from './interfaces';
|
||||
import vscode = require('vscode');
|
||||
import {IExtensionConstants} from '../models/contracts/contracts';
|
||||
import * as Constants from '../models/constants';
|
||||
import { IExtensionConstants } from '../models/contracts/contracts';
|
||||
import { Constants } from '../models/constants';
|
||||
|
||||
/*
|
||||
* The status class which includes the service initialization result.
|
||||
|
||||
@@ -1,44 +1,42 @@
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
* ------------------------------------------------------------------------------------------ */
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { ExtensionContext, workspace, window, OutputChannel, languages } from 'vscode';
|
||||
import { LanguageClient, LanguageClientOptions, ServerOptions,
|
||||
TransportKind, RequestType, NotificationType, NotificationHandler,
|
||||
ErrorAction, CloseAction } from 'dataprotocol-client';
|
||||
import {
|
||||
LanguageClient, LanguageClientOptions, ServerOptions,
|
||||
TransportKind, RequestType, NotificationType, NotificationHandler,
|
||||
ErrorAction, CloseAction
|
||||
} from 'dataprotocol-client';
|
||||
|
||||
import VscodeWrapper from '../controllers/vscodeWrapper';
|
||||
import Telemetry from '../models/telemetry';
|
||||
import * as Utils from '../models/utils';
|
||||
import {VersionRequest, IExtensionConstants} from '../models/contracts/contracts';
|
||||
import {Logger} from '../models/logger';
|
||||
import Constants = require('../models/constants');
|
||||
import {ILanguageClientHelper} from '../models/contracts/languageService';
|
||||
import { VscodeWrapper } from '../controllers/vscodeWrapper';
|
||||
import { Telemetry } from '../models/telemetry';
|
||||
import { Utils } from '../models/utils';
|
||||
import { VersionRequest, IExtensionConstants } from '../models/contracts/contracts';
|
||||
import { Logger } from '../models/logger';
|
||||
import ServerProvider from './server';
|
||||
import ServiceDownloadProvider from './serviceDownloadProvider';
|
||||
import DecompressProvider from './decompressProvider';
|
||||
import HttpClient from './httpClient';
|
||||
import ExtConfig from '../configurations/extConfig';
|
||||
import {PlatformInformation, Runtime} from '../models/platform';
|
||||
import {ServerInitializationResult, ServerStatusView} from './serverStatus';
|
||||
import ExtConfig from '../configurations/extConfig';
|
||||
import { PlatformInformation, Runtime } from '../models/platform';
|
||||
import { ServerInitializationResult, ServerStatusView } from './serverStatus';
|
||||
import StatusView from '../views/statusView';
|
||||
import * as LanguageServiceContracts from '../models/contracts/languageService';
|
||||
import * as SharedConstants from '../models/constants';
|
||||
import * as utils from '../models/utils';
|
||||
var path = require('path');
|
||||
import { Constants } from '../models/constants';
|
||||
import ServiceStatus from './serviceStatus';
|
||||
|
||||
let opener = require('opener');
|
||||
const opener = require('opener');
|
||||
const path = require('path');
|
||||
let _channel: OutputChannel = undefined;
|
||||
const fs = require('fs-extra');
|
||||
|
||||
/**
|
||||
* @interface IMessage
|
||||
*/
|
||||
interface IMessage {
|
||||
jsonrpc: string;
|
||||
jsonrpc: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,446 +45,446 @@ interface IMessage {
|
||||
*/
|
||||
class LanguageClientErrorHandler {
|
||||
|
||||
private vscodeWrapper: VscodeWrapper;
|
||||
private vscodeWrapper: VscodeWrapper;
|
||||
|
||||
/**
|
||||
* Creates an instance of LanguageClientErrorHandler.
|
||||
* @memberOf LanguageClientErrorHandler
|
||||
*/
|
||||
constructor(constants: IExtensionConstants) {
|
||||
if (!this.vscodeWrapper) {
|
||||
this.vscodeWrapper = new VscodeWrapper(constants);
|
||||
}
|
||||
Telemetry.getRuntimeId = this.vscodeWrapper.constants.getRuntimeId;
|
||||
}
|
||||
/**
|
||||
* Creates an instance of LanguageClientErrorHandler.
|
||||
* @memberOf LanguageClientErrorHandler
|
||||
*/
|
||||
constructor(constants: IExtensionConstants) {
|
||||
if (!this.vscodeWrapper) {
|
||||
this.vscodeWrapper = new VscodeWrapper(constants);
|
||||
}
|
||||
Telemetry.getRuntimeId = this.vscodeWrapper.constants.getRuntimeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an error message prompt with a link to known issues wiki page
|
||||
* @memberOf LanguageClientErrorHandler
|
||||
*/
|
||||
showOnErrorPrompt(): void {
|
||||
let extensionConstants = this.vscodeWrapper.constants;
|
||||
Telemetry.sendTelemetryEvent(extensionConstants.serviceName + 'Crash');
|
||||
this.vscodeWrapper.showErrorMessage(
|
||||
extensionConstants.serviceCrashMessage,
|
||||
SharedConstants.serviceCrashButton).then(action => {
|
||||
if (action && action === SharedConstants.serviceCrashButton) {
|
||||
opener(extensionConstants.serviceCrashLink);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Show an error message prompt with a link to known issues wiki page
|
||||
* @memberOf LanguageClientErrorHandler
|
||||
*/
|
||||
showOnErrorPrompt(): void {
|
||||
let extensionConstants = this.vscodeWrapper.constants;
|
||||
Telemetry.sendTelemetryEvent(extensionConstants.serviceName + 'Crash');
|
||||
this.vscodeWrapper.showErrorMessage(
|
||||
extensionConstants.serviceCrashMessage,
|
||||
Constants.serviceCrashButton).then(action => {
|
||||
if (action && action === Constants.serviceCrashButton) {
|
||||
opener(extensionConstants.serviceCrashLink);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for language service client error
|
||||
*
|
||||
* @param {Error} error
|
||||
* @param {Message} message
|
||||
* @param {number} count
|
||||
* @returns {ErrorAction}
|
||||
*
|
||||
* @memberOf LanguageClientErrorHandler
|
||||
*/
|
||||
error(error: Error, message: IMessage, count: number): ErrorAction {
|
||||
this.showOnErrorPrompt();
|
||||
/**
|
||||
* Callback for language service client error
|
||||
*
|
||||
* @param {Error} error
|
||||
* @param {Message} message
|
||||
* @param {number} count
|
||||
* @returns {ErrorAction}
|
||||
*
|
||||
* @memberOf LanguageClientErrorHandler
|
||||
*/
|
||||
error(error: Error, message: IMessage, count: number): ErrorAction {
|
||||
this.showOnErrorPrompt();
|
||||
|
||||
// we don't retry running the service since crashes leave the extension
|
||||
// in a bad, unrecovered state
|
||||
return ErrorAction.Shutdown;
|
||||
}
|
||||
// we don't retry running the service since crashes leave the extension
|
||||
// in a bad, unrecovered state
|
||||
return ErrorAction.Shutdown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for language service client closed
|
||||
*
|
||||
* @returns {CloseAction}
|
||||
*
|
||||
* @memberOf LanguageClientErrorHandler
|
||||
*/
|
||||
closed(): CloseAction {
|
||||
this.showOnErrorPrompt();
|
||||
/**
|
||||
* Callback for language service client closed
|
||||
*
|
||||
* @returns {CloseAction}
|
||||
*
|
||||
* @memberOf LanguageClientErrorHandler
|
||||
*/
|
||||
closed(): CloseAction {
|
||||
this.showOnErrorPrompt();
|
||||
|
||||
// we don't retry running the service since crashes leave the extension
|
||||
// in a bad, unrecovered state
|
||||
return CloseAction.DoNotRestart;
|
||||
}
|
||||
// we don't retry running the service since crashes leave the extension
|
||||
// in a bad, unrecovered state
|
||||
return CloseAction.DoNotRestart;
|
||||
}
|
||||
}
|
||||
|
||||
// The Service Client class handles communication with the VS Code LanguageClient
|
||||
export default class SqlToolsServiceClient {
|
||||
// singleton instance
|
||||
private static _instance: SqlToolsServiceClient = undefined;
|
||||
export class SqlToolsServiceClient {
|
||||
// singleton instance
|
||||
private static _instance: SqlToolsServiceClient = undefined;
|
||||
|
||||
private static _constants: IExtensionConstants = undefined;
|
||||
private static _constants: IExtensionConstants = undefined;
|
||||
|
||||
public static get constants(): IExtensionConstants {
|
||||
return this._constants;
|
||||
}
|
||||
public static get constants(): IExtensionConstants {
|
||||
return this._constants;
|
||||
}
|
||||
|
||||
public static set constants(constantsObject: IExtensionConstants) {
|
||||
this._constants = constantsObject;
|
||||
Telemetry.getRuntimeId = this._constants.getRuntimeId;
|
||||
}
|
||||
public static set constants(constantsObject: IExtensionConstants) {
|
||||
this._constants = constantsObject;
|
||||
Telemetry.getRuntimeId = this._constants.getRuntimeId;
|
||||
}
|
||||
|
||||
private static _helper: ILanguageClientHelper = undefined;
|
||||
private static _helper: LanguageServiceContracts.ILanguageClientHelper = undefined;
|
||||
|
||||
public static get helper(): ILanguageClientHelper {
|
||||
return this._helper;
|
||||
}
|
||||
public static get helper(): LanguageServiceContracts.ILanguageClientHelper {
|
||||
return this._helper;
|
||||
}
|
||||
|
||||
public static set helper(helperObject: ILanguageClientHelper) {
|
||||
this._helper = helperObject;
|
||||
}
|
||||
public static set helper(helperObject: LanguageServiceContracts.ILanguageClientHelper) {
|
||||
this._helper = helperObject;
|
||||
}
|
||||
|
||||
// VS Code Language Client
|
||||
private _client: LanguageClient = undefined;
|
||||
// VS Code Language Client
|
||||
private _client: LanguageClient = undefined;
|
||||
|
||||
// getter method for the Language Client
|
||||
private get client(): LanguageClient {
|
||||
return this._client;
|
||||
}
|
||||
// getter method for the Language Client
|
||||
private get client(): LanguageClient {
|
||||
return this._client;
|
||||
}
|
||||
|
||||
private set client(client: LanguageClient) {
|
||||
this._client = client;
|
||||
}
|
||||
private set client(client: LanguageClient) {
|
||||
this._client = client;
|
||||
}
|
||||
|
||||
public installDirectory: string;
|
||||
private _downloadProvider: ServiceDownloadProvider;
|
||||
private _vscodeWrapper: VscodeWrapper;
|
||||
public installDirectory: string;
|
||||
private _downloadProvider: ServiceDownloadProvider;
|
||||
private _vscodeWrapper: VscodeWrapper;
|
||||
|
||||
private _serviceStatus: ServiceStatus;
|
||||
private _serviceStatus: ServiceStatus;
|
||||
|
||||
private _languageClientStartTime: number = undefined;
|
||||
private _installationTime: number = undefined;
|
||||
private _languageClientStartTime: number = undefined;
|
||||
private _installationTime: number = undefined;
|
||||
|
||||
constructor(
|
||||
private _server: ServerProvider,
|
||||
private _logger: Logger,
|
||||
private _statusView: StatusView,
|
||||
private _config: ExtConfig) {
|
||||
this._downloadProvider = _server.downloadProvider;
|
||||
if (!this._vscodeWrapper) {
|
||||
this._vscodeWrapper = new VscodeWrapper(SqlToolsServiceClient.constants);
|
||||
}
|
||||
this._serviceStatus = new ServiceStatus(SqlToolsServiceClient._constants.serviceName);
|
||||
}
|
||||
constructor(
|
||||
private _server: ServerProvider,
|
||||
private _logger: Logger,
|
||||
private _statusView: StatusView,
|
||||
private _config: ExtConfig) {
|
||||
this._downloadProvider = _server.downloadProvider;
|
||||
if (!this._vscodeWrapper) {
|
||||
this._vscodeWrapper = new VscodeWrapper(SqlToolsServiceClient.constants);
|
||||
}
|
||||
this._serviceStatus = new ServiceStatus(SqlToolsServiceClient._constants.serviceName);
|
||||
}
|
||||
|
||||
// gets or creates the singleton service client instance
|
||||
public static get instance(): SqlToolsServiceClient {
|
||||
if (this._instance === undefined) {
|
||||
let constants = this._constants;
|
||||
let config = new ExtConfig(constants.extensionConfigSectionName);
|
||||
_channel = window.createOutputChannel(constants.serviceInitializingOutputChannelName);
|
||||
let logger = new Logger(text => _channel.append(text), constants);
|
||||
let serverStatusView = new ServerStatusView(constants);
|
||||
let httpClient = new HttpClient();
|
||||
let decompressProvider = new DecompressProvider();
|
||||
let downloadProvider = new ServiceDownloadProvider(config, logger, serverStatusView, httpClient,
|
||||
decompressProvider, constants, false);
|
||||
let serviceProvider = new ServerProvider(downloadProvider, config, serverStatusView, constants.extensionConfigSectionName);
|
||||
let statusView = new StatusView();
|
||||
this._instance = new SqlToolsServiceClient(serviceProvider, logger, statusView, config);
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
// gets or creates the singleton service client instance
|
||||
public static getInstance(path: string): SqlToolsServiceClient {
|
||||
if (this._instance === undefined) {
|
||||
let constants = this._constants;
|
||||
let config = new ExtConfig(constants.extensionConfigSectionName, undefined, path);
|
||||
_channel = window.createOutputChannel(constants.serviceInitializingOutputChannelName);
|
||||
let logger = new Logger(text => _channel.append(text), constants);
|
||||
let serverStatusView = new ServerStatusView(constants);
|
||||
let httpClient = new HttpClient();
|
||||
let decompressProvider = new DecompressProvider();
|
||||
let downloadProvider = new ServiceDownloadProvider(config, logger, serverStatusView, httpClient,
|
||||
decompressProvider, constants, false);
|
||||
let serviceProvider = new ServerProvider(downloadProvider, config, serverStatusView, constants.extensionConfigSectionName);
|
||||
let statusView = new StatusView();
|
||||
this._instance = new SqlToolsServiceClient(serviceProvider, logger, statusView, config);
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
|
||||
// initialize the Service Client instance by launching
|
||||
// out-of-proc server through the LanguageClient
|
||||
public initialize(context: ExtensionContext): Promise<any> {
|
||||
this._logger.appendLine(SqlToolsServiceClient._constants.serviceInitializing);
|
||||
this._languageClientStartTime = Date.now();
|
||||
return PlatformInformation.getCurrent(SqlToolsServiceClient._constants.getRuntimeId, SqlToolsServiceClient._constants.extensionName).then(platformInfo => {
|
||||
return this.initializeForPlatform(platformInfo, context);
|
||||
}).catch(err => {
|
||||
this._vscodeWrapper.showErrorMessage(err)
|
||||
});
|
||||
}
|
||||
// initialize the Service Client instance by launching
|
||||
// out-of-proc server through the LanguageClient
|
||||
public initialize(context: ExtensionContext): Promise<any> {
|
||||
this._logger.appendLine(SqlToolsServiceClient._constants.serviceInitializing);
|
||||
this._languageClientStartTime = Date.now();
|
||||
return PlatformInformation.getCurrent(SqlToolsServiceClient._constants.getRuntimeId, SqlToolsServiceClient._constants.extensionName).then(platformInfo => {
|
||||
return this.initializeForPlatform(platformInfo, context);
|
||||
}).catch(err => {
|
||||
this._vscodeWrapper.showErrorMessage(err);
|
||||
});
|
||||
}
|
||||
|
||||
public initializeForPlatform(platformInfo: PlatformInformation, context: ExtensionContext): Promise<ServerInitializationResult> {
|
||||
return new Promise<ServerInitializationResult>( (resolve, reject) => {
|
||||
this._logger.appendLine(SqlToolsServiceClient._constants.commandsNotAvailableWhileInstallingTheService);
|
||||
this._logger.appendLine();
|
||||
this._logger.append(`Platform: ${platformInfo.toString()}`);
|
||||
public initializeForPlatform(platformInfo: PlatformInformation, context: ExtensionContext): Promise<ServerInitializationResult> {
|
||||
return new Promise<ServerInitializationResult>((resolve, reject) => {
|
||||
this._logger.appendLine(SqlToolsServiceClient._constants.commandsNotAvailableWhileInstallingTheService);
|
||||
this._logger.appendLine();
|
||||
this._logger.append(`Platform: ${platformInfo.toString()}`);
|
||||
|
||||
if (!platformInfo.isValidRuntime()) {
|
||||
// if it's an unknown Linux distro then try generic Linux x64 and give a warning to the user
|
||||
if (platformInfo.isLinux()) {
|
||||
this._logger.appendLine(Constants.usingDefaultPlatformMessage);
|
||||
platformInfo.runtimeId = Runtime.Linux_64;
|
||||
}
|
||||
if (!platformInfo.isValidRuntime()) {
|
||||
// if it's an unknown Linux distro then try generic Linux x64 and give a warning to the user
|
||||
if (platformInfo.isLinux()) {
|
||||
this._logger.appendLine(Constants.usingDefaultPlatformMessage);
|
||||
platformInfo.runtimeId = Runtime.Linux_64;
|
||||
}
|
||||
|
||||
let ignoreWarning: boolean = this._config.getWorkspaceConfig(Constants.ignorePlatformWarning, false);
|
||||
if (!ignoreWarning) {
|
||||
this._vscodeWrapper.showErrorMessage(
|
||||
Constants.unsupportedPlatformErrorMessage,
|
||||
Constants.neverShowAgain)
|
||||
.then(action => {
|
||||
if (action === Constants.neverShowAgain) {
|
||||
this._config.updateWorkspaceConfig(Constants.ignorePlatformWarning, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
let ignoreWarning: boolean = this._config.getWorkspaceConfig(Constants.ignorePlatformWarning, false);
|
||||
if (!ignoreWarning) {
|
||||
this._vscodeWrapper.showErrorMessage(
|
||||
Constants.unsupportedPlatformErrorMessage,
|
||||
Constants.neverShowAgain)
|
||||
.then(action => {
|
||||
if (action === Constants.neverShowAgain) {
|
||||
this._config.updateWorkspaceConfig(Constants.ignorePlatformWarning, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Telemetry.sendTelemetryEvent('UnsupportedPlatform', {platform: platformInfo.toString()} );
|
||||
}
|
||||
Telemetry.sendTelemetryEvent('UnsupportedPlatform', { platform: platformInfo.toString() });
|
||||
}
|
||||
|
||||
if (platformInfo.runtimeId) {
|
||||
this._logger.appendLine(` (${platformInfo.getRuntimeDisplayName()})`);
|
||||
} else {
|
||||
this._logger.appendLine();
|
||||
}
|
||||
if (platformInfo.runtimeId) {
|
||||
this._logger.appendLine(` (${platformInfo.getRuntimeDisplayName()})`);
|
||||
} else {
|
||||
this._logger.appendLine();
|
||||
}
|
||||
|
||||
this._logger.appendLine();
|
||||
this._server.getServerPath(platformInfo.runtimeId).then(serverPath => {
|
||||
if (serverPath === undefined) {
|
||||
// Check if the service already installed and if not open the output channel to show the logs
|
||||
if (_channel !== undefined) {
|
||||
_channel.show();
|
||||
}
|
||||
let installationStartTime = Date.now();
|
||||
this._server.downloadServerFiles(platformInfo.runtimeId).then ( installedServerPath => {
|
||||
this._installationTime = Date.now() - installationStartTime;
|
||||
this.initializeLanguageClient(installedServerPath, context, platformInfo.runtimeId);
|
||||
resolve(new ServerInitializationResult(true, true, installedServerPath));
|
||||
}).catch(downloadErr => {
|
||||
reject(downloadErr);
|
||||
});
|
||||
} else {
|
||||
this.initializeLanguageClient(serverPath, context, platformInfo.runtimeId);
|
||||
resolve(new ServerInitializationResult(false, true, serverPath));
|
||||
}
|
||||
}).catch(err => {
|
||||
Utils.logDebug(SqlToolsServiceClient._constants.serviceLoadingFailed + ' ' + err, SqlToolsServiceClient._constants.extensionConfigSectionName);
|
||||
Utils.showErrorMsg(SqlToolsServiceClient._constants.serviceLoadingFailed, SqlToolsServiceClient._constants.extensionName);
|
||||
Telemetry.sendTelemetryEvent('ServiceInitializingFailed');
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
this._logger.appendLine();
|
||||
this._server.getServerPath(platformInfo.runtimeId).then(serverPath => {
|
||||
if (serverPath === undefined) {
|
||||
// Check if the service already installed and if not open the output channel to show the logs
|
||||
if (_channel !== undefined) {
|
||||
_channel.show();
|
||||
}
|
||||
let installationStartTime = Date.now();
|
||||
this._server.downloadServerFiles(platformInfo.runtimeId).then(installedServerPath => {
|
||||
this._installationTime = Date.now() - installationStartTime;
|
||||
this.initializeLanguageClient(installedServerPath, context, platformInfo.runtimeId);
|
||||
resolve(new ServerInitializationResult(true, true, installedServerPath));
|
||||
}).catch(downloadErr => {
|
||||
reject(downloadErr);
|
||||
});
|
||||
} else {
|
||||
this.initializeLanguageClient(serverPath, context, platformInfo.runtimeId);
|
||||
resolve(new ServerInitializationResult(false, true, serverPath));
|
||||
}
|
||||
}).catch(err => {
|
||||
Utils.logDebug(SqlToolsServiceClient._constants.serviceLoadingFailed + ' ' + err, SqlToolsServiceClient._constants.extensionConfigSectionName);
|
||||
Utils.showErrorMsg(SqlToolsServiceClient._constants.serviceLoadingFailed, SqlToolsServiceClient._constants.extensionName);
|
||||
Telemetry.sendTelemetryEvent('ServiceInitializingFailed');
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the SQL language configuration
|
||||
*
|
||||
* @memberOf SqlToolsServiceClient
|
||||
*/
|
||||
private initializeLanguageConfiguration(): void {
|
||||
languages.setLanguageConfiguration('sql', {
|
||||
comments: {
|
||||
lineComment: '--',
|
||||
blockComment: ['/*', '*/']
|
||||
},
|
||||
/**
|
||||
* Initializes the SQL language configuration
|
||||
*
|
||||
* @memberOf SqlToolsServiceClient
|
||||
*/
|
||||
private initializeLanguageConfiguration(): void {
|
||||
languages.setLanguageConfiguration('sql', {
|
||||
comments: {
|
||||
lineComment: '--',
|
||||
blockComment: ['/*', '*/']
|
||||
},
|
||||
|
||||
brackets: [
|
||||
['{', '}'],
|
||||
['[', ']'],
|
||||
['(', ')']
|
||||
],
|
||||
brackets: [
|
||||
['{', '}'],
|
||||
['[', ']'],
|
||||
['(', ')']
|
||||
],
|
||||
|
||||
__characterPairSupport: {
|
||||
autoClosingPairs: [
|
||||
{ open: '{', close: '}' },
|
||||
{ open: '[', close: ']' },
|
||||
{ open: '(', close: ')' },
|
||||
{ open: '"', close: '"', notIn: ['string'] },
|
||||
{ open: '\'', close: '\'', notIn: ['string', 'comment'] }
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
__characterPairSupport: {
|
||||
autoClosingPairs: [
|
||||
{ open: '{', close: '}' },
|
||||
{ open: '[', close: ']' },
|
||||
{ open: '(', close: ')' },
|
||||
{ open: '"', close: '"', notIn: ['string'] },
|
||||
{ open: '\'', close: '\'', notIn: ['string', 'comment'] }
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private initializeLanguageClient(serverPath: string, context: ExtensionContext, runtimeId: Runtime): void {
|
||||
if (serverPath === undefined) {
|
||||
Utils.logDebug(SqlToolsServiceClient._constants.invalidServiceFilePath, SqlToolsServiceClient._constants.extensionConfigSectionName);
|
||||
throw new Error(SqlToolsServiceClient._constants.invalidServiceFilePath);
|
||||
} else {
|
||||
let self = this;
|
||||
private initializeLanguageClient(serverPath: string, context: ExtensionContext, runtimeId: Runtime): void {
|
||||
if (serverPath === undefined) {
|
||||
Utils.logDebug(SqlToolsServiceClient._constants.invalidServiceFilePath, SqlToolsServiceClient._constants.extensionConfigSectionName);
|
||||
throw new Error(SqlToolsServiceClient._constants.invalidServiceFilePath);
|
||||
} else {
|
||||
let self = this;
|
||||
|
||||
if (SqlToolsServiceClient._constants.languageId === 'sql') {
|
||||
self.initializeLanguageConfiguration();
|
||||
}
|
||||
if (SqlToolsServiceClient._constants.languageId === 'sql') {
|
||||
self.initializeLanguageConfiguration();
|
||||
}
|
||||
|
||||
// Use default createServerOptions if one isn't specified
|
||||
let serverOptions: ServerOptions = SqlToolsServiceClient._helper ?
|
||||
SqlToolsServiceClient._helper.createServerOptions(serverPath, runtimeId) : self.createServerOptions(serverPath);
|
||||
this.client = this.createLanguageClient(serverOptions);
|
||||
this.installDirectory = this._downloadProvider.getInstallDirectory(runtimeId, SqlToolsServiceClient._constants.extensionConfigSectionName);
|
||||
// Use default createServerOptions if one isn't specified
|
||||
let serverOptions: ServerOptions = SqlToolsServiceClient._helper ?
|
||||
SqlToolsServiceClient._helper.createServerOptions(serverPath, runtimeId) : self.createServerOptions(serverPath);
|
||||
this.client = this.createLanguageClient(serverOptions);
|
||||
this.installDirectory = this._downloadProvider.getInstallDirectory(runtimeId, SqlToolsServiceClient._constants.extensionConfigSectionName);
|
||||
|
||||
if (context !== undefined) {
|
||||
// Create the language client and start the client.
|
||||
let disposable = this.client.start();
|
||||
if (context !== undefined) {
|
||||
// Create the language client and start the client.
|
||||
let disposable = this.client.start();
|
||||
|
||||
// Push the disposable to the context's subscriptions so that the
|
||||
// client can be deactivated on extension deactivation
|
||||
// Push the disposable to the context's subscriptions so that the
|
||||
// client can be deactivated on extension deactivation
|
||||
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
}
|
||||
}
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public createClient(context: ExtensionContext, runtimeId: Runtime, languageClientHelper: ILanguageClientHelper, executableFiles: string[]): Promise<LanguageClient> {
|
||||
return new Promise<LanguageClient>( (resolve, reject) => {
|
||||
let client: LanguageClient;
|
||||
this._server.findServerPath(this.installDirectory, executableFiles).then(serverPath => {
|
||||
if (serverPath === undefined) {
|
||||
reject(new Error(SqlToolsServiceClient._constants.invalidServiceFilePath));
|
||||
} else {
|
||||
public createClient(context: ExtensionContext, runtimeId: Runtime, languageClientHelper: LanguageServiceContracts.ILanguageClientHelper, executableFiles: string[]): Promise<LanguageClient> {
|
||||
return new Promise<LanguageClient>((resolve, reject) => {
|
||||
let client: LanguageClient;
|
||||
this._server.findServerPath(this.installDirectory, executableFiles).then(serverPath => {
|
||||
if (serverPath === undefined) {
|
||||
reject(new Error(SqlToolsServiceClient._constants.invalidServiceFilePath));
|
||||
} else {
|
||||
|
||||
let serverOptions: ServerOptions = languageClientHelper ?
|
||||
languageClientHelper.createServerOptions(serverPath, runtimeId) : this.createServerOptions(serverPath);
|
||||
let serverOptions: ServerOptions = languageClientHelper ?
|
||||
languageClientHelper.createServerOptions(serverPath, runtimeId) : this.createServerOptions(serverPath);
|
||||
|
||||
// Options to control the language client
|
||||
let clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [SqlToolsServiceClient._constants.languageId],
|
||||
providerId: '',
|
||||
synchronize: {
|
||||
configurationSection: SqlToolsServiceClient._constants.extensionConfigSectionName
|
||||
},
|
||||
errorHandler: new LanguageClientErrorHandler(SqlToolsServiceClient._constants),
|
||||
serverConnectionMetadata: this._config.getConfigValue(Constants.serverConnectionMetadata)
|
||||
};
|
||||
this._serviceStatus.showServiceLoading();
|
||||
// cache the client instance for later use
|
||||
client = new LanguageClient(SqlToolsServiceClient._constants.serviceName, serverOptions, clientOptions);
|
||||
// Options to control the language client
|
||||
let clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [SqlToolsServiceClient._constants.languageId],
|
||||
providerId: '',
|
||||
synchronize: {
|
||||
configurationSection: SqlToolsServiceClient._constants.extensionConfigSectionName
|
||||
},
|
||||
errorHandler: new LanguageClientErrorHandler(SqlToolsServiceClient._constants),
|
||||
serverConnectionMetadata: this._config.getConfigValue(Constants.serverConnectionMetadata)
|
||||
};
|
||||
this._serviceStatus.showServiceLoading();
|
||||
// cache the client instance for later use
|
||||
client = new LanguageClient(SqlToolsServiceClient._constants.serviceName, serverOptions, clientOptions);
|
||||
|
||||
if (context !== undefined) {
|
||||
// Create the language client and start the client.
|
||||
let disposable = client.start();
|
||||
if (context !== undefined) {
|
||||
// Create the language client and start the client.
|
||||
let disposable = client.start();
|
||||
|
||||
// Push the disposable to the context's subscriptions so that the
|
||||
// client can be deactivated on extension deactivation
|
||||
// Push the disposable to the context's subscriptions so that the
|
||||
// client can be deactivated on extension deactivation
|
||||
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
client.onReady().then(this._serviceStatus.showServiceLoaded);
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
client.onReady().then(this._serviceStatus.showServiceLoaded);
|
||||
|
||||
resolve(client);
|
||||
}
|
||||
}, error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
resolve(client);
|
||||
}
|
||||
}, error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private createServerOptions(servicePath): ServerOptions {
|
||||
let serverArgs = [];
|
||||
let serverCommand: string = servicePath;
|
||||
if (servicePath.endsWith('.dll')) {
|
||||
serverArgs = [servicePath];
|
||||
serverCommand = 'dotnet';
|
||||
}
|
||||
private createServerOptions(servicePath): ServerOptions {
|
||||
let serverArgs = [];
|
||||
let serverCommand: string = servicePath;
|
||||
if (servicePath.endsWith('.dll')) {
|
||||
serverArgs = [servicePath];
|
||||
serverCommand = 'dotnet';
|
||||
}
|
||||
|
||||
// Enable diagnostic logging in the service if it is configured
|
||||
let config = workspace.getConfiguration(SqlToolsServiceClient._constants.extensionConfigSectionName);
|
||||
if (config) {
|
||||
let logDebugInfo = config[Constants.configLogDebugInfo];
|
||||
if (logDebugInfo) {
|
||||
serverArgs.push('--enable-logging');
|
||||
}
|
||||
}
|
||||
serverArgs.push('--log-dir');
|
||||
let logFileLocation = path.join(utils.getDefaultLogLocation(), SqlToolsServiceClient.constants.extensionName);
|
||||
serverArgs.push(logFileLocation);
|
||||
// Enable diagnostic logging in the service if it is configured
|
||||
let config = workspace.getConfiguration(SqlToolsServiceClient._constants.extensionConfigSectionName);
|
||||
if (config) {
|
||||
let logDebugInfo = config[Constants.configLogDebugInfo];
|
||||
if (logDebugInfo) {
|
||||
serverArgs.push('--enable-logging');
|
||||
}
|
||||
}
|
||||
serverArgs.push('--log-dir');
|
||||
let logFileLocation = path.join(Utils.getDefaultLogLocation(), SqlToolsServiceClient.constants.extensionName);
|
||||
serverArgs.push(logFileLocation);
|
||||
|
||||
// run the service host using dotnet.exe from the path
|
||||
let serverOptions: ServerOptions = { command: serverCommand, args: serverArgs, transport: TransportKind.stdio };
|
||||
return serverOptions;
|
||||
}
|
||||
// run the service host using dotnet.exe from the path
|
||||
let serverOptions: ServerOptions = { command: serverCommand, args: serverArgs, transport: TransportKind.stdio };
|
||||
return serverOptions;
|
||||
}
|
||||
|
||||
private createLanguageClient(serverOptions: ServerOptions): LanguageClient {
|
||||
// Options to control the language client
|
||||
let clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [SqlToolsServiceClient._constants.languageId],
|
||||
providerId: SqlToolsServiceClient._constants.providerId,
|
||||
synchronize: {
|
||||
configurationSection: SqlToolsServiceClient._constants.extensionConfigSectionName
|
||||
},
|
||||
errorHandler: new LanguageClientErrorHandler(SqlToolsServiceClient._constants),
|
||||
serverConnectionMetadata: this._config.getConfigValue(Constants.serverConnectionMetadata)
|
||||
};
|
||||
private createLanguageClient(serverOptions: ServerOptions): LanguageClient {
|
||||
// Options to control the language client
|
||||
let clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [SqlToolsServiceClient._constants.languageId],
|
||||
providerId: SqlToolsServiceClient._constants.providerId,
|
||||
synchronize: {
|
||||
configurationSection: SqlToolsServiceClient._constants.extensionConfigSectionName
|
||||
},
|
||||
errorHandler: new LanguageClientErrorHandler(SqlToolsServiceClient._constants),
|
||||
serverConnectionMetadata: this._config.getConfigValue(Constants.serverConnectionMetadata)
|
||||
};
|
||||
|
||||
this._serviceStatus.showServiceLoading();
|
||||
// cache the client instance for later use
|
||||
let client = new LanguageClient(SqlToolsServiceClient._constants.serviceName, serverOptions, clientOptions);
|
||||
client.onReady().then( () => {
|
||||
this.checkServiceCompatibility();
|
||||
this._serviceStatus.showServiceLoaded();
|
||||
client.onNotification(LanguageServiceContracts.TelemetryNotification.type, this.handleLanguageServiceTelemetryNotification());
|
||||
client.onNotification(LanguageServiceContracts.StatusChangedNotification.type, this.handleLanguageServiceStatusNotification());
|
||||
this._serviceStatus.showServiceLoading();
|
||||
// cache the client instance for later use
|
||||
let client = new LanguageClient(SqlToolsServiceClient._constants.serviceName, serverOptions, clientOptions);
|
||||
client.onReady().then(() => {
|
||||
this.checkServiceCompatibility();
|
||||
this._serviceStatus.showServiceLoaded();
|
||||
client.onNotification(LanguageServiceContracts.TelemetryNotification.type, this.handleLanguageServiceTelemetryNotification());
|
||||
client.onNotification(LanguageServiceContracts.StatusChangedNotification.type, this.handleLanguageServiceStatusNotification());
|
||||
|
||||
// Report the language client startup time
|
||||
let endTime = Date.now();
|
||||
let installationTime = this._installationTime || 0;
|
||||
let totalTime = endTime - this._languageClientStartTime;
|
||||
let processStartupTime = totalTime - installationTime;
|
||||
Telemetry.sendTelemetryEvent('startup/LanguageClientStarted', {
|
||||
installationTime: String(installationTime),
|
||||
processStartupTime: String(processStartupTime),
|
||||
totalTime: String(totalTime),
|
||||
beginningTimestamp: String(this._languageClientStartTime)
|
||||
});
|
||||
this._languageClientStartTime = undefined;
|
||||
this._installationTime = undefined;
|
||||
});
|
||||
// Report the language client startup time
|
||||
let endTime = Date.now();
|
||||
let installationTime = this._installationTime || 0;
|
||||
let totalTime = endTime - this._languageClientStartTime;
|
||||
let processStartupTime = totalTime - installationTime;
|
||||
Telemetry.sendTelemetryEvent('startup/LanguageClientStarted', {
|
||||
installationTime: String(installationTime),
|
||||
processStartupTime: String(processStartupTime),
|
||||
totalTime: String(totalTime),
|
||||
beginningTimestamp: String(this._languageClientStartTime)
|
||||
});
|
||||
this._languageClientStartTime = undefined;
|
||||
this._installationTime = undefined;
|
||||
});
|
||||
|
||||
return client;
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
private handleLanguageServiceTelemetryNotification(): NotificationHandler<LanguageServiceContracts.TelemetryParams> {
|
||||
return (event: LanguageServiceContracts.TelemetryParams): void => {
|
||||
Telemetry.sendTelemetryEvent(event.params.eventName, event.params.properties, event.params.measures);
|
||||
};
|
||||
}
|
||||
private handleLanguageServiceTelemetryNotification(): NotificationHandler<LanguageServiceContracts.TelemetryParams> {
|
||||
return (event: LanguageServiceContracts.TelemetryParams): void => {
|
||||
Telemetry.sendTelemetryEvent(event.params.eventName, event.params.properties, event.params.measures);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Public for testing purposes only.
|
||||
*/
|
||||
public handleLanguageServiceStatusNotification(): NotificationHandler<LanguageServiceContracts.StatusChangeParams> {
|
||||
return (event: LanguageServiceContracts.StatusChangeParams): void => {
|
||||
this._statusView.languageServiceStatusChanged(event.ownerUri, event.status);
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Public for testing purposes only.
|
||||
*/
|
||||
public handleLanguageServiceStatusNotification(): NotificationHandler<LanguageServiceContracts.StatusChangeParams> {
|
||||
return (event: LanguageServiceContracts.StatusChangeParams): void => {
|
||||
this._statusView.languageServiceStatusChanged(event.ownerUri, event.status);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a request to the service client
|
||||
* @param type The of the request to make
|
||||
* @param params The params to pass with the request
|
||||
* @returns A thenable object for when the request receives a response
|
||||
*/
|
||||
public sendRequest<P, R, E>(type: RequestType<P, R, E>, params?: P, client: LanguageClient = undefined): Thenable<R> {
|
||||
if (client === undefined) {
|
||||
client = this._client;
|
||||
}
|
||||
if (client !== undefined) {
|
||||
return client.sendRequest(type, params);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Send a request to the service client
|
||||
* @param type The of the request to make
|
||||
* @param params The params to pass with the request
|
||||
* @returns A thenable object for when the request receives a response
|
||||
*/
|
||||
public sendRequest<P, R, E>(type: RequestType<P, R, E>, params?: P, client: LanguageClient = undefined): Thenable<R> {
|
||||
if (client === undefined) {
|
||||
client = this._client;
|
||||
}
|
||||
if (client !== undefined) {
|
||||
return client.sendRequest(type, params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a handler for a notification type
|
||||
* @param type The notification type to register the handler for
|
||||
* @param handler The handler to register
|
||||
*/
|
||||
public onNotification<P>(type: NotificationType<P>, handler: NotificationHandler<P>, client: LanguageClient = undefined): void {
|
||||
if (client === undefined) {
|
||||
client = this._client;
|
||||
}
|
||||
if (client !== undefined) {
|
||||
return client.onNotification(type, handler);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Register a handler for a notification type
|
||||
* @param type The notification type to register the handler for
|
||||
* @param handler The handler to register
|
||||
*/
|
||||
public onNotification<P>(type: NotificationType<P>, handler: NotificationHandler<P>, client: LanguageClient = undefined): void {
|
||||
if (client === undefined) {
|
||||
client = this._client;
|
||||
}
|
||||
if (client !== undefined) {
|
||||
return client.onNotification(type, handler);
|
||||
}
|
||||
}
|
||||
|
||||
public checkServiceCompatibility(): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
this._client.sendRequest(VersionRequest.type, undefined).then((result) => {
|
||||
Utils.logDebug(SqlToolsServiceClient._constants.extensionName + ' service client version: ' + result, SqlToolsServiceClient._constants.extensionConfigSectionName);
|
||||
public checkServiceCompatibility(): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
this._client.sendRequest(VersionRequest.type, undefined).then((result) => {
|
||||
Utils.logDebug(SqlToolsServiceClient._constants.extensionName + ' service client version: ' + result, SqlToolsServiceClient._constants.extensionConfigSectionName);
|
||||
|
||||
if (result === undefined || !result.startsWith(SqlToolsServiceClient._constants.serviceCompatibleVersion)) {
|
||||
Utils.showErrorMsg(Constants.serviceNotCompatibleError, SqlToolsServiceClient._constants.extensionName);
|
||||
Utils.logDebug(Constants.serviceNotCompatibleError, SqlToolsServiceClient._constants.extensionConfigSectionName);
|
||||
resolve(false);
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
if (result === undefined || !result.startsWith(SqlToolsServiceClient._constants.serviceCompatibleVersion)) {
|
||||
Utils.showErrorMsg(Constants.serviceNotCompatibleError, SqlToolsServiceClient._constants.extensionName);
|
||||
Utils.logDebug(Constants.serviceNotCompatibleError, SqlToolsServiceClient._constants.extensionConfigSectionName);
|
||||
resolve(false);
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ import { Runtime, getRuntimeDisplayName } from '../models/platform';
|
||||
import * as path from 'path';
|
||||
import { IConfig, IStatusView, IPackage, PackageError, IHttpClient, IDecompressProvider } from './interfaces';
|
||||
import { ILogger } from '../models/interfaces';
|
||||
import Constants = require('../models/constants');
|
||||
import { Constants } from '../models/constants';
|
||||
import * as tmp from 'tmp';
|
||||
import {IExtensionConstants} from '../models/contracts/contracts';
|
||||
import { IExtensionConstants } from '../models/contracts/contracts';
|
||||
|
||||
let fse = require('fs-extra');
|
||||
const fse = require('fs-extra');
|
||||
|
||||
/*
|
||||
* Service Download Provider class which handles downloading the SQL Tools service.
|
||||
|
||||
@@ -61,9 +61,9 @@ export class ServiceInstaller {
|
||||
private _serverProvider = undefined;
|
||||
private _extensionConstants = undefined;
|
||||
|
||||
constructor(extensionConstants: IExtensionConstants) {
|
||||
constructor(extensionConstants: IExtensionConstants, path?: string) {
|
||||
this._extensionConstants = extensionConstants;
|
||||
this._config = new Config(extensionConstants.extensionConfigSectionName, true);
|
||||
this._config = new Config(extensionConstants.extensionConfigSectionName, path, true);
|
||||
this._downloadProvider = new ServiceDownloadProvider(this._config, this._logger, this._statusView, this._httpClient, this._decompressProvider, extensionConstants, true);
|
||||
this._serverProvider = new ServerProvider(this._downloadProvider, this._config, this._statusView, extensionConstants.extensionConfigSectionName);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
* ------------------------------------------------------------------------------------------ */
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import vscode = require('vscode');
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import SqlToolsServiceClient from './languageservice/serviceClient';
|
||||
import ServerProvider from './languageservice/server';
|
||||
import VscodeWrapper from './controllers/vscodeWrapper';
|
||||
import * as SharedConstants from './models/constants';
|
||||
import * as Utils from './models/utils';
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
export * from './controllers/vscodeWrapper';
|
||||
export * from './models/constants';
|
||||
export * from './models/utils';
|
||||
|
||||
export {SqlToolsServiceClient, VscodeWrapper, SharedConstants, Utils};
|
||||
export {IExtensionConstants} from './models/contracts/contracts';
|
||||
export {ILanguageClientHelper} from './models/contracts/languageService';
|
||||
export {Runtime, PlatformInformation} from './models/platform';
|
||||
export {Telemetry} from './models/telemetry';
|
||||
export {LinuxDistribution} from './models/platform';
|
||||
export {ServiceInstaller} from './languageservice/serviceInstallerUtil';
|
||||
export { SqlToolsServiceClient } from './languageservice/serviceClient';
|
||||
export { IExtensionConstants } from './models/contracts/contracts';
|
||||
export { ILanguageClientHelper } from './models/contracts/languageService';
|
||||
export { Runtime, PlatformInformation } from './models/platform';
|
||||
export { Telemetry } from './models/telemetry';
|
||||
export { LinuxDistribution } from './models/platform';
|
||||
export { ServiceInstaller } from './languageservice/serviceInstallerUtil';
|
||||
@@ -3,24 +3,23 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
//constants
|
||||
export const configLogDebugInfo: string = 'logDebugInfo';
|
||||
export const serviceNotCompatibleError: string = "Client is not compatible with the service layer";
|
||||
export const serviceDownloading: string = "Downloading";
|
||||
export const serviceInstalling: string = "Installing";
|
||||
export const unsupportedPlatformErrorMessage: string = "This platform is unsupported and application services may not function correctly";
|
||||
export const extensionActivated: string = 'activated.';
|
||||
export const extensionDeactivated: string = 'de-activated.';
|
||||
export const configEnabled: string = 'enabled';
|
||||
export const configUseDebugSource = 'useDebugSource';
|
||||
export const serviceConfigKey = 'service';
|
||||
export const executableFilesConfigKey = 'executableFiles';
|
||||
export const versionConfigKey = 'version';
|
||||
export const downloadUrlConfigKey = 'downloadUrl';
|
||||
export const installDirConfigKey = 'installDir';
|
||||
export const serviceCrashButton = "View Known Issues";
|
||||
export const configDebugSourcePath = 'debugSourcePath';
|
||||
export const neverShowAgain = "Don't show again";
|
||||
export const ignorePlatformWarning = 'ignorePlatformWarning';
|
||||
export const usingDefaultPlatformMessage = "Unknown platform detected, defaulting to Linux_x64 platform";
|
||||
export const serverConnectionMetadata = "serverConnectionMetadata";
|
||||
export namespace Constants {
|
||||
//constants
|
||||
export const configLogDebugInfo: string = 'logDebugInfo';
|
||||
export const serviceNotCompatibleError: string = 'Client is not compatible with the service layer';
|
||||
export const serviceDownloading: string = 'Downloading';
|
||||
export const serviceInstalling: string = 'Installing';
|
||||
export const unsupportedPlatformErrorMessage: string = 'This platform is unsupported and application services may not function correctly';
|
||||
export const serviceConfigKey = 'service';
|
||||
export const executableFilesConfigKey = 'executableFiles';
|
||||
export const versionConfigKey = 'version';
|
||||
export const downloadUrlConfigKey = 'downloadUrl';
|
||||
export const installDirConfigKey = 'installDir';
|
||||
export const serviceCrashButton = 'View Known Issues';
|
||||
export const neverShowAgain = 'Do not show again';
|
||||
export const ignorePlatformWarning = 'ignorePlatformWarning';
|
||||
export const usingDefaultPlatformMessage = 'Unknown platform detected, defaulting to Linux_x64 platform';
|
||||
export const serverConnectionMetadata = 'serverConnectionMetadata';
|
||||
export const extensionDeactivated: string = 'de-activated.';
|
||||
export const extensionActivated: string = 'activated.';
|
||||
}
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict'
|
||||
'use strict';
|
||||
|
||||
import {RequestType} from 'dataprotocol-client';
|
||||
import {Runtime, LinuxDistribution} from '../platform';
|
||||
import { RequestType } from 'dataprotocol-client';
|
||||
import { Runtime, LinuxDistribution } from '../platform';
|
||||
|
||||
// --------------------------------- < Version Request > -------------------------------------------------
|
||||
|
||||
// Version request message callback declaration
|
||||
export namespace VersionRequest {
|
||||
export const type: RequestType<void, VersionResult, void> = { get method(): string { return 'version'; } };
|
||||
export const type: RequestType<void, VersionResult, void> = { get method(): string { return 'version'; } };
|
||||
}
|
||||
|
||||
// Version response format
|
||||
@@ -21,30 +21,30 @@ export type VersionResult = string;
|
||||
|
||||
// Constants interface for each extension
|
||||
export interface IExtensionConstants {
|
||||
// TODO: Fill in interface
|
||||
// TODO: Fill in interface
|
||||
|
||||
// Definitely dependent on the extension
|
||||
extensionName: string;
|
||||
invalidServiceFilePath: string;
|
||||
serviceName: string;
|
||||
extensionConfigSectionName: string;
|
||||
serviceCompatibleVersion: string;
|
||||
outputChannelName: string;
|
||||
languageId: string;
|
||||
serviceInstallingTo: string;
|
||||
serviceInitializing: string;
|
||||
serviceInstalled: string;
|
||||
serviceLoadingFailed: string;
|
||||
serviceInstallationFailed: string;
|
||||
serviceInitializingOutputChannelName: string;
|
||||
commandsNotAvailableWhileInstallingTheService : string;
|
||||
providerId: string;
|
||||
serviceCrashMessage: string;
|
||||
serviceCrashLink: string;
|
||||
installFolderName: string;
|
||||
telemetryExtensionName: string;
|
||||
// Definitely dependent on the extension
|
||||
extensionName: string;
|
||||
invalidServiceFilePath: string;
|
||||
serviceName: string;
|
||||
extensionConfigSectionName: string;
|
||||
serviceCompatibleVersion: string;
|
||||
outputChannelName: string;
|
||||
languageId: string;
|
||||
serviceInstallingTo: string;
|
||||
serviceInitializing: string;
|
||||
serviceInstalled: string;
|
||||
serviceLoadingFailed: string;
|
||||
serviceInstallationFailed: string;
|
||||
serviceInitializingOutputChannelName: string;
|
||||
commandsNotAvailableWhileInstallingTheService: string;
|
||||
providerId: string;
|
||||
serviceCrashMessage: string;
|
||||
serviceCrashLink: string;
|
||||
installFolderName: string;
|
||||
telemetryExtensionName: string;
|
||||
|
||||
getRuntimeId(platform: string, architecture: string, distribution: LinuxDistribution): Runtime;
|
||||
getRuntimeId(platform: string, architecture: string, distribution: LinuxDistribution): Runtime;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import {NotificationType, ServerOptions} from 'dataprotocol-client';
|
||||
import {ITelemetryEventProperties, ITelemetryEventMeasures} from '../telemetry';
|
||||
import {Runtime} from '../platform';
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { NotificationType, ServerOptions } from 'dataprotocol-client';
|
||||
import { ITelemetryEventProperties, ITelemetryEventMeasures } from '../telemetry';
|
||||
import { Runtime } from '../platform';
|
||||
|
||||
// ------------------------------- < Telemetry Sent Event > ------------------------------------
|
||||
|
||||
@@ -8,18 +12,18 @@ import {Runtime} from '../platform';
|
||||
* Event sent when the language service send a telemetry event
|
||||
*/
|
||||
export namespace TelemetryNotification {
|
||||
export const type: NotificationType<TelemetryParams> = { get method(): string { return 'telemetry/sqlevent'; } };
|
||||
export const type: NotificationType<TelemetryParams> = { get method(): string { return 'telemetry/sqlevent'; } };
|
||||
}
|
||||
|
||||
/**
|
||||
* Update event parameters
|
||||
*/
|
||||
export class TelemetryParams {
|
||||
public params: {
|
||||
eventName: string;
|
||||
properties: ITelemetryEventProperties;
|
||||
measures: ITelemetryEventMeasures;
|
||||
};
|
||||
public params: {
|
||||
eventName: string;
|
||||
properties: ITelemetryEventProperties;
|
||||
measures: ITelemetryEventMeasures;
|
||||
};
|
||||
}
|
||||
|
||||
// ------------------------------- </ Telemetry Sent Event > ----------------------------------
|
||||
@@ -30,26 +34,26 @@ export class TelemetryParams {
|
||||
* Event sent when the language service send a status change event
|
||||
*/
|
||||
export namespace StatusChangedNotification {
|
||||
export const type: NotificationType<StatusChangeParams> = { get method(): string { return 'textDocument/statusChanged'; } };
|
||||
export const type: NotificationType<StatusChangeParams> = { get method(): string { return 'textDocument/statusChanged'; } };
|
||||
}
|
||||
|
||||
/**
|
||||
* Update event parameters
|
||||
*/
|
||||
export class StatusChangeParams {
|
||||
/**
|
||||
* URI identifying the text document
|
||||
*/
|
||||
public ownerUri: string;
|
||||
/**
|
||||
* URI identifying the text document
|
||||
*/
|
||||
public ownerUri: string;
|
||||
|
||||
/**
|
||||
* The new status of the document
|
||||
*/
|
||||
public status: string;
|
||||
/**
|
||||
* The new status of the document
|
||||
*/
|
||||
public status: string;
|
||||
}
|
||||
|
||||
// ------------------------------- </ Status Sent Event > ----------------------------------
|
||||
|
||||
export interface ILanguageClientHelper {
|
||||
createServerOptions(servicePath: string, runtimeId?: Runtime): ServerOptions;
|
||||
createServerOptions(servicePath: string, runtimeId?: Runtime): ServerOptions;
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
export interface ILogger {
|
||||
logDebug(message: string): void;
|
||||
increaseIndent(): void;
|
||||
decreaseIndent(): void;
|
||||
append(message?: string): void;
|
||||
appendLine(message?: string): void;
|
||||
}
|
||||
|
||||
export interface IRuntime {
|
||||
getRuntimeDisplayName();
|
||||
logDebug(message: string): void;
|
||||
increaseIndent(): void;
|
||||
decreaseIndent(): void;
|
||||
append(message?: string): void;
|
||||
appendLine(message?: string): void;
|
||||
}
|
||||
|
||||
@@ -3,66 +3,67 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as os from 'os';
|
||||
import {ILogger} from './interfaces';
|
||||
import * as Utils from './utils';
|
||||
import {IExtensionConstants} from './contracts/contracts';
|
||||
import { ILogger } from './interfaces';
|
||||
import { Utils } from './utils';
|
||||
import { IExtensionConstants } from './contracts/contracts';
|
||||
|
||||
/*
|
||||
* Logger class handles logging messages using the Util functions.
|
||||
*/
|
||||
export class Logger implements ILogger {
|
||||
private _writer: (message: string) => void;
|
||||
private _prefix: string;
|
||||
private _extensionConstants: IExtensionConstants;
|
||||
private _writer: (message: string) => void;
|
||||
private _prefix: string;
|
||||
private _extensionConstants: IExtensionConstants;
|
||||
|
||||
private _indentLevel: number = 0;
|
||||
private _indentSize: number = 4;
|
||||
private _atLineStart: boolean = false;
|
||||
private _indentLevel: number = 0;
|
||||
private _indentSize: number = 4;
|
||||
private _atLineStart: boolean = false;
|
||||
|
||||
constructor(writer: (message: string) => void, extensionConstants: IExtensionConstants, prefix?: string) {
|
||||
this._writer = writer;
|
||||
this._prefix = prefix;
|
||||
this._extensionConstants = extensionConstants;
|
||||
}
|
||||
constructor(writer: (message: string) => void, extensionConstants: IExtensionConstants, prefix?: string) {
|
||||
this._writer = writer;
|
||||
this._prefix = prefix;
|
||||
this._extensionConstants = extensionConstants;
|
||||
}
|
||||
|
||||
public logDebug(message: string): void {
|
||||
Utils.logDebug(message, this._extensionConstants.extensionConfigSectionName);
|
||||
}
|
||||
public logDebug(message: string): void {
|
||||
Utils.logDebug(message, this._extensionConstants.extensionConfigSectionName);
|
||||
}
|
||||
|
||||
private _appendCore(message: string): void {
|
||||
if (this._atLineStart) {
|
||||
if (this._indentLevel > 0) {
|
||||
const indent = ' '.repeat(this._indentLevel * this._indentSize);
|
||||
this._writer(indent);
|
||||
}
|
||||
private _appendCore(message: string): void {
|
||||
if (this._atLineStart) {
|
||||
if (this._indentLevel > 0) {
|
||||
const indent = ' '.repeat(this._indentLevel * this._indentSize);
|
||||
this._writer(indent);
|
||||
}
|
||||
|
||||
if (this._prefix) {
|
||||
this._writer(`[${this._prefix}] `);
|
||||
}
|
||||
if (this._prefix) {
|
||||
this._writer(`[${this._prefix}] `);
|
||||
}
|
||||
|
||||
this._atLineStart = false;
|
||||
}
|
||||
this._atLineStart = false;
|
||||
}
|
||||
|
||||
this._writer(message);
|
||||
}
|
||||
this._writer(message);
|
||||
}
|
||||
|
||||
public increaseIndent(): void {
|
||||
this._indentLevel += 1;
|
||||
}
|
||||
public increaseIndent(): void {
|
||||
this._indentLevel += 1;
|
||||
}
|
||||
|
||||
public decreaseIndent(): void {
|
||||
if (this._indentLevel > 0) {
|
||||
this._indentLevel -= 1;
|
||||
}
|
||||
}
|
||||
public decreaseIndent(): void {
|
||||
if (this._indentLevel > 0) {
|
||||
this._indentLevel -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
public append(message?: string): void {
|
||||
message = message || '';
|
||||
this._appendCore(message);
|
||||
}
|
||||
public append(message?: string): void {
|
||||
message = message || '';
|
||||
this._appendCore(message);
|
||||
}
|
||||
|
||||
public appendLine(message?: string): void {
|
||||
message = message || '';
|
||||
this._appendCore(message + os.EOL);
|
||||
this._atLineStart = true;
|
||||
}
|
||||
public appendLine(message?: string): void {
|
||||
message = message || '';
|
||||
this._appendCore(message + os.EOL);
|
||||
this._atLineStart = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,284 +12,229 @@ import * as os from 'os';
|
||||
const unknown = 'unknown';
|
||||
|
||||
export enum Runtime {
|
||||
UnknownRuntime = <any>'Unknown',
|
||||
UnknownVersion = <any>'Unknown',
|
||||
Windows_86 = <any>'Windows_86',
|
||||
Windows_64 = <any>'Windows_64',
|
||||
OSX = <any> 'OSX',
|
||||
CentOS_7 = <any>'CentOS_7',
|
||||
Debian_8 = <any>'Debian_8',
|
||||
Fedora_23 = <any>'Fedora_23',
|
||||
OpenSUSE_13_2 = <any>'OpenSUSE_13_2',
|
||||
SLES_12_2 = <any>'SLES_12_2',
|
||||
RHEL_7 = <any>'RHEL_7',
|
||||
Ubuntu_14 = <any>'Ubuntu_14',
|
||||
Ubuntu_16 = <any>'Ubuntu_16',
|
||||
Linux_64 = <any>'Linux_64',
|
||||
Linux_86 = <any>'Linux-86'
|
||||
UnknownRuntime = <any>'Unknown',
|
||||
UnknownVersion = <any>'Unknown',
|
||||
Windows_86 = <any>'Windows_86',
|
||||
Windows_64 = <any>'Windows_64',
|
||||
OSX = <any>'OSX',
|
||||
CentOS_7 = <any>'CentOS_7',
|
||||
Debian_8 = <any>'Debian_8',
|
||||
Fedora_23 = <any>'Fedora_23',
|
||||
OpenSUSE_13_2 = <any>'OpenSUSE_13_2',
|
||||
SLES_12_2 = <any>'SLES_12_2',
|
||||
RHEL_7 = <any>'RHEL_7',
|
||||
Ubuntu_14 = <any>'Ubuntu_14',
|
||||
Ubuntu_16 = <any>'Ubuntu_16',
|
||||
Linux_64 = <any>'Linux_64',
|
||||
Linux_86 = <any>'Linux-86'
|
||||
}
|
||||
|
||||
export function getRuntimeDisplayName(runtime: Runtime): string {
|
||||
switch (runtime) {
|
||||
case Runtime.Windows_64:
|
||||
return 'Windows';
|
||||
case Runtime.Windows_86:
|
||||
return 'Windows';
|
||||
case Runtime.OSX:
|
||||
return 'OSX';
|
||||
case Runtime.CentOS_7:
|
||||
return 'Linux';
|
||||
case Runtime.Debian_8:
|
||||
return 'Linux';
|
||||
case Runtime.Fedora_23:
|
||||
return 'Linux';
|
||||
case Runtime.OpenSUSE_13_2:
|
||||
return 'Linux';
|
||||
case Runtime.SLES_12_2:
|
||||
return 'Linux';
|
||||
case Runtime.RHEL_7:
|
||||
return 'Linux';
|
||||
case Runtime.Ubuntu_14:
|
||||
return 'Linux';
|
||||
case Runtime.Ubuntu_16:
|
||||
return 'Linux';
|
||||
case Runtime.Linux_64:
|
||||
return 'Linux';
|
||||
case Runtime.Linux_86:
|
||||
return 'Linux';
|
||||
default:
|
||||
return 'Unknown';
|
||||
}
|
||||
switch (runtime) {
|
||||
case Runtime.Windows_64:
|
||||
return 'Windows';
|
||||
case Runtime.Windows_86:
|
||||
return 'Windows';
|
||||
case Runtime.OSX:
|
||||
return 'OSX';
|
||||
case Runtime.CentOS_7:
|
||||
return 'Linux';
|
||||
case Runtime.Debian_8:
|
||||
return 'Linux';
|
||||
case Runtime.Fedora_23:
|
||||
return 'Linux';
|
||||
case Runtime.OpenSUSE_13_2:
|
||||
return 'Linux';
|
||||
case Runtime.SLES_12_2:
|
||||
return 'Linux';
|
||||
case Runtime.RHEL_7:
|
||||
return 'Linux';
|
||||
case Runtime.Ubuntu_14:
|
||||
return 'Linux';
|
||||
case Runtime.Ubuntu_16:
|
||||
return 'Linux';
|
||||
case Runtime.Linux_64:
|
||||
return 'Linux';
|
||||
case Runtime.Linux_86:
|
||||
return 'Linux';
|
||||
default:
|
||||
return 'Unknown';
|
||||
}
|
||||
}
|
||||
|
||||
export class PlatformInformation {
|
||||
public runtimeId: Runtime;
|
||||
public runtimeId: Runtime;
|
||||
|
||||
public constructor(
|
||||
public platform: string,
|
||||
public architecture: string,
|
||||
public distribution: LinuxDistribution = undefined,
|
||||
public getRuntimeId: (platform: string, architecture: string, distribution: LinuxDistribution) => Runtime) {
|
||||
try {
|
||||
this.runtimeId = this.getRuntimeId(platform, architecture, distribution);
|
||||
} catch (err) {
|
||||
this.runtimeId = undefined;
|
||||
}
|
||||
}
|
||||
public constructor(
|
||||
public platform: string,
|
||||
public architecture: string,
|
||||
public distribution: LinuxDistribution = undefined,
|
||||
public getRuntimeId: (platform: string, architecture: string, distribution: LinuxDistribution) => Runtime) {
|
||||
try {
|
||||
this.runtimeId = this.getRuntimeId(platform, architecture, distribution);
|
||||
} catch (err) {
|
||||
this.runtimeId = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
public isWindows(): boolean {
|
||||
return this.platform === 'win32';
|
||||
}
|
||||
public isWindows(): boolean {
|
||||
return this.platform === 'win32';
|
||||
}
|
||||
|
||||
public isMacOS(): boolean {
|
||||
return this.platform === 'darwin';
|
||||
}
|
||||
public isMacOS(): boolean {
|
||||
return this.platform === 'darwin';
|
||||
}
|
||||
|
||||
public isLinux(): boolean {
|
||||
return this.platform === 'linux';
|
||||
}
|
||||
public isLinux(): boolean {
|
||||
return this.platform === 'linux';
|
||||
}
|
||||
|
||||
public isValidRuntime(): boolean {
|
||||
return this.runtimeId !== undefined && this.runtimeId !== Runtime.UnknownRuntime && this.runtimeId !== Runtime.UnknownVersion;
|
||||
}
|
||||
public isValidRuntime(): boolean {
|
||||
return this.runtimeId !== undefined && this.runtimeId !== Runtime.UnknownRuntime && this.runtimeId !== Runtime.UnknownVersion;
|
||||
}
|
||||
|
||||
public getRuntimeDisplayName(): string {
|
||||
return getRuntimeDisplayName(this.runtimeId);
|
||||
}
|
||||
public getRuntimeDisplayName(): string {
|
||||
return getRuntimeDisplayName(this.runtimeId);
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
let result = this.platform;
|
||||
public toString(): string {
|
||||
let result = this.platform;
|
||||
|
||||
if (this.architecture) {
|
||||
if (result) {
|
||||
result += ', ';
|
||||
}
|
||||
if (this.architecture) {
|
||||
if (result) {
|
||||
result += ', ';
|
||||
}
|
||||
|
||||
result += this.architecture;
|
||||
}
|
||||
result += this.architecture;
|
||||
}
|
||||
|
||||
if (this.distribution) {
|
||||
if (result) {
|
||||
result += ', ';
|
||||
}
|
||||
if (this.distribution) {
|
||||
if (result) {
|
||||
result += ', ';
|
||||
}
|
||||
|
||||
result += this.distribution.toString();
|
||||
}
|
||||
result += this.distribution.toString();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static getCurrent(getRuntimeId: (platform: string, architecture: string, distribution: LinuxDistribution) => Runtime,
|
||||
extensionName: string): Promise<any> {
|
||||
let platform = os.platform();
|
||||
let architecturePromise: Promise<string>;
|
||||
let distributionPromise: Promise<LinuxDistribution>;
|
||||
public static getCurrent(getRuntimeId: (platform: string, architecture: string, distribution: LinuxDistribution) => Runtime,
|
||||
extensionName: string): Promise<any> {
|
||||
let platform = os.platform();
|
||||
let architecturePromise: Promise<string>;
|
||||
let distributionPromise: Promise<LinuxDistribution>;
|
||||
|
||||
switch (platform) {
|
||||
case 'win32':
|
||||
architecturePromise = PlatformInformation.getWindowsArchitecture();
|
||||
distributionPromise = Promise.resolve(undefined);
|
||||
break;
|
||||
switch (platform) {
|
||||
case 'win32':
|
||||
architecturePromise = PlatformInformation.getWindowsArchitecture();
|
||||
distributionPromise = Promise.resolve(undefined);
|
||||
break;
|
||||
|
||||
case 'darwin':
|
||||
let osVersion = os.release();
|
||||
if (parseFloat(osVersion) < 16.0 && extensionName === 'mssql') {
|
||||
return Promise.reject('The current version of macOS is not supported. Only macOS Sierra and above (>= 10.12) are supported.')
|
||||
}
|
||||
architecturePromise = PlatformInformation.getUnixArchitecture();
|
||||
distributionPromise = Promise.resolve(undefined);
|
||||
break;
|
||||
case 'darwin':
|
||||
let osVersion = os.release();
|
||||
if (parseFloat(osVersion) < 16.0 && extensionName === 'mssql') {
|
||||
return Promise.reject('The current version of macOS is not supported. Only macOS Sierra and above (>= 10.12) are supported.');
|
||||
}
|
||||
architecturePromise = PlatformInformation.getUnixArchitecture();
|
||||
distributionPromise = Promise.resolve(undefined);
|
||||
break;
|
||||
|
||||
case 'linux':
|
||||
architecturePromise = PlatformInformation.getUnixArchitecture();
|
||||
distributionPromise = LinuxDistribution.getCurrent();
|
||||
break;
|
||||
case 'linux':
|
||||
architecturePromise = PlatformInformation.getUnixArchitecture();
|
||||
distributionPromise = LinuxDistribution.getCurrent();
|
||||
break;
|
||||
|
||||
default:
|
||||
return Promise.reject(`Unsupported platform: ${platform}`);
|
||||
}
|
||||
default:
|
||||
return Promise.reject(`Unsupported platform: ${platform}`);
|
||||
}
|
||||
|
||||
return architecturePromise.then( arch => {
|
||||
return distributionPromise.then(distro => {
|
||||
return new PlatformInformation(platform, arch, distro, getRuntimeId);
|
||||
});
|
||||
});
|
||||
}
|
||||
return architecturePromise.then(arch => {
|
||||
return distributionPromise.then(distro => {
|
||||
return new PlatformInformation(platform, arch, distro, getRuntimeId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static getWindowsArchitecture(): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
// try to get the architecture from WMIC
|
||||
PlatformInformation.getWindowsArchitectureWmic().then(architecture => {
|
||||
if (architecture && architecture !== unknown) {
|
||||
resolve(architecture);
|
||||
} else {
|
||||
// sometimes WMIC isn't available on the path so then try to parse the envvar
|
||||
PlatformInformation.getWindowsArchitectureEnv().then(architecture => {
|
||||
resolve(architecture);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
private static getWindowsArchitecture(): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
// try to get the architecture from WMIC
|
||||
PlatformInformation.getWindowsArchitectureWmic().then(architecture => {
|
||||
if (architecture && architecture !== unknown) {
|
||||
resolve(architecture);
|
||||
} else {
|
||||
// sometimes WMIC isn't available on the path so then try to parse the envvar
|
||||
PlatformInformation.getWindowsArchitectureEnv().then(architecture => {
|
||||
resolve(architecture);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private static getWindowsArchitectureWmic(): Promise<string> {
|
||||
return this.execChildProcess('wmic os get osarchitecture')
|
||||
.then(architecture => {
|
||||
if (architecture) {
|
||||
let archArray: string[] = architecture.split(os.EOL);
|
||||
if (archArray.length >= 2) {
|
||||
let arch = archArray[1].trim();
|
||||
private static getWindowsArchitectureWmic(): Promise<string> {
|
||||
return this.execChildProcess('wmic os get osarchitecture')
|
||||
.then(architecture => {
|
||||
if (architecture) {
|
||||
let archArray: string[] = architecture.split(os.EOL);
|
||||
if (archArray.length >= 2) {
|
||||
let arch = archArray[1].trim();
|
||||
|
||||
// Note: This string can be localized. So, we'll just check to see if it contains 32 or 64.
|
||||
if (arch.indexOf('64') >= 0) {
|
||||
return 'x86_64';
|
||||
} else if (arch.indexOf('32') >= 0) {
|
||||
return 'x86';
|
||||
}
|
||||
}
|
||||
}
|
||||
// Note: This string can be localized. So, we'll just check to see if it contains 32 or 64.
|
||||
if (arch.indexOf('64') >= 0) {
|
||||
return 'x86_64';
|
||||
} else if (arch.indexOf('32') >= 0) {
|
||||
return 'x86';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return unknown;
|
||||
}).catch((error) => {
|
||||
return unknown;
|
||||
});
|
||||
}
|
||||
return unknown;
|
||||
}).catch((error) => {
|
||||
return unknown;
|
||||
});
|
||||
}
|
||||
|
||||
private static getWindowsArchitectureEnv(): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
if (process.env.PROCESSOR_ARCHITECTURE === 'x86' && process.env.PROCESSOR_ARCHITEW6432 === undefined) {
|
||||
resolve('x86');
|
||||
}
|
||||
else {
|
||||
resolve('x86_64');
|
||||
}
|
||||
});
|
||||
}
|
||||
private static getWindowsArchitectureEnv(): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
if (process.env.PROCESSOR_ARCHITECTURE === 'x86' && process.env.PROCESSOR_ARCHITEW6432 === undefined) {
|
||||
resolve('x86');
|
||||
}
|
||||
else {
|
||||
resolve('x86_64');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static getUnixArchitecture(): Promise<string> {
|
||||
return this.execChildProcess('uname -m')
|
||||
.then(architecture => {
|
||||
if (architecture) {
|
||||
return architecture.trim();
|
||||
}
|
||||
private static getUnixArchitecture(): Promise<string> {
|
||||
return this.execChildProcess('uname -m')
|
||||
.then(architecture => {
|
||||
if (architecture) {
|
||||
return architecture.trim();
|
||||
}
|
||||
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
}
|
||||
|
||||
private static execChildProcess(process: string): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
child_process.exec(process, { maxBuffer: 500 * 1024 }, (error: Error, stdout: string, stderr: string) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
private static execChildProcess(process: string): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
child_process.exec(process, { maxBuffer: 500 * 1024 }, (error: Error, stdout: string, stderr: string) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (stderr && stderr.length > 0) {
|
||||
reject(new Error(stderr));
|
||||
return;
|
||||
}
|
||||
if (stderr && stderr.length > 0) {
|
||||
reject(new Error(stderr));
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(stdout);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private static getRuntimeIdHelper(distributionName: string, distributionVersion: string): Runtime {
|
||||
switch (distributionName) {
|
||||
case 'ubuntu':
|
||||
if (distributionVersion.startsWith('14')) {
|
||||
// This also works for Linux Mint
|
||||
return Runtime.Ubuntu_14;
|
||||
} else if (distributionVersion.startsWith('16')) {
|
||||
return Runtime.Ubuntu_16;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'elementary':
|
||||
case 'elementary OS':
|
||||
if (distributionVersion.startsWith('0.3')) {
|
||||
// Elementary OS 0.3 Freya is binary compatible with Ubuntu 14.04
|
||||
return Runtime.Ubuntu_14;
|
||||
} else if (distributionVersion.startsWith('0.4')) {
|
||||
// Elementary OS 0.4 Loki is binary compatible with Ubuntu 16.04
|
||||
return Runtime.Ubuntu_16;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'linuxmint':
|
||||
if (distributionVersion.startsWith('18')) {
|
||||
// Linux Mint 18 is binary compatible with Ubuntu 16.04
|
||||
return Runtime.Ubuntu_16;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'centos':
|
||||
case 'ol':
|
||||
// Oracle Linux is binary compatible with CentOS
|
||||
return Runtime.CentOS_7;
|
||||
case 'fedora':
|
||||
return Runtime.Fedora_23;
|
||||
case 'opensuse':
|
||||
return Runtime.OpenSUSE_13_2;
|
||||
case 'sles':
|
||||
return Runtime.SLES_12_2;
|
||||
case 'rhel':
|
||||
return Runtime.RHEL_7;
|
||||
case 'debian':
|
||||
return Runtime.Debian_8;
|
||||
case 'galliumos':
|
||||
if (distributionVersion.startsWith('2.0')) {
|
||||
return Runtime.Ubuntu_16;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return Runtime.Linux_64;
|
||||
}
|
||||
|
||||
return Runtime.Linux_64;
|
||||
}
|
||||
resolve(stdout);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,71 +244,71 @@ export class PlatformInformation {
|
||||
* https://www.freedesktop.org/software/systemd/man/os-release.html
|
||||
*/
|
||||
export class LinuxDistribution {
|
||||
public constructor(
|
||||
public name: string,
|
||||
public version: string,
|
||||
public idLike?: string[]) { }
|
||||
public constructor(
|
||||
public name: string,
|
||||
public version: string,
|
||||
public idLike?: string[]) { }
|
||||
|
||||
public static getCurrent(): Promise<LinuxDistribution> {
|
||||
// Try /etc/os-release and fallback to /usr/lib/os-release per the synopsis
|
||||
// at https://www.freedesktop.org/software/systemd/man/os-release.html.
|
||||
return LinuxDistribution.fromFilePath('/etc/os-release')
|
||||
.catch(() => LinuxDistribution.fromFilePath('/usr/lib/os-release'))
|
||||
.catch(() => Promise.resolve(new LinuxDistribution(unknown, unknown)));
|
||||
}
|
||||
public static getCurrent(): Promise<LinuxDistribution> {
|
||||
// Try /etc/os-release and fallback to /usr/lib/os-release per the synopsis
|
||||
// at https://www.freedesktop.org/software/systemd/man/os-release.html.
|
||||
return LinuxDistribution.fromFilePath('/etc/os-release')
|
||||
.catch(() => LinuxDistribution.fromFilePath('/usr/lib/os-release'))
|
||||
.catch(() => Promise.resolve(new LinuxDistribution(unknown, unknown)));
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return `name=${this.name}, version=${this.version}`;
|
||||
}
|
||||
public toString(): string {
|
||||
return `name=${this.name}, version=${this.version}`;
|
||||
}
|
||||
|
||||
private static fromFilePath(filePath: string): Promise<LinuxDistribution> {
|
||||
return new Promise<LinuxDistribution>((resolve, reject) => {
|
||||
fs.readFile(filePath, 'utf8', (error, data) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(LinuxDistribution.fromReleaseInfo(data));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
private static fromFilePath(filePath: string): Promise<LinuxDistribution> {
|
||||
return new Promise<LinuxDistribution>((resolve, reject) => {
|
||||
fs.readFile(filePath, 'utf8', (error, data) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(LinuxDistribution.fromReleaseInfo(data));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static fromReleaseInfo(releaseInfo: string, eol: string = os.EOL): LinuxDistribution {
|
||||
let name = unknown;
|
||||
let version = unknown;
|
||||
let idLike: string[] = undefined;
|
||||
public static fromReleaseInfo(releaseInfo: string, eol: string = os.EOL): LinuxDistribution {
|
||||
let name = unknown;
|
||||
let version = unknown;
|
||||
let idLike: string[] = undefined;
|
||||
|
||||
const lines = releaseInfo.split(eol);
|
||||
for (let line of lines) {
|
||||
line = line.trim();
|
||||
const lines = releaseInfo.split(eol);
|
||||
for (let line of lines) {
|
||||
line = line.trim();
|
||||
|
||||
let equalsIndex = line.indexOf('=');
|
||||
if (equalsIndex >= 0) {
|
||||
let key = line.substring(0, equalsIndex);
|
||||
let value = line.substring(equalsIndex + 1);
|
||||
let equalsIndex = line.indexOf('=');
|
||||
if (equalsIndex >= 0) {
|
||||
let key = line.substring(0, equalsIndex);
|
||||
let value = line.substring(equalsIndex + 1);
|
||||
|
||||
// Strip quotes if necessary
|
||||
if (value.length > 1 && value.startsWith('"') && value.endsWith('"')) {
|
||||
value = value.substring(1, value.length - 1);
|
||||
} else if (value.length > 1 && value.startsWith('\'') && value.endsWith('\'')) {
|
||||
value = value.substring(1, value.length - 1);
|
||||
}
|
||||
// Strip quotes if necessary
|
||||
if (value.length > 1 && value.startsWith('"') && value.endsWith('"')) {
|
||||
value = value.substring(1, value.length - 1);
|
||||
} else if (value.length > 1 && value.startsWith('\'') && value.endsWith('\'')) {
|
||||
value = value.substring(1, value.length - 1);
|
||||
}
|
||||
|
||||
if (key === 'ID') {
|
||||
name = value;
|
||||
} else if (key === 'VERSION_ID') {
|
||||
version = value;
|
||||
} else if (key === 'ID_LIKE') {
|
||||
idLike = value.split(' ');
|
||||
}
|
||||
if (key === 'ID') {
|
||||
name = value;
|
||||
} else if (key === 'VERSION_ID') {
|
||||
version = value;
|
||||
} else if (key === 'ID_LIKE') {
|
||||
idLike = value.split(' ');
|
||||
}
|
||||
|
||||
if (name !== unknown && version !== unknown && idLike !== undefined) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (name !== unknown && version !== unknown && idLike !== undefined) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new LinuxDistribution(name, version, idLike);
|
||||
}
|
||||
return new LinuxDistribution(name, version, idLike);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
'use strict';
|
||||
import vscode = require('vscode');
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
import Utils = require('./utils');
|
||||
import { Utils } from './utils';
|
||||
import { PlatformInformation, Runtime, LinuxDistribution } from './platform';
|
||||
import { IExtensionConstants } from './contracts/contracts';
|
||||
|
||||
export interface ITelemetryEventProperties {
|
||||
[key: string]: string;
|
||||
}
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
export interface ITelemetryEventMeasures {
|
||||
[key: string]: number;
|
||||
@@ -79,16 +79,16 @@ export class Telemetry {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Disable telemetry reporting
|
||||
*/
|
||||
/**
|
||||
* Disable telemetry reporting
|
||||
*/
|
||||
public static disable(): void {
|
||||
this.disabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the telemetry reporter for use.
|
||||
*/
|
||||
/**
|
||||
* Initialize the telemetry reporter for use.
|
||||
*/
|
||||
public static initialize(context: vscode.ExtensionContext, extensionConstants: IExtensionConstants): void {
|
||||
if (typeof this.reporter === 'undefined') {
|
||||
// Check if the user has opted out of telemetry
|
||||
@@ -102,9 +102,9 @@ export class Telemetry {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a telemetry event for an exception
|
||||
*/
|
||||
/**
|
||||
* Send a telemetry event for an exception
|
||||
*/
|
||||
public static sendTelemetryEventForException(
|
||||
err: any, methodName: string, extensionConfigName: string): void {
|
||||
try {
|
||||
@@ -127,9 +127,9 @@ export class Telemetry {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a telemetry event using application insights
|
||||
*/
|
||||
/**
|
||||
* Send a telemetry event using application insights
|
||||
*/
|
||||
public static sendTelemetryEvent(
|
||||
eventName: string,
|
||||
properties?: ITelemetryEventProperties,
|
||||
@@ -157,5 +157,3 @@ export class Telemetry {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default Telemetry;
|
||||
|
||||
@@ -1,264 +1,130 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
import * as crypto from 'crypto';
|
||||
import * as os from 'os';
|
||||
import vscode = require('vscode');
|
||||
import Constants = require('./constants');
|
||||
import {ExtensionContext} from 'vscode';
|
||||
import fs = require('fs');
|
||||
import { Constants } from './constants';
|
||||
import { ExtensionContext } from 'vscode';
|
||||
var path = require('path');
|
||||
|
||||
// CONSTANTS //////////////////////////////////////////////////////////////////////////////////////
|
||||
const msInH = 3.6e6;
|
||||
const msInM = 60000;
|
||||
const msInS = 1000;
|
||||
export namespace Utils {
|
||||
// INTERFACES /////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// INTERFACES /////////////////////////////////////////////////////////////////////////////////////
|
||||
// Interface for package.json information
|
||||
export interface IPackageInfo {
|
||||
name: string;
|
||||
version: string;
|
||||
aiKey: string;
|
||||
}
|
||||
|
||||
// Interface for package.json information
|
||||
export interface IPackageInfo {
|
||||
name: string;
|
||||
version: string;
|
||||
aiKey: string;
|
||||
}
|
||||
// FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////
|
||||
// Get information from the extension's package.json file
|
||||
export function getPackageInfo(context: ExtensionContext): IPackageInfo {
|
||||
let extensionPackage = require(context.asAbsolutePath('./package.json'));
|
||||
if (extensionPackage) {
|
||||
return {
|
||||
name: extensionPackage.name,
|
||||
version: extensionPackage.version,
|
||||
aiKey: extensionPackage.aiKey
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Get information from the extension's package.json file
|
||||
export function getPackageInfo(context: ExtensionContext): IPackageInfo {
|
||||
let extensionPackage = require(context.asAbsolutePath('./package.json'));
|
||||
if (extensionPackage) {
|
||||
return {
|
||||
name: extensionPackage.name,
|
||||
version: extensionPackage.version,
|
||||
aiKey: extensionPackage.aiKey
|
||||
};
|
||||
}
|
||||
}
|
||||
// Generate a new GUID
|
||||
export function generateGuid(): string {
|
||||
let hexValues: string[] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
|
||||
// c.f. rfc4122 (UUID version 4 = xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx)
|
||||
let oct: string = '';
|
||||
let tmp: number;
|
||||
/* tslint:disable:no-bitwise */
|
||||
for (let a: number = 0; a < 4; a++) {
|
||||
tmp = (4294967296 * Math.random()) | 0;
|
||||
oct += hexValues[tmp & 0xF] +
|
||||
hexValues[tmp >> 4 & 0xF] +
|
||||
hexValues[tmp >> 8 & 0xF] +
|
||||
hexValues[tmp >> 12 & 0xF] +
|
||||
hexValues[tmp >> 16 & 0xF] +
|
||||
hexValues[tmp >> 20 & 0xF] +
|
||||
hexValues[tmp >> 24 & 0xF] +
|
||||
hexValues[tmp >> 28 & 0xF];
|
||||
}
|
||||
|
||||
// Generate a new GUID
|
||||
export function generateGuid(): string {
|
||||
let hexValues: string[] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
|
||||
// c.f. rfc4122 (UUID version 4 = xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx)
|
||||
let oct: string = '';
|
||||
let tmp: number;
|
||||
/* tslint:disable:no-bitwise */
|
||||
for (let a: number = 0; a < 4; a++) {
|
||||
tmp = (4294967296 * Math.random()) | 0;
|
||||
oct += hexValues[tmp & 0xF] +
|
||||
hexValues[tmp >> 4 & 0xF] +
|
||||
hexValues[tmp >> 8 & 0xF] +
|
||||
hexValues[tmp >> 12 & 0xF] +
|
||||
hexValues[tmp >> 16 & 0xF] +
|
||||
hexValues[tmp >> 20 & 0xF] +
|
||||
hexValues[tmp >> 24 & 0xF] +
|
||||
hexValues[tmp >> 28 & 0xF];
|
||||
}
|
||||
// 'Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively'
|
||||
let clockSequenceHi: string = hexValues[8 + (Math.random() * 4) | 0];
|
||||
return oct.substr(0, 8) + '-' + oct.substr(9, 4) + '-4' + oct.substr(13, 3) + '-' + clockSequenceHi + oct.substr(16, 3) + '-' + oct.substr(19, 12);
|
||||
/* tslint:enable:no-bitwise */
|
||||
}
|
||||
|
||||
// 'Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively'
|
||||
let clockSequenceHi: string = hexValues[8 + (Math.random() * 4) | 0];
|
||||
return oct.substr(0, 8) + '-' + oct.substr(9, 4) + '-4' + oct.substr(13, 3) + '-' + clockSequenceHi + oct.substr(16, 3) + '-' + oct.substr(19, 12);
|
||||
/* tslint:enable:no-bitwise */
|
||||
}
|
||||
// Generate a unique, deterministic ID for the current user of the extension
|
||||
export function generateUserId(): Promise<string> {
|
||||
return new Promise<string>(resolve => {
|
||||
try {
|
||||
let interfaces = os.networkInterfaces();
|
||||
let mac;
|
||||
for (let key of Object.keys(interfaces)) {
|
||||
let item = interfaces[key][0];
|
||||
if (!item.internal) {
|
||||
mac = item.mac;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (mac) {
|
||||
resolve(crypto.createHash('sha256').update(mac + os.homedir(), 'utf8').digest('hex'));
|
||||
} else {
|
||||
resolve(generateGuid());
|
||||
}
|
||||
} catch (err) {
|
||||
resolve(generateGuid()); // fallback
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Generate a unique, deterministic ID for the current user of the extension
|
||||
export function generateUserId(): Promise<string> {
|
||||
return new Promise<string>(resolve => {
|
||||
try {
|
||||
let interfaces = os.networkInterfaces();
|
||||
let mac;
|
||||
for(let key of Object.keys(interfaces)) {
|
||||
let item = interfaces[key][0];
|
||||
if (!item.internal) {
|
||||
mac = item.mac;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (mac) {
|
||||
resolve(crypto.createHash('sha256').update(mac + os.homedir(), 'utf8').digest('hex'));
|
||||
} else {
|
||||
resolve(generateGuid());
|
||||
}
|
||||
} catch (err) {
|
||||
resolve(generateGuid()); // fallback
|
||||
}
|
||||
});
|
||||
}
|
||||
// Retrieve the URI for the currently open file if there is one; otherwise return the empty string
|
||||
export function getActiveTextEditorUri(): string {
|
||||
if (typeof vscode.window.activeTextEditor !== 'undefined' &&
|
||||
typeof vscode.window.activeTextEditor.document !== 'undefined') {
|
||||
return vscode.window.activeTextEditor.document.uri.toString();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
// Return 'true' if the active editor window has a .sql file, false otherwise
|
||||
export function isEditingSqlFile(languageId: string): boolean {
|
||||
let sqlFile = false;
|
||||
let editor = getActiveTextEditor();
|
||||
if (editor) {
|
||||
if (editor.document.languageId === languageId) {
|
||||
sqlFile = true;
|
||||
}
|
||||
}
|
||||
return sqlFile;
|
||||
}
|
||||
// Helper to log debug messages
|
||||
export function logDebug(msg: any, extensionConfigSectionName: string): void {
|
||||
let config = vscode.workspace.getConfiguration(extensionConfigSectionName);
|
||||
let logDebugInfo = config[Constants.configLogDebugInfo];
|
||||
if (logDebugInfo === true) {
|
||||
let currentTime = new Date().toLocaleTimeString();
|
||||
let outputMsg = '[' + currentTime + ']: ' + msg ? msg.toString() : '';
|
||||
console.log(outputMsg);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the active text editor if there's one
|
||||
export function getActiveTextEditor(): vscode.TextEditor {
|
||||
let editor = undefined;
|
||||
if (vscode.window && vscode.window.activeTextEditor) {
|
||||
editor = vscode.window.activeTextEditor;
|
||||
}
|
||||
return editor;
|
||||
}
|
||||
// Helper to show an error message
|
||||
export function showErrorMsg(msg: string, extensionName: string): void {
|
||||
vscode.window.showErrorMessage(extensionName + ': ' + msg);
|
||||
}
|
||||
|
||||
// Retrieve the URI for the currently open file if there is one; otherwise return the empty string
|
||||
export function getActiveTextEditorUri(): string {
|
||||
if (typeof vscode.window.activeTextEditor !== 'undefined' &&
|
||||
typeof vscode.window.activeTextEditor.document !== 'undefined') {
|
||||
return vscode.window.activeTextEditor.document.uri.toString();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
export function isEmpty(str: any): boolean {
|
||||
return (!str || '' === str);
|
||||
}
|
||||
|
||||
// Helper to log messages to output channel
|
||||
export function logToOutputChannel(msg: any, outputChannelName: string): void {
|
||||
let outputChannel = vscode.window.createOutputChannel(outputChannelName);
|
||||
outputChannel.show();
|
||||
if (msg instanceof Array) {
|
||||
msg.forEach(element => {
|
||||
outputChannel.appendLine(element.toString());
|
||||
});
|
||||
} else {
|
||||
outputChannel.appendLine(msg.toString());
|
||||
}
|
||||
}
|
||||
// The function is a duplicate of \src\paths.js. IT would be better to import path.js but it doesn't
|
||||
// work for now because the extension is running in different process.
|
||||
export function getAppDataPath() {
|
||||
var platform = process.platform;
|
||||
switch (platform) {
|
||||
case 'win32': return process.env['APPDATA'] || path.join(process.env['USERPROFILE'], 'AppData', 'Roaming');
|
||||
case 'darwin': return path.join(os.homedir(), 'Library', 'Application Support');
|
||||
case 'linux': return process.env['XDG_CONFIG_HOME'] || path.join(os.homedir(), '.config');
|
||||
default: throw new Error('Platform not supported');
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to log debug messages
|
||||
export function logDebug(msg: any, extensionConfigSectionName: string): void {
|
||||
let config = vscode.workspace.getConfiguration(extensionConfigSectionName);
|
||||
let logDebugInfo = config[Constants.configLogDebugInfo];
|
||||
if (logDebugInfo === true) {
|
||||
let currentTime = new Date().toLocaleTimeString();
|
||||
let outputMsg = '[' + currentTime + ']: ' + msg ? msg.toString() : '';
|
||||
console.log(outputMsg);
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to show an info message
|
||||
export function showInfoMsg(msg: string, extensionName: string): void {
|
||||
vscode.window.showInformationMessage(extensionName + ': ' + msg );
|
||||
}
|
||||
|
||||
// Helper to show an warn message
|
||||
export function showWarnMsg(msg: string, extensionName: string): void {
|
||||
vscode.window.showWarningMessage(extensionName + ': ' + msg );
|
||||
}
|
||||
|
||||
// Helper to show an error message
|
||||
export function showErrorMsg(msg: string, extensionName: string): void {
|
||||
vscode.window.showErrorMessage(extensionName + ': ' + msg );
|
||||
}
|
||||
|
||||
export function isEmpty(str: any): boolean {
|
||||
return (!str || '' === str);
|
||||
}
|
||||
|
||||
export function isNotEmpty(str: any): boolean {
|
||||
return <boolean>(str && '' !== str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a string. Behaves like C#'s string.Format() function.
|
||||
*/
|
||||
export function formatString(str: string, ...args: any[]): string {
|
||||
// This is based on code originally from https://github.com/Microsoft/vscode/blob/master/src/vs/nls.js
|
||||
// License: https://github.com/Microsoft/vscode/blob/master/LICENSE.txt
|
||||
let result: string;
|
||||
if (args.length === 0) {
|
||||
result = str;
|
||||
} else {
|
||||
result = str.replace(/\{(\d+)\}/g, (match, rest) => {
|
||||
let index = rest[0];
|
||||
return typeof args[index] !== 'undefined' ? args[index] : match;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a file exists on disk
|
||||
*/
|
||||
export function isFileExisting(filePath: string): boolean {
|
||||
try {
|
||||
fs.statSync(filePath);
|
||||
return true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a string in the format of HH:MM:SS.MS and returns a number representing the time in
|
||||
* miliseconds
|
||||
* @param value The string to convert to milliseconds
|
||||
* @return False is returned if the string is an invalid format,
|
||||
* the number of milliseconds in the time string is returned otherwise.
|
||||
*/
|
||||
export function parseTimeString(value: string): number | boolean {
|
||||
if (!value) {
|
||||
return false;
|
||||
}
|
||||
let tempVal = value.split('.');
|
||||
|
||||
if (tempVal.length !== 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let ms = parseInt(tempVal[1].substring(0, 3), 10);
|
||||
tempVal = tempVal[0].split(':');
|
||||
|
||||
if (tempVal.length !== 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let h = parseInt(tempVal[0], 10);
|
||||
let m = parseInt(tempVal[1], 10);
|
||||
let s = parseInt(tempVal[2], 10);
|
||||
|
||||
return ms + (h * msInH) + (m * msInM) + (s * msInS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a number of milliseconds and converts it to a string like HH:MM:SS.fff
|
||||
* @param value The number of milliseconds to convert to a timespan string
|
||||
* @returns A properly formatted timespan string.
|
||||
*/
|
||||
export function parseNumAsTimeString(value: number): string {
|
||||
let tempVal = value;
|
||||
let h = Math.floor(tempVal / msInH);
|
||||
tempVal %= msInH;
|
||||
let m = Math.floor(tempVal / msInM);
|
||||
tempVal %= msInM;
|
||||
let s = Math.floor(tempVal / msInS);
|
||||
tempVal %= msInS;
|
||||
|
||||
let hs = h < 10 ? '0' + h : '' + h;
|
||||
let ms = m < 10 ? '0' + m : '' + m;
|
||||
let ss = s < 10 ? '0' + s : '' + s;
|
||||
let mss = tempVal < 10 ? '00' + tempVal : tempVal < 100 ? '0' + tempVal : '' + tempVal;
|
||||
|
||||
let rs = hs + ':' + ms + ':' + ss;
|
||||
|
||||
return tempVal > 0 ? rs + '.' + mss : rs;
|
||||
}
|
||||
|
||||
|
||||
// The function is a duplicate of \src\paths.js. IT would be better to import path.js but it doesn't
|
||||
// work for now because the extension is running in different process.
|
||||
export function getAppDataPath() {
|
||||
var platform = process.platform;
|
||||
switch (platform) {
|
||||
case 'win32': return process.env['APPDATA'] || path.join(process.env['USERPROFILE'], 'AppData', 'Roaming');
|
||||
case 'darwin': return path.join(os.homedir(), 'Library', 'Application Support');
|
||||
case 'linux': return process.env['XDG_CONFIG_HOME'] || path.join(os.homedir(), '.config');
|
||||
default: throw new Error('Platform not supported');
|
||||
export function getDefaultLogLocation() {
|
||||
return path.join(getAppDataPath(), 'sqlops');
|
||||
}
|
||||
}
|
||||
export function getDefaultLogLocation() {
|
||||
return path.join(getAppDataPath(), 'sqlops');
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
export default require('error-ex')('EscapeException');
|
||||
@@ -1,3 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
export default require('error-ex')('ValidationException');
|
||||
@@ -1,142 +1,146 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import vscode = require('vscode');
|
||||
import * as Utils from '../models/utils';
|
||||
import { Utils } from '../models/utils';
|
||||
|
||||
// Status bar element for each file in the editor
|
||||
class FileStatusBar {
|
||||
// Item for the connection status
|
||||
public statusConnection: vscode.StatusBarItem;
|
||||
// Item for the connection status
|
||||
public statusConnection: vscode.StatusBarItem;
|
||||
|
||||
// Item for the query status
|
||||
public statusQuery: vscode.StatusBarItem;
|
||||
// Item for the query status
|
||||
public statusQuery: vscode.StatusBarItem;
|
||||
|
||||
// Item for language service status
|
||||
public statusLanguageService: vscode.StatusBarItem;
|
||||
// Item for language service status
|
||||
public statusLanguageService: vscode.StatusBarItem;
|
||||
|
||||
// Timer used for displaying a progress indicator on queries
|
||||
public progressTimerId: NodeJS.Timer;
|
||||
// Timer used for displaying a progress indicator on queries
|
||||
public progressTimerId: NodeJS.Timer;
|
||||
|
||||
public currentLanguageServiceStatus: string;
|
||||
public currentLanguageServiceStatus: string;
|
||||
}
|
||||
|
||||
export default class StatusView implements vscode.Disposable {
|
||||
private _statusBars: { [fileUri: string]: FileStatusBar };
|
||||
private _lastShownStatusBar: FileStatusBar;
|
||||
private _statusBars: { [fileUri: string]: FileStatusBar };
|
||||
private _lastShownStatusBar: FileStatusBar;
|
||||
|
||||
constructor() {
|
||||
this._statusBars = {};
|
||||
vscode.window.onDidChangeActiveTextEditor((params) => this.onDidChangeActiveTextEditor(params));
|
||||
vscode.workspace.onDidCloseTextDocument((params) => this.onDidCloseTextDocument(params));
|
||||
}
|
||||
constructor() {
|
||||
this._statusBars = {};
|
||||
vscode.window.onDidChangeActiveTextEditor((params) => this.onDidChangeActiveTextEditor(params));
|
||||
vscode.workspace.onDidCloseTextDocument((params) => this.onDidCloseTextDocument(params));
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
for (let bar in this._statusBars) {
|
||||
if (this._statusBars.hasOwnProperty(bar)) {
|
||||
this._statusBars[bar].statusConnection.dispose();
|
||||
this._statusBars[bar].statusQuery.dispose();
|
||||
this._statusBars[bar].statusLanguageService.dispose();
|
||||
clearInterval(this._statusBars[bar].progressTimerId);
|
||||
delete this._statusBars[bar];
|
||||
}
|
||||
}
|
||||
}
|
||||
dispose(): void {
|
||||
for (let bar in this._statusBars) {
|
||||
if (this._statusBars.hasOwnProperty(bar)) {
|
||||
this._statusBars[bar].statusConnection.dispose();
|
||||
this._statusBars[bar].statusQuery.dispose();
|
||||
this._statusBars[bar].statusLanguageService.dispose();
|
||||
clearInterval(this._statusBars[bar].progressTimerId);
|
||||
delete this._statusBars[bar];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create status bar item if needed
|
||||
private createStatusBar(fileUri: string): void {
|
||||
let bar = new FileStatusBar();
|
||||
bar.statusConnection = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
|
||||
bar.statusQuery = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
|
||||
bar.statusLanguageService = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
|
||||
this._statusBars[fileUri] = bar;
|
||||
}
|
||||
// Create status bar item if needed
|
||||
private createStatusBar(fileUri: string): void {
|
||||
let bar = new FileStatusBar();
|
||||
bar.statusConnection = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
|
||||
bar.statusQuery = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
|
||||
bar.statusLanguageService = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
|
||||
this._statusBars[fileUri] = bar;
|
||||
}
|
||||
|
||||
private destroyStatusBar(fileUri: string): void {
|
||||
let bar = this._statusBars[fileUri];
|
||||
if (bar) {
|
||||
if (bar.statusConnection) {
|
||||
bar.statusConnection.dispose();
|
||||
}
|
||||
if (bar.statusQuery) {
|
||||
bar.statusQuery.dispose();
|
||||
}
|
||||
if (bar.statusLanguageService) {
|
||||
bar.statusLanguageService.dispose();
|
||||
}
|
||||
if (bar.progressTimerId) {
|
||||
clearInterval(bar.progressTimerId);
|
||||
}
|
||||
private destroyStatusBar(fileUri: string): void {
|
||||
let bar = this._statusBars[fileUri];
|
||||
if (bar) {
|
||||
if (bar.statusConnection) {
|
||||
bar.statusConnection.dispose();
|
||||
}
|
||||
if (bar.statusQuery) {
|
||||
bar.statusQuery.dispose();
|
||||
}
|
||||
if (bar.statusLanguageService) {
|
||||
bar.statusLanguageService.dispose();
|
||||
}
|
||||
if (bar.progressTimerId) {
|
||||
clearInterval(bar.progressTimerId);
|
||||
}
|
||||
|
||||
delete this._statusBars[fileUri];
|
||||
}
|
||||
}
|
||||
delete this._statusBars[fileUri];
|
||||
}
|
||||
}
|
||||
|
||||
private getStatusBar(fileUri: string): FileStatusBar {
|
||||
if (!(fileUri in this._statusBars)) {
|
||||
// Create it if it does not exist
|
||||
this.createStatusBar(fileUri);
|
||||
}
|
||||
private getStatusBar(fileUri: string): FileStatusBar {
|
||||
if (!(fileUri in this._statusBars)) {
|
||||
// Create it if it does not exist
|
||||
this.createStatusBar(fileUri);
|
||||
}
|
||||
|
||||
let bar = this._statusBars[fileUri];
|
||||
if (bar.progressTimerId) {
|
||||
clearInterval(bar.progressTimerId);
|
||||
}
|
||||
return bar;
|
||||
}
|
||||
let bar = this._statusBars[fileUri];
|
||||
if (bar.progressTimerId) {
|
||||
clearInterval(bar.progressTimerId);
|
||||
}
|
||||
return bar;
|
||||
}
|
||||
|
||||
public languageServiceStatusChanged(fileUri: string, status: string): void {
|
||||
let bar = this.getStatusBar(fileUri);
|
||||
bar.currentLanguageServiceStatus = status;
|
||||
this.updateStatusMessage(status,
|
||||
() => { return bar.currentLanguageServiceStatus; }, (message) => {
|
||||
bar.statusLanguageService.text = message;
|
||||
this.showStatusBarItem(fileUri, bar.statusLanguageService);
|
||||
});
|
||||
}
|
||||
public languageServiceStatusChanged(fileUri: string, status: string): void {
|
||||
let bar = this.getStatusBar(fileUri);
|
||||
bar.currentLanguageServiceStatus = status;
|
||||
this.updateStatusMessage(status,
|
||||
() => { return bar.currentLanguageServiceStatus; }, (message) => {
|
||||
bar.statusLanguageService.text = message;
|
||||
this.showStatusBarItem(fileUri, bar.statusLanguageService);
|
||||
});
|
||||
}
|
||||
|
||||
public updateStatusMessage(
|
||||
newStatus: string,
|
||||
getCurrentStatus: () => string,
|
||||
updateMessage: (message: string) => void): void {
|
||||
}
|
||||
public updateStatusMessage(
|
||||
newStatus: string,
|
||||
getCurrentStatus: () => string,
|
||||
updateMessage: (message: string) => void): void {
|
||||
}
|
||||
|
||||
private hideLastShownStatusBar(): void {
|
||||
if (typeof this._lastShownStatusBar !== 'undefined') {
|
||||
this._lastShownStatusBar.statusConnection.hide();
|
||||
this._lastShownStatusBar.statusQuery.hide();
|
||||
this._lastShownStatusBar.statusLanguageService.hide();
|
||||
}
|
||||
}
|
||||
private hideLastShownStatusBar(): void {
|
||||
if (typeof this._lastShownStatusBar !== 'undefined') {
|
||||
this._lastShownStatusBar.statusConnection.hide();
|
||||
this._lastShownStatusBar.statusQuery.hide();
|
||||
this._lastShownStatusBar.statusLanguageService.hide();
|
||||
}
|
||||
}
|
||||
|
||||
private onDidChangeActiveTextEditor(editor: vscode.TextEditor): void {
|
||||
// Hide the most recently shown status bar
|
||||
this.hideLastShownStatusBar();
|
||||
private onDidChangeActiveTextEditor(editor: vscode.TextEditor): void {
|
||||
// Hide the most recently shown status bar
|
||||
this.hideLastShownStatusBar();
|
||||
|
||||
// Change the status bar to match the open file
|
||||
if (typeof editor !== 'undefined') {
|
||||
const fileUri = editor.document.uri.toString();
|
||||
const bar = this._statusBars[fileUri];
|
||||
if (bar) {
|
||||
this.showStatusBarItem(fileUri, bar.statusConnection);
|
||||
this.showStatusBarItem(fileUri, bar.statusLanguageService);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Change the status bar to match the open file
|
||||
if (typeof editor !== 'undefined') {
|
||||
const fileUri = editor.document.uri.toString();
|
||||
const bar = this._statusBars[fileUri];
|
||||
if (bar) {
|
||||
this.showStatusBarItem(fileUri, bar.statusConnection);
|
||||
this.showStatusBarItem(fileUri, bar.statusLanguageService);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private onDidCloseTextDocument(doc: vscode.TextDocument): void {
|
||||
// Remove the status bar associated with the document
|
||||
this.destroyStatusBar(doc.uri.toString());
|
||||
}
|
||||
private onDidCloseTextDocument(doc: vscode.TextDocument): void {
|
||||
// Remove the status bar associated with the document
|
||||
this.destroyStatusBar(doc.uri.toString());
|
||||
}
|
||||
|
||||
private showStatusBarItem(fileUri: string, statusBarItem: vscode.StatusBarItem): void {
|
||||
let currentOpenFile = Utils.getActiveTextEditorUri();
|
||||
private showStatusBarItem(fileUri: string, statusBarItem: vscode.StatusBarItem): void {
|
||||
let currentOpenFile = Utils.getActiveTextEditorUri();
|
||||
|
||||
// Only show the status bar if it matches the currently open file and is not empty
|
||||
if (fileUri === currentOpenFile && !Utils.isEmpty(statusBarItem.text) ) {
|
||||
statusBarItem.show();
|
||||
if (fileUri in this._statusBars) {
|
||||
this._lastShownStatusBar = this._statusBars[fileUri];
|
||||
}
|
||||
} else {
|
||||
statusBarItem.hide();
|
||||
}
|
||||
}
|
||||
// Only show the status bar if it matches the currently open file and is not empty
|
||||
if (fileUri === currentOpenFile && !Utils.isEmpty(statusBarItem.text)) {
|
||||
statusBarItem.show();
|
||||
if (fileUri in this._statusBars) {
|
||||
this._lastShownStatusBar = this._statusBars[fileUri];
|
||||
}
|
||||
} else {
|
||||
statusBarItem.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user