-
Notifications
You must be signed in to change notification settings - Fork 46
Set context keys for document language #608
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
Changes from 2 commits
11d1830
35ad78a
f1aa3fb
4a34c1f
c6f28f8
8d00a51
a3535e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import { isQuartoDoc, kQuartoDocSelector } from "../core/doc"; | |
| import { MarkdownEngine } from "../markdown/engine"; | ||
| import { isExecutableLanguageBlock } from "quarto-core"; | ||
| import { vscRange } from "../core/range"; | ||
| import { mainLanguage } from "../vdoc/vdoc"; | ||
|
|
||
| export function activateBackgroundHighlighter( | ||
| context: vscode.ExtensionContext, | ||
|
|
@@ -162,6 +163,10 @@ async function setEditorHighlightDecorations( | |
| blockRanges.push(vscRange(block.range)); | ||
| } | ||
|
|
||
| // expose cell language for use in keybindings, etc | ||
| const language = mainLanguage(tokens); | ||
| vscode.commands.executeCommand('setContext', 'quartoLangId', language?.ids[0]); | ||
|
||
|
|
||
|
||
| // find inline executable code | ||
| for (let i = 0; i < editor.document.lineCount; i++) { | ||
| const line = editor.document.lineAt(i); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
| * | ||
| */ | ||
|
|
||
| import { Position, TextDocument, Uri, Range, commands } from "vscode"; | ||
| import { Position, TextDocument, Uri, Range } from "vscode"; | ||
| import { Token, isExecutableLanguageBlock, languageBlockAtPosition, languageNameFromBlock } from "quarto-core"; | ||
|
|
||
| import { isQuartoDoc } from "../core/doc"; | ||
|
|
@@ -157,12 +157,8 @@ export async function virtualDocUri( | |
| export function languageAtPosition(tokens: Token[], position: Position) { | ||
| const block = languageBlockAtPosition(tokens, position); | ||
| if (block) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC, previously it attempted to update the context key dynamically on each cell "activation", right? That does seem hard to get 100% right. And now it tries to update the context key 1 time for whatever the main language in the document is. I suppose that could be mildly confusing. If you have 1 python cell in a mostly R document, then clicking in the python cell and running a keybinding will run the R version. That's kinda confusing, but I'm not sure what we can do better.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did hope for us to get this working really nicely for reticulate Quarto files (per cell), but when I tried to use the approach with |
||
| const language = languageFromBlock(block); | ||
| // expose cell language for use in keybindings, etc | ||
| commands.executeCommand('setContext', 'quarto.cellLangId', language?.ids[0]); | ||
| return language; | ||
| return languageFromBlock(block); | ||
| } else { | ||
| commands.executeCommand('setContext', 'quarto.cellLangId', undefined); | ||
| return undefined; | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if
highlightingConfigisn't enabled? See the if-block above.(See broader comment about using a different approach)