Skip to content

Commit

Permalink
expose context for cell language (#607)
Browse files Browse the repository at this point in the history
* expose context for cell language

* Switch to using a language ID

* Update changelog

---------

Co-authored-by: Julia Silge <[email protected]>
  • Loading branch information
isabelizimm and juliasilge authored Nov 22, 2024
1 parent 69fce35 commit d9d1515
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.118.0 (unreleased)

- Provide F1 help at cursor in Positron (<https://github.com/quarto-dev/quarto/pull/599>)
- Expose new context keys for the language of a specific cell (<https://github.com/quarto-dev/quarto/pull/607>)

## 1.117.0 (Release on 2024-11-07)

Expand Down
8 changes: 6 additions & 2 deletions apps/vscode/src/vdoc/vdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
*/

import { Position, TextDocument, Uri, Range } from "vscode";
import { Position, TextDocument, Uri, Range, commands } from "vscode";
import { Token, isExecutableLanguageBlock, languageBlockAtPosition, languageNameFromBlock } from "quarto-core";

import { isQuartoDoc } from "../core/doc";
Expand Down Expand Up @@ -157,8 +157,12 @@ export async function virtualDocUri(
export function languageAtPosition(tokens: Token[], position: Position) {
const block = languageBlockAtPosition(tokens, position);
if (block) {
return languageFromBlock(block);
const language = languageFromBlock(block);
// expose cell language for use in keybindings, etc
commands.executeCommand('setContext', 'quarto.cellLangId', language?.ids[0]);
return language;
} else {
commands.executeCommand('setContext', 'quarto.cellLangId', undefined);
return undefined;
}
}
Expand Down

0 comments on commit d9d1515

Please sign in to comment.