diff --git a/src/common/src/parseAttrs.ts b/src/common/src/parseAttrs.ts index f91c128..aae97ed 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 @@ -82,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) } 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)