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 pathCachingScopeDescriptorHelper.coffee
72 lines (62 loc) · 2.09 KB
/
CachingScopeDescriptorHelper.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
ScopeDescriptorHelper = require './ScopeDescriptorHelper'
module.exports =
##*
# Caching extension of ScopeDescriptorHelper.
##
class CachingScopeDescriptorHelper extends ScopeDescriptorHelper
###*
* @var {Object}
###
cache: null
###*
* @inherited
###
constructor: (@config) ->
@cache = {}
###*
* Clears the cache.
###
clearCache: () ->
@cache = {}
###*
* Internal convenience method that wraps a call to a parent method.
*
* @param {String} cacheKey
* @param {String} parentMethodName
* @param {Array} parameters
*
* @return {Promise|Object}
###
wrapCachedRequestToParent: (cacheKey, parentMethodName, parameters) ->
if cacheKey of @cache
return @cache[cacheKey]
else
@cache[cacheKey] = CachingScopeDescriptorHelper.__super__[parentMethodName].apply(this, parameters)
return @cache[cacheKey]
###*
* @inherited
###
getClassListForBufferPosition: (editor, bufferPosition, climbCount = 1) ->
return @wrapCachedRequestToParent(
"getClassListForBufferPosition-#{editor.getPath()}-#{bufferPosition.row}-#{bufferPosition.column}-#{climbCount}",
'getClassListForBufferPosition',
arguments
)
###*
* @inherited
###
getClassListFollowingBufferPosition: (editor, bufferPosition, climbCountForPosition) ->
return @wrapCachedRequestToParent(
"getClassListFollowingBufferPosition-#{editor.getPath()}-#{bufferPosition.row}-#{bufferPosition.column}-#{climbCountForPosition}",
'getClassListFollowingBufferPosition',
arguments
)
###*
* @inherited
###
getBufferRangeForClassListAtPosition: (editor, classList, bufferPosition, climbCount) ->
return @wrapCachedRequestToParent(
"getBufferRangeForClassListAtPosition-#{editor.getPath()}-#{classList.join('_')}-#{bufferPosition.row}-#{bufferPosition.column}-#{climbCount}",
'getBufferRangeForClassListAtPosition',
arguments
)