From 36cebd0f519e17d0c4533c04c05ad7e416a9f6a7 Mon Sep 17 00:00:00 2001 From: Rhys Date: Mon, 5 Dec 2022 11:29:15 -0500 Subject: [PATCH] chore(playgrounds): avoid export to language code actions refresh when nothing to refresh (#454) --- src/editors/playgroundController.ts | 46 +++++++++++++++++------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/editors/playgroundController.ts b/src/editors/playgroundController.ts index 1fddf8697..bc10cbcdb 100644 --- a/src/editors/playgroundController.ts +++ b/src/editors/playgroundController.ts @@ -161,27 +161,35 @@ export default class PlaygroundController { vscode.window.onDidChangeTextEditorSelection( async (changeEvent: vscode.TextEditorSelectionChangeEvent) => { - if (changeEvent?.textEditor?.document?.languageId === 'mongodb') { - // Sort lines selected as the may be mis-ordered from alt+click. - const sortedSelections = ( - changeEvent.selections as Array - ).sort((a, b) => (a.start.line > b.start.line ? 1 : -1)); - - this._selectedText = sortedSelections - .map((item) => this._getSelectedText(item)) - .join('\n'); - - const mode = - await this._languageServerController.getExportToLanguageMode({ - textFromEditor: this._getAllText(), - selection: sortedSelections[0], - }); - - this._codeActionProvider.refresh({ + if (changeEvent?.textEditor?.document?.languageId !== 'mongodb') { + return; + } + + // Sort lines selected as the may be mis-ordered from alt+click. + const sortedSelections = ( + changeEvent.selections as Array + ).sort((a, b) => (a.start.line > b.start.line ? 1 : -1)); + + const selectedText = sortedSelections + .map((item) => this._getSelectedText(item)) + .join('\n'); + + if (selectedText === this._selectedText) { + return; + } + + this._selectedText = selectedText; + + const mode = + await this._languageServerController.getExportToLanguageMode({ + textFromEditor: this._getAllText(), selection: sortedSelections[0], - mode, }); - } + + this._codeActionProvider.refresh({ + selection: sortedSelections[0], + mode, + }); } ); }