From 3f072e777ecab5d26e1777c05b06c88851b86d7a Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Thu, 29 Aug 2024 03:15:47 +0800 Subject: [PATCH] fix: transform range of `file-md` correctly --- packages/language-core/lib/plugins/file-md.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/language-core/lib/plugins/file-md.ts b/packages/language-core/lib/plugins/file-md.ts index 1c3bf353a5..3516476d8d 100644 --- a/packages/language-core/lib/plugins/file-md.ts +++ b/packages/language-core/lib/plugins/file-md.ts @@ -88,14 +88,17 @@ const plugin: VueLanguagePlugin = ({ vueCompilerOptions }) => { return sfc; function transformRange(block: SFCBlock) { - block.loc.start.offset = -1; - block.loc.end.offset = -1; - for (const [start] of file2VueSourceMap.toSourceLocation(block.loc.start.offset)) { - block.loc.start.offset = start; + const { start, end } = block.loc; + const startOffset = start.offset; + const endOffset = end.offset; + start.offset = -1; + end.offset = -1; + for (const [offset] of file2VueSourceMap.toSourceLocation(startOffset)) { + start.offset = offset; break; } - for (const [end] of file2VueSourceMap.toSourceLocation(block.loc.end.offset)) { - block.loc.end.offset = end; + for (const [offset] of file2VueSourceMap.toSourceLocation(endOffset)) { + end.offset = offset; break; } }