Skip to content

Commit d0015f2

Browse files
VSCODE-247: Replace code lenses with code actions (#318)
* feat: replace code lenses for partial execution with code actions VSCODE-247 * test: add code action tests * build: patch node gyp on windows * build: equal windows * build: revert * test: add integration test for partial playground execution * test: move timeout to suite * build: patch node gyp on windows with powershell * test: use command from code action
1 parent e63a769 commit d0015f2

13 files changed

+215
-422
lines changed

.github/workflows/test-and-build.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ jobs:
4545
- name: Install npm@7
4646
run: npm install -g npm@7
4747

48+
- name: Patch node gyp on Windows
49+
if: ${{ runner.os == 'Windows' }}
50+
shell: powershell
51+
run: |
52+
npm install --global node-gyp@latest
53+
npm prefix -g | % {npm config set node_gyp "$_\node_modules\node-gyp\bin\node-gyp.js"}
54+
4855
- name: Install Dependencies
4956
run: |
5057
npm ci

package-lock.json

Lines changed: 9 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@
873873
"@mongosh/i18n": "^1.0.4",
874874
"@mongosh/service-provider-server": "^1.0.4",
875875
"@mongosh/shell-api": "^1.0.4",
876-
"analytics-node": "^3.5.0",
876+
"analytics-node": "^5.0.0",
877877
"bson": "^4.4.1",
878878
"classnames": "^2.3.1",
879879
"debug": "^4.3.2",

src/editors/codeActionProvider.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as vscode from 'vscode';
2+
import EXTENSION_COMMANDS from '../commands';
3+
import PlaygroundController from './playgroundController';
4+
5+
export default class CodeActionProvider implements vscode.CodeActionProvider {
6+
_playgroundController: PlaygroundController;
7+
8+
static readonly providedCodeActionKinds = [vscode.CodeActionKind.QuickFix];
9+
10+
constructor(playgroundController: PlaygroundController) {
11+
this._playgroundController = playgroundController;
12+
}
13+
14+
provideCodeActions(): vscode.CodeAction[] | undefined {
15+
if (!this._playgroundController._selectedText) {
16+
return;
17+
}
18+
19+
const commandAction = new vscode.CodeAction('Run selected playground blocks', vscode.CodeActionKind.Empty);
20+
21+
commandAction.command = {
22+
command: EXTENSION_COMMANDS.MDB_RUN_SELECTED_PLAYGROUND_BLOCKS,
23+
title: 'Run selected playground blocks',
24+
tooltip: 'Run selected playground blocks'
25+
};
26+
27+
return [commandAction];
28+
}
29+
}

src/editors/editorsController.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode';
22
import { EJSON } from 'bson';
33

44
import ActiveConnectionCodeLensProvider from './activeConnectionCodeLensProvider';
5+
import CodeActionProvider from './codeActionProvider';
56
import ConnectionController from '../connectionController';
67
import CollectionDocumentsCodeLensProvider from './collectionDocumentsCodeLensProvider';
78
import CollectionDocumentsOperationsStore from './collectionDocumentsOperationsStore';
@@ -22,7 +23,6 @@ import MongoDBDocumentService, {
2223
DOCUMENT_SOURCE_URI_IDENTIFIER,
2324
VIEW_DOCUMENT_SCHEME
2425
} from './mongoDBDocumentService';
25-
import PartialExecutionCodeLensProvider from './partialExecutionCodeLensProvider';
2626
import PlaygroundController from './playgroundController';
2727
import PlaygroundResultProvider, {
2828
PLAYGROUND_RESULT_SCHEME
@@ -37,6 +37,7 @@ const log = createLogger('editors controller');
3737
* new editors and the data they need. It also manages active editors.
3838
*/
3939
export default class EditorsController {
40+
_codeActionProvider: CodeActionProvider;
4041
_connectionController: ConnectionController;
4142
_playgroundController: PlaygroundController;
4243
_collectionDocumentsOperationsStore = new CollectionDocumentsOperationsStore();
@@ -49,7 +50,6 @@ export default class EditorsController {
4950
_telemetryService: TelemetryService;
5051
_playgroundResultViewProvider: PlaygroundResultProvider;
5152
_activeConnectionCodeLensProvider: ActiveConnectionCodeLensProvider;
52-
_partialExecutionCodeLensProvider: PartialExecutionCodeLensProvider;
5353
_editDocumentCodeLensProvider: EditDocumentCodeLensProvider;
5454
_collectionDocumentsCodeLensProvider: CollectionDocumentsCodeLensProvider;
5555

@@ -61,7 +61,7 @@ export default class EditorsController {
6161
telemetryService: TelemetryService,
6262
playgroundResultViewProvider: PlaygroundResultProvider,
6363
activeConnectionCodeLensProvider: ActiveConnectionCodeLensProvider,
64-
partialExecutionCodeLensProvider: PartialExecutionCodeLensProvider,
64+
codeActionProvider: CodeActionProvider,
6565
editDocumentCodeLensProvider: EditDocumentCodeLensProvider
6666
) {
6767
log.info('activating...');
@@ -90,10 +90,10 @@ export default class EditorsController {
9090
);
9191
this._playgroundResultViewProvider = playgroundResultViewProvider;
9292
this._activeConnectionCodeLensProvider = activeConnectionCodeLensProvider;
93-
this._partialExecutionCodeLensProvider = partialExecutionCodeLensProvider;
9493
this._collectionDocumentsCodeLensProvider = new CollectionDocumentsCodeLensProvider(
9594
this._collectionDocumentsOperationsStore
9695
);
96+
this._codeActionProvider = codeActionProvider;
9797

9898
vscode.workspace.onDidCloseTextDocument((e) => {
9999
const uriParams = new URLSearchParams(e.uri.query);
@@ -372,12 +372,6 @@ export default class EditorsController {
372372
this._activeConnectionCodeLensProvider
373373
)
374374
);
375-
this._context.subscriptions.push(
376-
vscode.languages.registerCodeLensProvider(
377-
{ language: 'mongodb' },
378-
this._partialExecutionCodeLensProvider
379-
)
380-
);
381375
this._context.subscriptions.push(
382376
vscode.languages.registerCodeLensProvider(
383377
{
@@ -396,6 +390,11 @@ export default class EditorsController {
396390
this._editDocumentCodeLensProvider
397391
)
398392
);
393+
this._context.subscriptions.push(
394+
vscode.languages.registerCodeActionsProvider('mongodb', this._codeActionProvider, {
395+
providedCodeActionKinds: CodeActionProvider.providedCodeActionKinds
396+
})
397+
);
399398
}
400399

401400
deactivate(): void {

src/editors/partialExecutionCodeLensProvider.ts

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)