-
Notifications
You must be signed in to change notification settings - Fork 61
#| highlighting #1084
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
base: main
Are you sure you want to change the base?
#| highlighting #1084
Changes from all commits
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -170,6 +170,49 @@ | |||||||||||||||||||
| "path": "./languages/mermaid/mermaid.tmLanguage.json" | ||||||||||||||||||||
| } | ||||||||||||||||||||
| ], | ||||||||||||||||||||
| "semanticTokenTypes": [ | ||||||||||||||||||||
| { | ||||||||||||||||||||
| "id": "quartoYamlKey", | ||||||||||||||||||||
| "description": "YAML key in a Quarto cell option (#|) comment" | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| { | ||||||||||||||||||||
| "id": "quartoYamlString", | ||||||||||||||||||||
| "description": "YAML string value in a Quarto cell option (#|) comment" | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| { | ||||||||||||||||||||
| "id": "quartoYamlNumber", | ||||||||||||||||||||
| "description": "YAML number value in a Quarto cell option (#|) comment" | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| { | ||||||||||||||||||||
| "id": "quartoYamlBoolean", | ||||||||||||||||||||
| "description": "YAML boolean value in a Quarto cell option (#|) comment" | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| { | ||||||||||||||||||||
| "id": "quartoYamlNull", | ||||||||||||||||||||
| "description": "YAML null value in a Quarto cell option (#|) comment" | ||||||||||||||||||||
| } | ||||||||||||||||||||
| ], | ||||||||||||||||||||
| "semanticTokenScopes": [ | ||||||||||||||||||||
| { | ||||||||||||||||||||
| "scopes": { | ||||||||||||||||||||
| "quartoYamlKey": [ | ||||||||||||||||||||
| "entity.name.tag.yaml" | ||||||||||||||||||||
| ], | ||||||||||||||||||||
| "quartoYamlString": [ | ||||||||||||||||||||
| "string.unquoted.plain.out.yaml" | ||||||||||||||||||||
|
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. These five scopes all resolve to fully saturated code colors, so a cell option block really competes with the code below it. I think the highlighting needs to be quieter, because the background already shows where the block is. I resolved the scopes against the default themes in the Positron repo:
Two problems come out of this.
One line can show three different hues. My suggestion:
This gives one accent per line instead of three. If you want the quietest result, map both types to Note that the legend in
Member
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. Ah, nice catch. Looking into the mismatching highlighting you pointed out lead to me trying out this alternative approach #1092, which doesn't have mismatching highlighting, but might be a bit visually loud. |
||||||||||||||||||||
| ], | ||||||||||||||||||||
| "quartoYamlNumber": [ | ||||||||||||||||||||
| "constant.numeric.yaml" | ||||||||||||||||||||
| ], | ||||||||||||||||||||
| "quartoYamlBoolean": [ | ||||||||||||||||||||
| "constant.language.boolean.yaml" | ||||||||||||||||||||
| ], | ||||||||||||||||||||
| "quartoYamlNull": [ | ||||||||||||||||||||
| "constant.language.null.yaml" | ||||||||||||||||||||
| ] | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| ], | ||||||||||||||||||||
| "snippets": [ | ||||||||||||||||||||
| { | ||||||||||||||||||||
| "language": "quarto", | ||||||||||||||||||||
|
|
@@ -1529,7 +1572,8 @@ | |||||||||||||||||||
| "vscode-languageclient": "^8.1.0", | ||||||||||||||||||||
| "vscode-languageserver-types": "^3.17.3", | ||||||||||||||||||||
| "vscode-nls": "^5.2.0", | ||||||||||||||||||||
| "which": "^3.0.0" | ||||||||||||||||||||
| "which": "^3.0.0", | ||||||||||||||||||||
| "yaml": "^2.8.1" | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| "devDependencies": { | ||||||||||||||||||||
| "@types/axios": "^0.14.0", | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import { MarkdownEngine } from "../markdown/engine"; | |
| import { isExecutableLanguageBlock } from "quarto-core"; | ||
| import { vscRange } from "../core/range"; | ||
| import { createThrottle } from "../core/throttle"; | ||
| import { hashPipeYaml } from "./hash-pipe-yaml"; | ||
|
|
||
| export function activateBackgroundHighlighter( | ||
| context: vscode.ExtensionContext, | ||
|
|
@@ -153,13 +154,28 @@ async function setEditorHighlightDecorations( | |
| // ranges to highlight | ||
| const blockRanges: vscode.Range[] = []; | ||
| const inlineRanges: vscode.Range[] = []; | ||
| const optionLineRanges: vscode.Range[] = []; | ||
| const optionSeparatorRanges: vscode.Range[] = []; | ||
|
|
||
| if (highlightingConfig.enabled()) { | ||
|
|
||
| // find code blocks | ||
| const tokens = engine.parse(editor.document); | ||
| for (const block of tokens.filter(isExecutableLanguageBlock)) { | ||
| blockRanges.push(vscRange(block.range)); | ||
| const blockRange = vscRange(block.range); | ||
| blockRanges.push(blockRange); | ||
|
|
||
| // cell options (#| comments) get a darker background, and the last | ||
| // option line gets a separator (rendered as a bottom border) | ||
| const { lines } = hashPipeYaml(editor.document, blockRange); | ||
| for (const line of lines) { | ||
| optionLineRanges.push(editor.document.lineAt(line.docLine).range); | ||
| } | ||
| if (lines.length > 0) { | ||
| optionSeparatorRanges.push( | ||
| editor.document.lineAt(lines[lines.length - 1].docLine).range | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // find inline executable code | ||
|
|
@@ -186,12 +202,40 @@ async function setEditorHighlightDecorations( | |
| highlightingConfig.inlineBackgroundDecoration(), | ||
| inlineRanges | ||
| ); | ||
| editor.setDecorations(cellOptionsBackgroundDecoration, optionLineRanges); | ||
| editor.setDecorations(cellOptionsSeparatorDecoration, optionSeparatorRanges); | ||
| } | ||
|
|
||
| function clearEditorHighlightDecorations(editor: vscode.TextEditor) { | ||
| editor.setDecorations(highlightingConfig.backgroundDecoration(), []); | ||
| editor.setDecorations(cellOptionsBackgroundDecoration, []); | ||
| editor.setDecorations(cellOptionsSeparatorDecoration, []); | ||
| } | ||
|
|
||
| // these composite on top of the cell background decoration, so a | ||
| // translucent black overlay reads as "slightly darker" in both themes | ||
| const cellOptionsBackgroundDecoration = vscode.window.createTextEditorDecorationType({ | ||
| isWholeLine: true, | ||
| light: { | ||
| backgroundColor: "#00000012", | ||
| }, | ||
| dark: { | ||
| backgroundColor: "#00000033", | ||
| }, | ||
| }); | ||
|
|
||
| const cellOptionsSeparatorDecoration = vscode.window.createTextEditorDecorationType({ | ||
| isWholeLine: true, | ||
| borderStyle: "solid", | ||
| borderWidth: "0 0 1px 0", | ||
|
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.
This is because of the mechanism in VS Code itself, so I don't think we can code around it here very easily. I think I prefer to remove the separator and let the darker background show the boundary. The background already wraps correctly, and it is the only option here that is always correct. If you want to keep a rule, we could put it on the first line after the option block as a top border (
Member
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 figured out how to keep the bottom line but fix this problem in #1092 with a css trick. |
||
| light: { | ||
| borderColor: "#00000025", | ||
| }, | ||
| dark: { | ||
| borderColor: "#FFFFFF25", | ||
| }, | ||
| }); | ||
|
|
||
| enum CellBackgroundColor { | ||
| default = "default", | ||
| off = "off", | ||
|
|
||

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.
This code creates the promise before the cancellation check on line 216. The early return on line 217 does not await it. If
quarto.getYamlDiagnosticsrejects, the rejection is unhandled.apps/lsp/src/index.tsdoes not install anunhandledRejectionhandler. As a result, IIUC it terminates the server process.Could we do something like this instead?