From 530aa486a3d418d29295812ebd87c52acdd8a4ee Mon Sep 17 00:00:00 2001 From: isabelizimm Date: Thu, 21 Nov 2024 13:54:01 -0500 Subject: [PATCH 1/3] expose context for cell language --- apps/vscode/src/vdoc/vdoc.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/vscode/src/vdoc/vdoc.ts b/apps/vscode/src/vdoc/vdoc.ts index bfe942a9..5ba19c29 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.cellLang', language?.extension); + return language; } else { + commands.executeCommand('setContext', 'quarto.cellLang', undefined); return undefined; } } From 262ef4d058b6908d74abf52a0e9ab85feae99b99 Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Thu, 21 Nov 2024 16:58:43 -0700 Subject: [PATCH 2/3] Switch to using a language ID --- apps/vscode/src/vdoc/vdoc.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/vscode/src/vdoc/vdoc.ts b/apps/vscode/src/vdoc/vdoc.ts index 5ba19c29..4e011fd6 100644 --- a/apps/vscode/src/vdoc/vdoc.ts +++ b/apps/vscode/src/vdoc/vdoc.ts @@ -159,10 +159,10 @@ export function languageAtPosition(tokens: Token[], position: Position) { if (block) { const language = languageFromBlock(block); // expose cell language for use in keybindings, etc - commands.executeCommand('setContext', 'quarto.cellLang', language?.extension); + commands.executeCommand('setContext', 'quarto.cellLangId', language?.ids[0]); return language; } else { - commands.executeCommand('setContext', 'quarto.cellLang', undefined); + commands.executeCommand('setContext', 'quarto.cellLangId', undefined); return undefined; } } From 62c3a83d122be726d50607d46cbf8fa95d2a7860 Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Thu, 21 Nov 2024 17:17:04 -0700 Subject: [PATCH 3/3] Update changelog --- apps/vscode/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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)