Skip to content

Commit

Permalink
VSCODE-247: Replace code lenses with code actions (#318)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alenakhineika authored Aug 12, 2021
1 parent e63a769 commit d0015f2
Show file tree
Hide file tree
Showing 13 changed files with 215 additions and 422 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/test-and-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ jobs:
- name: Install npm@7
run: npm install -g npm@7

- name: Patch node gyp on Windows
if: ${{ runner.os == 'Windows' }}
shell: powershell
run: |
npm install --global node-gyp@latest
npm prefix -g | % {npm config set node_gyp "$_\node_modules\node-gyp\bin\node-gyp.js"}
- name: Install Dependencies
run: |
npm ci
Expand Down
33 changes: 9 additions & 24 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@
"@mongosh/i18n": "^1.0.4",
"@mongosh/service-provider-server": "^1.0.4",
"@mongosh/shell-api": "^1.0.4",
"analytics-node": "^3.5.0",
"analytics-node": "^5.0.0",
"bson": "^4.4.1",
"classnames": "^2.3.1",
"debug": "^4.3.2",
Expand Down
29 changes: 29 additions & 0 deletions src/editors/codeActionProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as vscode from 'vscode';
import EXTENSION_COMMANDS from '../commands';
import PlaygroundController from './playgroundController';

export default class CodeActionProvider implements vscode.CodeActionProvider {
_playgroundController: PlaygroundController;

static readonly providedCodeActionKinds = [vscode.CodeActionKind.QuickFix];

constructor(playgroundController: PlaygroundController) {
this._playgroundController = playgroundController;
}

provideCodeActions(): vscode.CodeAction[] | undefined {
if (!this._playgroundController._selectedText) {
return;
}

const commandAction = new vscode.CodeAction('Run selected playground blocks', vscode.CodeActionKind.Empty);

commandAction.command = {
command: EXTENSION_COMMANDS.MDB_RUN_SELECTED_PLAYGROUND_BLOCKS,
title: 'Run selected playground blocks',
tooltip: 'Run selected playground blocks'
};

return [commandAction];
}
}
19 changes: 9 additions & 10 deletions src/editors/editorsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from 'vscode';
import { EJSON } from 'bson';

import ActiveConnectionCodeLensProvider from './activeConnectionCodeLensProvider';
import CodeActionProvider from './codeActionProvider';
import ConnectionController from '../connectionController';
import CollectionDocumentsCodeLensProvider from './collectionDocumentsCodeLensProvider';
import CollectionDocumentsOperationsStore from './collectionDocumentsOperationsStore';
Expand All @@ -22,7 +23,6 @@ import MongoDBDocumentService, {
DOCUMENT_SOURCE_URI_IDENTIFIER,
VIEW_DOCUMENT_SCHEME
} from './mongoDBDocumentService';
import PartialExecutionCodeLensProvider from './partialExecutionCodeLensProvider';
import PlaygroundController from './playgroundController';
import PlaygroundResultProvider, {
PLAYGROUND_RESULT_SCHEME
Expand All @@ -37,6 +37,7 @@ const log = createLogger('editors controller');
* new editors and the data they need. It also manages active editors.
*/
export default class EditorsController {
_codeActionProvider: CodeActionProvider;
_connectionController: ConnectionController;
_playgroundController: PlaygroundController;
_collectionDocumentsOperationsStore = new CollectionDocumentsOperationsStore();
Expand All @@ -49,7 +50,6 @@ export default class EditorsController {
_telemetryService: TelemetryService;
_playgroundResultViewProvider: PlaygroundResultProvider;
_activeConnectionCodeLensProvider: ActiveConnectionCodeLensProvider;
_partialExecutionCodeLensProvider: PartialExecutionCodeLensProvider;
_editDocumentCodeLensProvider: EditDocumentCodeLensProvider;
_collectionDocumentsCodeLensProvider: CollectionDocumentsCodeLensProvider;

Expand All @@ -61,7 +61,7 @@ export default class EditorsController {
telemetryService: TelemetryService,
playgroundResultViewProvider: PlaygroundResultProvider,
activeConnectionCodeLensProvider: ActiveConnectionCodeLensProvider,
partialExecutionCodeLensProvider: PartialExecutionCodeLensProvider,
codeActionProvider: CodeActionProvider,
editDocumentCodeLensProvider: EditDocumentCodeLensProvider
) {
log.info('activating...');
Expand Down Expand Up @@ -90,10 +90,10 @@ export default class EditorsController {
);
this._playgroundResultViewProvider = playgroundResultViewProvider;
this._activeConnectionCodeLensProvider = activeConnectionCodeLensProvider;
this._partialExecutionCodeLensProvider = partialExecutionCodeLensProvider;
this._collectionDocumentsCodeLensProvider = new CollectionDocumentsCodeLensProvider(
this._collectionDocumentsOperationsStore
);
this._codeActionProvider = codeActionProvider;

vscode.workspace.onDidCloseTextDocument((e) => {
const uriParams = new URLSearchParams(e.uri.query);
Expand Down Expand Up @@ -372,12 +372,6 @@ export default class EditorsController {
this._activeConnectionCodeLensProvider
)
);
this._context.subscriptions.push(
vscode.languages.registerCodeLensProvider(
{ language: 'mongodb' },
this._partialExecutionCodeLensProvider
)
);
this._context.subscriptions.push(
vscode.languages.registerCodeLensProvider(
{
Expand All @@ -396,6 +390,11 @@ export default class EditorsController {
this._editDocumentCodeLensProvider
)
);
this._context.subscriptions.push(
vscode.languages.registerCodeActionsProvider('mongodb', this._codeActionProvider, {
providedCodeActionKinds: CodeActionProvider.providedCodeActionKinds
})
);
}

deactivate(): void {
Expand Down
92 changes: 0 additions & 92 deletions src/editors/partialExecutionCodeLensProvider.ts

This file was deleted.

Loading

0 comments on commit d0015f2

Please sign in to comment.