Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: misc aura/lwc lsp bug fixes, support lwc component methods in tree, unknown project types #1232

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/salesforcedx-vscode-lightning/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
],
"dependencies": {
"@salesforce/salesforcedx-utils-vscode": "45.9.0",
"@types/which": "^1.3.1",
"aura-language-server": "2.0.11",
"change-case": "^3.1.0",
"lightning-lsp-common": "2.0.11",
Expand All @@ -44,11 +45,9 @@
"mocha": "3.2.0",
"sinon": "^2.3.6",
"typescript": "3.1.6",
"vscode": "1.1.17"
"vscode": "1.1.17",
"which": "^1.3.1"
},
"extensionDependencies": [
"salesforce.salesforcedx-vscode-core"
],
"scripts": {
"vscode:prepublish": "npm prune --production",
"vscode:package": "vsce package",
Expand All @@ -65,7 +64,8 @@
},
"activationEvents": [
"workspaceContains:sfdx-project.json",
"workspaceContains:**/core/workspace-user.xml"
"workspaceContains:**/core/workspace-user.xml",
"onView:salesforce-lightning-components"
],
"main": "./out/src",
"contributes": {
Expand Down
10 changes: 10 additions & 0 deletions packages/salesforcedx-vscode-lightning/resources/method.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2019, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as vscode from 'vscode';

let wait: Promise<vscode.Extension<any>>;

export async function waitForDX(activate: boolean = false) {
if (!wait) {
wait = new Promise((resolve, reject) => {
// 120 seconds from now
const expires = new Date().getTime() + 1000 * 120;
const dosetup = () => {
let success = false;
try {
const coreDependency = vscode.extensions.getExtension(
'salesforce.salesforcedx-vscode-core'
);
if (coreDependency && !coreDependency.isActive && activate) {
return coreDependency.activate().then(api => {
resolve(
vscode.extensions.getExtension(
'salesforce.salesforcedx-vscode-core'
)
);
});
}
if (coreDependency && coreDependency.exports) {
success = true;
resolve(coreDependency);
}
} catch (ignore) {
// ignore
}
if (!success) {
if (new Date().getTime() > expires) {
const msg =
'salesforce.salesforcedx-vscode-core not installed or activated, some features unavailable';
console.log(msg);
reject(msg);
} else {
setTimeout(dosetup, 100);
}
}
};
setTimeout(dosetup, 100);
});
}
return wait;
}
45 changes: 27 additions & 18 deletions packages/salesforcedx-vscode-lightning/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { shared } from 'lightning-lsp-common';
import * as path from 'path';
import {
commands,
Expand All @@ -26,6 +27,12 @@ import { nls } from './messages';
import { telemetryService } from './telemetry';
import { ComponentTreeProvider } from './views/component-tree-provider';

import {
detectWorkspaceType,
WorkspaceType
} from 'lightning-lsp-common/lib/shared';
import { sync as which } from 'which';

let client: LanguageClient;

// See https://github.com/Microsoft/vscode-languageserver-node/issues/105
Expand All @@ -52,11 +59,14 @@ export async function activate(context: ExtensionContext) {
);

// The debug options for the server
const debugOptions = { execArgv: ['--nolazy', '--inspect=6020'] };
const debugOptions = {
execArgv: ['--nolazy', '--inspect=6020']
};
// let debugOptions = { };

// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used

const serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: {
Expand All @@ -65,6 +75,11 @@ export async function activate(context: ExtensionContext) {
options: debugOptions
}
};
const node = which('node', { nothrow: true });
if (node) {
serverOptions.run.runtime = node;
serverOptions.debug.runtime = node;
}

const clientOptions: LanguageClientOptions = {
outputChannelName: nls.localize('channel_name'),
Expand Down Expand Up @@ -122,7 +137,15 @@ export async function activate(context: ExtensionContext) {
createQuickOpenCommand(client)
)
);
const componentProvider = new ComponentTreeProvider(client, context);
const workspaceType: WorkspaceType = detectWorkspaceType(
workspace.workspaceFolders[0].uri.fsPath
);

const componentProvider = new ComponentTreeProvider(
client,
context,
workspaceType
);
window.registerTreeDataProvider(
'salesforce-lightning-components',
componentProvider
Expand All @@ -140,21 +163,7 @@ export async function activate(context: ExtensionContext) {
client.start();
context.subscriptions.push(this.client);

const sfdxCoreExtension = extensions.getExtension(
'salesforce.salesforcedx-vscode-core'
);

// Telemetry
if (sfdxCoreExtension && sfdxCoreExtension.exports) {
sfdxCoreExtension.exports.telemetryService.showTelemetryMessage();

telemetryService.initializeService(
sfdxCoreExtension.exports.telemetryService.getReporter(),
sfdxCoreExtension.exports.telemetryService.isTelemetryEnabled()
);
}

telemetryService.sendExtensionActivationEvent(extensionHRStart);
telemetryService.sendExtensionActivationEvent(extensionHRStart).catch();
}

let indexingResolve: any;
Expand Down Expand Up @@ -185,5 +194,5 @@ function reportIndexing(indexingPromise: Promise<void>) {

export function deactivate() {
console.log('Aura Components Extension Deactivated');
telemetryService.sendExtensionDeactivationEvent();
telemetryService.sendExtensionDeactivationEvent().catch();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
*/

import * as util from 'util';
import * as vscode from 'vscode';
import TelemetryReporter from 'vscode-extension-telemetry';
import { telemetryService } from '.';
import { waitForDX } from '../dxsupport/waitForDX';

const EXTENSION_NAME = 'salesforcedx-vscode-lightning';

export class TelemetryService {
private static instance: TelemetryService;
private reporter: TelemetryReporter | undefined;
private isTelemetryEnabled: boolean;
private setup: Promise<TelemetryService | undefined> | undefined;

constructor() {
this.isTelemetryEnabled = false;
Expand All @@ -26,6 +30,29 @@ export class TelemetryService {
return TelemetryService.instance;
}

public async setupVSCodeTelemetry() {
// if its already set up
if (this.reporter) {
return Promise.resolve(telemetryService);
}
if (!this.setup) {
this.setup = waitForDX(true)
.then((coreDependency: vscode.Extension<any>) => {
coreDependency.exports.telemetryService.showTelemetryMessage();

telemetryService.initializeService(
coreDependency.exports.telemetryService.getReporter(),
coreDependency.exports.telemetryService.isTelemetryEnabled()
);
return telemetryService;
})
.catch(err => {
return undefined;
});
}
return this.setup;
}

public initializeService(
reporter: TelemetryReporter,
isTelemetryEnabled: boolean
Expand All @@ -34,7 +61,10 @@ export class TelemetryService {
this.reporter = reporter;
}

public sendExtensionActivationEvent(hrstart: [number, number]): void {
public async sendExtensionActivationEvent(
hrstart: [number, number]
): Promise<void> {
await this.setupVSCodeTelemetry();
if (this.reporter !== undefined && this.isTelemetryEnabled) {
const startupTime = this.getEndHRTime(hrstart);
this.reporter.sendTelemetryEvent('activationEvent', {
Expand All @@ -44,14 +74,25 @@ export class TelemetryService {
}
}

public sendExtensionDeactivationEvent(): void {
public async sendExtensionDeactivationEvent(): Promise<void> {
await this.setupVSCodeTelemetry();
if (this.reporter !== undefined && this.isTelemetryEnabled) {
this.reporter.sendTelemetryEvent('deactivationEvent', {
extensionName: EXTENSION_NAME
});
}
}

public async sendCommandEvent(commandName?: string): Promise<void> {
await this.setupVSCodeTelemetry();
if (this.reporter !== undefined && this.isTelemetryEnabled && commandName) {
this.reporter.sendTelemetryEvent('commandExecution', {
extensionName: EXTENSION_NAME,
commandName
});
}
}

private getEndHRTime(hrstart: [number, number]): string {
const hrend = process.hrtime(hrstart);
return util.format('%d%d', hrend[0], hrend[1] / 1000000);
Expand Down
Loading