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

expose context for cell language #607

Merged
merged 3 commits into from
Nov 22, 2024
Merged

expose context for cell language #607

merged 3 commits into from
Nov 22, 2024

Conversation

isabelizimm
Copy link
Collaborator

@isabelizimm isabelizimm commented Nov 21, 2024

Notes

This will update the exposed language depending on what language chunk the user's cursor is in. It will expose the language extension (eg. py, r, jl) used to run the chunk.

The language at position does not immediately change when a cursor is placed, you have to delete or type something non-whitespace for the cell language to update. I still think this is the right place; BUT there is an alternative location where we would get feedback immediately with the language of the virtual doc, rather than the chunk. For reticulate documents, that means you'll never have Python exposed, only R.

Trying it out

I've been testing by creating a file something like:

---
title: new title
editor: source
---


```{r}

```


```{python}

```

and adding these keybindings via Command Palette -> Preferences: Open Keyboard Shortcuts (JSON):

// Place your key bindings in this file to override the defaults
[
    {
        "key": "cmd+shift+a",
        "command": "type",
        "args": { "text": "Hello PYTHON" },
        "when": "quarto.cellLang == 'py'"
      },
      {"key": "cmd+shift+a",
      "command": "type",
      "args": { "text": "Hello RLANG" },
      "when": "quarto.cellLang == 'r'"
    },
    {"key": "cmd+shift+a",
    "command": "type",
    "args": { "text": "Hello QUARTO" },
    "when": "quarto.cellLang == ''"
  },
]

Then I'll go into each chunk, start typing, then do command+shift+a.

@cscheid
Copy link
Contributor

cscheid commented Nov 21, 2024

(@isabelizimm I hope you don't mind I took the liberty to edit your post so the triple ticks render fine! The trick is to use more ticks on the outside than on the inside, ```` in this case.)

@isabelizimm
Copy link
Collaborator Author

The trick is to use more ticks on the outside than on the inside, ```` in this case.

TIL!!! Thank you so much, that looks much better 😺

return languageFromBlock(block);
const language = languageFromBlock(block);
// expose cell language for use in keybindings, etc
commands.executeCommand('setContext', 'quarto.cellLang', language?.extension);
Copy link
Collaborator

@juliasilge juliasilge Nov 21, 2024

Choose a reason for hiding this comment

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

Did you try using the ids element? It would be nice if we had the same string here that we can use with editorLangId, i.e. "python" and not "py".

Copy link
Collaborator

Choose a reason for hiding this comment

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

If so, it would be nice to make this quarto.cellLangId as well.

Copy link
Collaborator

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

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

I installed the .vsix and see the new context key, using "Developer: Inspect Context Keys":

Screenshot 2024-11-21 at 5 06 25 PM

I think it's very unlikely that one of the language keyboard shortcuts would be the first non-whitespace thing you type in a code cell, based on all the examples we currently have. I would rather risk that than have us provide R language shortcuts in a Python cell for knitr/reticulate .qmd files. Happy to re-evaluate if folks find it surprising!

@juliasilge juliasilge merged commit d9d1515 into main Nov 22, 2024
1 check passed
@juliasilge juliasilge deleted the cell-lang branch November 22, 2024 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants