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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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.

return language;
} else {
commands.executeCommand('setContext', 'quarto.cellLang', undefined);
return undefined;
}
}
Expand Down