-
Notifications
You must be signed in to change notification settings - Fork 0
/
HintRequestModule.js
98 lines (74 loc) · 2.58 KB
/
HintRequestModule.js
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
define(function (require, exports, module) {
"use strict";
var EditorManager = brackets.getModule("editor/EditorManager"),
ScssHintUtils = require("ScssHintUtils");
var cachedRequest = null,
currentRequest = null;
//Prototype functions
function Request(editor) {
var _editor = editor || EditorManager.getActiveEditor(),
pos = _editor.getCursorPos(),
file = _editor.getFile(),
filePath = file.fullpath || file._path,
token = ScssHintUtils.getToken(_editor, pos),
query = token.string;
this.pos = pos;
this.filePath = filePath || null;
this.token = token;
this.query = query;
this.editor = _editor;
this.type = null;
}
Request.prototype.canProvideHintsFor = function (anotherReq) {
if (!anotherReq) {
return false;
}
return (this.pos.line === anotherReq.pos.line &&
this.filePath === anotherReq.filePath &&
// this.token === anotherReq.token &&
this.type === anotherReq.type);
};
Request.prototype.inferType = function (prevKey) {
this.type = ScssHintUtils.getTypeForRequest(this, prevKey);
};
Request.prototype.refresh = function () {
this.pos = this.editor.getCursorPos(),
this.token = ScssHintUtils.getToken(this.editor, this.pos);
this.query = this.token.string;
if (this.token.end > this.pos.ch) {
this.query = this.query.substr(0, this.pos.ch - this.token.start);
}
};
Request.prototype.cacheHints = function (hints) {
this.hints = hints;
};
Request.prototype.updateHints = function (hints) {
this.hints = this.hints || [];
this.hints = this.hints.concat(hints);
};
function getCachedRequest() {
return cachedRequest;
}
function setCachedRequest(req) {
cachedRequest = req;
}
function resetCachedRequest() {
setCachedRequest(null);
}
function getCurrentRequest(refresh) {
if (refresh) {
currentRequest.refresh();
}
return currentRequest;
}
function setCurrentRequest(req) {
currentRequest = req;
}
exports.Request = Request;
exports.getCachedRequest = getCachedRequest;
exports.setCachedRequest = setCachedRequest;
exports.getCurrentRequest = getCurrentRequest;
exports.getCurrentRequest = getCurrentRequest;
exports.setCurrentRequest = setCurrentRequest;
exports.resetCachedRequest = resetCachedRequest;
});