From 6c1968eaa614d154adfd758978788686212b29d7 Mon Sep 17 00:00:00 2001 From: fanweijie Date: Thu, 5 Oct 2023 16:32:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E7=A9=BA=E6=A0=BC=E5=94=A4=E8=B5=B7?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=A1=A5=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/src/parseAttrs.ts | 7 ++++--- src/plugin/WxmlAutoCompletion.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/common/src/parseAttrs.ts b/src/common/src/parseAttrs.ts index f91c128..a8460c5 100644 --- a/src/common/src/parseAttrs.ts +++ b/src/common/src/parseAttrs.ts @@ -25,7 +25,8 @@ import { ComponentAttr } from './dev' const SINGLE_LINE_REGEXP = /^\s+(?:\w+.)?properties\s*[:=]\s*\{(.*)\}\s*$/m const MULTIPLE_LINE_START_REGEXP = /^(\s+)(?:\w+.)?properties\s*[:=]\s*\{(.*?)$/ -const DOC_REGEXP = /\/\*\*([\s\S]*?)\*\/[\s\n\r]*(\w+)\s*:/g +// 单行以及多行注释 +const DOC_REGEXP = /\/\*\*([\s\S]*?)\*\/[\s\n\r]*(\w+)\s*:|\/\/([\s\S]*?)[\s\n\r]*(\w+)\s*:/g const TYPE_REGEXP = /^function\s+(\w+)\(/ export function parseAttrs(content: string): ComponentAttr[] { @@ -34,14 +35,14 @@ export function parseAttrs(content: string): ComponentAttr[] { attrs = parseObjStr(RegExp.$1) } - if (!attrs) { + if (!attrs) { let flag = 0 let spaces = '' let objstr = '' content.split(/\r?\n/).forEach(l => { if (flag === 2) return if (flag === 1) { - if (l.trimRight() === spaces + '}') flag = 2 + if ([spaces + '},', spaces + '}'].includes(l.trimRight())) flag = 2 else objstr += '\n' + l } else if (MULTIPLE_LINE_START_REGEXP.test(l)) { flag = 1 diff --git a/src/plugin/WxmlAutoCompletion.ts b/src/plugin/WxmlAutoCompletion.ts index 6bc46e1..734ca06 100644 --- a/src/plugin/WxmlAutoCompletion.ts +++ b/src/plugin/WxmlAutoCompletion.ts @@ -43,7 +43,7 @@ export default class extends AutoCompletion implements CompletionItemProvider { if (/[\w\d$_]/.test(getLastChar(document, new Position(position.line, position.character + 1)))) { return Promise.resolve([]) } - return [] as any + return this.createComponentAttributeSnippetItems(language, document, position) case '"': case "'": return this.createComponentAttributeSnippetItems(language, document, position) From 8b3981c5e744bb4e6e975321b5200c02207d95b4 Mon Sep 17 00:00:00 2001 From: fanweijie Date: Sat, 7 Oct 2023 16:48:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E5=8D=95=E8=A1=8C=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/src/parseAttrs.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/src/parseAttrs.ts b/src/common/src/parseAttrs.ts index a8460c5..aae97ed 100644 --- a/src/common/src/parseAttrs.ts +++ b/src/common/src/parseAttrs.ts @@ -83,7 +83,9 @@ function parseObjStr(objstr: string) { return attr }) - objstr.replace(DOC_REGEXP, (r, doc, name) => { + objstr.replace(DOC_REGEXP, (r, mutiDoc, mutiName, singleDoc, singleName) => { + const name = mutiName || singleName; + const doc = mutiDoc || singleDoc; const index = attrs.findIndex(a => a.name === name) if (index >= 0) { attrs[index] = { ...attrs[index], ...parseDocStr(doc) }