Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 空格唤起自动补全 #173

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/common/src/parseAttrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {
Expand All @@ -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
Expand Down Expand Up @@ -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) }
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/WxmlAutoCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down