This repository was 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
/
Copy pathKeywordProvider.coffee
140 lines (129 loc) · 4.08 KB
/
KeywordProvider.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
AbstractProvider = require "./AbstractProvider"
module.exports =
##*
# Provides autocompletion for keywords.
##
class KeywordProvider 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 available suggestions.
*
* @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
text : tag.name
type : 'keyword',
description : 'PHP keyword.'
descriptionMoreURL : @config.get('php_documentation_base_urls').keywords
replacementPrefix : prefix
return suggestions
###*
* Retrieves a list of known docblock tags.
*
* @return {array}
###
fetchTagList: () ->
return [
{name : 'self'},
{name : 'static'},
{name : 'parent'},
# From https://secure.php.net/manual/en/reserved.other-reserved-words.php.
{name : 'int'},
{name : 'float'},
{name : 'bool'},
{name : 'string'},
{name : 'true'},
{name : 'false'},
{name : 'null'},
{name : 'void'},
{name : 'iterable'},
# From https://secure.php.net/manual/en/reserved.keywords.php.
{name : '__halt_compiler'},
{name : 'abstract'},
{name : 'and'},
{name : 'array'},
{name : 'as'},
{name : 'break'},
{name : 'callable'},
{name : 'case'},
{name : 'catch'},
{name : 'class'},
{name : 'clone'},
{name : 'const'},
{name : 'continue'},
{name : 'declare'},
{name : 'default'},
{name : 'die'},
{name : 'do'},
{name : 'echo'},
{name : 'else'},
{name : 'elseif'},
{name : 'empty'},
{name : 'enddeclare'},
{name : 'endfor'},
{name : 'endforeach'},
{name : 'endif'},
{name : 'endswitch'},
{name : 'endwhile'},
{name : 'eval'},
{name : 'exit'},
{name : 'extends'},
{name : 'final'},
{name : 'finally'},
{name : 'for'},
{name : 'foreach'},
{name : 'function'},
{name : 'global'},
{name : 'goto'},
{name : 'if'},
{name : 'implements'},
{name : 'include'},
{name : 'include_once'},
{name : 'instanceof'},
{name : 'insteadof'},
{name : 'interface'},
{name : 'isset'},
{name : 'list'},
{name : 'namespace'},
{name : 'new'},
{name : 'or'},
{name : 'print'},
{name : 'private'},
{name : 'protected'},
{name : 'public'},
{name : 'require'},
{name : 'require_once'},
{name : 'return'},
{name : 'static'},
{name : 'switch'},
{name : 'throw'},
{name : 'trait'},
{name : 'try'},
{name : 'unset'},
{name : 'use'},
{name : 'var'},
{name : 'while'},
{name : 'xor'},
{name : 'yield'}
]