|
Lines 122-127
define([
Link Here
|
| 122 |
getKind: function(ast, offset) { |
124 |
getKind: function(ast, offset) { |
| 123 |
var node = Finder.findNode(offset, ast, {parents:true}); |
125 |
var node = Finder.findNode(offset, ast, {parents:true}); |
| 124 |
if(node) { |
126 |
if(node) { |
|
|
127 |
if (node.type === 'Literal' && typeof node.value === 'string' && offset > node.range[0] && offset < node.range[1]){ |
| 128 |
// If we are inside the quotes of a string literal, don't offer template completions |
| 129 |
return {kind: 'string'}; |
| 130 |
} |
| 125 |
if(node.parents && node.parents.length > 0) { |
131 |
if(node.parents && node.parents.length > 0) { |
| 126 |
var prent = node.parents.pop(); |
132 |
var prent = node.parents.pop(); |
| 127 |
switch(prent.type) { |
133 |
switch(prent.type) { |
|
Lines 43-84
define([
Link Here
|
| 43 |
getTemplateProposals: function(prefix, offset, context, ast) { |
43 |
getTemplateProposals: function(prefix, offset, context, ast) { |
| 44 |
var proposals = []; |
44 |
var proposals = []; |
| 45 |
var k = this.getKind(ast, offset); |
45 |
var k = this.getKind(ast, offset); |
| 46 |
var templates = Templates.getTemplatesForKind(k.kind); |
46 |
if (k){ |
| 47 |
for (var t = 0; t < templates.length; t++) { |
47 |
var templates = Templates.getTemplatesForKind(k.kind); |
| 48 |
var template = templates[t]; |
48 |
for (var t = 0; t < templates.length; t++) { |
| 49 |
if (this.templateMatches(template, prefix, k, context)) { |
49 |
var template = templates[t]; |
| 50 |
var proposal = template.getProposal(prefix, offset, context); |
50 |
if (this.templateMatches(template, prefix, k, context)) { |
| 51 |
var _h; |
51 |
var proposal = template.getProposal(prefix, offset, context); |
| 52 |
if(template.doc) { |
52 |
var _h; |
| 53 |
_h = Hover.formatMarkdownHover(template.doc); |
53 |
if(template.doc) { |
| 54 |
} else { |
54 |
_h = Hover.formatMarkdownHover(template.doc); |
| 55 |
_h = Object.create(null); |
55 |
} else { |
| 56 |
_h.type = 'markdown'; //$NON-NLS-1$ |
56 |
_h = Object.create(null); |
| 57 |
_h.content = Messages['templateHoverHeader']; |
57 |
_h.type = 'markdown'; //$NON-NLS-1$ |
| 58 |
_h.content += proposal.proposal; |
58 |
_h.content = Messages['templateHoverHeader']; |
| 59 |
} |
59 |
_h.content += proposal.proposal; |
| 60 |
if(template.url) { |
60 |
} |
| 61 |
_h.content += i18nUtil.formatMessage.call(null, Messages['onlineDocumentationProposalEntry'], template.url); |
61 |
if(template.url) { |
| 62 |
} |
62 |
_h.content += i18nUtil.formatMessage.call(null, Messages['onlineDocumentationProposalEntry'], template.url); |
| 63 |
proposal.hover = _h; |
63 |
} |
| 64 |
proposal.style = 'emphasis'; //$NON-NLS-1$ |
64 |
proposal.hover = _h; |
| 65 |
this.removePrefix(prefix, proposal); |
65 |
proposal.style = 'emphasis'; //$NON-NLS-1$ |
| 66 |
proposal.kind = 'js'; //$NON-NLS-1$ |
66 |
this.removePrefix(prefix, proposal); |
| 67 |
proposals.push(proposal); |
67 |
proposal.kind = 'js'; //$NON-NLS-1$ |
| 68 |
} |
68 |
proposals.push(proposal); |
| 69 |
} |
|
|
| 70 |
|
| 71 |
if (0 < proposals.length) { |
| 72 |
//sort the proposals by name |
| 73 |
proposals.sort(function(p1, p2) { |
| 74 |
if (p1.name < p2.name) { |
| 75 |
return -1; |
| 76 |
} |
| 77 |
if (p1.name > p2.name) { |
| 78 |
return 1; |
| 79 |
} |
69 |
} |
| 80 |
return 0; |
70 |
} |
| 81 |
}); |
71 |
|
|
|
72 |
if (0 < proposals.length) { |
| 73 |
//sort the proposals by name |
| 74 |
proposals.sort(function(p1, p2) { |
| 75 |
if (p1.name < p2.name) { |
| 76 |
return -1; |
| 77 |
} |
| 78 |
if (p1.name > p2.name) { |
| 79 |
return 1; |
| 80 |
} |
| 81 |
return 0; |
| 82 |
}); |
| 83 |
} |
| 82 |
} |
84 |
} |
| 83 |
return proposals; |
85 |
return proposals; |
| 84 |
}, |
86 |
}, |