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 0
/
Copy pathPropertyProvider.coffee
157 lines (119 loc) · 5.21 KB
/
PropertyProvider.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
{Point, Range} = require 'atom'
AbstractProvider = require './AbstractProvider'
module.exports =
##*
# Provides code navigation for member properties.
##
class PropertyProvider extends AbstractProvider
###*
* @inheritdoc
###
canProvideForBufferPosition: (editor, bufferPosition) ->
classList = @scopeDescriptorHelper.getClassListForBufferPosition(editor, bufferPosition)
return false if 'php' not in classList
return true if 'property' in classList
# Ensure the dollar sign is also seen as a match
if 'punctuation' in classList and 'definition' in classList and 'variable' in classList
classList = @scopeDescriptorHelper.getClassListFollowingBufferPosition(editor, bufferPosition)
return true if 'variable' in classList and 'other' in classList and 'class' in classList
return false
###*
* @param {TextEditor} editor
* @param {Point} bufferPosition
###
getRangeForBufferPosition: (editor, bufferPosition) ->
classList = @scopeDescriptorHelper.getClassListForBufferPosition(editor, bufferPosition)
range = @scopeDescriptorHelper.getBufferRangeForClassListAtPosition(editor, classList, bufferPosition)
if 'punctuation' in classList and 'definition' in classList and 'variable' in classList
positionAfterBufferPosition = bufferPosition.copy()
positionAfterBufferPosition.column++
classList = @scopeDescriptorHelper.getClassListFollowingBufferPosition(editor, bufferPosition)
staticPropertyRange = @scopeDescriptorHelper.getBufferRangeForClassListAtPosition(editor, classList, positionAfterBufferPosition)
range = range.union(staticPropertyRange)
else # if it is a static property (but not its leading dollar sign)
prefixRange = new Range(
new Point(range.start.row, range.start.column - 1),
new Point(range.start.row, range.start.column - 0)
)
prefixText = editor.getTextInBufferRange(prefixRange)
if prefixText == '$'
range.start.column--
return range
###*
* Convenience method that returns information for the specified term.
*
* @param {TextEditor} editor
* @param {Point} bufferPosition
* @param {String} term
*
* @return {Promise}
###
getInfoFor: (editor, bufferPosition, term) ->
successHandler = (members) =>
return null unless members.length > 0
member = members[0]
return null unless member.declaringStructure.filename
return member
failureHandler = () ->
# Do nothing.
return @getClassPropertiesAt(editor, bufferPosition, term).then(successHandler, failureHandler)
###*
* Returns the class properties used at the specified location.
*
* @param {TextEditor} editor The text editor to use.
* @param {Point} bufferPosition The cursor location of the member.
* @param {String} name The name of the member to retrieve information about.
*
* @return {Promise}
###
getClassPropertiesAt: (editor, bufferPosition, name) ->
if not @isUsingProperty(editor, bufferPosition)
return new Promise (resolve, reject) ->
resolve(null)
successHandler = (types) =>
promises = []
for type in types
promises.push @getClassProperty(type, name)
return Promise.all(promises)
failureHandler = () ->
# Do nothing.
return @service.getResultingTypesAt(editor, bufferPosition, true).then(successHandler, failureHandler)
###*
* Retrieves information about the specified property of the specified class.
*
* @param {String} className The full name of the class to examine.
* @param {String} name The name of the property to retrieve information about.
*
* @return {Promise}
###
getClassProperty: (className, name) ->
successHandler = (classInfo) =>
if name of classInfo.properties
return classInfo.properties[name]
failureHandler = () ->
# Do nothing.
return @service.getClassInfo(className).then(successHandler, failureHandler)
###*
* @inheritdoc
###
handleSpecificNavigation: (editor, range, text) ->
successHandler = (info) =>
return if not info?
atom.workspace.open(info.declaringStructure.filename, {
initialLine : (info.declaringStructure.startLineMember - 1),
searchAllPanes : true
})
failureHandler = () ->
# Do nothing.
@getInfoFor(editor, range.start, text).then(successHandler, failureHandler)
###*
* @example When querying "$this->test", using a position inside 'test' will return true.
*
* @param {TextEditor} editor
* @param {Point} bufferPosition
*
* @return {boolean}
###
isUsingProperty: (editor, bufferPosition) ->
scopeDescriptor = editor.scopeDescriptorForBufferPosition(bufferPosition).getScopeChain()
return (scopeDescriptor.indexOf('.property') != -1)