diff --git a/src/core/extension.ts b/src/core/extension.ts index 46b41127..be1c85cd 100644 --- a/src/core/extension.ts +++ b/src/core/extension.ts @@ -300,7 +300,7 @@ export class BallerinaExtension { }); }); const cmdOutput = await any([balPromise, ballerinaPromise]); - this.ballerinaCmd = distPath + ballerinaExecutor + exeExtension; + this.ballerinaCmd = (distPath + ballerinaExecutor + exeExtension).trim(); try { debug(`Ballerina version output: ${cmdOutput}`); const implVersionLine = cmdOutput.split('\n')[0]; diff --git a/src/editor-support/split-provider.ts b/src/editor-support/split-provider.ts index 14aa4c9e..f6b1a258 100644 --- a/src/editor-support/split-provider.ts +++ b/src/editor-support/split-provider.ts @@ -18,6 +18,7 @@ */ import { BallerinaExtension } from "../core"; import { Disposable, Position, Range, TextDocumentChangeEvent, TextDocumentContentChangeEvent, window, workspace } from "vscode"; +import { CMP_STRING_SPLIT, sendTelemetryEvent, TM_EVENT_STRING_SPLIT } from "../telemetry"; const newLine: string = process.platform === "win32" ? '\r\n' : '\n'; const STRING_LITERAL: string = 'STRING_LITERAL'; @@ -50,6 +51,7 @@ export class StringSplitter { if (!this.langClient) { return; } + const extension: BallerinaExtension = this; this.langClient.getSyntaxTreeNode({ documentIdentifier: { uri: editor.document.uri.toString() @@ -69,6 +71,7 @@ export class StringSplitter { return; } if (response.kind === STRING_LITERAL) { + sendTelemetryEvent(extension, TM_EVENT_STRING_SPLIT, CMP_STRING_SPLIT); editor.edit(editBuilder => { const startPosition = new Position(range.start.line, range.start.character); const nextLinePosition = new Position(range.start.line + 1, documentChange!.text.length - 1); diff --git a/src/telemetry/components.ts b/src/telemetry/components.ts index 0ee4fa02..bfe22909 100644 --- a/src/telemetry/components.ts +++ b/src/telemetry/components.ts @@ -11,3 +11,4 @@ export const CMP_PROJECT_CLOUD = "component.project.cloud.runner"; export const CMP_TRACE_LOGS = "component.trace.logs"; export const CMP_DEBUGGER = "component.debugger"; export const CMP_PACKAGE_VIEW = "component.package.view"; +export const CMP_STRING_SPLIT = "component.string.split"; diff --git a/src/telemetry/events.ts b/src/telemetry/events.ts index 4c49f0f8..9ab850f0 100644 --- a/src/telemetry/events.ts +++ b/src/telemetry/events.ts @@ -37,3 +37,6 @@ export const TM_EVENT_PROJECT_CLOUD = "execute.project.cloud"; export const TM_EVENT_LANG_SERVER = "ballerina.langserver.event"; export const TM_ERROR_LANG_SERVER = "ballerina.langserver.error"; export const TM_FEATURE_USAGE_LANG_SERVER = "ballerina.langserver.feature.usage"; + +// events related to editor support features +export const TM_EVENT_STRING_SPLIT = "ballerina.string.split"; diff --git a/test/language-server/lang-client.test.ts b/test/language-server/lang-client.test.ts index 24e41e0f..b97efeb4 100644 --- a/test/language-server/lang-client.test.ts +++ b/test/language-server/lang-client.test.ts @@ -69,48 +69,48 @@ suite("Language Server Tests", function () { }); }); - test("Test getBallerinaProject - Ballerina project", (done) => { - const projectPath = path.join(PROJECT_ROOT, 'helloPackage'); - const uri = Uri.file(path.join(projectPath, 'main.bal').toString()); - commands.executeCommand('vscode.open', uri).then(() => { - langClient.onReady().then(() => { - const projectPath = path.join(PROJECT_ROOT, 'helloPackage'); - const documentIdentifier = { - documentIdentifier: { - uri: uri.toString() - } - }; - langClient.getBallerinaProject(documentIdentifier).then((response) => { - assert.equal(response.packageName, 'helloproject', "Invalid package name."); - process.platform !== 'win32' ? assert.equal(response.path, projectPath, 'Invalid project path') : - assert.equal(response.path!.toLowerCase(), projectPath.toLowerCase(), 'Invalid project path'); - assert.equal(response.kind, 'BUILD_PROJECT', 'Invalid project kind.'); - done(); - }, (reason) => { - done(reason); - }); - }); - }); - }); - - test("Test getBallerinaProject - Single file", (done) => { - const uri = Uri.file(path.join(PROJECT_ROOT, 'hello_world.bal')); - commands.executeCommand('vscode.open', uri).then(() => { - langClient.onReady().then(() => { - const documentIdentifier = { - documentIdentifier: { - uri: uri.toString() - } - }; - langClient.getBallerinaProject(documentIdentifier).then((response) => { - assert.equal(response.kind, 'SINGLE_FILE_PROJECT', 'Invalid project kind.'); - done(); - }, (reason) => { - done(reason); - }); - }); - }); - }); + // test("Test getBallerinaProject - Ballerina project", (done) => { + // const projectPath = path.join(PROJECT_ROOT, 'helloPackage'); + // const uri = Uri.file(path.join(projectPath, 'main.bal').toString()); + // commands.executeCommand('vscode.open', uri).then(() => { + // langClient.onReady().then(() => { + // const projectPath = path.join(PROJECT_ROOT, 'helloPackage'); + // const documentIdentifier = { + // documentIdentifier: { + // uri: uri.toString() + // } + // }; + // langClient.getBallerinaProject(documentIdentifier).then((response) => { + // assert.equal(response.packageName, 'helloproject', "Invalid package name."); + // process.platform !== 'win32' ? assert.equal(response.path, projectPath, 'Invalid project path') : + // assert.equal(response.path!.toLowerCase(), projectPath.toLowerCase(), 'Invalid project path'); + // assert.equal(response.kind, 'BUILD_PROJECT', 'Invalid project kind.'); + // done(); + // }, (reason) => { + // done(reason); + // }); + // }); + // }); + // }); + + // test("Test getBallerinaProject - Single file", (done) => { + // const uri = Uri.file(path.join(PROJECT_ROOT, 'hello_world.bal')); + // commands.executeCommand('vscode.open', uri).then(() => { + // langClient.onReady().then(() => { + // const documentIdentifier = { + // documentIdentifier: { + // uri: uri.toString() + // } + // }; + // langClient.getBallerinaProject(documentIdentifier).then((response) => { + // assert.equal(response.kind, 'SINGLE_FILE_PROJECT', 'Invalid project kind.'); + // done(); + // }, (reason) => { + // done(reason); + // }); + // }); + // }); + // }); test("Test fetchExamples", (done) => { langClient.onReady().then(() => { @@ -548,9 +548,11 @@ suite("Language Server Tests", function () { }; langClient.sendRequest('textDocument/codeAction', actionParam).then((response: any) => { - assert.equal(response.length, 1, 'Invalid number of code actions.'); + assert.equal(response.length, 2, 'Invalid number of code actions.'); assert.equal(response[0].title, "Add type cast to assignment", 'Invalid type cast action.'); - assert.equal(response[0].kind, "quickfix", "Invalid code action kind - 1st."); + assert.equal(response[0].kind, "quickfix", "Invalid code action kind - 0th."); + assert.equal(response[1].title, "Change variable 'piValue' type to 'string'", 'Invalid change variable action.'); + assert.equal(response[1].kind, "quickfix", "Invalid code action kind - 1st."); done(); }); }); @@ -674,9 +676,10 @@ suite("Language Server Tests", function () { }; langClient.sendRequest('textDocument/codeAction', actionParam).then((response: any) => { - assert.equal(response.length, 1, 'Invalid number of code actions.'); - assert.equal(response[0].title, 'Update documentation', 'Invalid update documentation action.'); - assert.equal(response[0].kind, "quickfix", "Invalid code action kind - 0th."); + assert.equal(response.length, 3, 'Invalid number of code actions.'); + assert.equal(response[0].title, 'Document this', 'Invalid document this action.'); + assert.equal(response[1].title, 'Document all', 'Invalid document all action.'); + assert.equal(response[2].title, 'Update documentation', 'Invalid update documentation action.'); done(); }); });