Skip to content

Commit

Permalink
fix(auto-complete): don't auto-complete bindings on wrong spots
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Lieben committed May 13, 2017
1 parent 093a36a commit e650d0d
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/server/CompletionItemFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,22 @@ export default class CompletionItemFactory {
// auto complete inside a tag
if (insideTag) {

if (this.notInAttributeValue(text.substring(insideTag.startOffset, positionNumber))) {
switch (triggerCharacter) {
case ' ':
return this.attributeCompletionFactory.create(insideTag.name, insideTag.attributes.map(i => i.name));
case '.':
return this.createBindingCompletion(insideTag, text, positionNumber);
case '"':
case '\'':
let elementString = text.substring(insideTag.startOffset, positionNumber);
if (this.notInAttributeValue(elementString)) {

if (triggerCharacter === ' ') {
return this.attributeCompletionFactory.create(insideTag.name, insideTag.attributes.map(i => i.name));
} else if (triggerCharacter === '.' && this.canExpandDot(elementString)) {
return this.createBindingCompletion(insideTag, text, positionNumber);
} else {
return [];
}

// inside attribute, perform attribute completion
} else if (triggerCharacter === '"' || triggerCharacter === '\'') {
return this.createValueCompletion(insideTag, text, positionNumber);
default:
return [];
}
} else {
return [];
}
}

Expand All @@ -81,6 +85,10 @@ export default class CompletionItemFactory {
return single % 2 == 0 && double % 2 == 0;
}

private canExpandDot(elementString) {
return !/([^a-zA-Z]|\.(bind|one-way|two-way|one-time|delegate|trigger|call|capture|ref))\.$/g.test(elementString);
}

private getOpenHtmlTags(nodes: Array<TagDefinition>, lastIdx: number) {
let tags: Array<string> = [];
for(let i = 0; i < lastIdx; i++) {
Expand Down

0 comments on commit e650d0d

Please sign in to comment.