From 7437e3b429555c85b9a92dd7b83f3c801a202378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=B1=E5=90=B9=E8=89=B2=E5=BE=A1=E5=AE=88?= <85992002+KazariEX@users.noreply.github.com> Date: Thu, 29 Aug 2024 07:38:12 +0800 Subject: [PATCH] fix(language-core): transform range of `file-md` correctly (#4735) --- 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; } }