From d9d15151187cd2222b0ce47e1654f3a92031b177 Mon Sep 17 00:00:00 2001 From: Isabel Zimmerman <54685329+isabelizimm@users.noreply.github.com> Date: Thu, 21 Nov 2024 19:28:27 -0500 Subject: [PATCH] expose context for cell language (#607) * expose context for cell language * Switch to using a language ID * Update changelog --------- Co-authored-by: Julia Silge --- apps/vscode/CHANGELOG.md | 1 + apps/vscode/src/vdoc/vdoc.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/vscode/CHANGELOG.md b/apps/vscode/CHANGELOG.md index 8e204361..5a979c7d 100644 --- a/apps/vscode/CHANGELOG.md +++ b/apps/vscode/CHANGELOG.md @@ -3,6 +3,7 @@ ## 1.118.0 (unreleased) - Provide F1 help at cursor in Positron () +- Expose new context keys for the language of a specific cell () ## 1.117.0 (Release on 2024-11-07) diff --git a/apps/vscode/src/vdoc/vdoc.ts b/apps/vscode/src/vdoc/vdoc.ts index bfe942a9..4e011fd6 100644 --- a/apps/vscode/src/vdoc/vdoc.ts +++ b/apps/vscode/src/vdoc/vdoc.ts @@ -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"; @@ -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; } }