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 pathFunctionProvider.coffee
116 lines (83 loc) · 3.81 KB
/
FunctionProvider.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
shell = require 'shell'
{Point, Range} = require 'atom'
AbstractProvider = require './AbstractProvider'
module.exports =
##*
# Provides code navigation for global functions.
##
class FunctionProvider extends AbstractProvider
###*
* @inheritdoc
###
canProvideForBufferPosition: (editor, bufferPosition) ->
range = @scopeDescriptorHelper.getBufferRangeForClassListAtPosition(editor, ['meta', 'function-call', 'php'], bufferPosition, 0)
return true if range?
classList = @scopeDescriptorHelper.getClassListForBufferPosition(editor, bufferPosition)
return false if 'php' not in classList
return true if 'support' in classList and 'function' in classList
if 'punctuation' in classList
classListFollowingBufferPosition = @scopeDescriptorHelper.getClassListFollowingBufferPosition(editor, bufferPosition)
return true if 'support' in classListFollowingBufferPosition and 'function' in classListFollowingBufferPosition
return false
###*
* @param {TextEditor} editor
* @param {Point} bufferPosition
###
getRangeForBufferPosition: (editor, bufferPosition) ->
range = @scopeDescriptorHelper.getBufferRangeForClassListAtPosition(editor, ['meta', 'function-call', 'php'], bufferPosition, 0)
if not range?
# Built-in function.
classList = @scopeDescriptorHelper.getClassListForBufferPosition(editor, bufferPosition)
range = @scopeDescriptorHelper.getBufferRangeForClassListAtPosition(editor, classList, bufferPosition)
if 'punctuation' in classList
# Include the function call after the leading slash.
positionAfterBufferPosition = bufferPosition.copy()
positionAfterBufferPosition.column++
classList = @scopeDescriptorHelper.getClassListFollowingBufferPosition(editor, bufferPosition)
functionCallRange = @scopeDescriptorHelper.getBufferRangeForClassListAtPosition(editor, classList, positionAfterBufferPosition)
range = range.union(functionCallRange)
else # .support.function.*.php
# Include a leading slash, if any.
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
###*
* @param {String} text
*
* @return {Promise}
###
getInfoFor: (text) ->
successHandler = (functions) =>
if text?[0] != '\\'
text = '\\' + text
return null unless functions and text of functions
return functions[text]
failureHandler = () ->
# Do nothing.
return @service.getGlobalFunctions().then(successHandler, failureHandler)
###*
* @inheritdoc
###
handleSpecificNavigation: (editor, range, text) ->
failureHandler = () ->
# Do nothing.
resolveTypeHandler = (type) =>
successHandler = (info) =>
return if not info?
if info.filename?
atom.workspace.open(info.filename, {
initialLine : (info.startLine - 1),
searchAllPanes : true
})
else
shell.openExternal(@service.getDocumentationUrlForFunction(info.name))
return @getInfoFor(type).then(successHandler, failureHandler)
@service.resolveType(editor.getPath(), range.start.row + 1, text, 'function').then(
resolveTypeHandler,
failureHandler
)