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

feat: playgrounds in JS VSCODE-372 #482

Merged
merged 33 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bcb63b9
feat: replace mongodb language with javascript in playgrounds
alenakhineika Jan 23, 2023
7441125
feat: use js grammar only
alenakhineika Jan 24, 2023
93fdf8c
feat: save playgrounds as mongodb ext
alenakhineika Feb 2, 2023
4b3c70c
docs: add comment about read-only root
alenakhineika Feb 2, 2023
7864768
refactor: clean up
alenakhineika Feb 2, 2023
be08215
refactor: better handling new files
alenakhineika Feb 3, 2023
5b3cc4f
refactor: drop fragment
alenakhineika Feb 3, 2023
ed9554c
feat: add mongodb grammar injection
alenakhineika Feb 16, 2023
bc1b982
refactor: restore update-grammar script
alenakhineika Feb 20, 2023
f261589
Merge remote-tracking branch 'origin/main' into playgrounds-in-js-lan…
alenakhineika Feb 20, 2023
3a3c520
docs: update contributing page
alenakhineika Feb 20, 2023
4fda3fa
refactor: update-grammar
alenakhineika Feb 20, 2023
2296df8
feat: update mongodb injection grammar
alenakhineika Feb 20, 2023
c924b69
test: update for playgrounds in js
alenakhineika Feb 20, 2023
a86e0ff
refactor: reformat
alenakhineika Feb 20, 2023
084bfd9
refactor: restore snippets
alenakhineika Feb 20, 2023
1a009ed
refactor: clean up
alenakhineika Feb 20, 2023
989675f
build: bump vscode engine
alenakhineika Feb 21, 2023
97c3cb2
build: clean up dependencies
alenakhineika Feb 21, 2023
5fd5077
refactor: reforamt
alenakhineika Feb 21, 2023
ee55d53
build: try with prev npm
alenakhineika Feb 21, 2023
a120824
build: try old deps
alenakhineika Feb 21, 2023
ad04e91
refactor: reformat
alenakhineika Feb 21, 2023
dd64167
test: use activeTextEditor from the playground controller
alenakhineika Feb 21, 2023
414c3a7
refactor: os homedir
alenakhineika Feb 24, 2023
8d77ef3
refactor: clean up
alenakhineika Feb 27, 2023
9f4f808
refactor: address pr comments
alenakhineika Feb 27, 2023
c8d59c9
test: try bigger timeout
alenakhineika Feb 27, 2023
1a09308
Merge remote-tracking branch 'origin/main' into playgrounds-in-js-lan…
alenakhineika Feb 27, 2023
d04bab4
test: less playground documents open
alenakhineika Feb 27, 2023
6c849d9
test: clean up
alenakhineika Feb 28, 2023
23f3e85
test: assert.strictEqual
alenakhineika Feb 28, 2023
f8b7326
test: mock text flaky text document
alenakhineika Feb 28, 2023
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
24 changes: 14 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@
{
"command": "mdb.runPlayground",
"group": "navigation",
"when": "mdb.showRunPlaygroundButton == true"
"when": "mdb.isPlayground == true"
}
],
"commandPalette": [
Expand All @@ -636,27 +636,31 @@
},
{
"command": "mdb.runSelectedPlaygroundBlocks",
"when": "mdb.showRunPlaygroundButton == true"
"when": "mdb.isPlayground == true"
},
{
"command": "mdb.runAllPlaygroundBlocks",
"when": "mdb.showRunPlaygroundButton == true"
"when": "mdb.isPlayground == true"
},
{
"command": "mdb.exportToRuby",
"when": "mdb.isPlayground == true"
},
{
"command": "mdb.exportToPython",
"when": "mdb.showRunPlaygroundButton == true"
"when": "mdb.isPlayground == true"
},
{
"command": "mdb.exportToJava",
"when": "mdb.showRunPlaygroundButton == true"
"when": "mdb.isPlayground == true"
},
{
"command": "mdb.exportToCsharp",
"when": "mdb.showRunPlaygroundButton == true"
"when": "mdb.isPlayground == true"
},
{
"command": "mdb.exportToNode",
"when": "mdb.showRunPlaygroundButton == true"
"when": "mdb.isPlayground == true"
},
{
"command": "mdb.refreshPlaygroundsFromTreeView",
Expand Down Expand Up @@ -813,19 +817,19 @@
"command": "mdb.runSelectedPlaygroundBlocks",
"key": "ctrl+alt+s",
"mac": "cmd+alt+s",
"when": "mdb.showRunPlaygroundButton == true"
"when": "mdb.isPlayground == true"
},
{
"command": "mdb.runAllPlaygroundBlocks",
"key": "ctrl+alt+r",
"mac": "cmd+alt+r",
"when": "mdb.showRunPlaygroundButton == true"
"when": "mdb.isPlayground == true"
},
{
"command": "mdb.saveMongoDBDocument",
"key": "ctrl+s",
"mac": "cmd+s",
"when": "editorLangId == json"
"when": "mdb.isPlayground == true"
}
],
"capabilities": {
Expand Down
2 changes: 0 additions & 2 deletions scripts/update-grammar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/env ts-node

import path from 'path';
import mkdirp from 'mkdirp';
import ora from 'ora';
Expand Down
2 changes: 0 additions & 2 deletions scripts/update-snippets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#! /usr/bin/env ts-node
addaleax marked this conversation as resolved.
Show resolved Hide resolved

import path from 'path';
import mkdirp from 'mkdirp';
import ora from 'ora';
Expand Down
20 changes: 6 additions & 14 deletions src/editors/playgroundController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,11 @@ export default class PlaygroundController {
this._playgroundResultTextDocument = editor?.document;
}

if (isPlayground(editor?.document.uri)) {
void vscode.commands.executeCommand(
'setContext',
'mdb.showRunPlaygroundButton',
true
);
} else {
void vscode.commands.executeCommand(
'setContext',
'mdb.showRunPlaygroundButton',
false
);
}
void vscode.commands.executeCommand(
'setContext',
'mdb.isPlayground',
isPlayground(editor?.document.uri)
);

if (editor?.document.languageId !== 'Log') {
this._activeTextEditor = editor;
Expand Down Expand Up @@ -276,7 +268,7 @@ export default class PlaygroundController {
try {
// The MacOS default folder for saving files is a read-only root (/) directory,
// therefore we explicitly specify the workspace folder path
// or OS temp directory if a user has not opened workspaces.
// or OS home directory if a user has not opened workspaces.
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
const filePath = workspaceFolder?.uri.fsPath || os.homedir();
addaleax marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ suite('Active Connection CodeLens Provider Test Suite', () => {
suite('the MongoDB playground in JS', () => {
beforeEach(async () => {
const fileName = path.join(
os.tmpdir(),
os.homedir(),
`playground-${uuidv4()}.mongodb.js`
);
const documentUri = vscode.Uri.from({
Expand Down Expand Up @@ -138,7 +138,7 @@ suite('Active Connection CodeLens Provider Test Suite', () => {

suite('the regular JS file', () => {
beforeEach(async () => {
const fileName = path.join(os.tmpdir(), `regular-file-${uuidv4()}.js`);
const fileName = path.join(os.homedir(), `regular-file-${uuidv4()}.js`);
const documentUri = vscode.Uri.from({
path: fileName,
scheme: 'untitled',
Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/editors/playgroundController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ suite('Playground Controller Test Suite', function () {

suite('playground is open', () => {
const fileName = path.join(
os.tmpdir(),
os.homedir(),
`playground-${uuidv4()}.mongodb.js`
);
const documentUri = vscode.Uri.from({ path: fileName, scheme: 'untitled' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ suite('Playground Selected CodeAction Provider Test Suite', function () {

beforeEach(async () => {
const fileName = path.join(
os.tmpdir(),
os.homedir(),
`playground-${uuidv4()}.mongodb.js`
);
const documentUri = vscode.Uri.from({
Expand Down Expand Up @@ -492,7 +492,7 @@ suite('Playground Selected CodeAction Provider Test Suite', function () {
const testCodeActionProvider = new PlaygroundSelectedCodeActionProvider();

beforeEach(async () => {
const fileName = path.join(os.tmpdir(), `regular-file-${uuidv4()}.js`);
const fileName = path.join(os.homedir(), `regular-file-${uuidv4()}.js`);
alenakhineika marked this conversation as resolved.
Show resolved Hide resolved
const documentUri = vscode.Uri.from({
path: fileName,
scheme: 'untitled',
Expand Down
36 changes: 23 additions & 13 deletions src/test/suite/telemetry/connectionTelemetry.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeEach, afterEach } from 'mocha';
import { connect } from 'mongodb-data-service';
import { before, after, beforeEach, afterEach } from 'mocha';
import { connect, DataServiceImpl } from 'mongodb-data-service';
import { expect } from 'chai';
import sinon from 'sinon';

Expand All @@ -12,20 +12,30 @@ suite('ConnectionTelemetry Controller Test Suite', function () {
this.timeout(8000);

suite('with mock data service', () => {
const mockDataService: any = {
getConnectionString: () => ({
let mockDataService: DataServiceImpl;

before(() => {
mockDataService = new DataServiceImpl({
connectionString: TEST_DATABASE_URI,
});

sinon.stub(mockDataService, 'getConnectionString').returns({
hosts: ['localhost:27018'],
searchParams: { get: () => null },
username: 'authMechanism',
}),
instance: () =>
Promise.resolve({
dataLake: {},
build: {},
genuineMongoDB: {},
host: {},
}),
};
} as unknown as ReturnType<DataServiceImpl['getConnectionString']>);

sinon.stub(mockDataService, 'instance').resolves({
dataLake: {},
build: {},
genuineMongoDB: {},
host: {},
} as unknown as Awaited<ReturnType<DataServiceImpl['instance']>>);
});

after(() => {
sinon.restore();
});
alenakhineika marked this conversation as resolved.
Show resolved Hide resolved

test('it returns is_used_connect_screen true when the connection type is form', async () => {
const instanceTelemetry = await getConnectionTelemetryProperties(
Expand Down