This repository has been archived by the owner on Feb 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
SnippetProvider.coffee
69 lines (59 loc) · 2.35 KB
/
SnippetProvider.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
AbstractProvider = require "./AbstractProvider"
module.exports =
##*
# Provides useful snippets.
##
class SnippetProvider extends AbstractProvider
###*
* @inheritdoc
*
* These can appear pretty much everywhere, but not in variable names or as class members. Note that functions can
* also appear inside namespaces, hence the middle part.
###
regex: /(?:^|[^\$:>\w])((?:[a-zA-Z_][a-zA-Z0-9_]*\\)*[a-z_]+)$/
###*
* @inheritdoc
###
getSuggestions: ({editor, bufferPosition, scopeDescriptor, prefix}) ->
return [] if not @service
prefix = @getPrefix(editor, bufferPosition)
return [] unless prefix != null
return @addSuggestions(@fetchTagList(), prefix.trim())
###*
* Returns suggestions available matching the given prefix.
*
* @param {array} tagList
* @param {string} prefix
*
* @return {array}
###
addSuggestions: (tagList, prefix) ->
suggestions = []
for tag in tagList
# NOTE: The description must not be empty for the 'More' button to show up.
suggestions.push
type : 'snippet',
description : 'PHP snippet.'
snippet : tag.snippet
displayText : tag.name
replacementPrefix : prefix
return suggestions
###*
* Retrieves a list of known docblock tags.
*
* @return {array}
###
fetchTagList: () ->
return [
# Useful snippets for keywords:
{name : 'catch', snippet : 'catch (${1:\Exception} ${2:\$e}) {\n ${3:// TODO: Handling.}\n}'},
{name : '__halt_compiler', snippet : '__halt_compiler()'},
{name : 'array', snippet : 'array($1)$0'},
{name : 'die', snippet : 'die($1)$0'},
{name : 'empty', snippet : 'empty(${1:expression})$0'},
{name : 'eval', snippet : 'eval(${1:expression})$0'},
{name : 'exit', snippet : 'exit($1)$0'},
{name : 'isset', snippet : 'isset(${1:${2:\$array}[\'${3:value}\']})$0'},
{name : 'list', snippet : 'list(${1:\$a, \$b})$0'},
{name : 'unset', snippet : 'unset(${1:${2:\$array}[\'${3:value}\']})$0'}
]