@@ -20,7 +20,16 @@ import { Decoration, DecorationSet } from "@codemirror/view";
2020import { StateField , StateEffect } from "@codemirror/state" ;
2121import { hoverTooltip } from "@codemirror/view" ;
2222
23- import { CodeViewCellContext , codeViewCellContext , kEndColumn , kEndRow , kStartColumn , kStartRow , LintItem } from "editor" ;
23+ import {
24+ CodeViewCellContext ,
25+ codeViewCellContext ,
26+ kEndColumn ,
27+ kEndRow ,
28+ kStartColumn ,
29+ kStartRow ,
30+ LintItem ,
31+ stripYamlFrontmatterDelimiters
32+ } from "editor" ;
2433import { lines } from "core" ;
2534import { Position } from "vscode-languageserver-types" ;
2635
@@ -52,13 +61,14 @@ export function diagnosticsBehavior(behaviorContext: BehaviorContext): Behavior
5261 if ( filepath === null ) return ;
5362
5463 const code = lines ( pmNode . textContent ) ;
64+ const strippedCodeLines = stripYamlFrontmatterDelimiters ( code ) ;
5565
5666 // here we hand-craft an artisinal cellContext because `codeViewCellContext(..)`
5767 // seems to return undefined inside of init
5868 const cellContext = {
5969 filepath,
6070 language : 'yaml' ,
61- code : code . map ( line => ! / ^ ( - - - | \. \. \. ) \s * $ / . test ( line ) ? line : "" ) ,
71+ code : strippedCodeLines ,
6272 cellBegin : 0 ,
6373 cellEnd : code . length - 1 ,
6474 selection : EMPTY_CODEVIEW_SELECTION
@@ -102,10 +112,7 @@ async function getDiagnostics(
102112 cellContext : CodeViewCellContext ,
103113 behaviorContext : BehaviorContext
104114) : Promise < LintItem [ ] | undefined > {
105- const diagnostics = await behaviorContext . pmContext . ui . codeview ?. codeViewDiagnostics ( cellContext ) ;
106- if ( ! diagnostics ) return undefined ;
107-
108- return diagnostics ;
115+ return await behaviorContext . pmContext . ui . codeview ?. codeViewDiagnostics ( cellContext ) ;
109116}
110117
111118//Check if there is an underline at position and display a tooltip there
@@ -205,14 +212,15 @@ const rangeAndSpecOfDecorationAtPos = (pos: number, d: DecorationSet) => {
205212} ;
206213
207214/**
208- * @param strs A representation of a string, split by newlines.
215+ * @param lines A representation of a string, split by newlines.
209216 * @param [row, col] row and column into the string, row being the same as line number
210- * @returns An index into the string i.e. An index into `strs .join('\n')`
217+ * @returns An index into the string i.e. An index into `lines .join('\n')`
211218 */
212- function rowColumnToIndex ( strs : string [ ] , [ col , row ] : [ number , number ] ) : number {
219+ function rowColumnToIndex ( lines : string [ ] , [ col , row ] : [ number , number ] ) : number {
213220 let index = 0 ;
214221 for ( let i = 0 ; i < row ; i ++ ) {
215- index += strs [ i ] . length + 1 ;
222+ // + 1 to account for the newline character
223+ index += lines [ i ] . length + 1 ;
216224 }
217225 return index + col ;
218226}
0 commit comments