Skip to content

Commit

Permalink
chore(playgrounds): avoid export to language code actions refresh whe…
Browse files Browse the repository at this point in the history
…n nothing to refresh (#454)
  • Loading branch information
Anemy authored Dec 5, 2022
1 parent eaca062 commit 36cebd0
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/editors/playgroundController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<vscode.Selection>
).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<vscode.Selection>
).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,
});
}
);
}
Expand Down

0 comments on commit 36cebd0

Please sign in to comment.