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

Update 'workbench.action.positronConsole.executeCode' to be used in Quarto #3107

Merged
merged 7 commits into from
May 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export function registerPositronConsoleActions() {
* Runs action.
* @param accessor The services accessor.
*/
juliasilge marked this conversation as resolved.
Show resolved Hide resolved
async run(accessor: ServicesAccessor, opts: { allowIncomplete?: boolean } = {}) {
async run(accessor: ServicesAccessor, opts: { allowIncomplete?: boolean; languageId?: string } = {}) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Quarto extension knows what language we are using and can send it over in opts.

// Access services.
const editorService = accessor.get(IEditorService);
const languageFeaturesService = accessor.get(ILanguageFeaturesService);
Expand Down Expand Up @@ -315,10 +315,21 @@ export function registerPositronConsoleActions() {
return;
}

// If we have a language ID opt (such as from Quarto), temporarily switch to it.
const originalLanguageId = model.getLanguageId();
if (opts.languageId) {
model.setLanguage(opts.languageId);
}

juliasilge marked this conversation as resolved.
Show resolved Hide resolved
// Get all the statement range providers for the active document.
const statementRangeProviders =
languageFeaturesService.statementRangeProvider.all(model);

// If we have a languageId opt (such as from Quarto), put back original languageId.
if (opts.languageId) {
model.setLanguage(originalLanguageId);
}

// If the user doesn't have an explicit selection, consult a statement range provider,
// which can be used to get the code to execute.
if (!isString(code) && statementRangeProviders.length > 0) {
Expand Down Expand Up @@ -499,7 +510,7 @@ export function registerPositronConsoleActions() {
}

// Now that we've gotten this far, ensure we have a target language.
const languageId = editorService.activeTextEditorLanguageId;
const languageId = opts.languageId ? opts.languageId : editorService.activeTextEditorLanguageId;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update here to get the console to execute it in the correct runtime.

if (!languageId) {
notificationService.notify({
severity: Severity.Info,
Expand All @@ -513,7 +524,7 @@ export function registerPositronConsoleActions() {
// By default, we don't allow incomplete code to be executed, but the language runtime can override this.
// This means that if allowIncomplete is false or undefined, the incomplete code will not be sent to the backend for execution.
// The console will continue to wait for more input until the user completes the code, or cancels out of the operation.
const { allowIncomplete } = opts;
const allowIncomplete = opts.allowIncomplete;


// Ask the Positron console service to execute the code. Do not focus the console as
Expand Down
Loading