|
Lines 186-194
Link Here
|
| 186 |
if (this.isCompletingCommentClose(node, params.offset)){ |
186 |
if (this.isCompletingCommentClose(node, params.offset)){ |
| 187 |
return this.getComment(node, params.offset, ast.source, false); |
187 |
return this.getComment(node, params.offset, ast.source, false); |
| 188 |
} else if (this.isCompletingAttributeValue(node, ast.source, params)) { |
188 |
} else if (this.isCompletingAttributeValue(node, ast.source, params)) { |
| 189 |
return this.getValuesForAttribute(node, params); |
189 |
return this.getValuesForAttribute(node, ast.source, params); |
| 190 |
} else if (this.isCompletingTagAttribute(node, ast.source, params)) { |
190 |
} else if (this.isCompletingTagAttribute(node, ast.source, params)) { |
| 191 |
return this.getAttributesForNode(node, params); |
191 |
return this.getAttributesForNode(node, ast.source, params); |
| 192 |
} else if (this.isCompletingTag(node, params)){ |
192 |
} else if (this.isCompletingTag(node, params)){ |
| 193 |
if (this.isCompletingCommentOpen(node)){ |
193 |
if (this.isCompletingCommentOpen(node)){ |
| 194 |
return this.getComment(node, params.offset, ast.source, true); |
194 |
return this.getComment(node, params.offset, ast.source, true); |
|
Lines 442-450
Link Here
|
| 442 |
* @returns {Array.<Object>} The array of proposals |
442 |
* @returns {Array.<Object>} The array of proposals |
| 443 |
* @since 10.0 |
443 |
* @since 10.0 |
| 444 |
*/ |
444 |
*/ |
| 445 |
getAttributesForNode: function(node, params) { |
445 |
getAttributesForNode: function(node, source, params) { |
| 446 |
var attrs = Attributes.getAttributesForNode(node); |
|
|
| 447 |
var proposals = []; |
446 |
var proposals = []; |
|
|
447 |
var prefix = params.prefix ? params.prefix : ""; |
| 448 |
// we need to check if we need to rebuild the prefix for completion that contains a '-' |
| 449 |
var index = params.offset - prefix.length - 1; |
| 450 |
if (index > 0 && index < source.length) { |
| 451 |
var precedingChar = source.charAt(index); |
| 452 |
if (precedingChar === '-') { |
| 453 |
index--; |
| 454 |
if (index !== 0) { |
| 455 |
// rebuild a prefix based on what characters (letter only) are before the '-' |
| 456 |
precedingChar = source.charAt(index); |
| 457 |
var currentPrefix = "-" + prefix; |
| 458 |
loop: while (index > 0 && /[A-Za-z0-9_-]/.test(precedingChar)) { |
| 459 |
index--; |
| 460 |
currentPrefix = precedingChar + currentPrefix; |
| 461 |
if (index === 0) { |
| 462 |
break loop; |
| 463 |
} |
| 464 |
precedingChar = source.charAt(index); |
| 465 |
} |
| 466 |
params.prefix = currentPrefix; |
| 467 |
} |
| 468 |
} else if (precedingChar === '=' && prefix.length === 0 && (index - 1) > 0) { |
| 469 |
precedingChar = source.charAt(index - 1); |
| 470 |
if (/[A-Za-z0-9_]/.test(precedingChar)) { |
| 471 |
proposals.push(this.makeComputedProposal("\"\"", Messages['addQuotesToAttributes'], " - \"\"", null, prefix)); //$NON-NLS-1$ //$NON-NLS-2$ |
| 472 |
return proposals; |
| 473 |
} |
| 474 |
} |
| 475 |
} |
| 476 |
var attrs = Attributes.getAttributesForNode(node); |
| 448 |
if(Array.isArray(attrs.global)) { |
477 |
if(Array.isArray(attrs.global)) { |
| 449 |
proposals = proposals.concat(this.addProposals(node, attrs.global, params)); |
478 |
proposals = proposals.concat(this.addProposals(node, attrs.global, params)); |
| 450 |
} |
479 |
} |
|
Lines 460-466
Link Here
|
| 460 |
}); |
489 |
}); |
| 461 |
proposals = proposals.concat(arr); |
490 |
proposals = proposals.concat(arr); |
| 462 |
} |
491 |
} |
| 463 |
|
|
|
| 464 |
} |
492 |
} |
| 465 |
if(Array.isArray(attrs.keyboardevents)) { |
493 |
if(Array.isArray(attrs.keyboardevents)) { |
| 466 |
arr = this.addProposals(node, attrs.keyboardevents, params); |
494 |
arr = this.addProposals(node, attrs.keyboardevents, params); |
|
Lines 474-480
Link Here
|
| 474 |
}); |
502 |
}); |
| 475 |
proposals = proposals.concat(arr); |
503 |
proposals = proposals.concat(arr); |
| 476 |
} |
504 |
} |
| 477 |
|
|
|
| 478 |
} |
505 |
} |
| 479 |
if(Array.isArray(attrs.mouseevents)) { |
506 |
if(Array.isArray(attrs.mouseevents)) { |
| 480 |
arr = this.addProposals(node, attrs.mouseevents, params); |
507 |
arr = this.addProposals(node, attrs.mouseevents, params); |
|
Lines 488-494
Link Here
|
| 488 |
}); |
515 |
}); |
| 489 |
proposals = proposals.concat(arr); |
516 |
proposals = proposals.concat(arr); |
| 490 |
} |
517 |
} |
| 491 |
|
|
|
| 492 |
} |
518 |
} |
| 493 |
if(Array.isArray(attrs.windowevents) && attrs.windowevents.length > 0) { |
519 |
if(Array.isArray(attrs.windowevents) && attrs.windowevents.length > 0) { |
| 494 |
arr = this.addProposals(node, attrs.windowevents, params); |
520 |
arr = this.addProposals(node, attrs.windowevents, params); |
|
Lines 502-508
Link Here
|
| 502 |
}); |
528 |
}); |
| 503 |
proposals = proposals.concat(arr); |
529 |
proposals = proposals.concat(arr); |
| 504 |
} |
530 |
} |
| 505 |
|
|
|
| 506 |
} |
531 |
} |
| 507 |
if(Array.isArray(attrs.aria)) { |
532 |
if(Array.isArray(attrs.aria)) { |
| 508 |
arr = this.addProposals(node, attrs.aria, params); |
533 |
arr = this.addProposals(node, attrs.aria, params); |
|
Lines 517-523
Link Here
|
| 517 |
proposals = proposals.concat(arr); |
542 |
proposals = proposals.concat(arr); |
| 518 |
} |
543 |
} |
| 519 |
} |
544 |
} |
| 520 |
return proposals; |
545 |
return proposals; |
| 521 |
}, |
546 |
}, |
| 522 |
|
547 |
|
| 523 |
addProposals: function addProposals(node, attrs, params) { |
548 |
addProposals: function addProposals(node, attrs, params) { |
|
Lines 652-660
Link Here
|
| 652 |
* @returns {Array.<Object>} The array of proposals |
677 |
* @returns {Array.<Object>} The array of proposals |
| 653 |
* @since 10.0 |
678 |
* @since 10.0 |
| 654 |
*/ |
679 |
*/ |
| 655 |
getValuesForAttribute: function(node, params) { |
680 |
getValuesForAttribute: function(node, source, params) { |
| 656 |
var vals = Attributes.getValuesForAttribute(node); |
|
|
| 657 |
var proposals = []; |
681 |
var proposals = []; |
|
|
682 |
var prefix = params.prefix ? params.prefix : ""; |
| 683 |
// we need to check if we need to rebuild the prefix for completion that contains a '-' |
| 684 |
var index = params.offset - prefix.length - 1; |
| 685 |
if (index > 0 && index < source.length) { |
| 686 |
var precedingChar = source.charAt(index); |
| 687 |
if (precedingChar === '=' && prefix.length === 0 && (index - 1) > 0) { |
| 688 |
precedingChar = source.charAt(index - 1); |
| 689 |
if (/[A-Za-z0-9_]/.test(precedingChar)) { |
| 690 |
if (index + 1 >= source.length || |
| 691 |
(source.charAt(index + 1) !== '\"' && source.charAt(index + 1) !== "'")) { |
| 692 |
proposals.push(this.makeComputedProposal("\"\"", Messages['addQuotesToAttributes'], " - \"\"", null, prefix)); //$NON-NLS-1$ //$NON-NLS-2$ |
| 693 |
} |
| 694 |
} |
| 695 |
} |
| 696 |
} |
| 697 |
var vals = Attributes.getValuesForAttribute(node); |
| 658 |
if(Array.isArray(vals)) { |
698 |
if(Array.isArray(vals)) { |
| 659 |
proposals = proposals.concat(this.addProposals(node, vals, params)); |
699 |
proposals = proposals.concat(this.addProposals(node, vals, params)); |
| 660 |
} |
700 |
} |
|
Lines 703-708
Link Here
|
| 703 |
isCompletingAttributeValue: function(node, source, params) { |
743 |
isCompletingAttributeValue: function(node, source, params) { |
| 704 |
// TODO We can do better with the new parser, handle no quotes cases too |
744 |
// TODO We can do better with the new parser, handle no quotes cases too |
| 705 |
if(node && node.type === 'attr') { |
745 |
if(node && node.type === 'attr') { |
|
|
746 |
if (node.valueRange) { |
| 747 |
var range = node.valueRange; |
| 748 |
return range[0] <= params.offset && range[1] >= params.offset; |
| 749 |
} |
| 706 |
return this.within('"', '"', source, params.offset, node.range) || //$NON-NLS-1$ //$NON-NLS-2$ |
750 |
return this.within('"', '"', source, params.offset, node.range) || //$NON-NLS-1$ //$NON-NLS-2$ |
| 707 |
this.within("'", "'", source, params.offset, node.range); //$NON-NLS-1$ //$NON-NLS-2$ |
751 |
this.within("'", "'", source, params.offset, node.range); //$NON-NLS-1$ //$NON-NLS-2$ |
| 708 |
} |
752 |
} |