Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 24bbaa9

Browse files
authored
Merge pull request #1 from subhashjha333/subhashMaster
Updating with new LSP Framework Implementation
2 parents 7479c03 + 29474b1 commit 24bbaa9

14 files changed

+2200
-0
lines changed

.eslintrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,15 @@ module.exports = {
8080
"Uint32Array": false,
8181
"WebSocket": false,
8282
"XMLHttpRequest": false
83+
},
84+
"parserOptions": {
85+
"ecmaVersion": 6,
86+
"sourceType": "script",
87+
"ecmaFeatures": {
88+
"arrowFunctions": true,
89+
"binaryLiterals": true,
90+
"blockBindings": true,
91+
"classes": true
92+
}
8393
}
8494
};

src/brackets.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ define(function (require, exports, module) {
154154
//Load common JS module
155155
require("JSUtils/Session");
156156
require("JSUtils/ScopeManager");
157+
158+
//load Language Tools Module
159+
require("languageTools/LanguageTools");
160+
require("languageTools/MessageHandler");
161+
require("languageTools/Interface/nodeInterface");
157162

158163
PerfUtils.addMeasurement("brackets module dependencies resolved");
159164

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
/*
2+
* Copyright (c) 2019 - present Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
/*global require, Promise, exports*/
25+
/*eslint no-invalid-this: 0*/
26+
/*eslint max-len: ["error", { "code": 200 }]*/
27+
(function () {
28+
29+
"use strict";
30+
31+
var EventEmitter = require("events"),
32+
bracketsEventHandler = new EventEmitter();
33+
34+
/** https://gist.github.com/LeverOne/1308368 */
35+
/*eslint-disable */
36+
function _generateUUID() {
37+
var result,
38+
numericSeed;
39+
for (
40+
result = numericSeed = '';
41+
numericSeed++ < 36;
42+
result += numericSeed * 51 & 52 ? (numericSeed ^ 15 ? 8 ^ Math.random() * (numericSeed ^ 20 ? 16 : 4) : 4).toString(16) : '-'
43+
);
44+
45+
return result;
46+
}
47+
/*eslint-enable */
48+
49+
function NodeToBracketsInterface(domainManager, domainName) {
50+
this.domainManager = domainManager;
51+
this.domainName = domainName;
52+
this.nodeFn = {};
53+
54+
this._registerDataEvents();
55+
}
56+
57+
NodeToBracketsInterface.prototype.processRequest = function (params) {
58+
var methodName = params.method;
59+
if (this.nodeFn[methodName]) {
60+
var method = this.nodeFn[methodName];
61+
return method.call(null, params.params);
62+
}
63+
};
64+
65+
NodeToBracketsInterface.prototype.processAsyncRequest = function (params, resolver) {
66+
var methodName = params.method;
67+
if (this.nodeFn[methodName]) {
68+
var method = this.nodeFn[methodName];
69+
method.call(null, params.params) //The Async function should return a promise
70+
.then(function (result) {
71+
resolver(null, result);
72+
}).catch(function (err) {
73+
resolver(err, null);
74+
});
75+
}
76+
};
77+
78+
NodeToBracketsInterface.prototype.processResponse = function (params) {
79+
if (params.requestId) {
80+
if (params.error) {
81+
bracketsEventHandler.emit(params.requestId, params.error);
82+
} else {
83+
bracketsEventHandler.emit(params.requestId, false, params.params);
84+
}
85+
} else {
86+
bracketsEventHandler.emit(params.requestId, "error");
87+
}
88+
};
89+
90+
NodeToBracketsInterface.prototype.createInterface = function (methodName, respond) {
91+
var self = this;
92+
return function (params) {
93+
var callObject = {
94+
method: methodName,
95+
params: params
96+
};
97+
98+
var retval = undefined;
99+
if (respond) {
100+
var requestId = _generateUUID();
101+
102+
callObject["respond"] = true;
103+
callObject["requestId"] = requestId;
104+
105+
self.domainManager.emitEvent(self.domainName, "data", callObject);
106+
107+
retval = new Promise(function (resolve, reject) {
108+
bracketsEventHandler.once(requestId, function (err, response) {
109+
if (err) {
110+
reject(err);
111+
} else {
112+
resolve(response);
113+
}
114+
});
115+
});
116+
} else {
117+
self.domainManager.emitEvent(self.domainName, "data", callObject);
118+
}
119+
return retval;
120+
};
121+
};
122+
123+
NodeToBracketsInterface.prototype.registerMethod = function (methodName, methodHandle) {
124+
var self = this;
125+
if (methodName && methodHandle &&
126+
typeof methodName === "string" && typeof methodHandle === "function") {
127+
self.nodeFn[methodName] = methodHandle;
128+
}
129+
};
130+
131+
NodeToBracketsInterface.prototype.registerMethods = function (methodList) {
132+
var self = this;
133+
methodList.forEach(function (methodObj) {
134+
self.registerMethod(methodObj.methodName, methodObj.methodHandle);
135+
});
136+
};
137+
138+
NodeToBracketsInterface.prototype._registerDataEvents = function () {
139+
if (!this.domainManager.hasDomain(this.domainName)) {
140+
this.domainManager.registerDomain(this.domainName, {
141+
major: 0,
142+
minor: 1
143+
});
144+
}
145+
146+
this.domainManager.registerCommand(
147+
this.domainName,
148+
"data",
149+
this.processRequest.bind(this),
150+
false,
151+
"Receives sync request from brackets",
152+
[
153+
{
154+
name: "params",
155+
type: "object",
156+
description: "json object containing message info"
157+
}
158+
],
159+
[]
160+
);
161+
162+
this.domainManager.registerCommand(
163+
this.domainName,
164+
"response",
165+
this.processResponse.bind(this),
166+
false,
167+
"Receives response from brackets for an earlier request",
168+
[
169+
{
170+
name: "params",
171+
type: "object",
172+
description: "json object containing message info"
173+
}
174+
],
175+
[]
176+
);
177+
178+
this.domainManager.registerCommand(
179+
this.domainName,
180+
"asyncData",
181+
this.processAsyncRequest.bind(this),
182+
true,
183+
"Receives async call request from brackets",
184+
[
185+
{
186+
name: "params",
187+
type: "object",
188+
description: "json object containing message info"
189+
},
190+
{
191+
name: "resolver",
192+
type: "function",
193+
description: "callback required to resolve the async request"
194+
}
195+
],
196+
[]
197+
);
198+
199+
this.domainManager.registerEvent(
200+
this.domainName,
201+
"data",
202+
[
203+
{
204+
name: "params",
205+
type: "object",
206+
description: "json object containing message info to pass to brackets"
207+
}
208+
]
209+
);
210+
};
211+
212+
exports.NodeToBracketsInterface = NodeToBracketsInterface;
213+
}());
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright (c) 2019 - present Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
/*eslint no-invalid-this: 0*/
25+
define(function (require, exports, module) {
26+
"use strict";
27+
28+
function BracketsToNodeInterface(domain) {
29+
this.domain = domain;
30+
this.bracketsFn = {};
31+
32+
this._registerDataEvent();
33+
}
34+
35+
BracketsToNodeInterface.prototype._messageHandler = function (evt, params) {
36+
var methodName = params.method,
37+
self = this;
38+
39+
function _getErrorString(err) {
40+
if (typeof err === "string") {
41+
return err;
42+
} else if (err && err.name && err.name === "Error") {
43+
return err.message;
44+
}
45+
return "Error in executing " + methodName;
46+
47+
}
48+
49+
function _sendResponse(response) {
50+
var responseParams = {
51+
requestId: params.requestId,
52+
params: response
53+
};
54+
self.domain.exec("response", responseParams);
55+
}
56+
57+
function _sendError(err) {
58+
var responseParams = {
59+
requestId: params.requestId,
60+
error: _getErrorString(err)
61+
};
62+
self.domain.exec("response", responseParams);
63+
}
64+
65+
if (self.bracketsFn[methodName]) {
66+
var method = self.bracketsFn[methodName];
67+
try {
68+
var response = method.call(null, params.params);
69+
if (params.respond && params.requestId) {
70+
if (response.promise) {
71+
response.done(function (result) {
72+
_sendResponse(result);
73+
}).fail(function (err) {
74+
_sendError(err);
75+
});
76+
} else {
77+
_sendResponse(response);
78+
}
79+
}
80+
} catch (err) {
81+
if (params.respond && params.requestId) {
82+
_sendError(err);
83+
}
84+
}
85+
}
86+
87+
};
88+
89+
90+
BracketsToNodeInterface.prototype._registerDataEvent = function () {
91+
this.domain.on("data", this._messageHandler.bind(this));
92+
};
93+
94+
BracketsToNodeInterface.prototype.createInterface = function (methodName, isAsync) {
95+
var self = this;
96+
return function (params) {
97+
var execEvent = isAsync ? "asyncData" : "data";
98+
var callObject = {
99+
method: methodName,
100+
params: params
101+
};
102+
return self.domain.exec(execEvent, callObject);
103+
};
104+
};
105+
106+
BracketsToNodeInterface.prototype.registerMethod = function (methodName, methodHandle) {
107+
if (methodName && methodHandle &&
108+
typeof methodName === "string" && typeof methodHandle === "function") {
109+
this.bracketsFn[methodName] = methodHandle;
110+
}
111+
};
112+
113+
BracketsToNodeInterface.prototype.registerMethods = function (methodList) {
114+
var self = this;
115+
methodList.forEach(function (methodObj) {
116+
self.registerMethod(methodObj.methodName, methodObj.methodHandle);
117+
});
118+
};
119+
120+
exports.BracketsToNodeInterface = BracketsToNodeInterface;
121+
});

0 commit comments

Comments
 (0)