Skip to content

Commit d9d1515

Browse files
expose context for cell language (#607)
* expose context for cell language * Switch to using a language ID * Update changelog --------- Co-authored-by: Julia Silge <julia.silge@gmail.com>
1 parent 69fce35 commit d9d1515

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

apps/vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 1.118.0 (unreleased)
44

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

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

apps/vscode/src/vdoc/vdoc.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*/
1515

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

1919
import { isQuartoDoc } from "../core/doc";
@@ -157,8 +157,12 @@ export async function virtualDocUri(
157157
export function languageAtPosition(tokens: Token[], position: Position) {
158158
const block = languageBlockAtPosition(tokens, position);
159159
if (block) {
160-
return languageFromBlock(block);
160+
const language = languageFromBlock(block);
161+
// expose cell language for use in keybindings, etc
162+
commands.executeCommand('setContext', 'quarto.cellLangId', language?.ids[0]);
163+
return language;
161164
} else {
165+
commands.executeCommand('setContext', 'quarto.cellLangId', undefined);
162166
return undefined;
163167
}
164168
}

0 commit comments

Comments
 (0)