forked from MiguelCastillo/Brackets-Ternific
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHintHelper.js
More file actions
95 lines (78 loc) · 2.15 KB
/
HintHelper.js
File metadata and controls
95 lines (78 loc) · 2.15 KB
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
/**
* This code has been taken from brackets javascriptcodehints.
*
*/
define(function(require, exports, module){
var SINGLE_QUOTE = "\'",
DOUBLE_QUOTE = "\"",
identifierRegex = /[0-9a-z_.\$]/i;
function pathFile(fullPath) {
var index = fullPath.lastIndexOf('/');
var pathName = fullPath.substr(0, index);
var fileName = fullPath.substr(index);
return {
path: pathName,
file: fileName
};
}
function typeDetails (type) {
var suffix;
if (type == "?") {
suffix = "unknown";
}
else if (type == "number" || type == "string" || type == "bool") {
suffix = type;
}
else if (/^fn\(/.test(type)) {
suffix = "fn";
}
else if (/^\[/.test(type)) {
suffix = "array";
}
else {
suffix = "object";
}
return {
icon: "Tern-completion Tern-completion-" + suffix,
name: suffix
};
}
///
/// The functions below were taken from brackets javascript hinting engine.
///
/**
* Is the string key perhaps a valid JavaScript identifier?
*
* @param {string} key - the string to test
* @return {boolean} - could key be a valid identifier?
*/
function maybeIdentifier(key) {
return identifierRegex.test(key) ||
(key.indexOf(SINGLE_QUOTE) === 0) ||
(key.indexOf(DOUBLE_QUOTE) === 0);
}
/**
* Is the token's class hintable? (A very conservative test.)
*
* @param {Object} token - the token to test for hintability
* @return {boolean} - could the token be hintable?
*/
function hintable(token) {
switch (token.className) {
case "comment":
case "number":
case "regexp":
return false;
default:
return true;
}
}
return {
SINGLE_QUOTE: SINGLE_QUOTE,
DOUBLE_QUOTE: DOUBLE_QUOTE,
typeDetails: typeDetails,
maybeIdentifier: maybeIdentifier,
hintable: hintable,
pathFile: pathFile
};
});