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: export to language actions appear for regular playground results VSCODE-334 #434

Merged
Merged
154 changes: 151 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/editors/exportToLanguageCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export default class ExportToLanguageCodeLensProvider
const buildersCodeLens = this.createCodeLens();
const exportToLanguageCodeLenses: vscode.CodeLens[] = [];

if (['json', 'plaintext'].includes(this._exportToLanguageAddons.language)) {
return [];
}

importStatementsCodeLens.command = {
title: this._exportToLanguageAddons.importStatements
? 'Exclude Import Statements'
Expand Down
5 changes: 5 additions & 0 deletions src/editors/playgroundController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ export default class PlaygroundController {
this._playgroundResultTextDocument,
language
);

this._exportToLanguageCodeLensProvider.refresh({
...this._exportToLanguageCodeLensProvider._exportToLanguageAddons,
language,
});
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/test/suite/connectionController.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as sinon from 'sinon';
import * as util from 'util';
import * as vscode from 'vscode';
import { afterEach, beforeEach } from 'mocha';
import { afterEach, beforeEach, before } from 'mocha';
import assert from 'assert';
import { connect } from 'mongodb-data-service';

Expand Down Expand Up @@ -51,6 +51,18 @@ suite('Connection Controller Test Suite', function () {
testTelemetryService
);

before(async () => {
// Disable the dialogue for prompting the user where to store the connection.
const connectionSaving = vscode.workspace.getConfiguration(
'mdb.connectionSaving'
);
await connectionSaving.update(
'hideOptionToChooseWhereToSaveNewConnections',
true,
vscode.ConfigurationTarget.Global
);
});

alenakhineika marked this conversation as resolved.
Show resolved Hide resolved
beforeEach(() => {
// Here we stub the showInformationMessage process because it is too much
// for the render process and leads to crashes while testing.
Expand Down
26 changes: 26 additions & 0 deletions src/test/suite/editors/exportToLanguageCodeLensProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,30 @@ suite('Export To Language Code Lens Provider Test Suite', function () {

expect(codeLenses.length).to.be.equal(2);
});

test('does not render code lenses for json text', () => {
testExportToLanguageCodeLensProvider.refresh({
...defaults,
builders: true,
mode: ExportToLanguageMode.OTHER,
language: 'json',
});

const codeLenses = testExportToLanguageCodeLensProvider.provideCodeLenses();

expect(codeLenses.length).to.be.equal(0);
});

test('does not render code lenses for plain text text', () => {
testExportToLanguageCodeLensProvider.refresh({
...defaults,
builders: true,
mode: ExportToLanguageMode.OTHER,
language: 'plaintext',
});

const codeLenses = testExportToLanguageCodeLensProvider.provideCodeLenses();

expect(codeLenses.length).to.be.equal(0);
});
});
35 changes: 14 additions & 21 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Mocha from 'mocha';
import glob from 'glob';
import * as vscode from 'vscode';
import path = require('path');
import MDBExtensionController from '../../mdbExtensionController';
import { ext } from '../../extensionConstants';
Expand Down Expand Up @@ -51,28 +50,22 @@ export async function run(): Promise<void> {
// headless linux.
ext.keytarModule = new KeytarStub();

// Disable the dialogue for prompting the user where to store the connection.
void vscode.workspace
.getConfiguration('mdb.connectionSaving')
.update('hideOptionToChooseWhereToSaveNewConnections', true)
.then(() => {
// Add files to the test suite.
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));
try {
// Run the mocha test.
mocha.run((failures) => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (mochaRunErr) {
console.error('Error running mocha tests:');
console.error(mochaRunErr);
e(mochaRunErr);
// Add files to the test suite.
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));
try {
// Run the mocha test.
mocha.run((failures) => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (mochaRunErr) {
console.error('Error running mocha tests:');
console.error(mochaRunErr);
e(mochaRunErr);
}
}
);
});
Expand Down