repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
adobe/brackets
|
src/extensions/default/HealthData/HealthDataManager.js
|
sendHealthDataToServer
|
function sendHealthDataToServer() {
var result = new $.Deferred();
getHealthData().done(function (healthData) {
var url = brackets.config.healthDataServerURL,
data = JSON.stringify(healthData);
$.ajax({
url: url,
type: "POST",
data: data,
dataType: "text",
contentType: "text/plain"
})
.done(function () {
result.resolve();
})
.fail(function (jqXHR, status, errorThrown) {
console.error("Error in sending Health Data. Response : " + jqXHR.responseText + ". Status : " + status + ". Error : " + errorThrown);
result.reject();
});
})
.fail(function () {
result.reject();
});
return result.promise();
}
|
javascript
|
function sendHealthDataToServer() {
var result = new $.Deferred();
getHealthData().done(function (healthData) {
var url = brackets.config.healthDataServerURL,
data = JSON.stringify(healthData);
$.ajax({
url: url,
type: "POST",
data: data,
dataType: "text",
contentType: "text/plain"
})
.done(function () {
result.resolve();
})
.fail(function (jqXHR, status, errorThrown) {
console.error("Error in sending Health Data. Response : " + jqXHR.responseText + ". Status : " + status + ". Error : " + errorThrown);
result.reject();
});
})
.fail(function () {
result.reject();
});
return result.promise();
}
|
[
"function",
"sendHealthDataToServer",
"(",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"getHealthData",
"(",
")",
".",
"done",
"(",
"function",
"(",
"healthData",
")",
"{",
"var",
"url",
"=",
"brackets",
".",
"config",
".",
"healthDataServerURL",
",",
"data",
"=",
"JSON",
".",
"stringify",
"(",
"healthData",
")",
";",
"$",
".",
"ajax",
"(",
"{",
"url",
":",
"url",
",",
"type",
":",
"\"POST\"",
",",
"data",
":",
"data",
",",
"dataType",
":",
"\"text\"",
",",
"contentType",
":",
"\"text/plain\"",
"}",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"result",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"jqXHR",
",",
"status",
",",
"errorThrown",
")",
"{",
"console",
".",
"error",
"(",
"\"Error in sending Health Data. Response : \"",
"+",
"jqXHR",
".",
"responseText",
"+",
"\". Status : \"",
"+",
"status",
"+",
"\". Error : \"",
"+",
"errorThrown",
")",
";",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Send data to the server
|
[
"Send",
"data",
"to",
"the",
"server"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/HealthData/HealthDataManager.js#L184-L212
|
train
|
adobe/brackets
|
src/extensions/default/HealthData/HealthDataManager.js
|
sendAnalyticsDataToServer
|
function sendAnalyticsDataToServer(eventParams) {
var result = new $.Deferred();
var analyticsData = getAnalyticsData(eventParams);
$.ajax({
url: brackets.config.analyticsDataServerURL,
type: "POST",
data: JSON.stringify({events: [analyticsData]}),
headers: {
"Content-Type": "application/json",
"x-api-key": brackets.config.serviceKey
}
})
.done(function () {
result.resolve();
})
.fail(function (jqXHR, status, errorThrown) {
console.error("Error in sending Adobe Analytics Data. Response : " + jqXHR.responseText + ". Status : " + status + ". Error : " + errorThrown);
result.reject();
});
return result.promise();
}
|
javascript
|
function sendAnalyticsDataToServer(eventParams) {
var result = new $.Deferred();
var analyticsData = getAnalyticsData(eventParams);
$.ajax({
url: brackets.config.analyticsDataServerURL,
type: "POST",
data: JSON.stringify({events: [analyticsData]}),
headers: {
"Content-Type": "application/json",
"x-api-key": brackets.config.serviceKey
}
})
.done(function () {
result.resolve();
})
.fail(function (jqXHR, status, errorThrown) {
console.error("Error in sending Adobe Analytics Data. Response : " + jqXHR.responseText + ". Status : " + status + ". Error : " + errorThrown);
result.reject();
});
return result.promise();
}
|
[
"function",
"sendAnalyticsDataToServer",
"(",
"eventParams",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"var",
"analyticsData",
"=",
"getAnalyticsData",
"(",
"eventParams",
")",
";",
"$",
".",
"ajax",
"(",
"{",
"url",
":",
"brackets",
".",
"config",
".",
"analyticsDataServerURL",
",",
"type",
":",
"\"POST\"",
",",
"data",
":",
"JSON",
".",
"stringify",
"(",
"{",
"events",
":",
"[",
"analyticsData",
"]",
"}",
")",
",",
"headers",
":",
"{",
"\"Content-Type\"",
":",
"\"application/json\"",
",",
"\"x-api-key\"",
":",
"brackets",
".",
"config",
".",
"serviceKey",
"}",
"}",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"result",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"jqXHR",
",",
"status",
",",
"errorThrown",
")",
"{",
"console",
".",
"error",
"(",
"\"Error in sending Adobe Analytics Data. Response : \"",
"+",
"jqXHR",
".",
"responseText",
"+",
"\". Status : \"",
"+",
"status",
"+",
"\". Error : \"",
"+",
"errorThrown",
")",
";",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Send Analytics data to Server
|
[
"Send",
"Analytics",
"data",
"to",
"Server"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/HealthData/HealthDataManager.js#L215-L237
|
train
|
adobe/brackets
|
src/LiveDevelopment/LiveDevMultiBrowser.js
|
_setStatus
|
function _setStatus(status, closeReason) {
// Don't send a notification when the status didn't actually change
if (status === exports.status) {
return;
}
exports.status = status;
var reason = status === STATUS_INACTIVE ? closeReason : null;
exports.trigger("statusChange", status, reason);
}
|
javascript
|
function _setStatus(status, closeReason) {
// Don't send a notification when the status didn't actually change
if (status === exports.status) {
return;
}
exports.status = status;
var reason = status === STATUS_INACTIVE ? closeReason : null;
exports.trigger("statusChange", status, reason);
}
|
[
"function",
"_setStatus",
"(",
"status",
",",
"closeReason",
")",
"{",
"if",
"(",
"status",
"===",
"exports",
".",
"status",
")",
"{",
"return",
";",
"}",
"exports",
".",
"status",
"=",
"status",
";",
"var",
"reason",
"=",
"status",
"===",
"STATUS_INACTIVE",
"?",
"closeReason",
":",
"null",
";",
"exports",
".",
"trigger",
"(",
"\"statusChange\"",
",",
"status",
",",
"reason",
")",
";",
"}"
] |
Update the status. Triggers a statusChange event.
@param {number} status new status
@param {?string} closeReason Optional string key suffix to display to
user when closing the live development connection (see LIVE_DEV_* keys)
|
[
"Update",
"the",
"status",
".",
"Triggers",
"a",
"statusChange",
"event",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/LiveDevMultiBrowser.js#L201-L211
|
train
|
adobe/brackets
|
src/LiveDevelopment/LiveDevMultiBrowser.js
|
_docIsOutOfSync
|
function _docIsOutOfSync(doc) {
var liveDoc = _server && _server.get(doc.file.fullPath),
isLiveEditingEnabled = liveDoc && liveDoc.isLiveEditingEnabled();
return doc.isDirty && !isLiveEditingEnabled;
}
|
javascript
|
function _docIsOutOfSync(doc) {
var liveDoc = _server && _server.get(doc.file.fullPath),
isLiveEditingEnabled = liveDoc && liveDoc.isLiveEditingEnabled();
return doc.isDirty && !isLiveEditingEnabled;
}
|
[
"function",
"_docIsOutOfSync",
"(",
"doc",
")",
"{",
"var",
"liveDoc",
"=",
"_server",
"&&",
"_server",
".",
"get",
"(",
"doc",
".",
"file",
".",
"fullPath",
")",
",",
"isLiveEditingEnabled",
"=",
"liveDoc",
"&&",
"liveDoc",
".",
"isLiveEditingEnabled",
"(",
")",
";",
"return",
"doc",
".",
"isDirty",
"&&",
"!",
"isLiveEditingEnabled",
";",
"}"
] |
Documents are considered to be out-of-sync if they are dirty and
do not have "update while editing" support
@param {Document} doc
@return {boolean}
|
[
"Documents",
"are",
"considered",
"to",
"be",
"out",
"-",
"of",
"-",
"sync",
"if",
"they",
"are",
"dirty",
"and",
"do",
"not",
"have",
"update",
"while",
"editing",
"support"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/LiveDevMultiBrowser.js#L278-L283
|
train
|
adobe/brackets
|
src/LiveDevelopment/LiveDevMultiBrowser.js
|
_styleSheetAdded
|
function _styleSheetAdded(event, url, roots) {
var path = _server && _server.urlToPath(url),
alreadyAdded = !!_relatedDocuments[url];
// path may be null if loading an external stylesheet.
// Also, the stylesheet may already exist and be reported as added twice
// due to Chrome reporting added/removed events after incremental changes
// are pushed to the browser
if (!path || alreadyAdded) {
return;
}
var docPromise = DocumentManager.getDocumentForPath(path);
docPromise.done(function (doc) {
if ((_classForDocument(doc) === LiveCSSDocument) &&
(!_liveDocument || (doc !== _liveDocument.doc))) {
var liveDoc = _createLiveDocument(doc, doc._masterEditor, roots);
if (liveDoc) {
_server.add(liveDoc);
_relatedDocuments[doc.url] = liveDoc;
liveDoc.on("updateDoc", function (event, url) {
var path = _server.urlToPath(url),
doc = getLiveDocForPath(path);
doc._updateBrowser();
});
}
}
});
}
|
javascript
|
function _styleSheetAdded(event, url, roots) {
var path = _server && _server.urlToPath(url),
alreadyAdded = !!_relatedDocuments[url];
// path may be null if loading an external stylesheet.
// Also, the stylesheet may already exist and be reported as added twice
// due to Chrome reporting added/removed events after incremental changes
// are pushed to the browser
if (!path || alreadyAdded) {
return;
}
var docPromise = DocumentManager.getDocumentForPath(path);
docPromise.done(function (doc) {
if ((_classForDocument(doc) === LiveCSSDocument) &&
(!_liveDocument || (doc !== _liveDocument.doc))) {
var liveDoc = _createLiveDocument(doc, doc._masterEditor, roots);
if (liveDoc) {
_server.add(liveDoc);
_relatedDocuments[doc.url] = liveDoc;
liveDoc.on("updateDoc", function (event, url) {
var path = _server.urlToPath(url),
doc = getLiveDocForPath(path);
doc._updateBrowser();
});
}
}
});
}
|
[
"function",
"_styleSheetAdded",
"(",
"event",
",",
"url",
",",
"roots",
")",
"{",
"var",
"path",
"=",
"_server",
"&&",
"_server",
".",
"urlToPath",
"(",
"url",
")",
",",
"alreadyAdded",
"=",
"!",
"!",
"_relatedDocuments",
"[",
"url",
"]",
";",
"if",
"(",
"!",
"path",
"||",
"alreadyAdded",
")",
"{",
"return",
";",
"}",
"var",
"docPromise",
"=",
"DocumentManager",
".",
"getDocumentForPath",
"(",
"path",
")",
";",
"docPromise",
".",
"done",
"(",
"function",
"(",
"doc",
")",
"{",
"if",
"(",
"(",
"_classForDocument",
"(",
"doc",
")",
"===",
"LiveCSSDocument",
")",
"&&",
"(",
"!",
"_liveDocument",
"||",
"(",
"doc",
"!==",
"_liveDocument",
".",
"doc",
")",
")",
")",
"{",
"var",
"liveDoc",
"=",
"_createLiveDocument",
"(",
"doc",
",",
"doc",
".",
"_masterEditor",
",",
"roots",
")",
";",
"if",
"(",
"liveDoc",
")",
"{",
"_server",
".",
"add",
"(",
"liveDoc",
")",
";",
"_relatedDocuments",
"[",
"doc",
".",
"url",
"]",
"=",
"liveDoc",
";",
"liveDoc",
".",
"on",
"(",
"\"updateDoc\"",
",",
"function",
"(",
"event",
",",
"url",
")",
"{",
"var",
"path",
"=",
"_server",
".",
"urlToPath",
"(",
"url",
")",
",",
"doc",
"=",
"getLiveDocForPath",
"(",
"path",
")",
";",
"doc",
".",
"_updateBrowser",
"(",
")",
";",
"}",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] |
Handles a notification from the browser that a stylesheet was loaded into
the live HTML document. If the stylesheet maps to a file in the project, then
creates a live document for the stylesheet and adds it to _relatedDocuments.
@param {$.Event} event
@param {string} url The URL of the stylesheet that was added.
@param {array} roots The URLs of the roots of the stylesheet (the css files loaded through <link>)
|
[
"Handles",
"a",
"notification",
"from",
"the",
"browser",
"that",
"a",
"stylesheet",
"was",
"loaded",
"into",
"the",
"live",
"HTML",
"document",
".",
"If",
"the",
"stylesheet",
"maps",
"to",
"a",
"file",
"in",
"the",
"project",
"then",
"creates",
"a",
"live",
"document",
"for",
"the",
"stylesheet",
"and",
"adds",
"it",
"to",
"_relatedDocuments",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/LiveDevMultiBrowser.js#L293-L322
|
train
|
adobe/brackets
|
src/LiveDevelopment/LiveDevMultiBrowser.js
|
open
|
function open() {
// TODO: need to run _onDocumentChange() after load if doc != currentDocument here? Maybe not, since activeEditorChange
// doesn't trigger it, while inline editors can still cause edits in doc other than currentDoc...
_getInitialDocFromCurrent().done(function (doc) {
var prepareServerPromise = (doc && _prepareServer(doc)) || new $.Deferred().reject(),
otherDocumentsInWorkingFiles;
if (doc && !doc._masterEditor) {
otherDocumentsInWorkingFiles = MainViewManager.getWorkingSetSize(MainViewManager.ALL_PANES);
MainViewManager.addToWorkingSet(MainViewManager.ACTIVE_PANE, doc.file);
if (!otherDocumentsInWorkingFiles) {
CommandManager.execute(Commands.CMD_OPEN, { fullPath: doc.file.fullPath });
}
}
// wait for server (StaticServer, Base URL or file:)
prepareServerPromise
.done(function () {
_setStatus(STATUS_CONNECTING);
_doLaunchAfterServerReady(doc);
})
.fail(function () {
_showWrongDocError();
});
});
}
|
javascript
|
function open() {
// TODO: need to run _onDocumentChange() after load if doc != currentDocument here? Maybe not, since activeEditorChange
// doesn't trigger it, while inline editors can still cause edits in doc other than currentDoc...
_getInitialDocFromCurrent().done(function (doc) {
var prepareServerPromise = (doc && _prepareServer(doc)) || new $.Deferred().reject(),
otherDocumentsInWorkingFiles;
if (doc && !doc._masterEditor) {
otherDocumentsInWorkingFiles = MainViewManager.getWorkingSetSize(MainViewManager.ALL_PANES);
MainViewManager.addToWorkingSet(MainViewManager.ACTIVE_PANE, doc.file);
if (!otherDocumentsInWorkingFiles) {
CommandManager.execute(Commands.CMD_OPEN, { fullPath: doc.file.fullPath });
}
}
// wait for server (StaticServer, Base URL or file:)
prepareServerPromise
.done(function () {
_setStatus(STATUS_CONNECTING);
_doLaunchAfterServerReady(doc);
})
.fail(function () {
_showWrongDocError();
});
});
}
|
[
"function",
"open",
"(",
")",
"{",
"_getInitialDocFromCurrent",
"(",
")",
".",
"done",
"(",
"function",
"(",
"doc",
")",
"{",
"var",
"prepareServerPromise",
"=",
"(",
"doc",
"&&",
"_prepareServer",
"(",
"doc",
")",
")",
"||",
"new",
"$",
".",
"Deferred",
"(",
")",
".",
"reject",
"(",
")",
",",
"otherDocumentsInWorkingFiles",
";",
"if",
"(",
"doc",
"&&",
"!",
"doc",
".",
"_masterEditor",
")",
"{",
"otherDocumentsInWorkingFiles",
"=",
"MainViewManager",
".",
"getWorkingSetSize",
"(",
"MainViewManager",
".",
"ALL_PANES",
")",
";",
"MainViewManager",
".",
"addToWorkingSet",
"(",
"MainViewManager",
".",
"ACTIVE_PANE",
",",
"doc",
".",
"file",
")",
";",
"if",
"(",
"!",
"otherDocumentsInWorkingFiles",
")",
"{",
"CommandManager",
".",
"execute",
"(",
"Commands",
".",
"CMD_OPEN",
",",
"{",
"fullPath",
":",
"doc",
".",
"file",
".",
"fullPath",
"}",
")",
";",
"}",
"}",
"prepareServerPromise",
".",
"done",
"(",
"function",
"(",
")",
"{",
"_setStatus",
"(",
"STATUS_CONNECTING",
")",
";",
"_doLaunchAfterServerReady",
"(",
"doc",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"_showWrongDocError",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Open a live preview on the current docuemnt.
|
[
"Open",
"a",
"live",
"preview",
"on",
"the",
"current",
"docuemnt",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/LiveDevMultiBrowser.js#L691-L717
|
train
|
adobe/brackets
|
src/LiveDevelopment/LiveDevMultiBrowser.js
|
init
|
function init(config) {
exports.config = config;
MainViewManager
.on("currentFileChange", _onFileChange);
DocumentManager
.on("documentSaved", _onDocumentSaved)
.on("dirtyFlagChange", _onDirtyFlagChange);
ProjectManager
.on("beforeProjectClose beforeAppClose", close);
// Default transport for live connection messages - can be changed
setTransport(NodeSocketTransport);
// Default launcher for preview browser - can be changed
setLauncher(DefaultLauncher);
// Initialize exports.status
_setStatus(STATUS_INACTIVE);
}
|
javascript
|
function init(config) {
exports.config = config;
MainViewManager
.on("currentFileChange", _onFileChange);
DocumentManager
.on("documentSaved", _onDocumentSaved)
.on("dirtyFlagChange", _onDirtyFlagChange);
ProjectManager
.on("beforeProjectClose beforeAppClose", close);
// Default transport for live connection messages - can be changed
setTransport(NodeSocketTransport);
// Default launcher for preview browser - can be changed
setLauncher(DefaultLauncher);
// Initialize exports.status
_setStatus(STATUS_INACTIVE);
}
|
[
"function",
"init",
"(",
"config",
")",
"{",
"exports",
".",
"config",
"=",
"config",
";",
"MainViewManager",
".",
"on",
"(",
"\"currentFileChange\"",
",",
"_onFileChange",
")",
";",
"DocumentManager",
".",
"on",
"(",
"\"documentSaved\"",
",",
"_onDocumentSaved",
")",
".",
"on",
"(",
"\"dirtyFlagChange\"",
",",
"_onDirtyFlagChange",
")",
";",
"ProjectManager",
".",
"on",
"(",
"\"beforeProjectClose beforeAppClose\"",
",",
"close",
")",
";",
"setTransport",
"(",
"NodeSocketTransport",
")",
";",
"setLauncher",
"(",
"DefaultLauncher",
")",
";",
"_setStatus",
"(",
"STATUS_INACTIVE",
")",
";",
"}"
] |
Initialize the LiveDevelopment module.
|
[
"Initialize",
"the",
"LiveDevelopment",
"module",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/LiveDevMultiBrowser.js#L818-L836
|
train
|
adobe/brackets
|
src/LiveDevelopment/LiveDevMultiBrowser.js
|
getCurrentProjectServerConfig
|
function getCurrentProjectServerConfig() {
return {
baseUrl: ProjectManager.getBaseUrl(),
pathResolver: ProjectManager.makeProjectRelativeIfPossible,
root: ProjectManager.getProjectRoot().fullPath
};
}
|
javascript
|
function getCurrentProjectServerConfig() {
return {
baseUrl: ProjectManager.getBaseUrl(),
pathResolver: ProjectManager.makeProjectRelativeIfPossible,
root: ProjectManager.getProjectRoot().fullPath
};
}
|
[
"function",
"getCurrentProjectServerConfig",
"(",
")",
"{",
"return",
"{",
"baseUrl",
":",
"ProjectManager",
".",
"getBaseUrl",
"(",
")",
",",
"pathResolver",
":",
"ProjectManager",
".",
"makeProjectRelativeIfPossible",
",",
"root",
":",
"ProjectManager",
".",
"getProjectRoot",
"(",
")",
".",
"fullPath",
"}",
";",
"}"
] |
Returns current project server config. Copied from original LiveDevelopment.
|
[
"Returns",
"current",
"project",
"server",
"config",
".",
"Copied",
"from",
"original",
"LiveDevelopment",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/LiveDevMultiBrowser.js#L894-L900
|
train
|
adobe/brackets
|
src/extensions/default/DebugCommands/NodeDebugUtils.js
|
logNodeState
|
function logNodeState() {
if (brackets.app && brackets.app.getNodeState) {
brackets.app.getNodeState(function (err, port) {
if (err) {
console.log("[NodeDebugUtils] Node is in error state " + err);
} else {
console.log("[NodeDebugUtils] Node is listening on port " + port);
}
});
} else {
console.error("[NodeDebugUtils] No brackets.app.getNodeState function. Maybe you're running the wrong shell?");
}
}
|
javascript
|
function logNodeState() {
if (brackets.app && brackets.app.getNodeState) {
brackets.app.getNodeState(function (err, port) {
if (err) {
console.log("[NodeDebugUtils] Node is in error state " + err);
} else {
console.log("[NodeDebugUtils] Node is listening on port " + port);
}
});
} else {
console.error("[NodeDebugUtils] No brackets.app.getNodeState function. Maybe you're running the wrong shell?");
}
}
|
[
"function",
"logNodeState",
"(",
")",
"{",
"if",
"(",
"brackets",
".",
"app",
"&&",
"brackets",
".",
"app",
".",
"getNodeState",
")",
"{",
"brackets",
".",
"app",
".",
"getNodeState",
"(",
"function",
"(",
"err",
",",
"port",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"\"[NodeDebugUtils] Node is in error state \"",
"+",
"err",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"\"[NodeDebugUtils] Node is listening on port \"",
"+",
"port",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"\"[NodeDebugUtils] No brackets.app.getNodeState function. Maybe you're running the wrong shell?\"",
")",
";",
"}",
"}"
] |
Logs the state of the current node server to the console.
|
[
"Logs",
"the",
"state",
"of",
"the",
"current",
"node",
"server",
"to",
"the",
"console",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/DebugCommands/NodeDebugUtils.js#L47-L59
|
train
|
adobe/brackets
|
src/extensions/default/DebugCommands/NodeDebugUtils.js
|
restartNode
|
function restartNode() {
try {
_nodeConnection.domains.base.restartNode();
} catch (e) {
window.alert("Failed trying to restart Node: " + e.message);
}
}
|
javascript
|
function restartNode() {
try {
_nodeConnection.domains.base.restartNode();
} catch (e) {
window.alert("Failed trying to restart Node: " + e.message);
}
}
|
[
"function",
"restartNode",
"(",
")",
"{",
"try",
"{",
"_nodeConnection",
".",
"domains",
".",
"base",
".",
"restartNode",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"window",
".",
"alert",
"(",
"\"Failed trying to restart Node: \"",
"+",
"e",
".",
"message",
")",
";",
"}",
"}"
] |
Sends a command to node to cause a restart.
|
[
"Sends",
"a",
"command",
"to",
"node",
"to",
"cause",
"a",
"restart",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/DebugCommands/NodeDebugUtils.js#L64-L70
|
train
|
adobe/brackets
|
src/extensions/default/DebugCommands/NodeDebugUtils.js
|
enableDebugger
|
function enableDebugger() {
try {
_nodeConnection.domains.base.enableDebugger();
} catch (e) {
window.alert("Failed trying to enable Node debugger: " + e.message);
}
}
|
javascript
|
function enableDebugger() {
try {
_nodeConnection.domains.base.enableDebugger();
} catch (e) {
window.alert("Failed trying to enable Node debugger: " + e.message);
}
}
|
[
"function",
"enableDebugger",
"(",
")",
"{",
"try",
"{",
"_nodeConnection",
".",
"domains",
".",
"base",
".",
"enableDebugger",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"window",
".",
"alert",
"(",
"\"Failed trying to enable Node debugger: \"",
"+",
"e",
".",
"message",
")",
";",
"}",
"}"
] |
Sends a command to node to enable the debugger.
|
[
"Sends",
"a",
"command",
"to",
"node",
"to",
"enable",
"the",
"debugger",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/DebugCommands/NodeDebugUtils.js#L75-L81
|
train
|
adobe/brackets
|
src/extensions/default/CSSCodeHints/main.js
|
formatHints
|
function formatHints(hints, query) {
var hasColorSwatch = hints.some(function (token) {
return token.color;
});
StringMatch.basicMatchSort(hints);
return hints.map(function (token) {
var $hintObj = $("<span>").addClass("brackets-css-hints");
// highlight the matched portion of each hint
if (token.stringRanges) {
token.stringRanges.forEach(function (item) {
if (item.matched) {
$hintObj.append($("<span>")
.text(item.text)
.addClass("matched-hint"));
} else {
$hintObj.append(item.text);
}
});
} else {
$hintObj.text(token.value);
}
if (hasColorSwatch) {
$hintObj = ColorUtils.formatColorHint($hintObj, token.color);
}
return $hintObj;
});
}
|
javascript
|
function formatHints(hints, query) {
var hasColorSwatch = hints.some(function (token) {
return token.color;
});
StringMatch.basicMatchSort(hints);
return hints.map(function (token) {
var $hintObj = $("<span>").addClass("brackets-css-hints");
// highlight the matched portion of each hint
if (token.stringRanges) {
token.stringRanges.forEach(function (item) {
if (item.matched) {
$hintObj.append($("<span>")
.text(item.text)
.addClass("matched-hint"));
} else {
$hintObj.append(item.text);
}
});
} else {
$hintObj.text(token.value);
}
if (hasColorSwatch) {
$hintObj = ColorUtils.formatColorHint($hintObj, token.color);
}
return $hintObj;
});
}
|
[
"function",
"formatHints",
"(",
"hints",
",",
"query",
")",
"{",
"var",
"hasColorSwatch",
"=",
"hints",
".",
"some",
"(",
"function",
"(",
"token",
")",
"{",
"return",
"token",
".",
"color",
";",
"}",
")",
";",
"StringMatch",
".",
"basicMatchSort",
"(",
"hints",
")",
";",
"return",
"hints",
".",
"map",
"(",
"function",
"(",
"token",
")",
"{",
"var",
"$hintObj",
"=",
"$",
"(",
"\"<span>\"",
")",
".",
"addClass",
"(",
"\"brackets-css-hints\"",
")",
";",
"if",
"(",
"token",
".",
"stringRanges",
")",
"{",
"token",
".",
"stringRanges",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"item",
".",
"matched",
")",
"{",
"$hintObj",
".",
"append",
"(",
"$",
"(",
"\"<span>\"",
")",
".",
"text",
"(",
"item",
".",
"text",
")",
".",
"addClass",
"(",
"\"matched-hint\"",
")",
")",
";",
"}",
"else",
"{",
"$hintObj",
".",
"append",
"(",
"item",
".",
"text",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"$hintObj",
".",
"text",
"(",
"token",
".",
"value",
")",
";",
"}",
"if",
"(",
"hasColorSwatch",
")",
"{",
"$hintObj",
"=",
"ColorUtils",
".",
"formatColorHint",
"(",
"$hintObj",
",",
"token",
".",
"color",
")",
";",
"}",
"return",
"$hintObj",
";",
"}",
")",
";",
"}"
] |
Returns a sorted and formatted list of hints with the query substring
highlighted.
@param {Array.<Object>} hints - the list of hints to format
@param {string} query - querystring used for highlighting matched
portions of each hint
@return {Array.jQuery} sorted Array of jQuery DOM elements to insert
|
[
"Returns",
"a",
"sorted",
"and",
"formatted",
"list",
"of",
"hints",
"with",
"the",
"query",
"substring",
"highlighted",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CSSCodeHints/main.js#L193-L223
|
train
|
adobe/brackets
|
src/filesystem/FileSystemEntry.js
|
compareFilesWithIndices
|
function compareFilesWithIndices(index1, index2) {
return entries[index1]._name.toLocaleLowerCase().localeCompare(entries[index2]._name.toLocaleLowerCase());
}
|
javascript
|
function compareFilesWithIndices(index1, index2) {
return entries[index1]._name.toLocaleLowerCase().localeCompare(entries[index2]._name.toLocaleLowerCase());
}
|
[
"function",
"compareFilesWithIndices",
"(",
"index1",
",",
"index2",
")",
"{",
"return",
"entries",
"[",
"index1",
"]",
".",
"_name",
".",
"toLocaleLowerCase",
"(",
")",
".",
"localeCompare",
"(",
"entries",
"[",
"index2",
"]",
".",
"_name",
".",
"toLocaleLowerCase",
"(",
")",
")",
";",
"}"
] |
sort entries if required
|
[
"sort",
"entries",
"if",
"required"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/FileSystemEntry.js#L510-L512
|
train
|
adobe/brackets
|
src/search/node/FindInFilesDomain.js
|
offsetToLineNum
|
function offsetToLineNum(textOrLines, offset) {
if (Array.isArray(textOrLines)) {
var lines = textOrLines,
total = 0,
line;
for (line = 0; line < lines.length; line++) {
if (total < offset) {
// add 1 per line since /n were removed by splitting, but they needed to
// contribute to the total offset count
total += lines[line].length + 1;
} else if (total === offset) {
return line;
} else {
return line - 1;
}
}
// if offset is NOT over the total then offset is in the last line
if (offset <= total) {
return line - 1;
} else {
return undefined;
}
} else {
return textOrLines.substr(0, offset).split("\n").length - 1;
}
}
|
javascript
|
function offsetToLineNum(textOrLines, offset) {
if (Array.isArray(textOrLines)) {
var lines = textOrLines,
total = 0,
line;
for (line = 0; line < lines.length; line++) {
if (total < offset) {
// add 1 per line since /n were removed by splitting, but they needed to
// contribute to the total offset count
total += lines[line].length + 1;
} else if (total === offset) {
return line;
} else {
return line - 1;
}
}
// if offset is NOT over the total then offset is in the last line
if (offset <= total) {
return line - 1;
} else {
return undefined;
}
} else {
return textOrLines.substr(0, offset).split("\n").length - 1;
}
}
|
[
"function",
"offsetToLineNum",
"(",
"textOrLines",
",",
"offset",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"textOrLines",
")",
")",
"{",
"var",
"lines",
"=",
"textOrLines",
",",
"total",
"=",
"0",
",",
"line",
";",
"for",
"(",
"line",
"=",
"0",
";",
"line",
"<",
"lines",
".",
"length",
";",
"line",
"++",
")",
"{",
"if",
"(",
"total",
"<",
"offset",
")",
"{",
"total",
"+=",
"lines",
"[",
"line",
"]",
".",
"length",
"+",
"1",
";",
"}",
"else",
"if",
"(",
"total",
"===",
"offset",
")",
"{",
"return",
"line",
";",
"}",
"else",
"{",
"return",
"line",
"-",
"1",
";",
"}",
"}",
"if",
"(",
"offset",
"<=",
"total",
")",
"{",
"return",
"line",
"-",
"1",
";",
"}",
"else",
"{",
"return",
"undefined",
";",
"}",
"}",
"else",
"{",
"return",
"textOrLines",
".",
"substr",
"(",
"0",
",",
"offset",
")",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"\\n",
"-",
"length",
";",
"}",
"}"
] |
Copied from StringUtils.js
Returns a line number corresponding to an offset in some text. The text can
be specified as a single string or as an array of strings that correspond to
the lines of the string.
Specify the text in lines when repeatedly calling the function on the same
text in a loop. Use getLines() to divide the text into lines, then repeatedly call
this function to compute a line number from the offset.
@param {string | Array.<string>} textOrLines - string or array of lines from which
to compute the line number from the offset
@param {number} offset
@return {number} line number
|
[
"Copied",
"from",
"StringUtils",
".",
"js",
"Returns",
"a",
"line",
"number",
"corresponding",
"to",
"an",
"offset",
"in",
"some",
"text",
".",
"The",
"text",
"can",
"be",
"specified",
"as",
"a",
"single",
"string",
"or",
"as",
"an",
"array",
"of",
"strings",
"that",
"correspond",
"to",
"the",
"lines",
"of",
"the",
"string",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/node/FindInFilesDomain.js#L68-L94
|
train
|
adobe/brackets
|
src/search/node/FindInFilesDomain.js
|
getSearchMatches
|
function getSearchMatches(contents, queryExpr) {
if (!contents) {
return;
}
// Quick exit if not found or if we hit the limit
if (foundMaximum || contents.search(queryExpr) === -1) {
return [];
}
var match, lineNum, line, ch, totalMatchLength, matchedLines, numMatchedLines, lastLineLength, endCh,
padding, leftPadding, rightPadding, highlightOffset, highlightEndCh,
lines = contents.split("\n"),
matches = [];
while ((match = queryExpr.exec(contents)) !== null) {
lineNum = offsetToLineNum(lines, match.index);
line = lines[lineNum];
ch = match.index - contents.lastIndexOf("\n", match.index) - 1; // 0-based index
matchedLines = match[0].split("\n");
numMatchedLines = matchedLines.length;
totalMatchLength = match[0].length;
lastLineLength = matchedLines[matchedLines.length - 1].length;
endCh = (numMatchedLines === 1 ? ch + totalMatchLength : lastLineLength);
highlightEndCh = (numMatchedLines === 1 ? endCh : line.length);
highlightOffset = 0;
if (highlightEndCh <= MAX_DISPLAY_LENGTH) {
// Don't store more than 200 chars per line
line = line.substr(0, Math.min(MAX_DISPLAY_LENGTH, line.length));
} else if (totalMatchLength > MAX_DISPLAY_LENGTH) {
// impossible to display the whole match
line = line.substr(ch, ch + MAX_DISPLAY_LENGTH);
highlightOffset = ch;
} else {
// Try to have both beginning and end of match displayed
padding = MAX_DISPLAY_LENGTH - totalMatchLength;
rightPadding = Math.floor(Math.min(padding / 2, line.length - highlightEndCh));
leftPadding = Math.ceil(padding - rightPadding);
highlightOffset = ch - leftPadding;
line = line.substring(highlightOffset, highlightEndCh + rightPadding);
}
matches.push({
start: {line: lineNum, ch: ch},
end: {line: lineNum + numMatchedLines - 1, ch: endCh},
highlightOffset: highlightOffset,
// Note that the following offsets from the beginning of the file are *not* updated if the search
// results change. These are currently only used for multi-file replacement, and we always
// abort the replace (by shutting the results panel) if we detect any result changes, so we don't
// need to keep them up to date. Eventually, we should either get rid of the need for these (by
// doing everything in terms of line/ch offsets, though that will require re-splitting files when
// doing a replace) or properly update them.
startOffset: match.index,
endOffset: match.index + totalMatchLength,
line: line,
result: match,
isChecked: true
});
// We have the max hits in just this 1 file. Stop searching this file.
// This fixed issue #1829 where code hangs on too many hits.
// Adds one over MAX_RESULTS_IN_A_FILE in order to know if the search has exceeded
// or is equal to MAX_RESULTS_IN_A_FILE. Additional result removed in SearchModel
if (matches.length > MAX_RESULTS_IN_A_FILE) {
queryExpr.lastIndex = 0;
break;
}
// Pathological regexps like /^/ return 0-length matches. Ensure we make progress anyway
if (totalMatchLength === 0) {
queryExpr.lastIndex++;
}
}
return matches;
}
|
javascript
|
function getSearchMatches(contents, queryExpr) {
if (!contents) {
return;
}
// Quick exit if not found or if we hit the limit
if (foundMaximum || contents.search(queryExpr) === -1) {
return [];
}
var match, lineNum, line, ch, totalMatchLength, matchedLines, numMatchedLines, lastLineLength, endCh,
padding, leftPadding, rightPadding, highlightOffset, highlightEndCh,
lines = contents.split("\n"),
matches = [];
while ((match = queryExpr.exec(contents)) !== null) {
lineNum = offsetToLineNum(lines, match.index);
line = lines[lineNum];
ch = match.index - contents.lastIndexOf("\n", match.index) - 1; // 0-based index
matchedLines = match[0].split("\n");
numMatchedLines = matchedLines.length;
totalMatchLength = match[0].length;
lastLineLength = matchedLines[matchedLines.length - 1].length;
endCh = (numMatchedLines === 1 ? ch + totalMatchLength : lastLineLength);
highlightEndCh = (numMatchedLines === 1 ? endCh : line.length);
highlightOffset = 0;
if (highlightEndCh <= MAX_DISPLAY_LENGTH) {
// Don't store more than 200 chars per line
line = line.substr(0, Math.min(MAX_DISPLAY_LENGTH, line.length));
} else if (totalMatchLength > MAX_DISPLAY_LENGTH) {
// impossible to display the whole match
line = line.substr(ch, ch + MAX_DISPLAY_LENGTH);
highlightOffset = ch;
} else {
// Try to have both beginning and end of match displayed
padding = MAX_DISPLAY_LENGTH - totalMatchLength;
rightPadding = Math.floor(Math.min(padding / 2, line.length - highlightEndCh));
leftPadding = Math.ceil(padding - rightPadding);
highlightOffset = ch - leftPadding;
line = line.substring(highlightOffset, highlightEndCh + rightPadding);
}
matches.push({
start: {line: lineNum, ch: ch},
end: {line: lineNum + numMatchedLines - 1, ch: endCh},
highlightOffset: highlightOffset,
// Note that the following offsets from the beginning of the file are *not* updated if the search
// results change. These are currently only used for multi-file replacement, and we always
// abort the replace (by shutting the results panel) if we detect any result changes, so we don't
// need to keep them up to date. Eventually, we should either get rid of the need for these (by
// doing everything in terms of line/ch offsets, though that will require re-splitting files when
// doing a replace) or properly update them.
startOffset: match.index,
endOffset: match.index + totalMatchLength,
line: line,
result: match,
isChecked: true
});
// We have the max hits in just this 1 file. Stop searching this file.
// This fixed issue #1829 where code hangs on too many hits.
// Adds one over MAX_RESULTS_IN_A_FILE in order to know if the search has exceeded
// or is equal to MAX_RESULTS_IN_A_FILE. Additional result removed in SearchModel
if (matches.length > MAX_RESULTS_IN_A_FILE) {
queryExpr.lastIndex = 0;
break;
}
// Pathological regexps like /^/ return 0-length matches. Ensure we make progress anyway
if (totalMatchLength === 0) {
queryExpr.lastIndex++;
}
}
return matches;
}
|
[
"function",
"getSearchMatches",
"(",
"contents",
",",
"queryExpr",
")",
"{",
"if",
"(",
"!",
"contents",
")",
"{",
"return",
";",
"}",
"if",
"(",
"foundMaximum",
"||",
"contents",
".",
"search",
"(",
"queryExpr",
")",
"===",
"-",
"1",
")",
"{",
"return",
"[",
"]",
";",
"}",
"var",
"match",
",",
"lineNum",
",",
"line",
",",
"ch",
",",
"totalMatchLength",
",",
"matchedLines",
",",
"numMatchedLines",
",",
"lastLineLength",
",",
"endCh",
",",
"padding",
",",
"leftPadding",
",",
"rightPadding",
",",
"highlightOffset",
",",
"highlightEndCh",
",",
"lines",
"=",
"contents",
".",
"split",
"(",
"\"\\n\"",
")",
",",
"\\n",
";",
"matches",
"=",
"[",
"]",
"while",
"(",
"(",
"match",
"=",
"queryExpr",
".",
"exec",
"(",
"contents",
")",
")",
"!==",
"null",
")",
"{",
"lineNum",
"=",
"offsetToLineNum",
"(",
"lines",
",",
"match",
".",
"index",
")",
";",
"line",
"=",
"lines",
"[",
"lineNum",
"]",
";",
"ch",
"=",
"match",
".",
"index",
"-",
"contents",
".",
"lastIndexOf",
"(",
"\"\\n\"",
",",
"\\n",
")",
"-",
"match",
".",
"index",
";",
"1",
"matchedLines",
"=",
"match",
"[",
"0",
"]",
".",
"split",
"(",
"\"\\n\"",
")",
";",
"\\n",
"numMatchedLines",
"=",
"matchedLines",
".",
"length",
";",
"totalMatchLength",
"=",
"match",
"[",
"0",
"]",
".",
"length",
";",
"lastLineLength",
"=",
"matchedLines",
"[",
"matchedLines",
".",
"length",
"-",
"1",
"]",
".",
"length",
";",
"endCh",
"=",
"(",
"numMatchedLines",
"===",
"1",
"?",
"ch",
"+",
"totalMatchLength",
":",
"lastLineLength",
")",
";",
"highlightEndCh",
"=",
"(",
"numMatchedLines",
"===",
"1",
"?",
"endCh",
":",
"line",
".",
"length",
")",
";",
"highlightOffset",
"=",
"0",
";",
"if",
"(",
"highlightEndCh",
"<=",
"MAX_DISPLAY_LENGTH",
")",
"{",
"line",
"=",
"line",
".",
"substr",
"(",
"0",
",",
"Math",
".",
"min",
"(",
"MAX_DISPLAY_LENGTH",
",",
"line",
".",
"length",
")",
")",
";",
"}",
"else",
"if",
"(",
"totalMatchLength",
">",
"MAX_DISPLAY_LENGTH",
")",
"{",
"line",
"=",
"line",
".",
"substr",
"(",
"ch",
",",
"ch",
"+",
"MAX_DISPLAY_LENGTH",
")",
";",
"highlightOffset",
"=",
"ch",
";",
"}",
"else",
"{",
"padding",
"=",
"MAX_DISPLAY_LENGTH",
"-",
"totalMatchLength",
";",
"rightPadding",
"=",
"Math",
".",
"floor",
"(",
"Math",
".",
"min",
"(",
"padding",
"/",
"2",
",",
"line",
".",
"length",
"-",
"highlightEndCh",
")",
")",
";",
"leftPadding",
"=",
"Math",
".",
"ceil",
"(",
"padding",
"-",
"rightPadding",
")",
";",
"highlightOffset",
"=",
"ch",
"-",
"leftPadding",
";",
"line",
"=",
"line",
".",
"substring",
"(",
"highlightOffset",
",",
"highlightEndCh",
"+",
"rightPadding",
")",
";",
"}",
"matches",
".",
"push",
"(",
"{",
"start",
":",
"{",
"line",
":",
"lineNum",
",",
"ch",
":",
"ch",
"}",
",",
"end",
":",
"{",
"line",
":",
"lineNum",
"+",
"numMatchedLines",
"-",
"1",
",",
"ch",
":",
"endCh",
"}",
",",
"highlightOffset",
":",
"highlightOffset",
",",
"startOffset",
":",
"match",
".",
"index",
",",
"endOffset",
":",
"match",
".",
"index",
"+",
"totalMatchLength",
",",
"line",
":",
"line",
",",
"result",
":",
"match",
",",
"isChecked",
":",
"true",
"}",
")",
";",
"}",
"}"
] |
Searches through the contents and returns an array of matches
@param {string} contents
@param {RegExp} queryExpr
@return {!Array.<{start: {line:number,ch:number}, end: {line:number,ch:number}, line: string}>}
|
[
"Searches",
"through",
"the",
"contents",
"and",
"returns",
"an",
"array",
"of",
"matches"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/node/FindInFilesDomain.js#L102-L180
|
train
|
adobe/brackets
|
src/search/node/FindInFilesDomain.js
|
getFilesizeInBytes
|
function getFilesizeInBytes(fileName) {
try {
var stats = fs.statSync(fileName);
return stats.size || 0;
} catch (ex) {
console.log(ex);
return 0;
}
}
|
javascript
|
function getFilesizeInBytes(fileName) {
try {
var stats = fs.statSync(fileName);
return stats.size || 0;
} catch (ex) {
console.log(ex);
return 0;
}
}
|
[
"function",
"getFilesizeInBytes",
"(",
"fileName",
")",
"{",
"try",
"{",
"var",
"stats",
"=",
"fs",
".",
"statSync",
"(",
"fileName",
")",
";",
"return",
"stats",
".",
"size",
"||",
"0",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"console",
".",
"log",
"(",
"ex",
")",
";",
"return",
"0",
";",
"}",
"}"
] |
Gets the file size in bytes.
@param {string} fileName The name of the file to get the size
@returns {Number} the file size in bytes
|
[
"Gets",
"the",
"file",
"size",
"in",
"bytes",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/node/FindInFilesDomain.js#L195-L203
|
train
|
adobe/brackets
|
src/search/node/FindInFilesDomain.js
|
setResults
|
function setResults(fullpath, resultInfo, maxResultsToReturn) {
if (results[fullpath]) {
numMatches -= results[fullpath].matches.length;
delete results[fullpath];
}
if (foundMaximum || !resultInfo || !resultInfo.matches || !resultInfo.matches.length) {
return;
}
// Make sure that the optional `collapsed` property is explicitly set to either true or false,
// to avoid logic issues later with comparing values.
resultInfo.collapsed = collapseResults;
results[fullpath] = resultInfo;
numMatches += resultInfo.matches.length;
evaluatedMatches += resultInfo.matches.length;
maxResultsToReturn = maxResultsToReturn || MAX_RESULTS_TO_RETURN;
if (numMatches >= maxResultsToReturn || evaluatedMatches > MAX_TOTAL_RESULTS) {
foundMaximum = true;
}
}
|
javascript
|
function setResults(fullpath, resultInfo, maxResultsToReturn) {
if (results[fullpath]) {
numMatches -= results[fullpath].matches.length;
delete results[fullpath];
}
if (foundMaximum || !resultInfo || !resultInfo.matches || !resultInfo.matches.length) {
return;
}
// Make sure that the optional `collapsed` property is explicitly set to either true or false,
// to avoid logic issues later with comparing values.
resultInfo.collapsed = collapseResults;
results[fullpath] = resultInfo;
numMatches += resultInfo.matches.length;
evaluatedMatches += resultInfo.matches.length;
maxResultsToReturn = maxResultsToReturn || MAX_RESULTS_TO_RETURN;
if (numMatches >= maxResultsToReturn || evaluatedMatches > MAX_TOTAL_RESULTS) {
foundMaximum = true;
}
}
|
[
"function",
"setResults",
"(",
"fullpath",
",",
"resultInfo",
",",
"maxResultsToReturn",
")",
"{",
"if",
"(",
"results",
"[",
"fullpath",
"]",
")",
"{",
"numMatches",
"-=",
"results",
"[",
"fullpath",
"]",
".",
"matches",
".",
"length",
";",
"delete",
"results",
"[",
"fullpath",
"]",
";",
"}",
"if",
"(",
"foundMaximum",
"||",
"!",
"resultInfo",
"||",
"!",
"resultInfo",
".",
"matches",
"||",
"!",
"resultInfo",
".",
"matches",
".",
"length",
")",
"{",
"return",
";",
"}",
"resultInfo",
".",
"collapsed",
"=",
"collapseResults",
";",
"results",
"[",
"fullpath",
"]",
"=",
"resultInfo",
";",
"numMatches",
"+=",
"resultInfo",
".",
"matches",
".",
"length",
";",
"evaluatedMatches",
"+=",
"resultInfo",
".",
"matches",
".",
"length",
";",
"maxResultsToReturn",
"=",
"maxResultsToReturn",
"||",
"MAX_RESULTS_TO_RETURN",
";",
"if",
"(",
"numMatches",
">=",
"maxResultsToReturn",
"||",
"evaluatedMatches",
">",
"MAX_TOTAL_RESULTS",
")",
"{",
"foundMaximum",
"=",
"true",
";",
"}",
"}"
] |
Sets the list of matches for the given path, removing the previous match info, if any, and updating
the total match count. Note that for the count to remain accurate, the previous match info must not have
been mutated since it was set.
@param {string} fullpath Full path to the file containing the matches.
@param {!{matches: Object, collapsed: boolean=}} resultInfo Info for the matches to set:
matches - Array of matches, in the format returned by FindInFiles.getSearchMatches()
collapsed - Optional: whether the results should be collapsed in the UI (default false).
|
[
"Sets",
"the",
"list",
"of",
"matches",
"for",
"the",
"given",
"path",
"removing",
"the",
"previous",
"match",
"info",
"if",
"any",
"and",
"updating",
"the",
"total",
"match",
"count",
".",
"Note",
"that",
"for",
"the",
"count",
"to",
"remain",
"accurate",
"the",
"previous",
"match",
"info",
"must",
"not",
"have",
"been",
"mutated",
"since",
"it",
"was",
"set",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/node/FindInFilesDomain.js#L237-L258
|
train
|
adobe/brackets
|
src/search/node/FindInFilesDomain.js
|
doSearchInOneFile
|
function doSearchInOneFile(filepath, text, queryExpr, maxResultsToReturn) {
var matches = getSearchMatches(text, queryExpr);
setResults(filepath, {matches: matches}, maxResultsToReturn);
}
|
javascript
|
function doSearchInOneFile(filepath, text, queryExpr, maxResultsToReturn) {
var matches = getSearchMatches(text, queryExpr);
setResults(filepath, {matches: matches}, maxResultsToReturn);
}
|
[
"function",
"doSearchInOneFile",
"(",
"filepath",
",",
"text",
",",
"queryExpr",
",",
"maxResultsToReturn",
")",
"{",
"var",
"matches",
"=",
"getSearchMatches",
"(",
"text",
",",
"queryExpr",
")",
";",
"setResults",
"(",
"filepath",
",",
"{",
"matches",
":",
"matches",
"}",
",",
"maxResultsToReturn",
")",
";",
"}"
] |
Finds search results in the given file and adds them to 'results'
@param {string} filepath
@param {string} text contents of the file
@param {Object} queryExpr
@param {number} maxResultsToReturn the maximum of results that should be returned in the current search.
|
[
"Finds",
"search",
"results",
"in",
"the",
"given",
"file",
"and",
"adds",
"them",
"to",
"results"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/node/FindInFilesDomain.js#L267-L270
|
train
|
adobe/brackets
|
src/search/node/FindInFilesDomain.js
|
doSearchInFiles
|
function doSearchInFiles(fileList, queryExpr, startFileIndex, maxResultsToReturn) {
var i;
if (fileList.length === 0) {
console.log('no files found');
return;
} else {
startFileIndex = startFileIndex || 0;
for (i = startFileIndex; i < fileList.length && !foundMaximum; i++) {
doSearchInOneFile(fileList[i], getFileContentsForFile(fileList[i]), queryExpr, maxResultsToReturn);
}
lastSearchedIndex = i;
}
}
|
javascript
|
function doSearchInFiles(fileList, queryExpr, startFileIndex, maxResultsToReturn) {
var i;
if (fileList.length === 0) {
console.log('no files found');
return;
} else {
startFileIndex = startFileIndex || 0;
for (i = startFileIndex; i < fileList.length && !foundMaximum; i++) {
doSearchInOneFile(fileList[i], getFileContentsForFile(fileList[i]), queryExpr, maxResultsToReturn);
}
lastSearchedIndex = i;
}
}
|
[
"function",
"doSearchInFiles",
"(",
"fileList",
",",
"queryExpr",
",",
"startFileIndex",
",",
"maxResultsToReturn",
")",
"{",
"var",
"i",
";",
"if",
"(",
"fileList",
".",
"length",
"===",
"0",
")",
"{",
"console",
".",
"log",
"(",
"'no files found'",
")",
";",
"return",
";",
"}",
"else",
"{",
"startFileIndex",
"=",
"startFileIndex",
"||",
"0",
";",
"for",
"(",
"i",
"=",
"startFileIndex",
";",
"i",
"<",
"fileList",
".",
"length",
"&&",
"!",
"foundMaximum",
";",
"i",
"++",
")",
"{",
"doSearchInOneFile",
"(",
"fileList",
"[",
"i",
"]",
",",
"getFileContentsForFile",
"(",
"fileList",
"[",
"i",
"]",
")",
",",
"queryExpr",
",",
"maxResultsToReturn",
")",
";",
"}",
"lastSearchedIndex",
"=",
"i",
";",
"}",
"}"
] |
Search in the list of files given and populate the results
@param {array} fileList array of file paths
@param {Object} queryExpr
@param {number} startFileIndex the start index of the array from which the search has to be done
@param {number} maxResultsToReturn the maximum number of results to return in this search
|
[
"Search",
"in",
"the",
"list",
"of",
"files",
"given",
"and",
"populate",
"the",
"results"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/node/FindInFilesDomain.js#L279-L292
|
train
|
adobe/brackets
|
src/search/node/FindInFilesDomain.js
|
fileCrawler
|
function fileCrawler() {
if (!files || (files && files.length === 0)) {
setTimeout(fileCrawler, 1000);
return;
}
var contents = "";
if (currentCrawlIndex < files.length) {
contents = getFileContentsForFile(files[currentCrawlIndex]);
if (contents) {
cacheSize += contents.length;
}
currentCrawlIndex++;
}
if (currentCrawlIndex < files.length) {
crawlComplete = false;
setImmediate(fileCrawler);
} else {
crawlComplete = true;
if (!crawlEventSent) {
crawlEventSent = true;
_domainManager.emitEvent("FindInFiles", "crawlComplete", [files.length, cacheSize]);
}
setTimeout(fileCrawler, 1000);
}
}
|
javascript
|
function fileCrawler() {
if (!files || (files && files.length === 0)) {
setTimeout(fileCrawler, 1000);
return;
}
var contents = "";
if (currentCrawlIndex < files.length) {
contents = getFileContentsForFile(files[currentCrawlIndex]);
if (contents) {
cacheSize += contents.length;
}
currentCrawlIndex++;
}
if (currentCrawlIndex < files.length) {
crawlComplete = false;
setImmediate(fileCrawler);
} else {
crawlComplete = true;
if (!crawlEventSent) {
crawlEventSent = true;
_domainManager.emitEvent("FindInFiles", "crawlComplete", [files.length, cacheSize]);
}
setTimeout(fileCrawler, 1000);
}
}
|
[
"function",
"fileCrawler",
"(",
")",
"{",
"if",
"(",
"!",
"files",
"||",
"(",
"files",
"&&",
"files",
".",
"length",
"===",
"0",
")",
")",
"{",
"setTimeout",
"(",
"fileCrawler",
",",
"1000",
")",
";",
"return",
";",
"}",
"var",
"contents",
"=",
"\"\"",
";",
"if",
"(",
"currentCrawlIndex",
"<",
"files",
".",
"length",
")",
"{",
"contents",
"=",
"getFileContentsForFile",
"(",
"files",
"[",
"currentCrawlIndex",
"]",
")",
";",
"if",
"(",
"contents",
")",
"{",
"cacheSize",
"+=",
"contents",
".",
"length",
";",
"}",
"currentCrawlIndex",
"++",
";",
"}",
"if",
"(",
"currentCrawlIndex",
"<",
"files",
".",
"length",
")",
"{",
"crawlComplete",
"=",
"false",
";",
"setImmediate",
"(",
"fileCrawler",
")",
";",
"}",
"else",
"{",
"crawlComplete",
"=",
"true",
";",
"if",
"(",
"!",
"crawlEventSent",
")",
"{",
"crawlEventSent",
"=",
"true",
";",
"_domainManager",
".",
"emitEvent",
"(",
"\"FindInFiles\"",
",",
"\"crawlComplete\"",
",",
"[",
"files",
".",
"length",
",",
"cacheSize",
"]",
")",
";",
"}",
"setTimeout",
"(",
"fileCrawler",
",",
"1000",
")",
";",
"}",
"}"
] |
Crawls through the files in the project ans stores them in cache. Since that could take a while
we do it in batches so that node wont be blocked.
|
[
"Crawls",
"through",
"the",
"files",
"in",
"the",
"project",
"ans",
"stores",
"them",
"in",
"cache",
".",
"Since",
"that",
"could",
"take",
"a",
"while",
"we",
"do",
"it",
"in",
"batches",
"so",
"that",
"node",
"wont",
"be",
"blocked",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/node/FindInFilesDomain.js#L343-L367
|
train
|
adobe/brackets
|
src/search/node/FindInFilesDomain.js
|
countNumMatches
|
function countNumMatches(contents, queryExpr) {
if (!contents) {
return 0;
}
var matches = contents.match(queryExpr);
return matches ? matches.length : 0;
}
|
javascript
|
function countNumMatches(contents, queryExpr) {
if (!contents) {
return 0;
}
var matches = contents.match(queryExpr);
return matches ? matches.length : 0;
}
|
[
"function",
"countNumMatches",
"(",
"contents",
",",
"queryExpr",
")",
"{",
"if",
"(",
"!",
"contents",
")",
"{",
"return",
"0",
";",
"}",
"var",
"matches",
"=",
"contents",
".",
"match",
"(",
"queryExpr",
")",
";",
"return",
"matches",
"?",
"matches",
".",
"length",
":",
"0",
";",
"}"
] |
Counts the number of matches matching the queryExpr in the given contents
@param {String} contents The contents to search on
@param {Object} queryExpr
@return {number} number of matches
|
[
"Counts",
"the",
"number",
"of",
"matches",
"matching",
"the",
"queryExpr",
"in",
"the",
"given",
"contents"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/node/FindInFilesDomain.js#L388-L394
|
train
|
adobe/brackets
|
src/search/node/FindInFilesDomain.js
|
getNumMatches
|
function getNumMatches(fileList, queryExpr) {
var i,
matches = 0;
for (i = 0; i < fileList.length; i++) {
var temp = countNumMatches(getFileContentsForFile(fileList[i]), queryExpr);
if (temp) {
numFiles++;
matches += temp;
}
if (matches > MAX_TOTAL_RESULTS) {
exceedsMaximum = true;
break;
}
}
return matches;
}
|
javascript
|
function getNumMatches(fileList, queryExpr) {
var i,
matches = 0;
for (i = 0; i < fileList.length; i++) {
var temp = countNumMatches(getFileContentsForFile(fileList[i]), queryExpr);
if (temp) {
numFiles++;
matches += temp;
}
if (matches > MAX_TOTAL_RESULTS) {
exceedsMaximum = true;
break;
}
}
return matches;
}
|
[
"function",
"getNumMatches",
"(",
"fileList",
",",
"queryExpr",
")",
"{",
"var",
"i",
",",
"matches",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"fileList",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"temp",
"=",
"countNumMatches",
"(",
"getFileContentsForFile",
"(",
"fileList",
"[",
"i",
"]",
")",
",",
"queryExpr",
")",
";",
"if",
"(",
"temp",
")",
"{",
"numFiles",
"++",
";",
"matches",
"+=",
"temp",
";",
"}",
"if",
"(",
"matches",
">",
"MAX_TOTAL_RESULTS",
")",
"{",
"exceedsMaximum",
"=",
"true",
";",
"break",
";",
"}",
"}",
"return",
"matches",
";",
"}"
] |
Get the total number of matches from all the files in fileList
@param {array} fileList file path array
@param {Object} queryExpr
@return {Number} total number of matches
|
[
"Get",
"the",
"total",
"number",
"of",
"matches",
"from",
"all",
"the",
"files",
"in",
"fileList"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/node/FindInFilesDomain.js#L402-L417
|
train
|
adobe/brackets
|
src/search/node/FindInFilesDomain.js
|
doSearch
|
function doSearch(searchObject, nextPages) {
savedSearchObject = searchObject;
if (!files) {
console.log("no file object found");
return {};
}
results = {};
numMatches = 0;
numFiles = 0;
foundMaximum = false;
if (!nextPages) {
exceedsMaximum = false;
evaluatedMatches = 0;
}
var queryObject = parseQueryInfo(searchObject.queryInfo);
if (searchObject.files) {
files = searchObject.files;
}
if (searchObject.getAllResults) {
searchObject.maxResultsToReturn = MAX_TOTAL_RESULTS;
}
doSearchInFiles(files, queryObject.queryExpr, searchObject.startFileIndex, searchObject.maxResultsToReturn);
if (crawlComplete && !nextPages) {
numMatches = getNumMatches(files, queryObject.queryExpr);
}
var send_object = {
"results": results,
"foundMaximum": foundMaximum,
"exceedsMaximum": exceedsMaximum
};
if (!nextPages) {
send_object.numMatches = numMatches;
send_object.numFiles = numFiles;
}
if (searchObject.getAllResults) {
send_object.allResultsAvailable = true;
}
return send_object;
}
|
javascript
|
function doSearch(searchObject, nextPages) {
savedSearchObject = searchObject;
if (!files) {
console.log("no file object found");
return {};
}
results = {};
numMatches = 0;
numFiles = 0;
foundMaximum = false;
if (!nextPages) {
exceedsMaximum = false;
evaluatedMatches = 0;
}
var queryObject = parseQueryInfo(searchObject.queryInfo);
if (searchObject.files) {
files = searchObject.files;
}
if (searchObject.getAllResults) {
searchObject.maxResultsToReturn = MAX_TOTAL_RESULTS;
}
doSearchInFiles(files, queryObject.queryExpr, searchObject.startFileIndex, searchObject.maxResultsToReturn);
if (crawlComplete && !nextPages) {
numMatches = getNumMatches(files, queryObject.queryExpr);
}
var send_object = {
"results": results,
"foundMaximum": foundMaximum,
"exceedsMaximum": exceedsMaximum
};
if (!nextPages) {
send_object.numMatches = numMatches;
send_object.numFiles = numFiles;
}
if (searchObject.getAllResults) {
send_object.allResultsAvailable = true;
}
return send_object;
}
|
[
"function",
"doSearch",
"(",
"searchObject",
",",
"nextPages",
")",
"{",
"savedSearchObject",
"=",
"searchObject",
";",
"if",
"(",
"!",
"files",
")",
"{",
"console",
".",
"log",
"(",
"\"no file object found\"",
")",
";",
"return",
"{",
"}",
";",
"}",
"results",
"=",
"{",
"}",
";",
"numMatches",
"=",
"0",
";",
"numFiles",
"=",
"0",
";",
"foundMaximum",
"=",
"false",
";",
"if",
"(",
"!",
"nextPages",
")",
"{",
"exceedsMaximum",
"=",
"false",
";",
"evaluatedMatches",
"=",
"0",
";",
"}",
"var",
"queryObject",
"=",
"parseQueryInfo",
"(",
"searchObject",
".",
"queryInfo",
")",
";",
"if",
"(",
"searchObject",
".",
"files",
")",
"{",
"files",
"=",
"searchObject",
".",
"files",
";",
"}",
"if",
"(",
"searchObject",
".",
"getAllResults",
")",
"{",
"searchObject",
".",
"maxResultsToReturn",
"=",
"MAX_TOTAL_RESULTS",
";",
"}",
"doSearchInFiles",
"(",
"files",
",",
"queryObject",
".",
"queryExpr",
",",
"searchObject",
".",
"startFileIndex",
",",
"searchObject",
".",
"maxResultsToReturn",
")",
";",
"if",
"(",
"crawlComplete",
"&&",
"!",
"nextPages",
")",
"{",
"numMatches",
"=",
"getNumMatches",
"(",
"files",
",",
"queryObject",
".",
"queryExpr",
")",
";",
"}",
"var",
"send_object",
"=",
"{",
"\"results\"",
":",
"results",
",",
"\"foundMaximum\"",
":",
"foundMaximum",
",",
"\"exceedsMaximum\"",
":",
"exceedsMaximum",
"}",
";",
"if",
"(",
"!",
"nextPages",
")",
"{",
"send_object",
".",
"numMatches",
"=",
"numMatches",
";",
"send_object",
".",
"numFiles",
"=",
"numFiles",
";",
"}",
"if",
"(",
"searchObject",
".",
"getAllResults",
")",
"{",
"send_object",
".",
"allResultsAvailable",
"=",
"true",
";",
"}",
"return",
"send_object",
";",
"}"
] |
Do a search with the searchObject context and return the results
@param {Object} searchObject
@param {boolean} nextPages set to true if to indicate that next page of an existing page is being fetched
@return {Object} search results
|
[
"Do",
"a",
"search",
"with",
"the",
"searchObject",
"context",
"and",
"return",
"the",
"results"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/node/FindInFilesDomain.js#L425-L466
|
train
|
adobe/brackets
|
src/search/node/FindInFilesDomain.js
|
removeFilesFromCache
|
function removeFilesFromCache(updateObject) {
var fileList = updateObject.fileList || [],
filesInSearchScope = updateObject.filesInSearchScope || [],
i = 0;
for (i = 0; i < fileList.length; i++) {
delete projectCache[fileList[i]];
}
function isNotInRemovedFilesList(path) {
return (filesInSearchScope.indexOf(path) === -1) ? true : false;
}
files = files ? files.filter(isNotInRemovedFilesList) : files;
}
|
javascript
|
function removeFilesFromCache(updateObject) {
var fileList = updateObject.fileList || [],
filesInSearchScope = updateObject.filesInSearchScope || [],
i = 0;
for (i = 0; i < fileList.length; i++) {
delete projectCache[fileList[i]];
}
function isNotInRemovedFilesList(path) {
return (filesInSearchScope.indexOf(path) === -1) ? true : false;
}
files = files ? files.filter(isNotInRemovedFilesList) : files;
}
|
[
"function",
"removeFilesFromCache",
"(",
"updateObject",
")",
"{",
"var",
"fileList",
"=",
"updateObject",
".",
"fileList",
"||",
"[",
"]",
",",
"filesInSearchScope",
"=",
"updateObject",
".",
"filesInSearchScope",
"||",
"[",
"]",
",",
"i",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"fileList",
".",
"length",
";",
"i",
"++",
")",
"{",
"delete",
"projectCache",
"[",
"fileList",
"[",
"i",
"]",
"]",
";",
"}",
"function",
"isNotInRemovedFilesList",
"(",
"path",
")",
"{",
"return",
"(",
"filesInSearchScope",
".",
"indexOf",
"(",
"path",
")",
"===",
"-",
"1",
")",
"?",
"true",
":",
"false",
";",
"}",
"files",
"=",
"files",
"?",
"files",
".",
"filter",
"(",
"isNotInRemovedFilesList",
")",
":",
"files",
";",
"}"
] |
Remove the list of given files from the project cache
@param {Object} updateObject
|
[
"Remove",
"the",
"list",
"of",
"given",
"files",
"from",
"the",
"project",
"cache"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/node/FindInFilesDomain.js#L472-L483
|
train
|
adobe/brackets
|
src/search/node/FindInFilesDomain.js
|
addFilesToCache
|
function addFilesToCache(updateObject) {
var fileList = updateObject.fileList || [],
filesInSearchScope = updateObject.filesInSearchScope || [],
i = 0,
changedFilesAlreadyInList = [],
newFiles = [];
for (i = 0; i < fileList.length; i++) {
// We just add a null entry indicating the precense of the file in the project list.
// The file will be later read when required.
projectCache[fileList[i]] = null;
}
//Now update the search scope
function isInChangedFileList(path) {
return (filesInSearchScope.indexOf(path) !== -1) ? true : false;
}
changedFilesAlreadyInList = files ? files.filter(isInChangedFileList) : [];
function isNotAlreadyInList(path) {
return (changedFilesAlreadyInList.indexOf(path) === -1) ? true : false;
}
newFiles = changedFilesAlreadyInList.filter(isNotAlreadyInList);
files.push.apply(files, newFiles);
}
|
javascript
|
function addFilesToCache(updateObject) {
var fileList = updateObject.fileList || [],
filesInSearchScope = updateObject.filesInSearchScope || [],
i = 0,
changedFilesAlreadyInList = [],
newFiles = [];
for (i = 0; i < fileList.length; i++) {
// We just add a null entry indicating the precense of the file in the project list.
// The file will be later read when required.
projectCache[fileList[i]] = null;
}
//Now update the search scope
function isInChangedFileList(path) {
return (filesInSearchScope.indexOf(path) !== -1) ? true : false;
}
changedFilesAlreadyInList = files ? files.filter(isInChangedFileList) : [];
function isNotAlreadyInList(path) {
return (changedFilesAlreadyInList.indexOf(path) === -1) ? true : false;
}
newFiles = changedFilesAlreadyInList.filter(isNotAlreadyInList);
files.push.apply(files, newFiles);
}
|
[
"function",
"addFilesToCache",
"(",
"updateObject",
")",
"{",
"var",
"fileList",
"=",
"updateObject",
".",
"fileList",
"||",
"[",
"]",
",",
"filesInSearchScope",
"=",
"updateObject",
".",
"filesInSearchScope",
"||",
"[",
"]",
",",
"i",
"=",
"0",
",",
"changedFilesAlreadyInList",
"=",
"[",
"]",
",",
"newFiles",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"fileList",
".",
"length",
";",
"i",
"++",
")",
"{",
"projectCache",
"[",
"fileList",
"[",
"i",
"]",
"]",
"=",
"null",
";",
"}",
"function",
"isInChangedFileList",
"(",
"path",
")",
"{",
"return",
"(",
"filesInSearchScope",
".",
"indexOf",
"(",
"path",
")",
"!==",
"-",
"1",
")",
"?",
"true",
":",
"false",
";",
"}",
"changedFilesAlreadyInList",
"=",
"files",
"?",
"files",
".",
"filter",
"(",
"isInChangedFileList",
")",
":",
"[",
"]",
";",
"function",
"isNotAlreadyInList",
"(",
"path",
")",
"{",
"return",
"(",
"changedFilesAlreadyInList",
".",
"indexOf",
"(",
"path",
")",
"===",
"-",
"1",
")",
"?",
"true",
":",
"false",
";",
"}",
"newFiles",
"=",
"changedFilesAlreadyInList",
".",
"filter",
"(",
"isNotAlreadyInList",
")",
";",
"files",
".",
"push",
".",
"apply",
"(",
"files",
",",
"newFiles",
")",
";",
"}"
] |
Adds the list of given files to the project cache. However the files will not be
read at this time. We just delete the project cache entry which will trigger a fetch on search.
@param {Object} updateObject
|
[
"Adds",
"the",
"list",
"of",
"given",
"files",
"to",
"the",
"project",
"cache",
".",
"However",
"the",
"files",
"will",
"not",
"be",
"read",
"at",
"this",
"time",
".",
"We",
"just",
"delete",
"the",
"project",
"cache",
"entry",
"which",
"will",
"trigger",
"a",
"fetch",
"on",
"search",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/node/FindInFilesDomain.js#L490-L512
|
train
|
adobe/brackets
|
src/search/node/FindInFilesDomain.js
|
getNextPage
|
function getNextPage() {
var send_object = {
"results": {},
"numMatches": 0,
"foundMaximum": foundMaximum,
"exceedsMaximum": exceedsMaximum
};
if (!savedSearchObject) {
return send_object;
}
savedSearchObject.startFileIndex = lastSearchedIndex;
return doSearch(savedSearchObject, true);
}
|
javascript
|
function getNextPage() {
var send_object = {
"results": {},
"numMatches": 0,
"foundMaximum": foundMaximum,
"exceedsMaximum": exceedsMaximum
};
if (!savedSearchObject) {
return send_object;
}
savedSearchObject.startFileIndex = lastSearchedIndex;
return doSearch(savedSearchObject, true);
}
|
[
"function",
"getNextPage",
"(",
")",
"{",
"var",
"send_object",
"=",
"{",
"\"results\"",
":",
"{",
"}",
",",
"\"numMatches\"",
":",
"0",
",",
"\"foundMaximum\"",
":",
"foundMaximum",
",",
"\"exceedsMaximum\"",
":",
"exceedsMaximum",
"}",
";",
"if",
"(",
"!",
"savedSearchObject",
")",
"{",
"return",
"send_object",
";",
"}",
"savedSearchObject",
".",
"startFileIndex",
"=",
"lastSearchedIndex",
";",
"return",
"doSearch",
"(",
"savedSearchObject",
",",
"true",
")",
";",
"}"
] |
Gets the next page of results of the ongoing search
@return {Object} search results
|
[
"Gets",
"the",
"next",
"page",
"of",
"results",
"of",
"the",
"ongoing",
"search"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/node/FindInFilesDomain.js#L526-L538
|
train
|
adobe/brackets
|
src/search/node/FindInFilesDomain.js
|
getAllResults
|
function getAllResults() {
var send_object = {
"results": {},
"numMatches": 0,
"foundMaximum": foundMaximum,
"exceedsMaximum": exceedsMaximum
};
if (!savedSearchObject) {
return send_object;
}
savedSearchObject.startFileIndex = 0;
savedSearchObject.getAllResults = true;
return doSearch(savedSearchObject);
}
|
javascript
|
function getAllResults() {
var send_object = {
"results": {},
"numMatches": 0,
"foundMaximum": foundMaximum,
"exceedsMaximum": exceedsMaximum
};
if (!savedSearchObject) {
return send_object;
}
savedSearchObject.startFileIndex = 0;
savedSearchObject.getAllResults = true;
return doSearch(savedSearchObject);
}
|
[
"function",
"getAllResults",
"(",
")",
"{",
"var",
"send_object",
"=",
"{",
"\"results\"",
":",
"{",
"}",
",",
"\"numMatches\"",
":",
"0",
",",
"\"foundMaximum\"",
":",
"foundMaximum",
",",
"\"exceedsMaximum\"",
":",
"exceedsMaximum",
"}",
";",
"if",
"(",
"!",
"savedSearchObject",
")",
"{",
"return",
"send_object",
";",
"}",
"savedSearchObject",
".",
"startFileIndex",
"=",
"0",
";",
"savedSearchObject",
".",
"getAllResults",
"=",
"true",
";",
"return",
"doSearch",
"(",
"savedSearchObject",
")",
";",
"}"
] |
Gets all the results for the saved search query if present or empty search results
@return {Object} The results object
|
[
"Gets",
"all",
"the",
"results",
"for",
"the",
"saved",
"search",
"query",
"if",
"present",
"or",
"empty",
"search",
"results"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/node/FindInFilesDomain.js#L544-L557
|
train
|
adobe/brackets
|
src/widgets/Dialogs.js
|
function (e, autoDismiss) {
var $primaryBtn = this.find(".primary"),
buttonId = null,
which = String.fromCharCode(e.which),
$focusedElement = this.find(".dialog-button:focus, a:focus");
function stopEvent() {
e.preventDefault();
e.stopPropagation();
}
// There might be a textfield in the dialog's UI; don't want to mistake normal typing for dialog dismissal
var inTextArea = (e.target.tagName === "TEXTAREA"),
inTypingField = inTextArea || ($(e.target).filter(":text, :password").length > 0);
if (e.which === KeyEvent.DOM_VK_TAB) {
// We don't want to stopEvent() in this case since we might want the default behavior.
// _handleTab takes care of stopping/preventing default as necessary.
_handleTab(e, this);
} else if (e.which === KeyEvent.DOM_VK_ESCAPE) {
buttonId = DIALOG_BTN_CANCEL;
} else if (e.which === KeyEvent.DOM_VK_RETURN && (!inTextArea || e.ctrlKey)) {
// Enter key in single-line text input always dismisses; in text area, only Ctrl+Enter dismisses
// Click primary
stopEvent();
if (e.target.tagName === "BUTTON") {
this.find(e.target).click();
} else if (e.target.tagName !== "INPUT") {
// If the target element is not BUTTON or INPUT, click the primary button
// We're making an exception for INPUT element because of this issue: GH-11416
$primaryBtn.click();
}
} else if (e.which === KeyEvent.DOM_VK_SPACE) {
if ($focusedElement.length) {
// Space bar on focused button or link
stopEvent();
$focusedElement.click();
}
} else if (brackets.platform === "mac") {
// CMD+Backspace Don't Save
if (e.metaKey && (e.which === KeyEvent.DOM_VK_BACK_SPACE)) {
if (_hasButton(this, DIALOG_BTN_DONTSAVE)) {
buttonId = DIALOG_BTN_DONTSAVE;
}
// FIXME (issue #418) CMD+. Cancel swallowed by native shell
} else if (e.metaKey && (e.which === KeyEvent.DOM_VK_PERIOD)) {
buttonId = DIALOG_BTN_CANCEL;
}
} else { // if (brackets.platform === "win") {
// 'N' Don't Save
if (which === "N" && !inTypingField) {
if (_hasButton(this, DIALOG_BTN_DONTSAVE)) {
buttonId = DIALOG_BTN_DONTSAVE;
}
}
}
if (buttonId) {
stopEvent();
_processButton(this, buttonId, autoDismiss);
}
// Stop any other global hooks from processing the event (but
// allow it to continue bubbling if we haven't otherwise stopped it).
return true;
}
|
javascript
|
function (e, autoDismiss) {
var $primaryBtn = this.find(".primary"),
buttonId = null,
which = String.fromCharCode(e.which),
$focusedElement = this.find(".dialog-button:focus, a:focus");
function stopEvent() {
e.preventDefault();
e.stopPropagation();
}
// There might be a textfield in the dialog's UI; don't want to mistake normal typing for dialog dismissal
var inTextArea = (e.target.tagName === "TEXTAREA"),
inTypingField = inTextArea || ($(e.target).filter(":text, :password").length > 0);
if (e.which === KeyEvent.DOM_VK_TAB) {
// We don't want to stopEvent() in this case since we might want the default behavior.
// _handleTab takes care of stopping/preventing default as necessary.
_handleTab(e, this);
} else if (e.which === KeyEvent.DOM_VK_ESCAPE) {
buttonId = DIALOG_BTN_CANCEL;
} else if (e.which === KeyEvent.DOM_VK_RETURN && (!inTextArea || e.ctrlKey)) {
// Enter key in single-line text input always dismisses; in text area, only Ctrl+Enter dismisses
// Click primary
stopEvent();
if (e.target.tagName === "BUTTON") {
this.find(e.target).click();
} else if (e.target.tagName !== "INPUT") {
// If the target element is not BUTTON or INPUT, click the primary button
// We're making an exception for INPUT element because of this issue: GH-11416
$primaryBtn.click();
}
} else if (e.which === KeyEvent.DOM_VK_SPACE) {
if ($focusedElement.length) {
// Space bar on focused button or link
stopEvent();
$focusedElement.click();
}
} else if (brackets.platform === "mac") {
// CMD+Backspace Don't Save
if (e.metaKey && (e.which === KeyEvent.DOM_VK_BACK_SPACE)) {
if (_hasButton(this, DIALOG_BTN_DONTSAVE)) {
buttonId = DIALOG_BTN_DONTSAVE;
}
// FIXME (issue #418) CMD+. Cancel swallowed by native shell
} else if (e.metaKey && (e.which === KeyEvent.DOM_VK_PERIOD)) {
buttonId = DIALOG_BTN_CANCEL;
}
} else { // if (brackets.platform === "win") {
// 'N' Don't Save
if (which === "N" && !inTypingField) {
if (_hasButton(this, DIALOG_BTN_DONTSAVE)) {
buttonId = DIALOG_BTN_DONTSAVE;
}
}
}
if (buttonId) {
stopEvent();
_processButton(this, buttonId, autoDismiss);
}
// Stop any other global hooks from processing the event (but
// allow it to continue bubbling if we haven't otherwise stopped it).
return true;
}
|
[
"function",
"(",
"e",
",",
"autoDismiss",
")",
"{",
"var",
"$primaryBtn",
"=",
"this",
".",
"find",
"(",
"\".primary\"",
")",
",",
"buttonId",
"=",
"null",
",",
"which",
"=",
"String",
".",
"fromCharCode",
"(",
"e",
".",
"which",
")",
",",
"$focusedElement",
"=",
"this",
".",
"find",
"(",
"\".dialog-button:focus, a:focus\"",
")",
";",
"function",
"stopEvent",
"(",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"e",
".",
"stopPropagation",
"(",
")",
";",
"}",
"var",
"inTextArea",
"=",
"(",
"e",
".",
"target",
".",
"tagName",
"===",
"\"TEXTAREA\"",
")",
",",
"inTypingField",
"=",
"inTextArea",
"||",
"(",
"$",
"(",
"e",
".",
"target",
")",
".",
"filter",
"(",
"\":text, :password\"",
")",
".",
"length",
">",
"0",
")",
";",
"if",
"(",
"e",
".",
"which",
"===",
"KeyEvent",
".",
"DOM_VK_TAB",
")",
"{",
"_handleTab",
"(",
"e",
",",
"this",
")",
";",
"}",
"else",
"if",
"(",
"e",
".",
"which",
"===",
"KeyEvent",
".",
"DOM_VK_ESCAPE",
")",
"{",
"buttonId",
"=",
"DIALOG_BTN_CANCEL",
";",
"}",
"else",
"if",
"(",
"e",
".",
"which",
"===",
"KeyEvent",
".",
"DOM_VK_RETURN",
"&&",
"(",
"!",
"inTextArea",
"||",
"e",
".",
"ctrlKey",
")",
")",
"{",
"stopEvent",
"(",
")",
";",
"if",
"(",
"e",
".",
"target",
".",
"tagName",
"===",
"\"BUTTON\"",
")",
"{",
"this",
".",
"find",
"(",
"e",
".",
"target",
")",
".",
"click",
"(",
")",
";",
"}",
"else",
"if",
"(",
"e",
".",
"target",
".",
"tagName",
"!==",
"\"INPUT\"",
")",
"{",
"$primaryBtn",
".",
"click",
"(",
")",
";",
"}",
"}",
"else",
"if",
"(",
"e",
".",
"which",
"===",
"KeyEvent",
".",
"DOM_VK_SPACE",
")",
"{",
"if",
"(",
"$focusedElement",
".",
"length",
")",
"{",
"stopEvent",
"(",
")",
";",
"$focusedElement",
".",
"click",
"(",
")",
";",
"}",
"}",
"else",
"if",
"(",
"brackets",
".",
"platform",
"===",
"\"mac\"",
")",
"{",
"if",
"(",
"e",
".",
"metaKey",
"&&",
"(",
"e",
".",
"which",
"===",
"KeyEvent",
".",
"DOM_VK_BACK_SPACE",
")",
")",
"{",
"if",
"(",
"_hasButton",
"(",
"this",
",",
"DIALOG_BTN_DONTSAVE",
")",
")",
"{",
"buttonId",
"=",
"DIALOG_BTN_DONTSAVE",
";",
"}",
"}",
"else",
"if",
"(",
"e",
".",
"metaKey",
"&&",
"(",
"e",
".",
"which",
"===",
"KeyEvent",
".",
"DOM_VK_PERIOD",
")",
")",
"{",
"buttonId",
"=",
"DIALOG_BTN_CANCEL",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"which",
"===",
"\"N\"",
"&&",
"!",
"inTypingField",
")",
"{",
"if",
"(",
"_hasButton",
"(",
"this",
",",
"DIALOG_BTN_DONTSAVE",
")",
")",
"{",
"buttonId",
"=",
"DIALOG_BTN_DONTSAVE",
";",
"}",
"}",
"}",
"if",
"(",
"buttonId",
")",
"{",
"stopEvent",
"(",
")",
";",
"_processButton",
"(",
"this",
",",
"buttonId",
",",
"autoDismiss",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Handles the keyDown event for the dialogs
@param {$.Event} e
@param {boolean} autoDismiss
@return {boolean}
|
[
"Handles",
"the",
"keyDown",
"event",
"for",
"the",
"dialogs"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/widgets/Dialogs.js#L142-L207
|
train
|
|
adobe/brackets
|
src/widgets/Dialogs.js
|
setDialogMaxSize
|
function setDialogMaxSize() {
var maxWidth, maxHeight,
$dlgs = $(".modal-inner-wrapper > .instance");
// Verify 1 or more modal dialogs are showing
if ($dlgs.length > 0) {
maxWidth = $("body").width();
maxHeight = $("body").height();
$dlgs.css({
"max-width": maxWidth,
"max-height": maxHeight,
"overflow": "auto"
});
}
}
|
javascript
|
function setDialogMaxSize() {
var maxWidth, maxHeight,
$dlgs = $(".modal-inner-wrapper > .instance");
// Verify 1 or more modal dialogs are showing
if ($dlgs.length > 0) {
maxWidth = $("body").width();
maxHeight = $("body").height();
$dlgs.css({
"max-width": maxWidth,
"max-height": maxHeight,
"overflow": "auto"
});
}
}
|
[
"function",
"setDialogMaxSize",
"(",
")",
"{",
"var",
"maxWidth",
",",
"maxHeight",
",",
"$dlgs",
"=",
"$",
"(",
"\".modal-inner-wrapper > .instance\"",
")",
";",
"if",
"(",
"$dlgs",
".",
"length",
">",
"0",
")",
"{",
"maxWidth",
"=",
"$",
"(",
"\"body\"",
")",
".",
"width",
"(",
")",
";",
"maxHeight",
"=",
"$",
"(",
"\"body\"",
")",
".",
"height",
"(",
")",
";",
"$dlgs",
".",
"css",
"(",
"{",
"\"max-width\"",
":",
"maxWidth",
",",
"\"max-height\"",
":",
"maxHeight",
",",
"\"overflow\"",
":",
"\"auto\"",
"}",
")",
";",
"}",
"}"
] |
Don't allow dialog to exceed viewport size
|
[
"Don",
"t",
"allow",
"dialog",
"to",
"exceed",
"viewport",
"size"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/widgets/Dialogs.js#L260-L275
|
train
|
adobe/brackets
|
src/widgets/Dialogs.js
|
showModalDialog
|
function showModalDialog(dlgClass, title, message, buttons, autoDismiss) {
var templateVars = {
dlgClass: dlgClass,
title: title || "",
message: message || "",
buttons: buttons || [{ className: DIALOG_BTN_CLASS_PRIMARY, id: DIALOG_BTN_OK, text: Strings.OK }]
};
var template = Mustache.render(DialogTemplate, templateVars);
return showModalDialogUsingTemplate(template, autoDismiss);
}
|
javascript
|
function showModalDialog(dlgClass, title, message, buttons, autoDismiss) {
var templateVars = {
dlgClass: dlgClass,
title: title || "",
message: message || "",
buttons: buttons || [{ className: DIALOG_BTN_CLASS_PRIMARY, id: DIALOG_BTN_OK, text: Strings.OK }]
};
var template = Mustache.render(DialogTemplate, templateVars);
return showModalDialogUsingTemplate(template, autoDismiss);
}
|
[
"function",
"showModalDialog",
"(",
"dlgClass",
",",
"title",
",",
"message",
",",
"buttons",
",",
"autoDismiss",
")",
"{",
"var",
"templateVars",
"=",
"{",
"dlgClass",
":",
"dlgClass",
",",
"title",
":",
"title",
"||",
"\"\"",
",",
"message",
":",
"message",
"||",
"\"\"",
",",
"buttons",
":",
"buttons",
"||",
"[",
"{",
"className",
":",
"DIALOG_BTN_CLASS_PRIMARY",
",",
"id",
":",
"DIALOG_BTN_OK",
",",
"text",
":",
"Strings",
".",
"OK",
"}",
"]",
"}",
";",
"var",
"template",
"=",
"Mustache",
".",
"render",
"(",
"DialogTemplate",
",",
"templateVars",
")",
";",
"return",
"showModalDialogUsingTemplate",
"(",
"template",
",",
"autoDismiss",
")",
";",
"}"
] |
Creates a new general purpose modal dialog using the default template and the template variables given
as parameters as described.
@param {string} dlgClass A class name identifier for the dialog. Typically one of DefaultDialogs.*
@param {string=} title The title of the dialog. Can contain HTML markup. Defaults to "".
@param {string=} message The message to display in the dialog. Can contain HTML markup. Defaults to "".
@param {Array.<{className: string, id: string, text: string}>=} buttons An array of buttons where each button
has a class, id and text property. The id is used in "data-button-id". Defaults to a single Ok button.
Typically className is one of DIALOG_BTN_CLASS_*, id is one of DIALOG_BTN_*
@param {boolean=} autoDismiss Whether to automatically dismiss the dialog when one of the buttons
is clicked. Default true. If false, you'll need to manually handle button clicks and the Esc
key, and dismiss the dialog yourself when ready by calling `close()` on the returned dialog.
@return {Dialog}
|
[
"Creates",
"a",
"new",
"general",
"purpose",
"modal",
"dialog",
"using",
"the",
"default",
"template",
"and",
"the",
"template",
"variables",
"given",
"as",
"parameters",
"as",
"described",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/widgets/Dialogs.js#L397-L407
|
train
|
adobe/brackets
|
src/utils/BuildInfoUtils.js
|
_loadSHA
|
function _loadSHA(path, callback) {
var result = new $.Deferred();
if (brackets.inBrowser) {
result.reject();
} else {
// HEAD contains a SHA in detached-head mode; otherwise it contains a relative path
// to a file in /refs which in turn contains the SHA
var file = FileSystem.getFileForPath(path);
FileUtils.readAsText(file).done(function (text) {
if (text.indexOf("ref: ") === 0) {
// e.g. "ref: refs/heads/branchname"
var basePath = path.substr(0, path.lastIndexOf("/")),
refRelPath = text.substr(5).trim(),
branch = text.substr(16).trim();
_loadSHA(basePath + "/" + refRelPath, callback).done(function (data) {
result.resolve({ branch: branch, sha: data.sha.trim() });
}).fail(function () {
result.resolve({ branch: branch });
});
} else {
result.resolve({ sha: text });
}
}).fail(function () {
result.reject();
});
}
return result.promise();
}
|
javascript
|
function _loadSHA(path, callback) {
var result = new $.Deferred();
if (brackets.inBrowser) {
result.reject();
} else {
// HEAD contains a SHA in detached-head mode; otherwise it contains a relative path
// to a file in /refs which in turn contains the SHA
var file = FileSystem.getFileForPath(path);
FileUtils.readAsText(file).done(function (text) {
if (text.indexOf("ref: ") === 0) {
// e.g. "ref: refs/heads/branchname"
var basePath = path.substr(0, path.lastIndexOf("/")),
refRelPath = text.substr(5).trim(),
branch = text.substr(16).trim();
_loadSHA(basePath + "/" + refRelPath, callback).done(function (data) {
result.resolve({ branch: branch, sha: data.sha.trim() });
}).fail(function () {
result.resolve({ branch: branch });
});
} else {
result.resolve({ sha: text });
}
}).fail(function () {
result.reject();
});
}
return result.promise();
}
|
[
"function",
"_loadSHA",
"(",
"path",
",",
"callback",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"if",
"(",
"brackets",
".",
"inBrowser",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
"else",
"{",
"var",
"file",
"=",
"FileSystem",
".",
"getFileForPath",
"(",
"path",
")",
";",
"FileUtils",
".",
"readAsText",
"(",
"file",
")",
".",
"done",
"(",
"function",
"(",
"text",
")",
"{",
"if",
"(",
"text",
".",
"indexOf",
"(",
"\"ref: \"",
")",
"===",
"0",
")",
"{",
"var",
"basePath",
"=",
"path",
".",
"substr",
"(",
"0",
",",
"path",
".",
"lastIndexOf",
"(",
"\"/\"",
")",
")",
",",
"refRelPath",
"=",
"text",
".",
"substr",
"(",
"5",
")",
".",
"trim",
"(",
")",
",",
"branch",
"=",
"text",
".",
"substr",
"(",
"16",
")",
".",
"trim",
"(",
")",
";",
"_loadSHA",
"(",
"basePath",
"+",
"\"/\"",
"+",
"refRelPath",
",",
"callback",
")",
".",
"done",
"(",
"function",
"(",
"data",
")",
"{",
"result",
".",
"resolve",
"(",
"{",
"branch",
":",
"branch",
",",
"sha",
":",
"data",
".",
"sha",
".",
"trim",
"(",
")",
"}",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"result",
".",
"resolve",
"(",
"{",
"branch",
":",
"branch",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"result",
".",
"resolve",
"(",
"{",
"sha",
":",
"text",
"}",
")",
";",
"}",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"}",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Loads a SHA from Git metadata file. If the file contains a symbolic ref name, follows the ref
and loads the SHA from that file in turn.
|
[
"Loads",
"a",
"SHA",
"from",
"Git",
"metadata",
"file",
".",
"If",
"the",
"file",
"contains",
"a",
"symbolic",
"ref",
"name",
"follows",
"the",
"ref",
"and",
"loads",
"the",
"SHA",
"from",
"that",
"file",
"in",
"turn",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/BuildInfoUtils.js#L41-L71
|
train
|
adobe/brackets
|
src/utils/UpdateNotification.js
|
_getVersionInfoUrl
|
function _getVersionInfoUrl(locale, removeCountryPartOfLocale) {
locale = locale || brackets.getLocale();
if (removeCountryPartOfLocale) {
locale = locale.substring(0, 2);
}
//AUTOUPDATE_PRERELEASE_BEGIN
// The following code is needed for supporting Auto Update in prerelease,
//and will be removed eventually for stable releases
{
if (locale) {
if(locale.length > 2) {
locale = locale.substring(0, 2);
}
switch(locale) {
case "de":
break;
case "es":
break;
case "fr":
break;
case "ja":
break;
case "en":
default:
locale = "en";
}
return brackets.config.update_info_url.replace("<locale>", locale);
}
}
//AUTOUPDATE_PRERELEASE_END
return brackets.config.update_info_url + '?locale=' + locale;
}
|
javascript
|
function _getVersionInfoUrl(locale, removeCountryPartOfLocale) {
locale = locale || brackets.getLocale();
if (removeCountryPartOfLocale) {
locale = locale.substring(0, 2);
}
//AUTOUPDATE_PRERELEASE_BEGIN
// The following code is needed for supporting Auto Update in prerelease,
//and will be removed eventually for stable releases
{
if (locale) {
if(locale.length > 2) {
locale = locale.substring(0, 2);
}
switch(locale) {
case "de":
break;
case "es":
break;
case "fr":
break;
case "ja":
break;
case "en":
default:
locale = "en";
}
return brackets.config.update_info_url.replace("<locale>", locale);
}
}
//AUTOUPDATE_PRERELEASE_END
return brackets.config.update_info_url + '?locale=' + locale;
}
|
[
"function",
"_getVersionInfoUrl",
"(",
"locale",
",",
"removeCountryPartOfLocale",
")",
"{",
"locale",
"=",
"locale",
"||",
"brackets",
".",
"getLocale",
"(",
")",
";",
"if",
"(",
"removeCountryPartOfLocale",
")",
"{",
"locale",
"=",
"locale",
".",
"substring",
"(",
"0",
",",
"2",
")",
";",
"}",
"{",
"if",
"(",
"locale",
")",
"{",
"if",
"(",
"locale",
".",
"length",
">",
"2",
")",
"{",
"locale",
"=",
"locale",
".",
"substring",
"(",
"0",
",",
"2",
")",
";",
"}",
"switch",
"(",
"locale",
")",
"{",
"case",
"\"de\"",
":",
"break",
";",
"case",
"\"es\"",
":",
"break",
";",
"case",
"\"fr\"",
":",
"break",
";",
"case",
"\"ja\"",
":",
"break",
";",
"case",
"\"en\"",
":",
"default",
":",
"locale",
"=",
"\"en\"",
";",
"}",
"return",
"brackets",
".",
"config",
".",
"update_info_url",
".",
"replace",
"(",
"\"<locale>\"",
",",
"locale",
")",
";",
"}",
"}",
"return",
"brackets",
".",
"config",
".",
"update_info_url",
"+",
"'?locale='",
"+",
"locale",
";",
"}"
] |
Construct a new version update url with the given locale.
@param {string=} locale - optional locale, defaults to 'brackets.getLocale()' when omitted.
@param {boolean=} removeCountryPartOfLocale - optional, remove existing country information from locale 'en-gb' => 'en'
return {string} the new version update url
|
[
"Construct",
"a",
"new",
"version",
"update",
"url",
"with",
"the",
"given",
"locale",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/UpdateNotification.js#L110-L145
|
train
|
adobe/brackets
|
src/utils/UpdateNotification.js
|
_getUpdateInformation
|
function _getUpdateInformation(force, dontCache, _versionInfoUrl) {
// Last time the versionInfoURL was fetched
var lastInfoURLFetchTime = PreferencesManager.getViewState("lastInfoURLFetchTime");
var result = new $.Deferred();
var fetchData = false;
var data;
// If force is true, always fetch
if (force) {
fetchData = true;
}
// If we don't have data saved in prefs, fetch
data = PreferencesManager.getViewState("updateInfo");
if (!data) {
fetchData = true;
}
// If more than 24 hours have passed since our last fetch, fetch again
if ((new Date()).getTime() > lastInfoURLFetchTime + ONE_DAY) {
fetchData = true;
}
if (fetchData) {
var lookupPromise = new $.Deferred(),
localVersionInfoUrl;
// If the current locale isn't "en" or "en-US", check whether we actually have a
// locale-specific update notification, and fall back to "en" if not.
// Note: we check for both "en" and "en-US" to watch for the general case or
// country-specific English locale. The former appears default on Mac, while
// the latter appears default on Windows.
var locale = brackets.getLocale().toLowerCase();
if (locale !== "en" && locale !== "en-us") {
localVersionInfoUrl = _versionInfoUrl || _getVersionInfoUrl();
$.ajax({
url: localVersionInfoUrl,
cache: false,
type: "HEAD"
}).fail(function (jqXHR, status, error) {
// get rid of any country information from locale and try again
var tmpUrl = _getVersionInfoUrl(brackets.getLocale(), true);
if (tmpUrl !== localVersionInfoUrl) {
$.ajax({
url: tmpUrl,
cache: false,
type: "HEAD"
}).fail(function (jqXHR, status, error) {
localVersionInfoUrl = _getVersionInfoUrl("en");
}).done(function (jqXHR, status, error) {
localVersionInfoUrl = tmpUrl;
}).always(function (jqXHR, status, error) {
lookupPromise.resolve();
});
} else {
localVersionInfoUrl = _getVersionInfoUrl("en");
lookupPromise.resolve();
}
}).done(function (jqXHR, status, error) {
lookupPromise.resolve();
});
} else {
localVersionInfoUrl = _versionInfoUrl || _getVersionInfoUrl("en");
lookupPromise.resolve();
}
lookupPromise.done(function () {
$.ajax({
url: localVersionInfoUrl,
dataType: "json",
cache: false
}).done(function (updateInfo, textStatus, jqXHR) {
if (!dontCache) {
lastInfoURLFetchTime = (new Date()).getTime();
PreferencesManager.setViewState("lastInfoURLFetchTime", lastInfoURLFetchTime);
PreferencesManager.setViewState("updateInfo", updateInfo);
}
result.resolve(updateInfo);
}).fail(function (jqXHR, status, error) {
// When loading data for unit tests, the error handler is
// called but the responseText is valid. Try to use it here,
// but *don't* save the results in prefs.
if (!jqXHR.responseText) {
// Text is NULL or empty string, reject().
result.reject();
return;
}
try {
data = JSON.parse(jqXHR.responseText);
result.resolve(data);
} catch (e) {
result.reject();
}
});
});
} else {
result.resolve(data);
}
return result.promise();
}
|
javascript
|
function _getUpdateInformation(force, dontCache, _versionInfoUrl) {
// Last time the versionInfoURL was fetched
var lastInfoURLFetchTime = PreferencesManager.getViewState("lastInfoURLFetchTime");
var result = new $.Deferred();
var fetchData = false;
var data;
// If force is true, always fetch
if (force) {
fetchData = true;
}
// If we don't have data saved in prefs, fetch
data = PreferencesManager.getViewState("updateInfo");
if (!data) {
fetchData = true;
}
// If more than 24 hours have passed since our last fetch, fetch again
if ((new Date()).getTime() > lastInfoURLFetchTime + ONE_DAY) {
fetchData = true;
}
if (fetchData) {
var lookupPromise = new $.Deferred(),
localVersionInfoUrl;
// If the current locale isn't "en" or "en-US", check whether we actually have a
// locale-specific update notification, and fall back to "en" if not.
// Note: we check for both "en" and "en-US" to watch for the general case or
// country-specific English locale. The former appears default on Mac, while
// the latter appears default on Windows.
var locale = brackets.getLocale().toLowerCase();
if (locale !== "en" && locale !== "en-us") {
localVersionInfoUrl = _versionInfoUrl || _getVersionInfoUrl();
$.ajax({
url: localVersionInfoUrl,
cache: false,
type: "HEAD"
}).fail(function (jqXHR, status, error) {
// get rid of any country information from locale and try again
var tmpUrl = _getVersionInfoUrl(brackets.getLocale(), true);
if (tmpUrl !== localVersionInfoUrl) {
$.ajax({
url: tmpUrl,
cache: false,
type: "HEAD"
}).fail(function (jqXHR, status, error) {
localVersionInfoUrl = _getVersionInfoUrl("en");
}).done(function (jqXHR, status, error) {
localVersionInfoUrl = tmpUrl;
}).always(function (jqXHR, status, error) {
lookupPromise.resolve();
});
} else {
localVersionInfoUrl = _getVersionInfoUrl("en");
lookupPromise.resolve();
}
}).done(function (jqXHR, status, error) {
lookupPromise.resolve();
});
} else {
localVersionInfoUrl = _versionInfoUrl || _getVersionInfoUrl("en");
lookupPromise.resolve();
}
lookupPromise.done(function () {
$.ajax({
url: localVersionInfoUrl,
dataType: "json",
cache: false
}).done(function (updateInfo, textStatus, jqXHR) {
if (!dontCache) {
lastInfoURLFetchTime = (new Date()).getTime();
PreferencesManager.setViewState("lastInfoURLFetchTime", lastInfoURLFetchTime);
PreferencesManager.setViewState("updateInfo", updateInfo);
}
result.resolve(updateInfo);
}).fail(function (jqXHR, status, error) {
// When loading data for unit tests, the error handler is
// called but the responseText is valid. Try to use it here,
// but *don't* save the results in prefs.
if (!jqXHR.responseText) {
// Text is NULL or empty string, reject().
result.reject();
return;
}
try {
data = JSON.parse(jqXHR.responseText);
result.resolve(data);
} catch (e) {
result.reject();
}
});
});
} else {
result.resolve(data);
}
return result.promise();
}
|
[
"function",
"_getUpdateInformation",
"(",
"force",
",",
"dontCache",
",",
"_versionInfoUrl",
")",
"{",
"var",
"lastInfoURLFetchTime",
"=",
"PreferencesManager",
".",
"getViewState",
"(",
"\"lastInfoURLFetchTime\"",
")",
";",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"var",
"fetchData",
"=",
"false",
";",
"var",
"data",
";",
"if",
"(",
"force",
")",
"{",
"fetchData",
"=",
"true",
";",
"}",
"data",
"=",
"PreferencesManager",
".",
"getViewState",
"(",
"\"updateInfo\"",
")",
";",
"if",
"(",
"!",
"data",
")",
"{",
"fetchData",
"=",
"true",
";",
"}",
"if",
"(",
"(",
"new",
"Date",
"(",
")",
")",
".",
"getTime",
"(",
")",
">",
"lastInfoURLFetchTime",
"+",
"ONE_DAY",
")",
"{",
"fetchData",
"=",
"true",
";",
"}",
"if",
"(",
"fetchData",
")",
"{",
"var",
"lookupPromise",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
",",
"localVersionInfoUrl",
";",
"var",
"locale",
"=",
"brackets",
".",
"getLocale",
"(",
")",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"locale",
"!==",
"\"en\"",
"&&",
"locale",
"!==",
"\"en-us\"",
")",
"{",
"localVersionInfoUrl",
"=",
"_versionInfoUrl",
"||",
"_getVersionInfoUrl",
"(",
")",
";",
"$",
".",
"ajax",
"(",
"{",
"url",
":",
"localVersionInfoUrl",
",",
"cache",
":",
"false",
",",
"type",
":",
"\"HEAD\"",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"jqXHR",
",",
"status",
",",
"error",
")",
"{",
"var",
"tmpUrl",
"=",
"_getVersionInfoUrl",
"(",
"brackets",
".",
"getLocale",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"tmpUrl",
"!==",
"localVersionInfoUrl",
")",
"{",
"$",
".",
"ajax",
"(",
"{",
"url",
":",
"tmpUrl",
",",
"cache",
":",
"false",
",",
"type",
":",
"\"HEAD\"",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"jqXHR",
",",
"status",
",",
"error",
")",
"{",
"localVersionInfoUrl",
"=",
"_getVersionInfoUrl",
"(",
"\"en\"",
")",
";",
"}",
")",
".",
"done",
"(",
"function",
"(",
"jqXHR",
",",
"status",
",",
"error",
")",
"{",
"localVersionInfoUrl",
"=",
"tmpUrl",
";",
"}",
")",
".",
"always",
"(",
"function",
"(",
"jqXHR",
",",
"status",
",",
"error",
")",
"{",
"lookupPromise",
".",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"localVersionInfoUrl",
"=",
"_getVersionInfoUrl",
"(",
"\"en\"",
")",
";",
"lookupPromise",
".",
"resolve",
"(",
")",
";",
"}",
"}",
")",
".",
"done",
"(",
"function",
"(",
"jqXHR",
",",
"status",
",",
"error",
")",
"{",
"lookupPromise",
".",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"localVersionInfoUrl",
"=",
"_versionInfoUrl",
"||",
"_getVersionInfoUrl",
"(",
"\"en\"",
")",
";",
"lookupPromise",
".",
"resolve",
"(",
")",
";",
"}",
"lookupPromise",
".",
"done",
"(",
"function",
"(",
")",
"{",
"$",
".",
"ajax",
"(",
"{",
"url",
":",
"localVersionInfoUrl",
",",
"dataType",
":",
"\"json\"",
",",
"cache",
":",
"false",
"}",
")",
".",
"done",
"(",
"function",
"(",
"updateInfo",
",",
"textStatus",
",",
"jqXHR",
")",
"{",
"if",
"(",
"!",
"dontCache",
")",
"{",
"lastInfoURLFetchTime",
"=",
"(",
"new",
"Date",
"(",
")",
")",
".",
"getTime",
"(",
")",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"\"lastInfoURLFetchTime\"",
",",
"lastInfoURLFetchTime",
")",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"\"updateInfo\"",
",",
"updateInfo",
")",
";",
"}",
"result",
".",
"resolve",
"(",
"updateInfo",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"jqXHR",
",",
"status",
",",
"error",
")",
"{",
"if",
"(",
"!",
"jqXHR",
".",
"responseText",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"return",
";",
"}",
"try",
"{",
"data",
"=",
"JSON",
".",
"parse",
"(",
"jqXHR",
".",
"responseText",
")",
";",
"result",
".",
"resolve",
"(",
"data",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"result",
".",
"resolve",
"(",
"data",
")",
";",
"}",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Get a data structure that has information for all builds of Brackets.
If force is true, the information is always fetched from _versionInfoURL.
If force is false, we try to use cached information. If more than
24 hours have passed since the last fetch, or if cached data can't be found,
the data is fetched again.
If new data is fetched and dontCache is false, the data is saved in preferences
for quick fetching later.
_versionInfoUrl is used for unit testing.
|
[
"Get",
"a",
"data",
"structure",
"that",
"has",
"information",
"for",
"all",
"builds",
"of",
"Brackets",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/UpdateNotification.js#L159-L262
|
train
|
adobe/brackets
|
src/utils/UpdateNotification.js
|
_stripOldVersionInfo
|
function _stripOldVersionInfo(versionInfo, buildNumber) {
// Do a simple linear search. Since we are going in reverse-chronological order, we
// should get through the search quickly.
var lastIndex = 0;
var len = versionInfo.length;
var versionEntry;
var validBuildEntries;
while (lastIndex < len) {
versionEntry = versionInfo[lastIndex];
if (versionEntry.buildNumber <= buildNumber) {
break;
}
lastIndex++;
}
if (lastIndex > 0) {
// Filter recent update entries based on applicability to current platform
validBuildEntries = versionInfo.slice(0, lastIndex).filter(_checkBuildApplicability);
}
return validBuildEntries;
}
|
javascript
|
function _stripOldVersionInfo(versionInfo, buildNumber) {
// Do a simple linear search. Since we are going in reverse-chronological order, we
// should get through the search quickly.
var lastIndex = 0;
var len = versionInfo.length;
var versionEntry;
var validBuildEntries;
while (lastIndex < len) {
versionEntry = versionInfo[lastIndex];
if (versionEntry.buildNumber <= buildNumber) {
break;
}
lastIndex++;
}
if (lastIndex > 0) {
// Filter recent update entries based on applicability to current platform
validBuildEntries = versionInfo.slice(0, lastIndex).filter(_checkBuildApplicability);
}
return validBuildEntries;
}
|
[
"function",
"_stripOldVersionInfo",
"(",
"versionInfo",
",",
"buildNumber",
")",
"{",
"var",
"lastIndex",
"=",
"0",
";",
"var",
"len",
"=",
"versionInfo",
".",
"length",
";",
"var",
"versionEntry",
";",
"var",
"validBuildEntries",
";",
"while",
"(",
"lastIndex",
"<",
"len",
")",
"{",
"versionEntry",
"=",
"versionInfo",
"[",
"lastIndex",
"]",
";",
"if",
"(",
"versionEntry",
".",
"buildNumber",
"<=",
"buildNumber",
")",
"{",
"break",
";",
"}",
"lastIndex",
"++",
";",
"}",
"if",
"(",
"lastIndex",
">",
"0",
")",
"{",
"validBuildEntries",
"=",
"versionInfo",
".",
"slice",
"(",
"0",
",",
"lastIndex",
")",
".",
"filter",
"(",
"_checkBuildApplicability",
")",
";",
"}",
"return",
"validBuildEntries",
";",
"}"
] |
Return a new array of version information that is newer than "buildNumber".
Returns null if there is no new version information.
|
[
"Return",
"a",
"new",
"array",
"of",
"version",
"information",
"that",
"is",
"newer",
"than",
"buildNumber",
".",
"Returns",
"null",
"if",
"there",
"is",
"no",
"new",
"version",
"information",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/UpdateNotification.js#L275-L297
|
train
|
adobe/brackets
|
src/utils/UpdateNotification.js
|
_showUpdateNotificationDialog
|
function _showUpdateNotificationDialog(updates, force) {
Dialogs.showModalDialogUsingTemplate(Mustache.render(UpdateDialogTemplate, Strings))
.done(function (id) {
if (id === Dialogs.DIALOG_BTN_DOWNLOAD) {
HealthLogger.sendAnalyticsData(
eventNames.AUTOUPDATE_UPDATENOW_CLICK,
"autoUpdate",
"updateNotification",
"updateNow",
"click"
);
handleUpdateProcess(updates);
} else {
HealthLogger.sendAnalyticsData(
eventNames.AUTOUPDATE_CANCEL_CLICK,
"autoUpdate",
"updateNotification",
"cancel",
"click"
);
}
});
// Populate the update data
var $dlg = $(".update-dialog.instance"),
$updateList = $dlg.find(".update-info"),
subTypeString = force ? "userAction" : "auto";
// Make the update notification icon clickable again
_addedClickHandler = false;
updates.Strings = Strings;
$updateList.html(Mustache.render(UpdateListTemplate, updates));
HealthLogger.sendAnalyticsData(
eventNames.AUTOUPDATE_UPDATE_AVAILABLE_DIALOG_BOX_RENDERED,
"autoUpdate",
"updateNotification",
"render",
subTypeString
);
}
|
javascript
|
function _showUpdateNotificationDialog(updates, force) {
Dialogs.showModalDialogUsingTemplate(Mustache.render(UpdateDialogTemplate, Strings))
.done(function (id) {
if (id === Dialogs.DIALOG_BTN_DOWNLOAD) {
HealthLogger.sendAnalyticsData(
eventNames.AUTOUPDATE_UPDATENOW_CLICK,
"autoUpdate",
"updateNotification",
"updateNow",
"click"
);
handleUpdateProcess(updates);
} else {
HealthLogger.sendAnalyticsData(
eventNames.AUTOUPDATE_CANCEL_CLICK,
"autoUpdate",
"updateNotification",
"cancel",
"click"
);
}
});
// Populate the update data
var $dlg = $(".update-dialog.instance"),
$updateList = $dlg.find(".update-info"),
subTypeString = force ? "userAction" : "auto";
// Make the update notification icon clickable again
_addedClickHandler = false;
updates.Strings = Strings;
$updateList.html(Mustache.render(UpdateListTemplate, updates));
HealthLogger.sendAnalyticsData(
eventNames.AUTOUPDATE_UPDATE_AVAILABLE_DIALOG_BOX_RENDERED,
"autoUpdate",
"updateNotification",
"render",
subTypeString
);
}
|
[
"function",
"_showUpdateNotificationDialog",
"(",
"updates",
",",
"force",
")",
"{",
"Dialogs",
".",
"showModalDialogUsingTemplate",
"(",
"Mustache",
".",
"render",
"(",
"UpdateDialogTemplate",
",",
"Strings",
")",
")",
".",
"done",
"(",
"function",
"(",
"id",
")",
"{",
"if",
"(",
"id",
"===",
"Dialogs",
".",
"DIALOG_BTN_DOWNLOAD",
")",
"{",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"eventNames",
".",
"AUTOUPDATE_UPDATENOW_CLICK",
",",
"\"autoUpdate\"",
",",
"\"updateNotification\"",
",",
"\"updateNow\"",
",",
"\"click\"",
")",
";",
"handleUpdateProcess",
"(",
"updates",
")",
";",
"}",
"else",
"{",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"eventNames",
".",
"AUTOUPDATE_CANCEL_CLICK",
",",
"\"autoUpdate\"",
",",
"\"updateNotification\"",
",",
"\"cancel\"",
",",
"\"click\"",
")",
";",
"}",
"}",
")",
";",
"var",
"$dlg",
"=",
"$",
"(",
"\".update-dialog.instance\"",
")",
",",
"$updateList",
"=",
"$dlg",
".",
"find",
"(",
"\".update-info\"",
")",
",",
"subTypeString",
"=",
"force",
"?",
"\"userAction\"",
":",
"\"auto\"",
";",
"_addedClickHandler",
"=",
"false",
";",
"updates",
".",
"Strings",
"=",
"Strings",
";",
"$updateList",
".",
"html",
"(",
"Mustache",
".",
"render",
"(",
"UpdateListTemplate",
",",
"updates",
")",
")",
";",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"eventNames",
".",
"AUTOUPDATE_UPDATE_AVAILABLE_DIALOG_BOX_RENDERED",
",",
"\"autoUpdate\"",
",",
"\"updateNotification\"",
",",
"\"render\"",
",",
"subTypeString",
")",
";",
"}"
] |
Show a dialog that shows the update
|
[
"Show",
"a",
"dialog",
"that",
"shows",
"the",
"update"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/UpdateNotification.js#L302-L342
|
train
|
adobe/brackets
|
src/utils/UpdateNotification.js
|
_onRegistryDownloaded
|
function _onRegistryDownloaded() {
var availableUpdates = ExtensionManager.getAvailableUpdates();
PreferencesManager.setViewState("extensionUpdateInfo", availableUpdates);
PreferencesManager.setViewState("lastExtensionRegistryCheckTime", (new Date()).getTime());
$("#toolbar-extension-manager").toggleClass("updatesAvailable", availableUpdates.length > 0);
}
|
javascript
|
function _onRegistryDownloaded() {
var availableUpdates = ExtensionManager.getAvailableUpdates();
PreferencesManager.setViewState("extensionUpdateInfo", availableUpdates);
PreferencesManager.setViewState("lastExtensionRegistryCheckTime", (new Date()).getTime());
$("#toolbar-extension-manager").toggleClass("updatesAvailable", availableUpdates.length > 0);
}
|
[
"function",
"_onRegistryDownloaded",
"(",
")",
"{",
"var",
"availableUpdates",
"=",
"ExtensionManager",
".",
"getAvailableUpdates",
"(",
")",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"\"extensionUpdateInfo\"",
",",
"availableUpdates",
")",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"\"lastExtensionRegistryCheckTime\"",
",",
"(",
"new",
"Date",
"(",
")",
")",
".",
"getTime",
"(",
")",
")",
";",
"$",
"(",
"\"#toolbar-extension-manager\"",
")",
".",
"toggleClass",
"(",
"\"updatesAvailable\"",
",",
"availableUpdates",
".",
"length",
">",
"0",
")",
";",
"}"
] |
Calculate state of notification everytime registries are downloaded - no matter who triggered the download
|
[
"Calculate",
"state",
"of",
"notification",
"everytime",
"registries",
"are",
"downloaded",
"-",
"no",
"matter",
"who",
"triggered",
"the",
"download"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/UpdateNotification.js#L347-L352
|
train
|
adobe/brackets
|
src/utils/UpdateNotification.js
|
handleUpdateProcess
|
function handleUpdateProcess(updates) {
var handler = _updateProcessHandler || _defaultUpdateProcessHandler;
var initSuccess = handler(updates);
if (_updateProcessHandler && !initSuccess) {
// Give a chance to default handler in case
// the auot update mechanism has failed.
_defaultUpdateProcessHandler(updates);
}
}
|
javascript
|
function handleUpdateProcess(updates) {
var handler = _updateProcessHandler || _defaultUpdateProcessHandler;
var initSuccess = handler(updates);
if (_updateProcessHandler && !initSuccess) {
// Give a chance to default handler in case
// the auot update mechanism has failed.
_defaultUpdateProcessHandler(updates);
}
}
|
[
"function",
"handleUpdateProcess",
"(",
"updates",
")",
"{",
"var",
"handler",
"=",
"_updateProcessHandler",
"||",
"_defaultUpdateProcessHandler",
";",
"var",
"initSuccess",
"=",
"handler",
"(",
"updates",
")",
";",
"if",
"(",
"_updateProcessHandler",
"&&",
"!",
"initSuccess",
")",
"{",
"_defaultUpdateProcessHandler",
"(",
"updates",
")",
";",
"}",
"}"
] |
Handles the update process
@param {Array} updates - array object containing info of updates
|
[
"Handles",
"the",
"update",
"process"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/UpdateNotification.js#L523-L531
|
train
|
adobe/brackets
|
src/extensions/default/InlineColorEditor/ColorEditor.js
|
_0xColorToHex
|
function _0xColorToHex(color, convertToStr) {
var hexColor = tinycolor(color.replace("0x", "#"));
hexColor._format = "0x";
if (convertToStr) {
return hexColor.toString();
}
return hexColor;
}
|
javascript
|
function _0xColorToHex(color, convertToStr) {
var hexColor = tinycolor(color.replace("0x", "#"));
hexColor._format = "0x";
if (convertToStr) {
return hexColor.toString();
}
return hexColor;
}
|
[
"function",
"_0xColorToHex",
"(",
"color",
",",
"convertToStr",
")",
"{",
"var",
"hexColor",
"=",
"tinycolor",
"(",
"color",
".",
"replace",
"(",
"\"0x\"",
",",
"\"#\"",
")",
")",
";",
"hexColor",
".",
"_format",
"=",
"\"0x\"",
";",
"if",
"(",
"convertToStr",
")",
"{",
"return",
"hexColor",
".",
"toString",
"(",
")",
";",
"}",
"return",
"hexColor",
";",
"}"
] |
Converts 0x-prefixed color to hex
@param {string} color - Color to convert
@param {boolean} convertToString - true if color should
be returned as string
@returns {tinycolor|string} - Hex color as a Tinycolor object
or a hex string
|
[
"Converts",
"0x",
"-",
"prefixed",
"color",
"to",
"hex"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineColorEditor/ColorEditor.js#L71-L79
|
train
|
adobe/brackets
|
src/extensions/default/InlineColorEditor/ColorEditor.js
|
checkSetFormat
|
function checkSetFormat(color, convertToStr) {
if ((/^0x/).test(color)) {
return _0xColorToHex(color, convertToStr);
}
if (convertToStr) {
return tinycolor(color).toString();
}
return tinycolor(color);
}
|
javascript
|
function checkSetFormat(color, convertToStr) {
if ((/^0x/).test(color)) {
return _0xColorToHex(color, convertToStr);
}
if (convertToStr) {
return tinycolor(color).toString();
}
return tinycolor(color);
}
|
[
"function",
"checkSetFormat",
"(",
"color",
",",
"convertToStr",
")",
"{",
"if",
"(",
"(",
"/",
"^0x",
"/",
")",
".",
"test",
"(",
"color",
")",
")",
"{",
"return",
"_0xColorToHex",
"(",
"color",
",",
"convertToStr",
")",
";",
"}",
"if",
"(",
"convertToStr",
")",
"{",
"return",
"tinycolor",
"(",
"color",
")",
".",
"toString",
"(",
")",
";",
"}",
"return",
"tinycolor",
"(",
"color",
")",
";",
"}"
] |
Ensures that a string is in Tinycolor supported format
@param {string} color - Color to check the format for
@param {boolean} convertToString - true if color should
be returned as string
@returns {tinycolor|string} - Color as a Tinycolor object
or a hex string
|
[
"Ensures",
"that",
"a",
"string",
"is",
"in",
"Tinycolor",
"supported",
"format"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineColorEditor/ColorEditor.js#L89-L97
|
train
|
adobe/brackets
|
src/extensions/default/InlineColorEditor/ColorEditor.js
|
ColorEditor
|
function ColorEditor($parent, color, callback, swatches) {
// Create the DOM structure, filling in localized strings via Mustache
this.$element = $(Mustache.render(ColorEditorTemplate, Strings));
$parent.append(this.$element);
this._callback = callback;
this._handleKeydown = this._handleKeydown.bind(this);
this._handleOpacityKeydown = this._handleOpacityKeydown.bind(this);
this._handleHslKeydown = this._handleHslKeydown.bind(this);
this._handleHueKeydown = this._handleHueKeydown.bind(this);
this._handleSelectionKeydown = this._handleSelectionKeydown.bind(this);
this._handleOpacityDrag = this._handleOpacityDrag.bind(this);
this._handleHueDrag = this._handleHueDrag.bind(this);
this._handleSelectionFieldDrag = this._handleSelectionFieldDrag.bind(this);
this._originalColor = color;
this._color = checkSetFormat(color);
this._redoColor = null;
this._isUpperCase = PreferencesManager.get("uppercaseColors");
PreferencesManager.on("change", "uppercaseColors", function () {
this._isUpperCase = PreferencesManager.get("uppercaseColors");
}.bind(this));
this.$colorValue = this.$element.find(".color-value");
this.$buttonList = this.$element.find("ul.button-bar");
this.$rgbaButton = this.$element.find(".rgba");
this.$hexButton = this.$element.find(".hex");
this.$hslButton = this.$element.find(".hsla");
this.$0xButton = this.$element.find(".0x");
this.$currentColor = this.$element.find(".current-color");
this.$originalColor = this.$element.find(".original-color");
this.$selection = this.$element.find(".color-selection-field");
this.$selectionBase = this.$element.find(".color-selection-field .selector-base");
this.$hueBase = this.$element.find(".hue-slider .selector-base");
this.$opacityGradient = this.$element.find(".opacity-gradient");
this.$hueSlider = this.$element.find(".hue-slider");
this.$hueSelector = this.$element.find(".hue-slider .selector-base");
this.$opacitySlider = this.$element.find(".opacity-slider");
this.$opacitySelector = this.$element.find(".opacity-slider .selector-base");
this.$swatches = this.$element.find(".swatches");
// Create quick-access color swatches
this._addSwatches(swatches);
// Attach event listeners to main UI elements
this._addListeners();
// Initially selected color
this.$originalColor.css("background-color", checkSetFormat(this._originalColor));
this._commitColor(color);
}
|
javascript
|
function ColorEditor($parent, color, callback, swatches) {
// Create the DOM structure, filling in localized strings via Mustache
this.$element = $(Mustache.render(ColorEditorTemplate, Strings));
$parent.append(this.$element);
this._callback = callback;
this._handleKeydown = this._handleKeydown.bind(this);
this._handleOpacityKeydown = this._handleOpacityKeydown.bind(this);
this._handleHslKeydown = this._handleHslKeydown.bind(this);
this._handleHueKeydown = this._handleHueKeydown.bind(this);
this._handleSelectionKeydown = this._handleSelectionKeydown.bind(this);
this._handleOpacityDrag = this._handleOpacityDrag.bind(this);
this._handleHueDrag = this._handleHueDrag.bind(this);
this._handleSelectionFieldDrag = this._handleSelectionFieldDrag.bind(this);
this._originalColor = color;
this._color = checkSetFormat(color);
this._redoColor = null;
this._isUpperCase = PreferencesManager.get("uppercaseColors");
PreferencesManager.on("change", "uppercaseColors", function () {
this._isUpperCase = PreferencesManager.get("uppercaseColors");
}.bind(this));
this.$colorValue = this.$element.find(".color-value");
this.$buttonList = this.$element.find("ul.button-bar");
this.$rgbaButton = this.$element.find(".rgba");
this.$hexButton = this.$element.find(".hex");
this.$hslButton = this.$element.find(".hsla");
this.$0xButton = this.$element.find(".0x");
this.$currentColor = this.$element.find(".current-color");
this.$originalColor = this.$element.find(".original-color");
this.$selection = this.$element.find(".color-selection-field");
this.$selectionBase = this.$element.find(".color-selection-field .selector-base");
this.$hueBase = this.$element.find(".hue-slider .selector-base");
this.$opacityGradient = this.$element.find(".opacity-gradient");
this.$hueSlider = this.$element.find(".hue-slider");
this.$hueSelector = this.$element.find(".hue-slider .selector-base");
this.$opacitySlider = this.$element.find(".opacity-slider");
this.$opacitySelector = this.$element.find(".opacity-slider .selector-base");
this.$swatches = this.$element.find(".swatches");
// Create quick-access color swatches
this._addSwatches(swatches);
// Attach event listeners to main UI elements
this._addListeners();
// Initially selected color
this.$originalColor.css("background-color", checkSetFormat(this._originalColor));
this._commitColor(color);
}
|
[
"function",
"ColorEditor",
"(",
"$parent",
",",
"color",
",",
"callback",
",",
"swatches",
")",
"{",
"this",
".",
"$element",
"=",
"$",
"(",
"Mustache",
".",
"render",
"(",
"ColorEditorTemplate",
",",
"Strings",
")",
")",
";",
"$parent",
".",
"append",
"(",
"this",
".",
"$element",
")",
";",
"this",
".",
"_callback",
"=",
"callback",
";",
"this",
".",
"_handleKeydown",
"=",
"this",
".",
"_handleKeydown",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_handleOpacityKeydown",
"=",
"this",
".",
"_handleOpacityKeydown",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_handleHslKeydown",
"=",
"this",
".",
"_handleHslKeydown",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_handleHueKeydown",
"=",
"this",
".",
"_handleHueKeydown",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_handleSelectionKeydown",
"=",
"this",
".",
"_handleSelectionKeydown",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_handleOpacityDrag",
"=",
"this",
".",
"_handleOpacityDrag",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_handleHueDrag",
"=",
"this",
".",
"_handleHueDrag",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_handleSelectionFieldDrag",
"=",
"this",
".",
"_handleSelectionFieldDrag",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_originalColor",
"=",
"color",
";",
"this",
".",
"_color",
"=",
"checkSetFormat",
"(",
"color",
")",
";",
"this",
".",
"_redoColor",
"=",
"null",
";",
"this",
".",
"_isUpperCase",
"=",
"PreferencesManager",
".",
"get",
"(",
"\"uppercaseColors\"",
")",
";",
"PreferencesManager",
".",
"on",
"(",
"\"change\"",
",",
"\"uppercaseColors\"",
",",
"function",
"(",
")",
"{",
"this",
".",
"_isUpperCase",
"=",
"PreferencesManager",
".",
"get",
"(",
"\"uppercaseColors\"",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"$colorValue",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".color-value\"",
")",
";",
"this",
".",
"$buttonList",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\"ul.button-bar\"",
")",
";",
"this",
".",
"$rgbaButton",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".rgba\"",
")",
";",
"this",
".",
"$hexButton",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".hex\"",
")",
";",
"this",
".",
"$hslButton",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".hsla\"",
")",
";",
"this",
".",
"$0xButton",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".0x\"",
")",
";",
"this",
".",
"$currentColor",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".current-color\"",
")",
";",
"this",
".",
"$originalColor",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".original-color\"",
")",
";",
"this",
".",
"$selection",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".color-selection-field\"",
")",
";",
"this",
".",
"$selectionBase",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".color-selection-field .selector-base\"",
")",
";",
"this",
".",
"$hueBase",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".hue-slider .selector-base\"",
")",
";",
"this",
".",
"$opacityGradient",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".opacity-gradient\"",
")",
";",
"this",
".",
"$hueSlider",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".hue-slider\"",
")",
";",
"this",
".",
"$hueSelector",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".hue-slider .selector-base\"",
")",
";",
"this",
".",
"$opacitySlider",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".opacity-slider\"",
")",
";",
"this",
".",
"$opacitySelector",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".opacity-slider .selector-base\"",
")",
";",
"this",
".",
"$swatches",
"=",
"this",
".",
"$element",
".",
"find",
"(",
"\".swatches\"",
")",
";",
"this",
".",
"_addSwatches",
"(",
"swatches",
")",
";",
"this",
".",
"_addListeners",
"(",
")",
";",
"this",
".",
"$originalColor",
".",
"css",
"(",
"\"background-color\"",
",",
"checkSetFormat",
"(",
"this",
".",
"_originalColor",
")",
")",
";",
"this",
".",
"_commitColor",
"(",
"color",
")",
";",
"}"
] |
Color picker control; may be used standalone or within an InlineColorEditor inline widget.
@param {!jQuery} $parent DOM node into which to append the root of the color picker UI
@param {!string} color Initially selected color
@param {!function(string)} callback Called whenever selected color changes
@param {!Array.<{value:string, count:number}>} swatches Quick-access color swatches to include in UI
|
[
"Color",
"picker",
"control",
";",
"may",
"be",
"used",
"standalone",
"or",
"within",
"an",
"InlineColorEditor",
"inline",
"widget",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineColorEditor/ColorEditor.js#L106-L159
|
train
|
adobe/brackets
|
src/search/FindBar.js
|
_handleKeydown
|
function _handleKeydown(e) {
if (e.keyCode === KeyEvent.DOM_VK_ESCAPE) {
e.stopPropagation();
e.preventDefault();
self.close();
}
}
|
javascript
|
function _handleKeydown(e) {
if (e.keyCode === KeyEvent.DOM_VK_ESCAPE) {
e.stopPropagation();
e.preventDefault();
self.close();
}
}
|
[
"function",
"_handleKeydown",
"(",
"e",
")",
"{",
"if",
"(",
"e",
".",
"keyCode",
"===",
"KeyEvent",
".",
"DOM_VK_ESCAPE",
")",
"{",
"e",
".",
"stopPropagation",
"(",
")",
";",
"e",
".",
"preventDefault",
"(",
")",
";",
"self",
".",
"close",
"(",
")",
";",
"}",
"}"
] |
Done this way because ModalBar.js seems to react unreliably when modifying it to handle the escape key - the findbar wasn't getting closed as it should, instead persisting in the background
|
[
"Done",
"this",
"way",
"because",
"ModalBar",
".",
"js",
"seems",
"to",
"react",
"unreliably",
"when",
"modifying",
"it",
"to",
"handle",
"the",
"escape",
"key",
"-",
"the",
"findbar",
"wasn",
"t",
"getting",
"closed",
"as",
"it",
"should",
"instead",
"persisting",
"in",
"the",
"background"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindBar.js#L288-L294
|
train
|
adobe/brackets
|
src/extensions/default/RemoteFileAdapter/main.js
|
_setMenuItemsVisible
|
function _setMenuItemsVisible() {
var file = MainViewManager.getCurrentlyViewedFile(MainViewManager.ACTIVE_PANE),
cMenuItems = [Commands.FILE_SAVE, Commands.FILE_RENAME, Commands.NAVIGATE_SHOW_IN_FILE_TREE, Commands.NAVIGATE_SHOW_IN_OS],
// Enable menu options when no file is present in active pane
enable = !file || (file.constructor.name !== "RemoteFile");
// Enable or disable commands based on whether the file is a remoteFile or not.
cMenuItems.forEach(function (item) {
CommandManager.get(item).setEnabled(enable);
});
}
|
javascript
|
function _setMenuItemsVisible() {
var file = MainViewManager.getCurrentlyViewedFile(MainViewManager.ACTIVE_PANE),
cMenuItems = [Commands.FILE_SAVE, Commands.FILE_RENAME, Commands.NAVIGATE_SHOW_IN_FILE_TREE, Commands.NAVIGATE_SHOW_IN_OS],
// Enable menu options when no file is present in active pane
enable = !file || (file.constructor.name !== "RemoteFile");
// Enable or disable commands based on whether the file is a remoteFile or not.
cMenuItems.forEach(function (item) {
CommandManager.get(item).setEnabled(enable);
});
}
|
[
"function",
"_setMenuItemsVisible",
"(",
")",
"{",
"var",
"file",
"=",
"MainViewManager",
".",
"getCurrentlyViewedFile",
"(",
"MainViewManager",
".",
"ACTIVE_PANE",
")",
",",
"cMenuItems",
"=",
"[",
"Commands",
".",
"FILE_SAVE",
",",
"Commands",
".",
"FILE_RENAME",
",",
"Commands",
".",
"NAVIGATE_SHOW_IN_FILE_TREE",
",",
"Commands",
".",
"NAVIGATE_SHOW_IN_OS",
"]",
",",
"enable",
"=",
"!",
"file",
"||",
"(",
"file",
".",
"constructor",
".",
"name",
"!==",
"\"RemoteFile\"",
")",
";",
"cMenuItems",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"CommandManager",
".",
"get",
"(",
"item",
")",
".",
"setEnabled",
"(",
"enable",
")",
";",
"}",
")",
";",
"}"
] |
Disable context menus which are not useful for remote file
|
[
"Disable",
"context",
"menus",
"which",
"are",
"not",
"useful",
"for",
"remote",
"file"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RemoteFileAdapter/main.js#L59-L69
|
train
|
adobe/brackets
|
src/extensions/default/JavaScriptRefactoring/RefactoringUtils.js
|
getUniqueIdentifierName
|
function getUniqueIdentifierName(scopes, prefix, num) {
if (!scopes) {
return prefix;
}
var props = scopes.reduce(function(props, scope) {
return _.union(props, _.keys(scope.props));
}, []);
if (!props) {
return prefix;
}
num = num || "1";
var name;
while (num < 100) { // limit search length
name = prefix + num;
if (props.indexOf(name) === -1) {
break;
}
++num;
}
return name;
}
|
javascript
|
function getUniqueIdentifierName(scopes, prefix, num) {
if (!scopes) {
return prefix;
}
var props = scopes.reduce(function(props, scope) {
return _.union(props, _.keys(scope.props));
}, []);
if (!props) {
return prefix;
}
num = num || "1";
var name;
while (num < 100) { // limit search length
name = prefix + num;
if (props.indexOf(name) === -1) {
break;
}
++num;
}
return name;
}
|
[
"function",
"getUniqueIdentifierName",
"(",
"scopes",
",",
"prefix",
",",
"num",
")",
"{",
"if",
"(",
"!",
"scopes",
")",
"{",
"return",
"prefix",
";",
"}",
"var",
"props",
"=",
"scopes",
".",
"reduce",
"(",
"function",
"(",
"props",
",",
"scope",
")",
"{",
"return",
"_",
".",
"union",
"(",
"props",
",",
"_",
".",
"keys",
"(",
"scope",
".",
"props",
")",
")",
";",
"}",
",",
"[",
"]",
")",
";",
"if",
"(",
"!",
"props",
")",
"{",
"return",
"prefix",
";",
"}",
"num",
"=",
"num",
"||",
"\"1\"",
";",
"var",
"name",
";",
"while",
"(",
"num",
"<",
"100",
")",
"{",
"name",
"=",
"prefix",
"+",
"num",
";",
"if",
"(",
"props",
".",
"indexOf",
"(",
"name",
")",
"===",
"-",
"1",
")",
"{",
"break",
";",
"}",
"++",
"num",
";",
"}",
"return",
"name",
";",
"}"
] |
Gets a unique identifier name in the scope that starts with prefix
@param {!Scope} scopes - an array of all scopes returned from tern (each element contains 'props' with identifiers
in that scope)
@param {!string} prefix - prefix of the identifier
@param {number} num - number to start checking for
@return {!string} identifier name
|
[
"Gets",
"a",
"unique",
"identifier",
"name",
"in",
"the",
"scope",
"that",
"starts",
"with",
"prefix"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptRefactoring/RefactoringUtils.js#L148-L171
|
train
|
adobe/brackets
|
src/extensions/default/JavaScriptRefactoring/RefactoringUtils.js
|
isStandAloneExpression
|
function isStandAloneExpression(text) {
var found = ASTWalker.findNodeAt(getAST(text), 0, text.length, function (nodeType, node) {
if (nodeType === "Expression") {
return true;
}
return false;
});
return found && found.node;
}
|
javascript
|
function isStandAloneExpression(text) {
var found = ASTWalker.findNodeAt(getAST(text), 0, text.length, function (nodeType, node) {
if (nodeType === "Expression") {
return true;
}
return false;
});
return found && found.node;
}
|
[
"function",
"isStandAloneExpression",
"(",
"text",
")",
"{",
"var",
"found",
"=",
"ASTWalker",
".",
"findNodeAt",
"(",
"getAST",
"(",
"text",
")",
",",
"0",
",",
"text",
".",
"length",
",",
"function",
"(",
"nodeType",
",",
"node",
")",
"{",
"if",
"(",
"nodeType",
"===",
"\"Expression\"",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
")",
";",
"return",
"found",
"&&",
"found",
".",
"node",
";",
"}"
] |
Checks whether the text forms a stand alone expression without considering the context of text
@param {!string} text
@return {boolean}
|
[
"Checks",
"whether",
"the",
"text",
"forms",
"a",
"stand",
"alone",
"expression",
"without",
"considering",
"the",
"context",
"of",
"text"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptRefactoring/RefactoringUtils.js#L187-L195
|
train
|
adobe/brackets
|
src/extensions/default/JavaScriptRefactoring/RefactoringUtils.js
|
getScopeData
|
function getScopeData(session, offset) {
var path = session.path,
fileInfo = {
type: MessageIds.TERN_FILE_INFO_TYPE_FULL,
name: path,
offsetLines: 0,
text: ScopeManager.filterText(session.getJavascriptText())
};
ScopeManager.postMessage({
type: MessageIds.TERN_SCOPEDATA_MSG,
fileInfo: fileInfo,
offset: offset
});
var ternPromise = ScopeManager.addPendingRequest(fileInfo.name, offset, MessageIds.TERN_SCOPEDATA_MSG);
var result = new $.Deferred();
ternPromise.done(function (response) {
result.resolveWith(null, [response.scope]);
}).fail(function () {
result.reject();
});
return result;
}
|
javascript
|
function getScopeData(session, offset) {
var path = session.path,
fileInfo = {
type: MessageIds.TERN_FILE_INFO_TYPE_FULL,
name: path,
offsetLines: 0,
text: ScopeManager.filterText(session.getJavascriptText())
};
ScopeManager.postMessage({
type: MessageIds.TERN_SCOPEDATA_MSG,
fileInfo: fileInfo,
offset: offset
});
var ternPromise = ScopeManager.addPendingRequest(fileInfo.name, offset, MessageIds.TERN_SCOPEDATA_MSG);
var result = new $.Deferred();
ternPromise.done(function (response) {
result.resolveWith(null, [response.scope]);
}).fail(function () {
result.reject();
});
return result;
}
|
[
"function",
"getScopeData",
"(",
"session",
",",
"offset",
")",
"{",
"var",
"path",
"=",
"session",
".",
"path",
",",
"fileInfo",
"=",
"{",
"type",
":",
"MessageIds",
".",
"TERN_FILE_INFO_TYPE_FULL",
",",
"name",
":",
"path",
",",
"offsetLines",
":",
"0",
",",
"text",
":",
"ScopeManager",
".",
"filterText",
"(",
"session",
".",
"getJavascriptText",
"(",
")",
")",
"}",
";",
"ScopeManager",
".",
"postMessage",
"(",
"{",
"type",
":",
"MessageIds",
".",
"TERN_SCOPEDATA_MSG",
",",
"fileInfo",
":",
"fileInfo",
",",
"offset",
":",
"offset",
"}",
")",
";",
"var",
"ternPromise",
"=",
"ScopeManager",
".",
"addPendingRequest",
"(",
"fileInfo",
".",
"name",
",",
"offset",
",",
"MessageIds",
".",
"TERN_SCOPEDATA_MSG",
")",
";",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"ternPromise",
".",
"done",
"(",
"function",
"(",
"response",
")",
"{",
"result",
".",
"resolveWith",
"(",
"null",
",",
"[",
"response",
".",
"scope",
"]",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"return",
"result",
";",
"}"
] |
Requests scope data from tern
@param {!Session} session
@param {!{line: number, ch: number}} offset
@return {!$.Promise} a jQuery promise that will be resolved with the scope data
|
[
"Requests",
"scope",
"data",
"from",
"tern"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptRefactoring/RefactoringUtils.js#L203-L229
|
train
|
adobe/brackets
|
src/extensions/default/JavaScriptRefactoring/RefactoringUtils.js
|
normalizeText
|
function normalizeText(text, start, end, removeTrailingSemiColons) {
var trimmedText;
// Remove leading spaces
trimmedText = _.trimLeft(text);
if (trimmedText.length < text.length) {
start += (text.length - trimmedText.length);
}
text = trimmedText;
// Remove trailing spaces
trimmedText = _.trimRight(text);
if (trimmedText.length < text.length) {
end -= (text.length - trimmedText.length);
}
text = trimmedText;
// Remove trailing semicolons
if (removeTrailingSemiColons) {
trimmedText = _.trimRight(text, ';');
if (trimmedText.length < text.length) {
end -= (text.length - trimmedText.length);
}
}
return {
text: trimmedText,
start: start,
end: end
};
}
|
javascript
|
function normalizeText(text, start, end, removeTrailingSemiColons) {
var trimmedText;
// Remove leading spaces
trimmedText = _.trimLeft(text);
if (trimmedText.length < text.length) {
start += (text.length - trimmedText.length);
}
text = trimmedText;
// Remove trailing spaces
trimmedText = _.trimRight(text);
if (trimmedText.length < text.length) {
end -= (text.length - trimmedText.length);
}
text = trimmedText;
// Remove trailing semicolons
if (removeTrailingSemiColons) {
trimmedText = _.trimRight(text, ';');
if (trimmedText.length < text.length) {
end -= (text.length - trimmedText.length);
}
}
return {
text: trimmedText,
start: start,
end: end
};
}
|
[
"function",
"normalizeText",
"(",
"text",
",",
"start",
",",
"end",
",",
"removeTrailingSemiColons",
")",
"{",
"var",
"trimmedText",
";",
"trimmedText",
"=",
"_",
".",
"trimLeft",
"(",
"text",
")",
";",
"if",
"(",
"trimmedText",
".",
"length",
"<",
"text",
".",
"length",
")",
"{",
"start",
"+=",
"(",
"text",
".",
"length",
"-",
"trimmedText",
".",
"length",
")",
";",
"}",
"text",
"=",
"trimmedText",
";",
"trimmedText",
"=",
"_",
".",
"trimRight",
"(",
"text",
")",
";",
"if",
"(",
"trimmedText",
".",
"length",
"<",
"text",
".",
"length",
")",
"{",
"end",
"-=",
"(",
"text",
".",
"length",
"-",
"trimmedText",
".",
"length",
")",
";",
"}",
"text",
"=",
"trimmedText",
";",
"if",
"(",
"removeTrailingSemiColons",
")",
"{",
"trimmedText",
"=",
"_",
".",
"trimRight",
"(",
"text",
",",
"';'",
")",
";",
"if",
"(",
"trimmedText",
".",
"length",
"<",
"text",
".",
"length",
")",
"{",
"end",
"-=",
"(",
"text",
".",
"length",
"-",
"trimmedText",
".",
"length",
")",
";",
"}",
"}",
"return",
"{",
"text",
":",
"trimmedText",
",",
"start",
":",
"start",
",",
"end",
":",
"end",
"}",
";",
"}"
] |
Normalize text by removing leading and trailing whitespace characters
and moves the start and end offset to reflect the new offset
@param {!string} text - selected text
@param {!number} start - the start offset of the text
@param {!number} end - the end offset of the text
@param {!boolean} removeTrailingSemiColons - removes trailing semicolons also if true
@return {!{text: string, start: number, end: number}}
|
[
"Normalize",
"text",
"by",
"removing",
"leading",
"and",
"trailing",
"whitespace",
"characters",
"and",
"moves",
"the",
"start",
"and",
"end",
"offset",
"to",
"reflect",
"the",
"new",
"offset"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptRefactoring/RefactoringUtils.js#L240-L275
|
train
|
adobe/brackets
|
src/extensions/default/JavaScriptRefactoring/RefactoringUtils.js
|
findSurroundASTNode
|
function findSurroundASTNode(ast, expn, types) {
var foundNode = ASTWalker.findNodeAround(ast, expn.start, function (nodeType, node) {
if (expn.end) {
return types.includes(nodeType) && node.end >= expn.end;
} else {
return types.includes(nodeType);
}
});
return foundNode && _.clone(foundNode.node);
}
|
javascript
|
function findSurroundASTNode(ast, expn, types) {
var foundNode = ASTWalker.findNodeAround(ast, expn.start, function (nodeType, node) {
if (expn.end) {
return types.includes(nodeType) && node.end >= expn.end;
} else {
return types.includes(nodeType);
}
});
return foundNode && _.clone(foundNode.node);
}
|
[
"function",
"findSurroundASTNode",
"(",
"ast",
",",
"expn",
",",
"types",
")",
"{",
"var",
"foundNode",
"=",
"ASTWalker",
".",
"findNodeAround",
"(",
"ast",
",",
"expn",
".",
"start",
",",
"function",
"(",
"nodeType",
",",
"node",
")",
"{",
"if",
"(",
"expn",
".",
"end",
")",
"{",
"return",
"types",
".",
"includes",
"(",
"nodeType",
")",
"&&",
"node",
".",
"end",
">=",
"expn",
".",
"end",
";",
"}",
"else",
"{",
"return",
"types",
".",
"includes",
"(",
"nodeType",
")",
";",
"}",
"}",
")",
";",
"return",
"foundNode",
"&&",
"_",
".",
"clone",
"(",
"foundNode",
".",
"node",
")",
";",
"}"
] |
Finds the surrounding ast node of the given expression of any of the given types
@param {!ASTNode} ast
@param {!{start: number, end: number}} expn - contains start and end offsets of expn
@param {!Array.<string>} types
@return {?ASTNode}
|
[
"Finds",
"the",
"surrounding",
"ast",
"node",
"of",
"the",
"given",
"expression",
"of",
"any",
"of",
"the",
"given",
"types"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptRefactoring/RefactoringUtils.js#L322-L331
|
train
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/transports/remote/NodeSocketTransportRemote.js
|
function (url) {
var self = this;
this._ws = new WebSocket(url);
// One potential source of confusion: the transport sends two "types" of messages -
// these are distinct from the protocol's own messages. This is because this transport
// needs to send an initial "connect" message telling the Brackets side of the transport
// the URL of the page that it's connecting from, distinct from the actual protocol
// message traffic. Actual protocol messages are sent as a JSON payload in a message of
// type "message".
//
// Other transports might not need to do this - for example, a transport that simply
// talks to an iframe within the same process already knows what URL that iframe is
// pointing to, so the only comunication that needs to happen via postMessage() is the
// actual protocol message strings, and no extra wrapping is necessary.
this._ws.onopen = function (event) {
// Send the initial "connect" message to tell the other end what URL we're from.
self._ws.send(JSON.stringify({
type: "connect",
url: global.location.href
}));
console.log("[Brackets LiveDev] Connected to Brackets at " + url);
if (self._callbacks && self._callbacks.connect) {
self._callbacks.connect();
}
};
this._ws.onmessage = function (event) {
console.log("[Brackets LiveDev] Got message: " + event.data);
if (self._callbacks && self._callbacks.message) {
self._callbacks.message(event.data);
}
};
this._ws.onclose = function (event) {
self._ws = null;
if (self._callbacks && self._callbacks.close) {
self._callbacks.close();
}
};
// TODO: onerror
}
|
javascript
|
function (url) {
var self = this;
this._ws = new WebSocket(url);
// One potential source of confusion: the transport sends two "types" of messages -
// these are distinct from the protocol's own messages. This is because this transport
// needs to send an initial "connect" message telling the Brackets side of the transport
// the URL of the page that it's connecting from, distinct from the actual protocol
// message traffic. Actual protocol messages are sent as a JSON payload in a message of
// type "message".
//
// Other transports might not need to do this - for example, a transport that simply
// talks to an iframe within the same process already knows what URL that iframe is
// pointing to, so the only comunication that needs to happen via postMessage() is the
// actual protocol message strings, and no extra wrapping is necessary.
this._ws.onopen = function (event) {
// Send the initial "connect" message to tell the other end what URL we're from.
self._ws.send(JSON.stringify({
type: "connect",
url: global.location.href
}));
console.log("[Brackets LiveDev] Connected to Brackets at " + url);
if (self._callbacks && self._callbacks.connect) {
self._callbacks.connect();
}
};
this._ws.onmessage = function (event) {
console.log("[Brackets LiveDev] Got message: " + event.data);
if (self._callbacks && self._callbacks.message) {
self._callbacks.message(event.data);
}
};
this._ws.onclose = function (event) {
self._ws = null;
if (self._callbacks && self._callbacks.close) {
self._callbacks.close();
}
};
// TODO: onerror
}
|
[
"function",
"(",
"url",
")",
"{",
"var",
"self",
"=",
"this",
";",
"this",
".",
"_ws",
"=",
"new",
"WebSocket",
"(",
"url",
")",
";",
"this",
".",
"_ws",
".",
"onopen",
"=",
"function",
"(",
"event",
")",
"{",
"self",
".",
"_ws",
".",
"send",
"(",
"JSON",
".",
"stringify",
"(",
"{",
"type",
":",
"\"connect\"",
",",
"url",
":",
"global",
".",
"location",
".",
"href",
"}",
")",
")",
";",
"console",
".",
"log",
"(",
"\"[Brackets LiveDev] Connected to Brackets at \"",
"+",
"url",
")",
";",
"if",
"(",
"self",
".",
"_callbacks",
"&&",
"self",
".",
"_callbacks",
".",
"connect",
")",
"{",
"self",
".",
"_callbacks",
".",
"connect",
"(",
")",
";",
"}",
"}",
";",
"this",
".",
"_ws",
".",
"onmessage",
"=",
"function",
"(",
"event",
")",
"{",
"console",
".",
"log",
"(",
"\"[Brackets LiveDev] Got message: \"",
"+",
"event",
".",
"data",
")",
";",
"if",
"(",
"self",
".",
"_callbacks",
"&&",
"self",
".",
"_callbacks",
".",
"message",
")",
"{",
"self",
".",
"_callbacks",
".",
"message",
"(",
"event",
".",
"data",
")",
";",
"}",
"}",
";",
"this",
".",
"_ws",
".",
"onclose",
"=",
"function",
"(",
"event",
")",
"{",
"self",
".",
"_ws",
"=",
"null",
";",
"if",
"(",
"self",
".",
"_callbacks",
"&&",
"self",
".",
"_callbacks",
".",
"close",
")",
"{",
"self",
".",
"_callbacks",
".",
"close",
"(",
")",
";",
"}",
"}",
";",
"}"
] |
Connects to the NodeSocketTransport in Brackets at the given WebSocket URL.
@param {string} url
|
[
"Connects",
"to",
"the",
"NodeSocketTransport",
"in",
"Brackets",
"at",
"the",
"given",
"WebSocket",
"URL",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/transports/remote/NodeSocketTransportRemote.js#L68-L108
|
train
|
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/transports/remote/NodeSocketTransportRemote.js
|
function (msgStr) {
if (this._ws) {
// See comment in `connect()` above about why we wrap the message in a transport message
// object.
this._ws.send(JSON.stringify({
type: "message",
message: msgStr
}));
} else {
console.log("[Brackets LiveDev] Tried to send message over closed connection: " + msgStr);
}
}
|
javascript
|
function (msgStr) {
if (this._ws) {
// See comment in `connect()` above about why we wrap the message in a transport message
// object.
this._ws.send(JSON.stringify({
type: "message",
message: msgStr
}));
} else {
console.log("[Brackets LiveDev] Tried to send message over closed connection: " + msgStr);
}
}
|
[
"function",
"(",
"msgStr",
")",
"{",
"if",
"(",
"this",
".",
"_ws",
")",
"{",
"this",
".",
"_ws",
".",
"send",
"(",
"JSON",
".",
"stringify",
"(",
"{",
"type",
":",
"\"message\"",
",",
"message",
":",
"msgStr",
"}",
")",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"\"[Brackets LiveDev] Tried to send message over closed connection: \"",
"+",
"msgStr",
")",
";",
"}",
"}"
] |
Sends a message over the transport.
@param {string} msgStr The message to send.
|
[
"Sends",
"a",
"message",
"over",
"the",
"transport",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/transports/remote/NodeSocketTransportRemote.js#L114-L125
|
train
|
|
adobe/brackets
|
src/extensions/default/CloseOthers/main.js
|
handleClose
|
function handleClose(mode) {
var targetIndex = MainViewManager.findInWorkingSet(MainViewManager.ACTIVE_PANE, MainViewManager.getCurrentlyViewedPath(MainViewManager.ACTIVE_PANE)),
workingSetList = MainViewManager.getWorkingSet(MainViewManager.ACTIVE_PANE),
start = (mode === closeBelow) ? (targetIndex + 1) : 0,
end = (mode === closeAbove) ? (targetIndex) : (workingSetList.length),
files = [],
i;
for (i = start; i < end; i++) {
if ((mode === closeOthers && i !== targetIndex) || (mode !== closeOthers)) {
files.push(workingSetList[i]);
}
}
CommandManager.execute(Commands.FILE_CLOSE_LIST, {fileList: files});
}
|
javascript
|
function handleClose(mode) {
var targetIndex = MainViewManager.findInWorkingSet(MainViewManager.ACTIVE_PANE, MainViewManager.getCurrentlyViewedPath(MainViewManager.ACTIVE_PANE)),
workingSetList = MainViewManager.getWorkingSet(MainViewManager.ACTIVE_PANE),
start = (mode === closeBelow) ? (targetIndex + 1) : 0,
end = (mode === closeAbove) ? (targetIndex) : (workingSetList.length),
files = [],
i;
for (i = start; i < end; i++) {
if ((mode === closeOthers && i !== targetIndex) || (mode !== closeOthers)) {
files.push(workingSetList[i]);
}
}
CommandManager.execute(Commands.FILE_CLOSE_LIST, {fileList: files});
}
|
[
"function",
"handleClose",
"(",
"mode",
")",
"{",
"var",
"targetIndex",
"=",
"MainViewManager",
".",
"findInWorkingSet",
"(",
"MainViewManager",
".",
"ACTIVE_PANE",
",",
"MainViewManager",
".",
"getCurrentlyViewedPath",
"(",
"MainViewManager",
".",
"ACTIVE_PANE",
")",
")",
",",
"workingSetList",
"=",
"MainViewManager",
".",
"getWorkingSet",
"(",
"MainViewManager",
".",
"ACTIVE_PANE",
")",
",",
"start",
"=",
"(",
"mode",
"===",
"closeBelow",
")",
"?",
"(",
"targetIndex",
"+",
"1",
")",
":",
"0",
",",
"end",
"=",
"(",
"mode",
"===",
"closeAbove",
")",
"?",
"(",
"targetIndex",
")",
":",
"(",
"workingSetList",
".",
"length",
")",
",",
"files",
"=",
"[",
"]",
",",
"i",
";",
"for",
"(",
"i",
"=",
"start",
";",
"i",
"<",
"end",
";",
"i",
"++",
")",
"{",
"if",
"(",
"(",
"mode",
"===",
"closeOthers",
"&&",
"i",
"!==",
"targetIndex",
")",
"||",
"(",
"mode",
"!==",
"closeOthers",
")",
")",
"{",
"files",
".",
"push",
"(",
"workingSetList",
"[",
"i",
"]",
")",
";",
"}",
"}",
"CommandManager",
".",
"execute",
"(",
"Commands",
".",
"FILE_CLOSE_LIST",
",",
"{",
"fileList",
":",
"files",
"}",
")",
";",
"}"
] |
Handle the different Close Other commands
@param {string} mode
|
[
"Handle",
"the",
"different",
"Close",
"Other",
"commands"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CloseOthers/main.js#L59-L74
|
train
|
adobe/brackets
|
src/extensions/default/CloseOthers/main.js
|
initializeCommands
|
function initializeCommands() {
var prefs = getPreferences();
CommandManager.register(Strings.CMD_FILE_CLOSE_BELOW, closeBelow, function () {
handleClose(closeBelow);
});
CommandManager.register(Strings.CMD_FILE_CLOSE_OTHERS, closeOthers, function () {
handleClose(closeOthers);
});
CommandManager.register(Strings.CMD_FILE_CLOSE_ABOVE, closeAbove, function () {
handleClose(closeAbove);
});
if (prefs.closeBelow) {
workingSetListCmenu.addMenuItem(closeBelow, "", Menus.AFTER, Commands.FILE_CLOSE);
}
if (prefs.closeOthers) {
workingSetListCmenu.addMenuItem(closeOthers, "", Menus.AFTER, Commands.FILE_CLOSE);
}
if (prefs.closeAbove) {
workingSetListCmenu.addMenuItem(closeAbove, "", Menus.AFTER, Commands.FILE_CLOSE);
}
menuEntriesShown = prefs;
}
|
javascript
|
function initializeCommands() {
var prefs = getPreferences();
CommandManager.register(Strings.CMD_FILE_CLOSE_BELOW, closeBelow, function () {
handleClose(closeBelow);
});
CommandManager.register(Strings.CMD_FILE_CLOSE_OTHERS, closeOthers, function () {
handleClose(closeOthers);
});
CommandManager.register(Strings.CMD_FILE_CLOSE_ABOVE, closeAbove, function () {
handleClose(closeAbove);
});
if (prefs.closeBelow) {
workingSetListCmenu.addMenuItem(closeBelow, "", Menus.AFTER, Commands.FILE_CLOSE);
}
if (prefs.closeOthers) {
workingSetListCmenu.addMenuItem(closeOthers, "", Menus.AFTER, Commands.FILE_CLOSE);
}
if (prefs.closeAbove) {
workingSetListCmenu.addMenuItem(closeAbove, "", Menus.AFTER, Commands.FILE_CLOSE);
}
menuEntriesShown = prefs;
}
|
[
"function",
"initializeCommands",
"(",
")",
"{",
"var",
"prefs",
"=",
"getPreferences",
"(",
")",
";",
"CommandManager",
".",
"register",
"(",
"Strings",
".",
"CMD_FILE_CLOSE_BELOW",
",",
"closeBelow",
",",
"function",
"(",
")",
"{",
"handleClose",
"(",
"closeBelow",
")",
";",
"}",
")",
";",
"CommandManager",
".",
"register",
"(",
"Strings",
".",
"CMD_FILE_CLOSE_OTHERS",
",",
"closeOthers",
",",
"function",
"(",
")",
"{",
"handleClose",
"(",
"closeOthers",
")",
";",
"}",
")",
";",
"CommandManager",
".",
"register",
"(",
"Strings",
".",
"CMD_FILE_CLOSE_ABOVE",
",",
"closeAbove",
",",
"function",
"(",
")",
"{",
"handleClose",
"(",
"closeAbove",
")",
";",
"}",
")",
";",
"if",
"(",
"prefs",
".",
"closeBelow",
")",
"{",
"workingSetListCmenu",
".",
"addMenuItem",
"(",
"closeBelow",
",",
"\"\"",
",",
"Menus",
".",
"AFTER",
",",
"Commands",
".",
"FILE_CLOSE",
")",
";",
"}",
"if",
"(",
"prefs",
".",
"closeOthers",
")",
"{",
"workingSetListCmenu",
".",
"addMenuItem",
"(",
"closeOthers",
",",
"\"\"",
",",
"Menus",
".",
"AFTER",
",",
"Commands",
".",
"FILE_CLOSE",
")",
";",
"}",
"if",
"(",
"prefs",
".",
"closeAbove",
")",
"{",
"workingSetListCmenu",
".",
"addMenuItem",
"(",
"closeAbove",
",",
"\"\"",
",",
"Menus",
".",
"AFTER",
",",
"Commands",
".",
"FILE_CLOSE",
")",
";",
"}",
"menuEntriesShown",
"=",
"prefs",
";",
"}"
] |
Register the Commands and add the Menu Items, if required
|
[
"Register",
"the",
"Commands",
"and",
"add",
"the",
"Menu",
"Items",
"if",
"required"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CloseOthers/main.js#L157-L180
|
train
|
adobe/brackets
|
src/view/Pane.js
|
_ensurePaneIsFocused
|
function _ensurePaneIsFocused(paneId) {
var pane = MainViewManager._getPane(paneId);
// Defer the focusing until other focus events have occurred.
setTimeout(function () {
// Focus has most likely changed: give it back to the given pane.
pane.focus();
this._lastFocusedElement = pane.$el[0];
MainViewManager.setActivePaneId(paneId);
}, 1);
}
|
javascript
|
function _ensurePaneIsFocused(paneId) {
var pane = MainViewManager._getPane(paneId);
// Defer the focusing until other focus events have occurred.
setTimeout(function () {
// Focus has most likely changed: give it back to the given pane.
pane.focus();
this._lastFocusedElement = pane.$el[0];
MainViewManager.setActivePaneId(paneId);
}, 1);
}
|
[
"function",
"_ensurePaneIsFocused",
"(",
"paneId",
")",
"{",
"var",
"pane",
"=",
"MainViewManager",
".",
"_getPane",
"(",
"paneId",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"pane",
".",
"focus",
"(",
")",
";",
"this",
".",
"_lastFocusedElement",
"=",
"pane",
".",
"$el",
"[",
"0",
"]",
";",
"MainViewManager",
".",
"setActivePaneId",
"(",
"paneId",
")",
";",
"}",
",",
"1",
")",
";",
"}"
] |
Ensures that the given pane is focused after other focus related events occur
@params {string} paneId - paneId of the pane to focus
@private
|
[
"Ensures",
"that",
"the",
"given",
"pane",
"is",
"focused",
"after",
"other",
"focus",
"related",
"events",
"occur"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/Pane.js#L216-L226
|
train
|
adobe/brackets
|
src/view/Pane.js
|
tryFocusingCurrentView
|
function tryFocusingCurrentView() {
if (self._currentView) {
if (self._currentView.focus) {
// Views can implement a focus
// method for focusing a complex
// DOM like codemirror
self._currentView.focus();
} else {
// Otherwise, no focus method
// just try and give the DOM
// element focus
self._currentView.$el.focus();
}
} else {
// no view so just focus the pane
self.$el.focus();
}
}
|
javascript
|
function tryFocusingCurrentView() {
if (self._currentView) {
if (self._currentView.focus) {
// Views can implement a focus
// method for focusing a complex
// DOM like codemirror
self._currentView.focus();
} else {
// Otherwise, no focus method
// just try and give the DOM
// element focus
self._currentView.$el.focus();
}
} else {
// no view so just focus the pane
self.$el.focus();
}
}
|
[
"function",
"tryFocusingCurrentView",
"(",
")",
"{",
"if",
"(",
"self",
".",
"_currentView",
")",
"{",
"if",
"(",
"self",
".",
"_currentView",
".",
"focus",
")",
"{",
"self",
".",
"_currentView",
".",
"focus",
"(",
")",
";",
"}",
"else",
"{",
"self",
".",
"_currentView",
".",
"$el",
".",
"focus",
"(",
")",
";",
"}",
"}",
"else",
"{",
"self",
".",
"$el",
".",
"focus",
"(",
")",
";",
"}",
"}"
] |
Helper to focus the current view if it can
|
[
"Helper",
"to",
"focus",
"the",
"current",
"view",
"if",
"it",
"can"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/Pane.js#L1428-L1445
|
train
|
adobe/brackets
|
src/editor/CodeHintManager.js
|
registerHintProvider
|
function registerHintProvider(providerInfo, languageIds, priority) {
var providerObj = { provider: providerInfo,
priority: priority || 0 };
if (languageIds.indexOf("all") !== -1) {
// Ignore anything else in languageIds and just register for every language. This includes
// the special "all" language since its key is in the hintProviders map from the beginning.
var languageId;
for (languageId in hintProviders) {
if (hintProviders.hasOwnProperty(languageId)) {
hintProviders[languageId].push(providerObj);
hintProviders[languageId].sort(_providerSort);
}
}
} else {
languageIds.forEach(function (languageId) {
if (!hintProviders[languageId]) {
// Initialize provider list with any existing all-language providers
hintProviders[languageId] = Array.prototype.concat(hintProviders.all);
}
hintProviders[languageId].push(providerObj);
hintProviders[languageId].sort(_providerSort);
});
}
}
|
javascript
|
function registerHintProvider(providerInfo, languageIds, priority) {
var providerObj = { provider: providerInfo,
priority: priority || 0 };
if (languageIds.indexOf("all") !== -1) {
// Ignore anything else in languageIds and just register for every language. This includes
// the special "all" language since its key is in the hintProviders map from the beginning.
var languageId;
for (languageId in hintProviders) {
if (hintProviders.hasOwnProperty(languageId)) {
hintProviders[languageId].push(providerObj);
hintProviders[languageId].sort(_providerSort);
}
}
} else {
languageIds.forEach(function (languageId) {
if (!hintProviders[languageId]) {
// Initialize provider list with any existing all-language providers
hintProviders[languageId] = Array.prototype.concat(hintProviders.all);
}
hintProviders[languageId].push(providerObj);
hintProviders[languageId].sort(_providerSort);
});
}
}
|
[
"function",
"registerHintProvider",
"(",
"providerInfo",
",",
"languageIds",
",",
"priority",
")",
"{",
"var",
"providerObj",
"=",
"{",
"provider",
":",
"providerInfo",
",",
"priority",
":",
"priority",
"||",
"0",
"}",
";",
"if",
"(",
"languageIds",
".",
"indexOf",
"(",
"\"all\"",
")",
"!==",
"-",
"1",
")",
"{",
"var",
"languageId",
";",
"for",
"(",
"languageId",
"in",
"hintProviders",
")",
"{",
"if",
"(",
"hintProviders",
".",
"hasOwnProperty",
"(",
"languageId",
")",
")",
"{",
"hintProviders",
"[",
"languageId",
"]",
".",
"push",
"(",
"providerObj",
")",
";",
"hintProviders",
"[",
"languageId",
"]",
".",
"sort",
"(",
"_providerSort",
")",
";",
"}",
"}",
"}",
"else",
"{",
"languageIds",
".",
"forEach",
"(",
"function",
"(",
"languageId",
")",
"{",
"if",
"(",
"!",
"hintProviders",
"[",
"languageId",
"]",
")",
"{",
"hintProviders",
"[",
"languageId",
"]",
"=",
"Array",
".",
"prototype",
".",
"concat",
"(",
"hintProviders",
".",
"all",
")",
";",
"}",
"hintProviders",
"[",
"languageId",
"]",
".",
"push",
"(",
"providerObj",
")",
";",
"hintProviders",
"[",
"languageId",
"]",
".",
"sort",
"(",
"_providerSort",
")",
";",
"}",
")",
";",
"}",
"}"
] |
The method by which a CodeHintProvider registers its willingness to
providing hints for editors in a given language.
@param {!CodeHintProvider} provider
The hint provider to be registered, described below.
@param {!Array.<string>} languageIds
The set of language ids for which the provider is capable of
providing hints. If the special language id name "all" is included then
the provider may be called for any language.
@param {?number} priority
Used to break ties among hint providers for a particular language.
Providers with a higher number will be asked for hints before those
with a lower priority value. Defaults to zero.
|
[
"The",
"method",
"by",
"which",
"a",
"CodeHintProvider",
"registers",
"its",
"willingness",
"to",
"providing",
"hints",
"for",
"editors",
"in",
"a",
"given",
"language",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/CodeHintManager.js#L290-L314
|
train
|
adobe/brackets
|
src/editor/CodeHintManager.js
|
_endSession
|
function _endSession() {
if (!hintList) {
return;
}
hintList.close();
hintList = null;
codeHintOpened = false;
keyDownEditor = null;
sessionProvider = null;
sessionEditor = null;
if (deferredHints) {
deferredHints.reject();
deferredHints = null;
}
}
|
javascript
|
function _endSession() {
if (!hintList) {
return;
}
hintList.close();
hintList = null;
codeHintOpened = false;
keyDownEditor = null;
sessionProvider = null;
sessionEditor = null;
if (deferredHints) {
deferredHints.reject();
deferredHints = null;
}
}
|
[
"function",
"_endSession",
"(",
")",
"{",
"if",
"(",
"!",
"hintList",
")",
"{",
"return",
";",
"}",
"hintList",
".",
"close",
"(",
")",
";",
"hintList",
"=",
"null",
";",
"codeHintOpened",
"=",
"false",
";",
"keyDownEditor",
"=",
"null",
";",
"sessionProvider",
"=",
"null",
";",
"sessionEditor",
"=",
"null",
";",
"if",
"(",
"deferredHints",
")",
"{",
"deferredHints",
".",
"reject",
"(",
")",
";",
"deferredHints",
"=",
"null",
";",
"}",
"}"
] |
End the current hinting session
|
[
"End",
"the",
"current",
"hinting",
"session"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/CodeHintManager.js#L373-L387
|
train
|
adobe/brackets
|
src/editor/CodeHintManager.js
|
_inSession
|
function _inSession(editor) {
if (sessionEditor) {
if (sessionEditor === editor &&
(hintList.isOpen() ||
(deferredHints && deferredHints.state() === "pending"))) {
return true;
} else {
// the editor has changed
_endSession();
}
}
return false;
}
|
javascript
|
function _inSession(editor) {
if (sessionEditor) {
if (sessionEditor === editor &&
(hintList.isOpen() ||
(deferredHints && deferredHints.state() === "pending"))) {
return true;
} else {
// the editor has changed
_endSession();
}
}
return false;
}
|
[
"function",
"_inSession",
"(",
"editor",
")",
"{",
"if",
"(",
"sessionEditor",
")",
"{",
"if",
"(",
"sessionEditor",
"===",
"editor",
"&&",
"(",
"hintList",
".",
"isOpen",
"(",
")",
"||",
"(",
"deferredHints",
"&&",
"deferredHints",
".",
"state",
"(",
")",
"===",
"\"pending\"",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"_endSession",
"(",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Is there a hinting session active for a given editor?
NOTE: the sessionEditor, sessionProvider and hintList objects are
only guaranteed to be initialized during an active session.
@param {Editor} editor
@return boolean
|
[
"Is",
"there",
"a",
"hinting",
"session",
"active",
"for",
"a",
"given",
"editor?"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/CodeHintManager.js#L398-L410
|
train
|
adobe/brackets
|
src/editor/CodeHintManager.js
|
_updateHintList
|
function _updateHintList(callMoveUpEvent) {
callMoveUpEvent = typeof callMoveUpEvent === "undefined" ? false : callMoveUpEvent;
if (deferredHints) {
deferredHints.reject();
deferredHints = null;
}
if (callMoveUpEvent) {
return hintList.callMoveUp(callMoveUpEvent);
}
var response = sessionProvider.getHints(lastChar);
lastChar = null;
if (!response) {
// the provider wishes to close the session
_endSession();
} else {
// if the response is true, end the session and begin another
if (response === true) {
var previousEditor = sessionEditor;
_endSession();
_beginSession(previousEditor);
} else if (response.hasOwnProperty("hints")) { // a synchronous response
if (hintList.isOpen()) {
// the session is open
hintList.update(response);
} else {
hintList.open(response);
}
} else { // response is a deferred
deferredHints = response;
response.done(function (hints) {
// Guard against timing issues where the session ends before the
// response gets a chance to execute the callback. If the session
// ends first while still waiting on the response, then hintList
// will get cleared up.
if (!hintList) {
return;
}
if (hintList.isOpen()) {
// the session is open
hintList.update(hints);
} else {
hintList.open(hints);
}
});
}
}
}
|
javascript
|
function _updateHintList(callMoveUpEvent) {
callMoveUpEvent = typeof callMoveUpEvent === "undefined" ? false : callMoveUpEvent;
if (deferredHints) {
deferredHints.reject();
deferredHints = null;
}
if (callMoveUpEvent) {
return hintList.callMoveUp(callMoveUpEvent);
}
var response = sessionProvider.getHints(lastChar);
lastChar = null;
if (!response) {
// the provider wishes to close the session
_endSession();
} else {
// if the response is true, end the session and begin another
if (response === true) {
var previousEditor = sessionEditor;
_endSession();
_beginSession(previousEditor);
} else if (response.hasOwnProperty("hints")) { // a synchronous response
if (hintList.isOpen()) {
// the session is open
hintList.update(response);
} else {
hintList.open(response);
}
} else { // response is a deferred
deferredHints = response;
response.done(function (hints) {
// Guard against timing issues where the session ends before the
// response gets a chance to execute the callback. If the session
// ends first while still waiting on the response, then hintList
// will get cleared up.
if (!hintList) {
return;
}
if (hintList.isOpen()) {
// the session is open
hintList.update(hints);
} else {
hintList.open(hints);
}
});
}
}
}
|
[
"function",
"_updateHintList",
"(",
"callMoveUpEvent",
")",
"{",
"callMoveUpEvent",
"=",
"typeof",
"callMoveUpEvent",
"===",
"\"undefined\"",
"?",
"false",
":",
"callMoveUpEvent",
";",
"if",
"(",
"deferredHints",
")",
"{",
"deferredHints",
".",
"reject",
"(",
")",
";",
"deferredHints",
"=",
"null",
";",
"}",
"if",
"(",
"callMoveUpEvent",
")",
"{",
"return",
"hintList",
".",
"callMoveUp",
"(",
"callMoveUpEvent",
")",
";",
"}",
"var",
"response",
"=",
"sessionProvider",
".",
"getHints",
"(",
"lastChar",
")",
";",
"lastChar",
"=",
"null",
";",
"if",
"(",
"!",
"response",
")",
"{",
"_endSession",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"response",
"===",
"true",
")",
"{",
"var",
"previousEditor",
"=",
"sessionEditor",
";",
"_endSession",
"(",
")",
";",
"_beginSession",
"(",
"previousEditor",
")",
";",
"}",
"else",
"if",
"(",
"response",
".",
"hasOwnProperty",
"(",
"\"hints\"",
")",
")",
"{",
"if",
"(",
"hintList",
".",
"isOpen",
"(",
")",
")",
"{",
"hintList",
".",
"update",
"(",
"response",
")",
";",
"}",
"else",
"{",
"hintList",
".",
"open",
"(",
"response",
")",
";",
"}",
"}",
"else",
"{",
"deferredHints",
"=",
"response",
";",
"response",
".",
"done",
"(",
"function",
"(",
"hints",
")",
"{",
"if",
"(",
"!",
"hintList",
")",
"{",
"return",
";",
"}",
"if",
"(",
"hintList",
".",
"isOpen",
"(",
")",
")",
"{",
"hintList",
".",
"update",
"(",
"hints",
")",
";",
"}",
"else",
"{",
"hintList",
".",
"open",
"(",
"hints",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
"}"
] |
From an active hinting session, get hints from the current provider and
render the hint list window.
Assumes that it is called when a session is active (i.e. sessionProvider is not null).
|
[
"From",
"an",
"active",
"hinting",
"session",
"get",
"hints",
"from",
"the",
"current",
"provider",
"and",
"render",
"the",
"hint",
"list",
"window",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/CodeHintManager.js#L417-L470
|
train
|
adobe/brackets
|
src/editor/CodeHintManager.js
|
_handleKeydownEvent
|
function _handleKeydownEvent(jqEvent, editor, event) {
keyDownEditor = editor;
if (!(event.ctrlKey || event.altKey || event.metaKey) &&
(event.keyCode === KeyEvent.DOM_VK_ENTER ||
event.keyCode === KeyEvent.DOM_VK_RETURN ||
event.keyCode === KeyEvent.DOM_VK_TAB)) {
lastChar = String.fromCharCode(event.keyCode);
}
}
|
javascript
|
function _handleKeydownEvent(jqEvent, editor, event) {
keyDownEditor = editor;
if (!(event.ctrlKey || event.altKey || event.metaKey) &&
(event.keyCode === KeyEvent.DOM_VK_ENTER ||
event.keyCode === KeyEvent.DOM_VK_RETURN ||
event.keyCode === KeyEvent.DOM_VK_TAB)) {
lastChar = String.fromCharCode(event.keyCode);
}
}
|
[
"function",
"_handleKeydownEvent",
"(",
"jqEvent",
",",
"editor",
",",
"event",
")",
"{",
"keyDownEditor",
"=",
"editor",
";",
"if",
"(",
"!",
"(",
"event",
".",
"ctrlKey",
"||",
"event",
".",
"altKey",
"||",
"event",
".",
"metaKey",
")",
"&&",
"(",
"event",
".",
"keyCode",
"===",
"KeyEvent",
".",
"DOM_VK_ENTER",
"||",
"event",
".",
"keyCode",
"===",
"KeyEvent",
".",
"DOM_VK_RETURN",
"||",
"event",
".",
"keyCode",
"===",
"KeyEvent",
".",
"DOM_VK_TAB",
")",
")",
"{",
"lastChar",
"=",
"String",
".",
"fromCharCode",
"(",
"event",
".",
"keyCode",
")",
";",
"}",
"}"
] |
Handles keys related to displaying, searching, and navigating the hint list.
This gets called before handleChange.
TODO: Ideally, we'd get a more semantic event from the editor that told us
what changed so that we could do all of this logic without looking at
key events. Then, the purposes of handleKeyEvent and handleChange could be
combined. Doing this well requires changing CodeMirror.
@param {Event} jqEvent
@param {Editor} editor
@param {KeyboardEvent} event
|
[
"Handles",
"keys",
"related",
"to",
"displaying",
"searching",
"and",
"navigating",
"the",
"hint",
"list",
".",
"This",
"gets",
"called",
"before",
"handleChange",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/CodeHintManager.js#L556-L564
|
train
|
adobe/brackets
|
src/editor/CodeHintManager.js
|
_startNewSession
|
function _startNewSession(editor) {
if (isOpen()) {
return;
}
if (!editor) {
editor = EditorManager.getFocusedEditor();
}
if (editor) {
lastChar = null;
if (_inSession(editor)) {
_endSession();
}
// Begin a new explicit session
_beginSession(editor);
}
}
|
javascript
|
function _startNewSession(editor) {
if (isOpen()) {
return;
}
if (!editor) {
editor = EditorManager.getFocusedEditor();
}
if (editor) {
lastChar = null;
if (_inSession(editor)) {
_endSession();
}
// Begin a new explicit session
_beginSession(editor);
}
}
|
[
"function",
"_startNewSession",
"(",
"editor",
")",
"{",
"if",
"(",
"isOpen",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"editor",
")",
"{",
"editor",
"=",
"EditorManager",
".",
"getFocusedEditor",
"(",
")",
";",
"}",
"if",
"(",
"editor",
")",
"{",
"lastChar",
"=",
"null",
";",
"if",
"(",
"_inSession",
"(",
"editor",
")",
")",
"{",
"_endSession",
"(",
")",
";",
"}",
"_beginSession",
"(",
"editor",
")",
";",
"}",
"}"
] |
Explicitly start a new session. If we have an existing session,
then close the current one and restart a new one.
@param {Editor} editor
|
[
"Explicitly",
"start",
"a",
"new",
"session",
".",
"If",
"we",
"have",
"an",
"existing",
"session",
"then",
"close",
"the",
"current",
"one",
"and",
"restart",
"a",
"new",
"one",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/CodeHintManager.js#L680-L697
|
train
|
adobe/brackets
|
src/features/JumpToDefManager.js
|
_doJumpToDef
|
function _doJumpToDef() {
var request = null,
result = new $.Deferred(),
jumpToDefProvider = null,
editor = EditorManager.getActiveEditor();
if (editor) {
// Find a suitable provider, if any
var language = editor.getLanguageForSelection(),
enabledProviders = _providerRegistrationHandler.getProvidersForLanguageId(language.getId());
enabledProviders.some(function (item, index) {
if (item.provider.canJumpToDef(editor)) {
jumpToDefProvider = item.provider;
return true;
}
});
if (jumpToDefProvider) {
request = jumpToDefProvider.doJumpToDef(editor);
if (request) {
request.done(function () {
result.resolve();
}).fail(function () {
result.reject();
});
} else {
result.reject();
}
} else {
result.reject();
}
} else {
result.reject();
}
return result.promise();
}
|
javascript
|
function _doJumpToDef() {
var request = null,
result = new $.Deferred(),
jumpToDefProvider = null,
editor = EditorManager.getActiveEditor();
if (editor) {
// Find a suitable provider, if any
var language = editor.getLanguageForSelection(),
enabledProviders = _providerRegistrationHandler.getProvidersForLanguageId(language.getId());
enabledProviders.some(function (item, index) {
if (item.provider.canJumpToDef(editor)) {
jumpToDefProvider = item.provider;
return true;
}
});
if (jumpToDefProvider) {
request = jumpToDefProvider.doJumpToDef(editor);
if (request) {
request.done(function () {
result.resolve();
}).fail(function () {
result.reject();
});
} else {
result.reject();
}
} else {
result.reject();
}
} else {
result.reject();
}
return result.promise();
}
|
[
"function",
"_doJumpToDef",
"(",
")",
"{",
"var",
"request",
"=",
"null",
",",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
",",
"jumpToDefProvider",
"=",
"null",
",",
"editor",
"=",
"EditorManager",
".",
"getActiveEditor",
"(",
")",
";",
"if",
"(",
"editor",
")",
"{",
"var",
"language",
"=",
"editor",
".",
"getLanguageForSelection",
"(",
")",
",",
"enabledProviders",
"=",
"_providerRegistrationHandler",
".",
"getProvidersForLanguageId",
"(",
"language",
".",
"getId",
"(",
")",
")",
";",
"enabledProviders",
".",
"some",
"(",
"function",
"(",
"item",
",",
"index",
")",
"{",
"if",
"(",
"item",
".",
"provider",
".",
"canJumpToDef",
"(",
"editor",
")",
")",
"{",
"jumpToDefProvider",
"=",
"item",
".",
"provider",
";",
"return",
"true",
";",
"}",
"}",
")",
";",
"if",
"(",
"jumpToDefProvider",
")",
"{",
"request",
"=",
"jumpToDefProvider",
".",
"doJumpToDef",
"(",
"editor",
")",
";",
"if",
"(",
"request",
")",
"{",
"request",
".",
"done",
"(",
"function",
"(",
")",
"{",
"result",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
"}",
"else",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
"}",
"else",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Asynchronously asks providers to handle jump-to-definition.
@return {!Promise} Resolved when the provider signals that it's done; rejected if no
provider responded or the provider that responded failed.
|
[
"Asynchronously",
"asks",
"providers",
"to",
"handle",
"jump",
"-",
"to",
"-",
"definition",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/features/JumpToDefManager.js#L44-L83
|
train
|
adobe/brackets
|
src/features/ParameterHintsManager.js
|
positionHint
|
function positionHint(xpos, ypos, ybot) {
var hintWidth = $hintContainer.width(),
hintHeight = $hintContainer.height(),
top = ypos - hintHeight - POINTER_TOP_OFFSET,
left = xpos,
$editorHolder = $("#editor-holder"),
editorLeft;
if ($editorHolder.offset() === undefined) {
// this happens in jasmine tests that run
// without a windowed document.
return;
}
editorLeft = $editorHolder.offset().left;
left = Math.max(left, editorLeft);
left = Math.min(left, editorLeft + $editorHolder.width() - hintWidth);
if (top < 0) {
$hintContainer.removeClass("preview-bubble-above");
$hintContainer.addClass("preview-bubble-below");
top = ybot + POSITION_BELOW_OFFSET;
$hintContainer.offset({
left: left,
top: top
});
} else {
$hintContainer.removeClass("preview-bubble-below");
$hintContainer.addClass("preview-bubble-above");
$hintContainer.offset({
left: left,
top: top - POINTER_TOP_OFFSET
});
}
}
|
javascript
|
function positionHint(xpos, ypos, ybot) {
var hintWidth = $hintContainer.width(),
hintHeight = $hintContainer.height(),
top = ypos - hintHeight - POINTER_TOP_OFFSET,
left = xpos,
$editorHolder = $("#editor-holder"),
editorLeft;
if ($editorHolder.offset() === undefined) {
// this happens in jasmine tests that run
// without a windowed document.
return;
}
editorLeft = $editorHolder.offset().left;
left = Math.max(left, editorLeft);
left = Math.min(left, editorLeft + $editorHolder.width() - hintWidth);
if (top < 0) {
$hintContainer.removeClass("preview-bubble-above");
$hintContainer.addClass("preview-bubble-below");
top = ybot + POSITION_BELOW_OFFSET;
$hintContainer.offset({
left: left,
top: top
});
} else {
$hintContainer.removeClass("preview-bubble-below");
$hintContainer.addClass("preview-bubble-above");
$hintContainer.offset({
left: left,
top: top - POINTER_TOP_OFFSET
});
}
}
|
[
"function",
"positionHint",
"(",
"xpos",
",",
"ypos",
",",
"ybot",
")",
"{",
"var",
"hintWidth",
"=",
"$hintContainer",
".",
"width",
"(",
")",
",",
"hintHeight",
"=",
"$hintContainer",
".",
"height",
"(",
")",
",",
"top",
"=",
"ypos",
"-",
"hintHeight",
"-",
"POINTER_TOP_OFFSET",
",",
"left",
"=",
"xpos",
",",
"$editorHolder",
"=",
"$",
"(",
"\"#editor-holder\"",
")",
",",
"editorLeft",
";",
"if",
"(",
"$editorHolder",
".",
"offset",
"(",
")",
"===",
"undefined",
")",
"{",
"return",
";",
"}",
"editorLeft",
"=",
"$editorHolder",
".",
"offset",
"(",
")",
".",
"left",
";",
"left",
"=",
"Math",
".",
"max",
"(",
"left",
",",
"editorLeft",
")",
";",
"left",
"=",
"Math",
".",
"min",
"(",
"left",
",",
"editorLeft",
"+",
"$editorHolder",
".",
"width",
"(",
")",
"-",
"hintWidth",
")",
";",
"if",
"(",
"top",
"<",
"0",
")",
"{",
"$hintContainer",
".",
"removeClass",
"(",
"\"preview-bubble-above\"",
")",
";",
"$hintContainer",
".",
"addClass",
"(",
"\"preview-bubble-below\"",
")",
";",
"top",
"=",
"ybot",
"+",
"POSITION_BELOW_OFFSET",
";",
"$hintContainer",
".",
"offset",
"(",
"{",
"left",
":",
"left",
",",
"top",
":",
"top",
"}",
")",
";",
"}",
"else",
"{",
"$hintContainer",
".",
"removeClass",
"(",
"\"preview-bubble-below\"",
")",
";",
"$hintContainer",
".",
"addClass",
"(",
"\"preview-bubble-above\"",
")",
";",
"$hintContainer",
".",
"offset",
"(",
"{",
"left",
":",
"left",
",",
"top",
":",
"top",
"-",
"POINTER_TOP_OFFSET",
"}",
")",
";",
"}",
"}"
] |
Position a function hint.
@param {number} xpos
@param {number} ypos
@param {number} ybot
|
[
"Position",
"a",
"function",
"hint",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/features/ParameterHintsManager.js#L81-L115
|
train
|
adobe/brackets
|
src/features/ParameterHintsManager.js
|
formatHint
|
function formatHint(hints) {
$hintContent.empty();
$hintContent.addClass("brackets-hints");
function appendSeparators(separators) {
$hintContent.append(separators);
}
function appendParameter(param, documentation, index) {
if (hints.currentIndex === index) {
$hintContent.append($("<span>")
.append(_.escape(param))
.addClass("current-parameter"));
} else {
$hintContent.append($("<span>")
.append(_.escape(param))
.addClass("parameter"));
}
}
if (hints.parameters.length > 0) {
_formatParameterHint(hints.parameters, appendSeparators, appendParameter);
} else {
$hintContent.append(_.escape(Strings.NO_ARGUMENTS));
}
}
|
javascript
|
function formatHint(hints) {
$hintContent.empty();
$hintContent.addClass("brackets-hints");
function appendSeparators(separators) {
$hintContent.append(separators);
}
function appendParameter(param, documentation, index) {
if (hints.currentIndex === index) {
$hintContent.append($("<span>")
.append(_.escape(param))
.addClass("current-parameter"));
} else {
$hintContent.append($("<span>")
.append(_.escape(param))
.addClass("parameter"));
}
}
if (hints.parameters.length > 0) {
_formatParameterHint(hints.parameters, appendSeparators, appendParameter);
} else {
$hintContent.append(_.escape(Strings.NO_ARGUMENTS));
}
}
|
[
"function",
"formatHint",
"(",
"hints",
")",
"{",
"$hintContent",
".",
"empty",
"(",
")",
";",
"$hintContent",
".",
"addClass",
"(",
"\"brackets-hints\"",
")",
";",
"function",
"appendSeparators",
"(",
"separators",
")",
"{",
"$hintContent",
".",
"append",
"(",
"separators",
")",
";",
"}",
"function",
"appendParameter",
"(",
"param",
",",
"documentation",
",",
"index",
")",
"{",
"if",
"(",
"hints",
".",
"currentIndex",
"===",
"index",
")",
"{",
"$hintContent",
".",
"append",
"(",
"$",
"(",
"\"<span>\"",
")",
".",
"append",
"(",
"_",
".",
"escape",
"(",
"param",
")",
")",
".",
"addClass",
"(",
"\"current-parameter\"",
")",
")",
";",
"}",
"else",
"{",
"$hintContent",
".",
"append",
"(",
"$",
"(",
"\"<span>\"",
")",
".",
"append",
"(",
"_",
".",
"escape",
"(",
"param",
")",
")",
".",
"addClass",
"(",
"\"parameter\"",
")",
")",
";",
"}",
"}",
"if",
"(",
"hints",
".",
"parameters",
".",
"length",
">",
"0",
")",
"{",
"_formatParameterHint",
"(",
"hints",
".",
"parameters",
",",
"appendSeparators",
",",
"appendParameter",
")",
";",
"}",
"else",
"{",
"$hintContent",
".",
"append",
"(",
"_",
".",
"escape",
"(",
"Strings",
".",
"NO_ARGUMENTS",
")",
")",
";",
"}",
"}"
] |
Bold the parameter at the caret.
@param {{inFunctionCall: boolean, functionCallPos: {line: number, ch: number}}} functionInfo -
tells if the caret is in a function call and the position
of the function call.
|
[
"Bold",
"the",
"parameter",
"at",
"the",
"caret",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/features/ParameterHintsManager.js#L199-L224
|
train
|
adobe/brackets
|
src/features/ParameterHintsManager.js
|
dismissHint
|
function dismissHint(editor) {
if (hintState.visible) {
$hintContainer.hide();
$hintContent.empty();
hintState = {};
if (editor) {
editor.off("cursorActivity.ParameterHinting", handleCursorActivity);
sessionEditor = null;
} else if (sessionEditor) {
sessionEditor.off("cursorActivity.ParameterHinting", handleCursorActivity);
sessionEditor = null;
}
}
}
|
javascript
|
function dismissHint(editor) {
if (hintState.visible) {
$hintContainer.hide();
$hintContent.empty();
hintState = {};
if (editor) {
editor.off("cursorActivity.ParameterHinting", handleCursorActivity);
sessionEditor = null;
} else if (sessionEditor) {
sessionEditor.off("cursorActivity.ParameterHinting", handleCursorActivity);
sessionEditor = null;
}
}
}
|
[
"function",
"dismissHint",
"(",
"editor",
")",
"{",
"if",
"(",
"hintState",
".",
"visible",
")",
"{",
"$hintContainer",
".",
"hide",
"(",
")",
";",
"$hintContent",
".",
"empty",
"(",
")",
";",
"hintState",
"=",
"{",
"}",
";",
"if",
"(",
"editor",
")",
"{",
"editor",
".",
"off",
"(",
"\"cursorActivity.ParameterHinting\"",
",",
"handleCursorActivity",
")",
";",
"sessionEditor",
"=",
"null",
";",
"}",
"else",
"if",
"(",
"sessionEditor",
")",
"{",
"sessionEditor",
".",
"off",
"(",
"\"cursorActivity.ParameterHinting\"",
",",
"handleCursorActivity",
")",
";",
"sessionEditor",
"=",
"null",
";",
"}",
"}",
"}"
] |
Dismiss the function hint.
|
[
"Dismiss",
"the",
"function",
"hint",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/features/ParameterHintsManager.js#L230-L244
|
train
|
adobe/brackets
|
src/features/ParameterHintsManager.js
|
popUpHint
|
function popUpHint(editor, explicit, onCursorActivity) {
var request = null;
var $deferredPopUp = $.Deferred();
var sessionProvider = null;
dismissHint(editor);
// Find a suitable provider, if any
var language = editor.getLanguageForSelection(),
enabledProviders = _providerRegistrationHandler.getProvidersForLanguageId(language.getId());
enabledProviders.some(function (item, index) {
if (item.provider.hasParameterHints(editor, lastChar)) {
sessionProvider = item.provider;
return true;
}
});
if (sessionProvider) {
request = sessionProvider.getParameterHints(explicit, onCursorActivity);
}
if (request) {
request.done(function (parameterHint) {
var cm = editor._codeMirror,
pos = parameterHint.functionCallPos || editor.getCursorPos();
pos = cm.charCoords(pos);
formatHint(parameterHint);
$hintContainer.show();
positionHint(pos.left, pos.top, pos.bottom);
hintState.visible = true;
sessionEditor = editor;
editor.on("cursorActivity.ParameterHinting", handleCursorActivity);
$deferredPopUp.resolveWith(null);
}).fail(function () {
hintState = {};
});
}
return $deferredPopUp;
}
|
javascript
|
function popUpHint(editor, explicit, onCursorActivity) {
var request = null;
var $deferredPopUp = $.Deferred();
var sessionProvider = null;
dismissHint(editor);
// Find a suitable provider, if any
var language = editor.getLanguageForSelection(),
enabledProviders = _providerRegistrationHandler.getProvidersForLanguageId(language.getId());
enabledProviders.some(function (item, index) {
if (item.provider.hasParameterHints(editor, lastChar)) {
sessionProvider = item.provider;
return true;
}
});
if (sessionProvider) {
request = sessionProvider.getParameterHints(explicit, onCursorActivity);
}
if (request) {
request.done(function (parameterHint) {
var cm = editor._codeMirror,
pos = parameterHint.functionCallPos || editor.getCursorPos();
pos = cm.charCoords(pos);
formatHint(parameterHint);
$hintContainer.show();
positionHint(pos.left, pos.top, pos.bottom);
hintState.visible = true;
sessionEditor = editor;
editor.on("cursorActivity.ParameterHinting", handleCursorActivity);
$deferredPopUp.resolveWith(null);
}).fail(function () {
hintState = {};
});
}
return $deferredPopUp;
}
|
[
"function",
"popUpHint",
"(",
"editor",
",",
"explicit",
",",
"onCursorActivity",
")",
"{",
"var",
"request",
"=",
"null",
";",
"var",
"$deferredPopUp",
"=",
"$",
".",
"Deferred",
"(",
")",
";",
"var",
"sessionProvider",
"=",
"null",
";",
"dismissHint",
"(",
"editor",
")",
";",
"var",
"language",
"=",
"editor",
".",
"getLanguageForSelection",
"(",
")",
",",
"enabledProviders",
"=",
"_providerRegistrationHandler",
".",
"getProvidersForLanguageId",
"(",
"language",
".",
"getId",
"(",
")",
")",
";",
"enabledProviders",
".",
"some",
"(",
"function",
"(",
"item",
",",
"index",
")",
"{",
"if",
"(",
"item",
".",
"provider",
".",
"hasParameterHints",
"(",
"editor",
",",
"lastChar",
")",
")",
"{",
"sessionProvider",
"=",
"item",
".",
"provider",
";",
"return",
"true",
";",
"}",
"}",
")",
";",
"if",
"(",
"sessionProvider",
")",
"{",
"request",
"=",
"sessionProvider",
".",
"getParameterHints",
"(",
"explicit",
",",
"onCursorActivity",
")",
";",
"}",
"if",
"(",
"request",
")",
"{",
"request",
".",
"done",
"(",
"function",
"(",
"parameterHint",
")",
"{",
"var",
"cm",
"=",
"editor",
".",
"_codeMirror",
",",
"pos",
"=",
"parameterHint",
".",
"functionCallPos",
"||",
"editor",
".",
"getCursorPos",
"(",
")",
";",
"pos",
"=",
"cm",
".",
"charCoords",
"(",
"pos",
")",
";",
"formatHint",
"(",
"parameterHint",
")",
";",
"$hintContainer",
".",
"show",
"(",
")",
";",
"positionHint",
"(",
"pos",
".",
"left",
",",
"pos",
".",
"top",
",",
"pos",
".",
"bottom",
")",
";",
"hintState",
".",
"visible",
"=",
"true",
";",
"sessionEditor",
"=",
"editor",
";",
"editor",
".",
"on",
"(",
"\"cursorActivity.ParameterHinting\"",
",",
"handleCursorActivity",
")",
";",
"$deferredPopUp",
".",
"resolveWith",
"(",
"null",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"hintState",
"=",
"{",
"}",
";",
"}",
")",
";",
"}",
"return",
"$deferredPopUp",
";",
"}"
] |
Pop up a function hint on the line above the caret position.
@param {object=} editor - current Active Editor
@param {boolean} True if hints are invoked through cursor activity.
@return {jQuery.Promise} - The promise will not complete until the
hint has completed. Returns null, if the function hint is already
displayed or there is no function hint at the cursor.
|
[
"Pop",
"up",
"a",
"function",
"hint",
"on",
"the",
"line",
"above",
"the",
"caret",
"position",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/features/ParameterHintsManager.js#L256-L298
|
train
|
adobe/brackets
|
src/features/ParameterHintsManager.js
|
installListeners
|
function installListeners(editor) {
editor.on("keydown.ParameterHinting", function (event, editor, domEvent) {
if (domEvent.keyCode === KeyEvent.DOM_VK_ESCAPE) {
dismissHint(editor);
}
}).on("scroll.ParameterHinting", function () {
dismissHint(editor);
})
.on("editorChange.ParameterHinting", _handleChange)
.on("keypress.ParameterHinting", _handleKeypressEvent);
}
|
javascript
|
function installListeners(editor) {
editor.on("keydown.ParameterHinting", function (event, editor, domEvent) {
if (domEvent.keyCode === KeyEvent.DOM_VK_ESCAPE) {
dismissHint(editor);
}
}).on("scroll.ParameterHinting", function () {
dismissHint(editor);
})
.on("editorChange.ParameterHinting", _handleChange)
.on("keypress.ParameterHinting", _handleKeypressEvent);
}
|
[
"function",
"installListeners",
"(",
"editor",
")",
"{",
"editor",
".",
"on",
"(",
"\"keydown.ParameterHinting\"",
",",
"function",
"(",
"event",
",",
"editor",
",",
"domEvent",
")",
"{",
"if",
"(",
"domEvent",
".",
"keyCode",
"===",
"KeyEvent",
".",
"DOM_VK_ESCAPE",
")",
"{",
"dismissHint",
"(",
"editor",
")",
";",
"}",
"}",
")",
".",
"on",
"(",
"\"scroll.ParameterHinting\"",
",",
"function",
"(",
")",
"{",
"dismissHint",
"(",
"editor",
")",
";",
"}",
")",
".",
"on",
"(",
"\"editorChange.ParameterHinting\"",
",",
"_handleChange",
")",
".",
"on",
"(",
"\"keypress.ParameterHinting\"",
",",
"_handleKeypressEvent",
")",
";",
"}"
] |
Install function hint listeners.
@param {Editor} editor - editor context on which to listen for
changes
|
[
"Install",
"function",
"hint",
"listeners",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/features/ParameterHintsManager.js#L318-L328
|
train
|
adobe/brackets
|
src/file/FileUtils.js
|
readAsText
|
function readAsText(file) {
var result = new $.Deferred();
// Measure performance
var perfTimerName = PerfUtils.markStart("readAsText:\t" + file.fullPath);
result.always(function () {
PerfUtils.addMeasurement(perfTimerName);
});
// Read file
file.read(function (err, data, encoding, stat) {
if (!err) {
result.resolve(data, stat.mtime);
} else {
result.reject(err);
}
});
return result.promise();
}
|
javascript
|
function readAsText(file) {
var result = new $.Deferred();
// Measure performance
var perfTimerName = PerfUtils.markStart("readAsText:\t" + file.fullPath);
result.always(function () {
PerfUtils.addMeasurement(perfTimerName);
});
// Read file
file.read(function (err, data, encoding, stat) {
if (!err) {
result.resolve(data, stat.mtime);
} else {
result.reject(err);
}
});
return result.promise();
}
|
[
"function",
"readAsText",
"(",
"file",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"var",
"perfTimerName",
"=",
"PerfUtils",
".",
"markStart",
"(",
"\"readAsText:\\t\"",
"+",
"\\t",
")",
";",
"file",
".",
"fullPath",
"result",
".",
"always",
"(",
"function",
"(",
")",
"{",
"PerfUtils",
".",
"addMeasurement",
"(",
"perfTimerName",
")",
";",
"}",
")",
";",
"file",
".",
"read",
"(",
"function",
"(",
"err",
",",
"data",
",",
"encoding",
",",
"stat",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"result",
".",
"resolve",
"(",
"data",
",",
"stat",
".",
"mtime",
")",
";",
"}",
"else",
"{",
"result",
".",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Asynchronously reads a file as UTF-8 encoded text.
@param {!File} file File to read
@return {$.Promise} a jQuery promise that will be resolved with the
file's text content plus its timestamp, or rejected with a FileSystemError string
constant if the file can not be read.
|
[
"Asynchronously",
"reads",
"a",
"file",
"as",
"UTF",
"-",
"8",
"encoded",
"text",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/file/FileUtils.js#L70-L89
|
train
|
adobe/brackets
|
src/file/FileUtils.js
|
writeText
|
function writeText(file, text, allowBlindWrite) {
var result = new $.Deferred(),
options = {};
if (allowBlindWrite) {
options.blind = true;
}
file.write(text, options, function (err) {
if (!err) {
result.resolve();
} else {
result.reject(err);
}
});
return result.promise();
}
|
javascript
|
function writeText(file, text, allowBlindWrite) {
var result = new $.Deferred(),
options = {};
if (allowBlindWrite) {
options.blind = true;
}
file.write(text, options, function (err) {
if (!err) {
result.resolve();
} else {
result.reject(err);
}
});
return result.promise();
}
|
[
"function",
"writeText",
"(",
"file",
",",
"text",
",",
"allowBlindWrite",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
",",
"options",
"=",
"{",
"}",
";",
"if",
"(",
"allowBlindWrite",
")",
"{",
"options",
".",
"blind",
"=",
"true",
";",
"}",
"file",
".",
"write",
"(",
"text",
",",
"options",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"result",
".",
"resolve",
"(",
")",
";",
"}",
"else",
"{",
"result",
".",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Asynchronously writes a file as UTF-8 encoded text.
@param {!File} file File to write
@param {!string} text
@param {boolean=} allowBlindWrite Indicates whether or not CONTENTS_MODIFIED
errors---which can be triggered if the actual file contents differ from
the FileSystem's last-known contents---should be ignored.
@return {$.Promise} a jQuery promise that will be resolved when
file writing completes, or rejected with a FileSystemError string constant.
|
[
"Asynchronously",
"writes",
"a",
"file",
"as",
"UTF",
"-",
"8",
"encoded",
"text",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/file/FileUtils.js#L101-L118
|
train
|
adobe/brackets
|
src/file/FileUtils.js
|
sniffLineEndings
|
function sniffLineEndings(text) {
var subset = text.substr(0, 1000); // (length is clipped to text.length)
var hasCRLF = /\r\n/.test(subset);
var hasLF = /[^\r]\n/.test(subset);
if ((hasCRLF && hasLF) || (!hasCRLF && !hasLF)) {
return null;
} else {
return hasCRLF ? LINE_ENDINGS_CRLF : LINE_ENDINGS_LF;
}
}
|
javascript
|
function sniffLineEndings(text) {
var subset = text.substr(0, 1000); // (length is clipped to text.length)
var hasCRLF = /\r\n/.test(subset);
var hasLF = /[^\r]\n/.test(subset);
if ((hasCRLF && hasLF) || (!hasCRLF && !hasLF)) {
return null;
} else {
return hasCRLF ? LINE_ENDINGS_CRLF : LINE_ENDINGS_LF;
}
}
|
[
"function",
"sniffLineEndings",
"(",
"text",
")",
"{",
"var",
"subset",
"=",
"text",
".",
"substr",
"(",
"0",
",",
"1000",
")",
";",
"var",
"hasCRLF",
"=",
"/",
"\\r\\n",
"/",
".",
"test",
"(",
"subset",
")",
";",
"var",
"hasLF",
"=",
"/",
"[^\\r]\\n",
"/",
".",
"test",
"(",
"subset",
")",
";",
"if",
"(",
"(",
"hasCRLF",
"&&",
"hasLF",
")",
"||",
"(",
"!",
"hasCRLF",
"&&",
"!",
"hasLF",
")",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"return",
"hasCRLF",
"?",
"LINE_ENDINGS_CRLF",
":",
"LINE_ENDINGS_LF",
";",
"}",
"}"
] |
Scans the first 1000 chars of the text to determine how it encodes line endings. Returns
null if usage is mixed or if no line endings found.
@param {!string} text
@return {null|LINE_ENDINGS_CRLF|LINE_ENDINGS_LF}
|
[
"Scans",
"the",
"first",
"1000",
"chars",
"of",
"the",
"text",
"to",
"determine",
"how",
"it",
"encodes",
"line",
"endings",
".",
"Returns",
"null",
"if",
"usage",
"is",
"mixed",
"or",
"if",
"no",
"line",
"endings",
"found",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/file/FileUtils.js#L141-L151
|
train
|
adobe/brackets
|
src/file/FileUtils.js
|
translateLineEndings
|
function translateLineEndings(text, lineEndings) {
if (lineEndings !== LINE_ENDINGS_CRLF && lineEndings !== LINE_ENDINGS_LF) {
lineEndings = getPlatformLineEndings();
}
var eolStr = (lineEndings === LINE_ENDINGS_CRLF ? "\r\n" : "\n");
var findAnyEol = /\r\n|\r|\n/g;
return text.replace(findAnyEol, eolStr);
}
|
javascript
|
function translateLineEndings(text, lineEndings) {
if (lineEndings !== LINE_ENDINGS_CRLF && lineEndings !== LINE_ENDINGS_LF) {
lineEndings = getPlatformLineEndings();
}
var eolStr = (lineEndings === LINE_ENDINGS_CRLF ? "\r\n" : "\n");
var findAnyEol = /\r\n|\r|\n/g;
return text.replace(findAnyEol, eolStr);
}
|
[
"function",
"translateLineEndings",
"(",
"text",
",",
"lineEndings",
")",
"{",
"if",
"(",
"lineEndings",
"!==",
"LINE_ENDINGS_CRLF",
"&&",
"lineEndings",
"!==",
"LINE_ENDINGS_LF",
")",
"{",
"lineEndings",
"=",
"getPlatformLineEndings",
"(",
")",
";",
"}",
"var",
"eolStr",
"=",
"(",
"lineEndings",
"===",
"LINE_ENDINGS_CRLF",
"?",
"\"\\r\\n\"",
":",
"\\r",
")",
";",
"\\n",
"\"\\n\"",
"}"
] |
Translates any line ending types in the given text to the be the single form specified
@param {!string} text
@param {null|LINE_ENDINGS_CRLF|LINE_ENDINGS_LF} lineEndings
@return {string}
|
[
"Translates",
"any",
"line",
"ending",
"types",
"in",
"the",
"given",
"text",
"to",
"the",
"be",
"the",
"single",
"form",
"specified"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/file/FileUtils.js#L159-L168
|
train
|
adobe/brackets
|
src/file/FileUtils.js
|
makeDialogFileList
|
function makeDialogFileList(paths) {
var result = "<ul class='dialog-list'>";
paths.forEach(function (path) {
result += "<li><span class='dialog-filename'>";
result += StringUtils.breakableUrl(path);
result += "</span></li>";
});
result += "</ul>";
return result;
}
|
javascript
|
function makeDialogFileList(paths) {
var result = "<ul class='dialog-list'>";
paths.forEach(function (path) {
result += "<li><span class='dialog-filename'>";
result += StringUtils.breakableUrl(path);
result += "</span></li>";
});
result += "</ul>";
return result;
}
|
[
"function",
"makeDialogFileList",
"(",
"paths",
")",
"{",
"var",
"result",
"=",
"\"<ul class='dialog-list'>\"",
";",
"paths",
".",
"forEach",
"(",
"function",
"(",
"path",
")",
"{",
"result",
"+=",
"\"<li><span class='dialog-filename'>\"",
";",
"result",
"+=",
"StringUtils",
".",
"breakableUrl",
"(",
"path",
")",
";",
"result",
"+=",
"\"</span></li>\"",
";",
"}",
")",
";",
"result",
"+=",
"\"</ul>\"",
";",
"return",
"result",
";",
"}"
] |
Creates an HTML string for a list of files to be reported on, suitable for use in a dialog.
@param {Array.<string>} Array of filenames or paths to display.
|
[
"Creates",
"an",
"HTML",
"string",
"for",
"a",
"list",
"of",
"files",
"to",
"be",
"reported",
"on",
"suitable",
"for",
"use",
"in",
"a",
"dialog",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/file/FileUtils.js#L221-L230
|
train
|
adobe/brackets
|
src/file/FileUtils.js
|
getBaseName
|
function getBaseName(fullPath) {
var lastSlash = fullPath.lastIndexOf("/");
if (lastSlash === fullPath.length - 1) { // directory: exclude trailing "/" too
return fullPath.slice(fullPath.lastIndexOf("/", fullPath.length - 2) + 1, -1);
} else {
return fullPath.slice(lastSlash + 1);
}
}
|
javascript
|
function getBaseName(fullPath) {
var lastSlash = fullPath.lastIndexOf("/");
if (lastSlash === fullPath.length - 1) { // directory: exclude trailing "/" too
return fullPath.slice(fullPath.lastIndexOf("/", fullPath.length - 2) + 1, -1);
} else {
return fullPath.slice(lastSlash + 1);
}
}
|
[
"function",
"getBaseName",
"(",
"fullPath",
")",
"{",
"var",
"lastSlash",
"=",
"fullPath",
".",
"lastIndexOf",
"(",
"\"/\"",
")",
";",
"if",
"(",
"lastSlash",
"===",
"fullPath",
".",
"length",
"-",
"1",
")",
"{",
"return",
"fullPath",
".",
"slice",
"(",
"fullPath",
".",
"lastIndexOf",
"(",
"\"/\"",
",",
"fullPath",
".",
"length",
"-",
"2",
")",
"+",
"1",
",",
"-",
"1",
")",
";",
"}",
"else",
"{",
"return",
"fullPath",
".",
"slice",
"(",
"lastSlash",
"+",
"1",
")",
";",
"}",
"}"
] |
Get the name of a file or a directory, removing any preceding path.
@param {string} fullPath full path to a file or directory
@return {string} Returns the base name of a file or the name of a
directory
|
[
"Get",
"the",
"name",
"of",
"a",
"file",
"or",
"a",
"directory",
"removing",
"any",
"preceding",
"path",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/file/FileUtils.js#L287-L294
|
train
|
adobe/brackets
|
src/file/FileUtils.js
|
getNativeModuleDirectoryPath
|
function getNativeModuleDirectoryPath(module) {
var path;
if (module && module.uri) {
path = decodeURI(module.uri);
// Remove module name and trailing slash from path.
path = path.substr(0, path.lastIndexOf("/"));
}
return path;
}
|
javascript
|
function getNativeModuleDirectoryPath(module) {
var path;
if (module && module.uri) {
path = decodeURI(module.uri);
// Remove module name and trailing slash from path.
path = path.substr(0, path.lastIndexOf("/"));
}
return path;
}
|
[
"function",
"getNativeModuleDirectoryPath",
"(",
"module",
")",
"{",
"var",
"path",
";",
"if",
"(",
"module",
"&&",
"module",
".",
"uri",
")",
"{",
"path",
"=",
"decodeURI",
"(",
"module",
".",
"uri",
")",
";",
"path",
"=",
"path",
".",
"substr",
"(",
"0",
",",
"path",
".",
"lastIndexOf",
"(",
"\"/\"",
")",
")",
";",
"}",
"return",
"path",
";",
"}"
] |
Given the module object passed to JS module define function,
convert the path to a native absolute path.
Returns a native absolute path to the module folder.
WARNING: unlike most paths in Brackets, this path EXCLUDES the trailing "/".
@return {string}
|
[
"Given",
"the",
"module",
"object",
"passed",
"to",
"JS",
"module",
"define",
"function",
"convert",
"the",
"path",
"to",
"a",
"native",
"absolute",
"path",
".",
"Returns",
"a",
"native",
"absolute",
"path",
"to",
"the",
"module",
"folder",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/file/FileUtils.js#L318-L328
|
train
|
adobe/brackets
|
src/file/FileUtils.js
|
getFilenameWithoutExtension
|
function getFilenameWithoutExtension(filename) {
var index = filename.lastIndexOf(".");
return index === -1 ? filename : filename.slice(0, index);
}
|
javascript
|
function getFilenameWithoutExtension(filename) {
var index = filename.lastIndexOf(".");
return index === -1 ? filename : filename.slice(0, index);
}
|
[
"function",
"getFilenameWithoutExtension",
"(",
"filename",
")",
"{",
"var",
"index",
"=",
"filename",
".",
"lastIndexOf",
"(",
"\".\"",
")",
";",
"return",
"index",
"===",
"-",
"1",
"?",
"filename",
":",
"filename",
".",
"slice",
"(",
"0",
",",
"index",
")",
";",
"}"
] |
Get the file name without the extension. Returns "" if name starts with "."
@param {string} filename File name of a file or directory, without preceding path
@return {string} Returns the file name without the extension
|
[
"Get",
"the",
"file",
"name",
"without",
"the",
"extension",
".",
"Returns",
"if",
"name",
"starts",
"with",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/file/FileUtils.js#L428-L431
|
train
|
adobe/brackets
|
src/utils/DropdownEventHandler.js
|
DropdownEventHandler
|
function DropdownEventHandler($list, selectionCallback, closeCallback) {
this.$list = $list;
this.$items = $list.find("li");
this.selectionCallback = selectionCallback;
this.closeCallback = closeCallback;
this.scrolling = false;
/**
* @private
* The selected position in the list; otherwise -1.
* @type {number}
*/
this._selectedIndex = -1;
}
|
javascript
|
function DropdownEventHandler($list, selectionCallback, closeCallback) {
this.$list = $list;
this.$items = $list.find("li");
this.selectionCallback = selectionCallback;
this.closeCallback = closeCallback;
this.scrolling = false;
/**
* @private
* The selected position in the list; otherwise -1.
* @type {number}
*/
this._selectedIndex = -1;
}
|
[
"function",
"DropdownEventHandler",
"(",
"$list",
",",
"selectionCallback",
",",
"closeCallback",
")",
"{",
"this",
".",
"$list",
"=",
"$list",
";",
"this",
".",
"$items",
"=",
"$list",
".",
"find",
"(",
"\"li\"",
")",
";",
"this",
".",
"selectionCallback",
"=",
"selectionCallback",
";",
"this",
".",
"closeCallback",
"=",
"closeCallback",
";",
"this",
".",
"scrolling",
"=",
"false",
";",
"this",
".",
"_selectedIndex",
"=",
"-",
"1",
";",
"}"
] |
Object to handle events for a dropdown list.
DropdownEventHandler handles these events:
Mouse:
- click - execute selection callback and dismiss list
- mouseover - highlight item
- mouseleave - remove mouse highlighting
Keyboard:
- Enter - execute selection callback and dismiss list
- Esc - dismiss list
- Up/Down - change selection
- PageUp/Down - change selection
Items whose <a> has the .disabled class do not respond to selection.
@constructor
@param {jQueryObject} $list associated list object
@param {Function} selectionCallback function called when list item is selected.
|
[
"Object",
"to",
"handle",
"events",
"for",
"a",
"dropdown",
"list",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/DropdownEventHandler.js#L54-L68
|
train
|
adobe/brackets
|
src/utils/DropdownEventHandler.js
|
_keydownHook
|
function _keydownHook(event) {
var keyCode;
// (page) up, (page) down, enter and tab key are handled by the list
if (event.type === "keydown") {
keyCode = event.keyCode;
if (keyCode === KeyEvent.DOM_VK_TAB) {
self.close();
} else if (keyCode === KeyEvent.DOM_VK_UP) {
// Move up one, wrapping at edges (if nothing selected, select the last item)
self._tryToSelect(self._selectedIndex === -1 ? -1 : self._selectedIndex - 1, -1);
} else if (keyCode === KeyEvent.DOM_VK_DOWN) {
// Move down one, wrapping at edges (if nothing selected, select the first item)
self._tryToSelect(self._selectedIndex === -1 ? 0 : self._selectedIndex + 1, +1);
} else if (keyCode === KeyEvent.DOM_VK_PAGE_UP) {
// Move up roughly one 'page', stopping at edges (not wrapping) (if nothing selected, selects the first item)
self._tryToSelect((self._selectedIndex || 0) - self._itemsPerPage(), -1, true);
} else if (keyCode === KeyEvent.DOM_VK_PAGE_DOWN) {
// Move down roughly one 'page', stopping at edges (not wrapping) (if nothing selected, selects the item one page down from the top)
self._tryToSelect((self._selectedIndex || 0) + self._itemsPerPage(), +1, true);
} else if (keyCode === KeyEvent.DOM_VK_HOME) {
self._tryToSelect(0, +1);
} else if (keyCode === KeyEvent.DOM_VK_END) {
self._tryToSelect(self.$items.length - 1, -1);
} else if (self._selectedIndex !== -1 &&
(keyCode === KeyEvent.DOM_VK_RETURN)) {
// Trigger a click handler to commmit the selected item
self._selectionHandler();
} else {
// Let the event bubble.
return false;
}
event.stopImmediatePropagation();
event.preventDefault();
return true;
}
// If we didn't handle it, let other global keydown hooks handle it.
return false;
}
|
javascript
|
function _keydownHook(event) {
var keyCode;
// (page) up, (page) down, enter and tab key are handled by the list
if (event.type === "keydown") {
keyCode = event.keyCode;
if (keyCode === KeyEvent.DOM_VK_TAB) {
self.close();
} else if (keyCode === KeyEvent.DOM_VK_UP) {
// Move up one, wrapping at edges (if nothing selected, select the last item)
self._tryToSelect(self._selectedIndex === -1 ? -1 : self._selectedIndex - 1, -1);
} else if (keyCode === KeyEvent.DOM_VK_DOWN) {
// Move down one, wrapping at edges (if nothing selected, select the first item)
self._tryToSelect(self._selectedIndex === -1 ? 0 : self._selectedIndex + 1, +1);
} else if (keyCode === KeyEvent.DOM_VK_PAGE_UP) {
// Move up roughly one 'page', stopping at edges (not wrapping) (if nothing selected, selects the first item)
self._tryToSelect((self._selectedIndex || 0) - self._itemsPerPage(), -1, true);
} else if (keyCode === KeyEvent.DOM_VK_PAGE_DOWN) {
// Move down roughly one 'page', stopping at edges (not wrapping) (if nothing selected, selects the item one page down from the top)
self._tryToSelect((self._selectedIndex || 0) + self._itemsPerPage(), +1, true);
} else if (keyCode === KeyEvent.DOM_VK_HOME) {
self._tryToSelect(0, +1);
} else if (keyCode === KeyEvent.DOM_VK_END) {
self._tryToSelect(self.$items.length - 1, -1);
} else if (self._selectedIndex !== -1 &&
(keyCode === KeyEvent.DOM_VK_RETURN)) {
// Trigger a click handler to commmit the selected item
self._selectionHandler();
} else {
// Let the event bubble.
return false;
}
event.stopImmediatePropagation();
event.preventDefault();
return true;
}
// If we didn't handle it, let other global keydown hooks handle it.
return false;
}
|
[
"function",
"_keydownHook",
"(",
"event",
")",
"{",
"var",
"keyCode",
";",
"if",
"(",
"event",
".",
"type",
"===",
"\"keydown\"",
")",
"{",
"keyCode",
"=",
"event",
".",
"keyCode",
";",
"if",
"(",
"keyCode",
"===",
"KeyEvent",
".",
"DOM_VK_TAB",
")",
"{",
"self",
".",
"close",
"(",
")",
";",
"}",
"else",
"if",
"(",
"keyCode",
"===",
"KeyEvent",
".",
"DOM_VK_UP",
")",
"{",
"self",
".",
"_tryToSelect",
"(",
"self",
".",
"_selectedIndex",
"===",
"-",
"1",
"?",
"-",
"1",
":",
"self",
".",
"_selectedIndex",
"-",
"1",
",",
"-",
"1",
")",
";",
"}",
"else",
"if",
"(",
"keyCode",
"===",
"KeyEvent",
".",
"DOM_VK_DOWN",
")",
"{",
"self",
".",
"_tryToSelect",
"(",
"self",
".",
"_selectedIndex",
"===",
"-",
"1",
"?",
"0",
":",
"self",
".",
"_selectedIndex",
"+",
"1",
",",
"+",
"1",
")",
";",
"}",
"else",
"if",
"(",
"keyCode",
"===",
"KeyEvent",
".",
"DOM_VK_PAGE_UP",
")",
"{",
"self",
".",
"_tryToSelect",
"(",
"(",
"self",
".",
"_selectedIndex",
"||",
"0",
")",
"-",
"self",
".",
"_itemsPerPage",
"(",
")",
",",
"-",
"1",
",",
"true",
")",
";",
"}",
"else",
"if",
"(",
"keyCode",
"===",
"KeyEvent",
".",
"DOM_VK_PAGE_DOWN",
")",
"{",
"self",
".",
"_tryToSelect",
"(",
"(",
"self",
".",
"_selectedIndex",
"||",
"0",
")",
"+",
"self",
".",
"_itemsPerPage",
"(",
")",
",",
"+",
"1",
",",
"true",
")",
";",
"}",
"else",
"if",
"(",
"keyCode",
"===",
"KeyEvent",
".",
"DOM_VK_HOME",
")",
"{",
"self",
".",
"_tryToSelect",
"(",
"0",
",",
"+",
"1",
")",
";",
"}",
"else",
"if",
"(",
"keyCode",
"===",
"KeyEvent",
".",
"DOM_VK_END",
")",
"{",
"self",
".",
"_tryToSelect",
"(",
"self",
".",
"$items",
".",
"length",
"-",
"1",
",",
"-",
"1",
")",
";",
"}",
"else",
"if",
"(",
"self",
".",
"_selectedIndex",
"!==",
"-",
"1",
"&&",
"(",
"keyCode",
"===",
"KeyEvent",
".",
"DOM_VK_RETURN",
")",
")",
"{",
"self",
".",
"_selectionHandler",
"(",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"event",
".",
"stopImmediatePropagation",
"(",
")",
";",
"event",
".",
"preventDefault",
"(",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Convert keydown events into hint list navigation actions.
@param {KeyboardEvent} event
@return {boolean} true if key was handled, otherwise false.
|
[
"Convert",
"keydown",
"events",
"into",
"hint",
"list",
"navigation",
"actions",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/DropdownEventHandler.js#L82-L126
|
train
|
adobe/brackets
|
src/language/XMLUtils.js
|
_createTagInfo
|
function _createTagInfo(token, tokenType, offset, exclusionList, tagName, attrName, shouldReplace) {
return {
token: token || null,
tokenType: tokenType || null,
offset: offset || 0,
exclusionList: exclusionList || [],
tagName: tagName || "",
attrName: attrName || "",
shouldReplace: shouldReplace || false
};
}
|
javascript
|
function _createTagInfo(token, tokenType, offset, exclusionList, tagName, attrName, shouldReplace) {
return {
token: token || null,
tokenType: tokenType || null,
offset: offset || 0,
exclusionList: exclusionList || [],
tagName: tagName || "",
attrName: attrName || "",
shouldReplace: shouldReplace || false
};
}
|
[
"function",
"_createTagInfo",
"(",
"token",
",",
"tokenType",
",",
"offset",
",",
"exclusionList",
",",
"tagName",
",",
"attrName",
",",
"shouldReplace",
")",
"{",
"return",
"{",
"token",
":",
"token",
"||",
"null",
",",
"tokenType",
":",
"tokenType",
"||",
"null",
",",
"offset",
":",
"offset",
"||",
"0",
",",
"exclusionList",
":",
"exclusionList",
"||",
"[",
"]",
",",
"tagName",
":",
"tagName",
"||",
"\"\"",
",",
"attrName",
":",
"attrName",
"||",
"\"\"",
",",
"shouldReplace",
":",
"shouldReplace",
"||",
"false",
"}",
";",
"}"
] |
Returns an object that represents all its params.
@param {!Token} token CodeMirror token at the current pos
@param {number} tokenType Type of current token
@param {number} offset Offset in current token
@param {Array.<string>} exclusionList List of attributes of a tag or attribute options used by an attribute
@param {string} tagName Name of the current tag
@param {string} attrName Name of the current attribute
@param {boolean} shouldReplace true if we don't want to append ="" to an attribute
@return {!{token: Token, tokenType: int, offset: int, exclusionList: Array.<string>, tagName: string, attrName: string, shouldReplace: boolean}}
|
[
"Returns",
"an",
"object",
"that",
"represents",
"all",
"its",
"params",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/XMLUtils.js#L50-L60
|
train
|
adobe/brackets
|
src/language/XMLUtils.js
|
_getTagAttributes
|
function _getTagAttributes(editor, constPos) {
var pos, ctx, ctxPrev, ctxNext, ctxTemp, tagName, exclusionList = [], shouldReplace;
pos = $.extend({}, constPos);
ctx = TokenUtils.getInitialContext(editor._codeMirror, pos);
// Stop if the cursor is before = or an attribute value.
ctxTemp = $.extend(true, {}, ctx);
if (ctxTemp.token.type === null && regexWhitespace.test(ctxTemp.token.string)) {
if (TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctxTemp)) {
if ((ctxTemp.token.type === null && ctxTemp.token.string === "=") ||
ctxTemp.token.type === "string") {
return null;
}
TokenUtils.moveSkippingWhitespace(TokenUtils.movePrevToken, ctxTemp);
}
}
// Incase an attribute is followed by an equal sign, shouldReplace will be used
// to prevent from appending ="" again.
if (ctxTemp.token.type === "attribute") {
if (TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctxTemp)) {
if (ctxTemp.token.type === null && ctxTemp.token.string === "=") {
shouldReplace = true;
}
}
}
// Look-Back and get the attributes and tag name.
pos = $.extend({}, constPos);
ctxPrev = TokenUtils.getInitialContext(editor._codeMirror, pos);
while (TokenUtils.movePrevToken(ctxPrev)) {
if (ctxPrev.token.type && ctxPrev.token.type.indexOf("tag bracket") >= 0) {
// Disallow hints in closed tag and inside tag content
if (ctxPrev.token.string === "</" || ctxPrev.token.string.indexOf(">") !== -1) {
return null;
}
}
// Get attributes.
if (ctxPrev.token.type === "attribute") {
exclusionList.push(ctxPrev.token.string);
}
// Get tag.
if (ctxPrev.token.type === "tag") {
tagName = ctxPrev.token.string;
if (TokenUtils.movePrevToken(ctxPrev)) {
if (ctxPrev.token.type === "tag bracket" && ctxPrev.token.string === "<") {
break;
}
return null;
}
}
}
// Look-Ahead and find rest of the attributes.
pos = $.extend({}, constPos);
ctxNext = TokenUtils.getInitialContext(editor._codeMirror, pos);
while (TokenUtils.moveNextToken(ctxNext)) {
if (ctxNext.token.type === "string" && ctxNext.token.string === "\"") {
return null;
}
// Stop on closing bracket of its own tag or opening bracket of next tag.
if (ctxNext.token.type === "tag bracket" &&
(ctxNext.token.string.indexOf(">") >= 0 || ctxNext.token.string === "<")) {
break;
}
if (ctxNext.token.type === "attribute" && exclusionList.indexOf(ctxNext.token.string) === -1) {
exclusionList.push(ctxNext.token.string);
}
}
return {
tagName: tagName,
exclusionList: exclusionList,
shouldReplace: shouldReplace
};
}
|
javascript
|
function _getTagAttributes(editor, constPos) {
var pos, ctx, ctxPrev, ctxNext, ctxTemp, tagName, exclusionList = [], shouldReplace;
pos = $.extend({}, constPos);
ctx = TokenUtils.getInitialContext(editor._codeMirror, pos);
// Stop if the cursor is before = or an attribute value.
ctxTemp = $.extend(true, {}, ctx);
if (ctxTemp.token.type === null && regexWhitespace.test(ctxTemp.token.string)) {
if (TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctxTemp)) {
if ((ctxTemp.token.type === null && ctxTemp.token.string === "=") ||
ctxTemp.token.type === "string") {
return null;
}
TokenUtils.moveSkippingWhitespace(TokenUtils.movePrevToken, ctxTemp);
}
}
// Incase an attribute is followed by an equal sign, shouldReplace will be used
// to prevent from appending ="" again.
if (ctxTemp.token.type === "attribute") {
if (TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctxTemp)) {
if (ctxTemp.token.type === null && ctxTemp.token.string === "=") {
shouldReplace = true;
}
}
}
// Look-Back and get the attributes and tag name.
pos = $.extend({}, constPos);
ctxPrev = TokenUtils.getInitialContext(editor._codeMirror, pos);
while (TokenUtils.movePrevToken(ctxPrev)) {
if (ctxPrev.token.type && ctxPrev.token.type.indexOf("tag bracket") >= 0) {
// Disallow hints in closed tag and inside tag content
if (ctxPrev.token.string === "</" || ctxPrev.token.string.indexOf(">") !== -1) {
return null;
}
}
// Get attributes.
if (ctxPrev.token.type === "attribute") {
exclusionList.push(ctxPrev.token.string);
}
// Get tag.
if (ctxPrev.token.type === "tag") {
tagName = ctxPrev.token.string;
if (TokenUtils.movePrevToken(ctxPrev)) {
if (ctxPrev.token.type === "tag bracket" && ctxPrev.token.string === "<") {
break;
}
return null;
}
}
}
// Look-Ahead and find rest of the attributes.
pos = $.extend({}, constPos);
ctxNext = TokenUtils.getInitialContext(editor._codeMirror, pos);
while (TokenUtils.moveNextToken(ctxNext)) {
if (ctxNext.token.type === "string" && ctxNext.token.string === "\"") {
return null;
}
// Stop on closing bracket of its own tag or opening bracket of next tag.
if (ctxNext.token.type === "tag bracket" &&
(ctxNext.token.string.indexOf(">") >= 0 || ctxNext.token.string === "<")) {
break;
}
if (ctxNext.token.type === "attribute" && exclusionList.indexOf(ctxNext.token.string) === -1) {
exclusionList.push(ctxNext.token.string);
}
}
return {
tagName: tagName,
exclusionList: exclusionList,
shouldReplace: shouldReplace
};
}
|
[
"function",
"_getTagAttributes",
"(",
"editor",
",",
"constPos",
")",
"{",
"var",
"pos",
",",
"ctx",
",",
"ctxPrev",
",",
"ctxNext",
",",
"ctxTemp",
",",
"tagName",
",",
"exclusionList",
"=",
"[",
"]",
",",
"shouldReplace",
";",
"pos",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"constPos",
")",
";",
"ctx",
"=",
"TokenUtils",
".",
"getInitialContext",
"(",
"editor",
".",
"_codeMirror",
",",
"pos",
")",
";",
"ctxTemp",
"=",
"$",
".",
"extend",
"(",
"true",
",",
"{",
"}",
",",
"ctx",
")",
";",
"if",
"(",
"ctxTemp",
".",
"token",
".",
"type",
"===",
"null",
"&&",
"regexWhitespace",
".",
"test",
"(",
"ctxTemp",
".",
"token",
".",
"string",
")",
")",
"{",
"if",
"(",
"TokenUtils",
".",
"moveSkippingWhitespace",
"(",
"TokenUtils",
".",
"moveNextToken",
",",
"ctxTemp",
")",
")",
"{",
"if",
"(",
"(",
"ctxTemp",
".",
"token",
".",
"type",
"===",
"null",
"&&",
"ctxTemp",
".",
"token",
".",
"string",
"===",
"\"=\"",
")",
"||",
"ctxTemp",
".",
"token",
".",
"type",
"===",
"\"string\"",
")",
"{",
"return",
"null",
";",
"}",
"TokenUtils",
".",
"moveSkippingWhitespace",
"(",
"TokenUtils",
".",
"movePrevToken",
",",
"ctxTemp",
")",
";",
"}",
"}",
"if",
"(",
"ctxTemp",
".",
"token",
".",
"type",
"===",
"\"attribute\"",
")",
"{",
"if",
"(",
"TokenUtils",
".",
"moveSkippingWhitespace",
"(",
"TokenUtils",
".",
"moveNextToken",
",",
"ctxTemp",
")",
")",
"{",
"if",
"(",
"ctxTemp",
".",
"token",
".",
"type",
"===",
"null",
"&&",
"ctxTemp",
".",
"token",
".",
"string",
"===",
"\"=\"",
")",
"{",
"shouldReplace",
"=",
"true",
";",
"}",
"}",
"}",
"pos",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"constPos",
")",
";",
"ctxPrev",
"=",
"TokenUtils",
".",
"getInitialContext",
"(",
"editor",
".",
"_codeMirror",
",",
"pos",
")",
";",
"while",
"(",
"TokenUtils",
".",
"movePrevToken",
"(",
"ctxPrev",
")",
")",
"{",
"if",
"(",
"ctxPrev",
".",
"token",
".",
"type",
"&&",
"ctxPrev",
".",
"token",
".",
"type",
".",
"indexOf",
"(",
"\"tag bracket\"",
")",
">=",
"0",
")",
"{",
"if",
"(",
"ctxPrev",
".",
"token",
".",
"string",
"===",
"\"</\"",
"||",
"ctxPrev",
".",
"token",
".",
"string",
".",
"indexOf",
"(",
"\">\"",
")",
"!==",
"-",
"1",
")",
"{",
"return",
"null",
";",
"}",
"}",
"if",
"(",
"ctxPrev",
".",
"token",
".",
"type",
"===",
"\"attribute\"",
")",
"{",
"exclusionList",
".",
"push",
"(",
"ctxPrev",
".",
"token",
".",
"string",
")",
";",
"}",
"if",
"(",
"ctxPrev",
".",
"token",
".",
"type",
"===",
"\"tag\"",
")",
"{",
"tagName",
"=",
"ctxPrev",
".",
"token",
".",
"string",
";",
"if",
"(",
"TokenUtils",
".",
"movePrevToken",
"(",
"ctxPrev",
")",
")",
"{",
"if",
"(",
"ctxPrev",
".",
"token",
".",
"type",
"===",
"\"tag bracket\"",
"&&",
"ctxPrev",
".",
"token",
".",
"string",
"===",
"\"<\"",
")",
"{",
"break",
";",
"}",
"return",
"null",
";",
"}",
"}",
"}",
"pos",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"constPos",
")",
";",
"ctxNext",
"=",
"TokenUtils",
".",
"getInitialContext",
"(",
"editor",
".",
"_codeMirror",
",",
"pos",
")",
";",
"while",
"(",
"TokenUtils",
".",
"moveNextToken",
"(",
"ctxNext",
")",
")",
"{",
"if",
"(",
"ctxNext",
".",
"token",
".",
"type",
"===",
"\"string\"",
"&&",
"ctxNext",
".",
"token",
".",
"string",
"===",
"\"\\\"\"",
")",
"\\\"",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"ctxNext",
".",
"token",
".",
"type",
"===",
"\"tag bracket\"",
"&&",
"(",
"ctxNext",
".",
"token",
".",
"string",
".",
"indexOf",
"(",
"\">\"",
")",
">=",
"0",
"||",
"ctxNext",
".",
"token",
".",
"string",
"===",
"\"<\"",
")",
")",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"ctxNext",
".",
"token",
".",
"type",
"===",
"\"attribute\"",
"&&",
"exclusionList",
".",
"indexOf",
"(",
"ctxNext",
".",
"token",
".",
"string",
")",
"===",
"-",
"1",
")",
"{",
"exclusionList",
".",
"push",
"(",
"ctxNext",
".",
"token",
".",
"string",
")",
";",
"}",
"}"
] |
Return the tagName and a list of attributes used by the tag.
@param {!Editor} editor An instance of active editor
@param {!{line: number, ch: number}} constPos The position of cursor in the active editor
@return {!{tagName: string, exclusionList: Array.<string>, shouldReplace: boolean}}
|
[
"Return",
"the",
"tagName",
"and",
"a",
"list",
"of",
"attributes",
"used",
"by",
"the",
"tag",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/XMLUtils.js#L69-L147
|
train
|
adobe/brackets
|
src/language/XMLUtils.js
|
_getTagAttributeValue
|
function _getTagAttributeValue(editor, pos) {
var ctx, tagName, attrName, exclusionList = [], offset, textBefore, textAfter;
ctx = TokenUtils.getInitialContext(editor._codeMirror, pos);
offset = TokenUtils.offsetInToken(ctx);
// To support multiple options on the same attribute, we have
// to break the value, these values will not be available then.
if (ctx.token.type === "string" && /\s+/.test(ctx.token.string)) {
textBefore = ctx.token.string.substr(1, offset);
textAfter = ctx.token.string.substr(offset);
// Remove quote from end of the string.
if (/^['"]$/.test(ctx.token.string.substr(-1, 1))) {
textAfter = textAfter.substr(0, textAfter.length - 1);
}
// Split the text before and after the offset, skipping the current query.
exclusionList = exclusionList.concat(textBefore.split(/\s+/).slice(0, -1));
exclusionList = exclusionList.concat(textAfter.split(/\s+/));
// Filter through the list removing empty strings.
exclusionList = exclusionList.filter(function (value) {
if (value.length > 0) {
return true;
}
});
}
// Look-back and find tag and attributes.
while (TokenUtils.movePrevToken(ctx)) {
if (ctx.token.type === "tag bracket") {
// Disallow hints in closing tags.
if (ctx.token.string === "</") {
return null;
}
// Stop when closing bracket of another tag or opening bracket of its own in encountered.
if (ctx.token.string.indexOf(">") >= 0 || ctx.token.string === "<") {
break;
}
}
// Get the first previous attribute.
if (ctx.token.type === "attribute" && !attrName) {
attrName = ctx.token.string;
}
// Stop if we get a bracket after tag.
if (ctx.token.type === "tag") {
tagName = ctx.token.string;
if (TokenUtils.movePrevToken(ctx)) {
if (ctx.token.type === "tag bracket" && ctx.token.string === "<") {
break;
}
return null;
}
}
}
return {
tagName: tagName,
attrName: attrName,
exclusionList: exclusionList
};
}
|
javascript
|
function _getTagAttributeValue(editor, pos) {
var ctx, tagName, attrName, exclusionList = [], offset, textBefore, textAfter;
ctx = TokenUtils.getInitialContext(editor._codeMirror, pos);
offset = TokenUtils.offsetInToken(ctx);
// To support multiple options on the same attribute, we have
// to break the value, these values will not be available then.
if (ctx.token.type === "string" && /\s+/.test(ctx.token.string)) {
textBefore = ctx.token.string.substr(1, offset);
textAfter = ctx.token.string.substr(offset);
// Remove quote from end of the string.
if (/^['"]$/.test(ctx.token.string.substr(-1, 1))) {
textAfter = textAfter.substr(0, textAfter.length - 1);
}
// Split the text before and after the offset, skipping the current query.
exclusionList = exclusionList.concat(textBefore.split(/\s+/).slice(0, -1));
exclusionList = exclusionList.concat(textAfter.split(/\s+/));
// Filter through the list removing empty strings.
exclusionList = exclusionList.filter(function (value) {
if (value.length > 0) {
return true;
}
});
}
// Look-back and find tag and attributes.
while (TokenUtils.movePrevToken(ctx)) {
if (ctx.token.type === "tag bracket") {
// Disallow hints in closing tags.
if (ctx.token.string === "</") {
return null;
}
// Stop when closing bracket of another tag or opening bracket of its own in encountered.
if (ctx.token.string.indexOf(">") >= 0 || ctx.token.string === "<") {
break;
}
}
// Get the first previous attribute.
if (ctx.token.type === "attribute" && !attrName) {
attrName = ctx.token.string;
}
// Stop if we get a bracket after tag.
if (ctx.token.type === "tag") {
tagName = ctx.token.string;
if (TokenUtils.movePrevToken(ctx)) {
if (ctx.token.type === "tag bracket" && ctx.token.string === "<") {
break;
}
return null;
}
}
}
return {
tagName: tagName,
attrName: attrName,
exclusionList: exclusionList
};
}
|
[
"function",
"_getTagAttributeValue",
"(",
"editor",
",",
"pos",
")",
"{",
"var",
"ctx",
",",
"tagName",
",",
"attrName",
",",
"exclusionList",
"=",
"[",
"]",
",",
"offset",
",",
"textBefore",
",",
"textAfter",
";",
"ctx",
"=",
"TokenUtils",
".",
"getInitialContext",
"(",
"editor",
".",
"_codeMirror",
",",
"pos",
")",
";",
"offset",
"=",
"TokenUtils",
".",
"offsetInToken",
"(",
"ctx",
")",
";",
"if",
"(",
"ctx",
".",
"token",
".",
"type",
"===",
"\"string\"",
"&&",
"/",
"\\s+",
"/",
".",
"test",
"(",
"ctx",
".",
"token",
".",
"string",
")",
")",
"{",
"textBefore",
"=",
"ctx",
".",
"token",
".",
"string",
".",
"substr",
"(",
"1",
",",
"offset",
")",
";",
"textAfter",
"=",
"ctx",
".",
"token",
".",
"string",
".",
"substr",
"(",
"offset",
")",
";",
"if",
"(",
"/",
"^['\"]$",
"/",
".",
"test",
"(",
"ctx",
".",
"token",
".",
"string",
".",
"substr",
"(",
"-",
"1",
",",
"1",
")",
")",
")",
"{",
"textAfter",
"=",
"textAfter",
".",
"substr",
"(",
"0",
",",
"textAfter",
".",
"length",
"-",
"1",
")",
";",
"}",
"exclusionList",
"=",
"exclusionList",
".",
"concat",
"(",
"textBefore",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
".",
"slice",
"(",
"0",
",",
"-",
"1",
")",
")",
";",
"exclusionList",
"=",
"exclusionList",
".",
"concat",
"(",
"textAfter",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
")",
";",
"exclusionList",
"=",
"exclusionList",
".",
"filter",
"(",
"function",
"(",
"value",
")",
"{",
"if",
"(",
"value",
".",
"length",
">",
"0",
")",
"{",
"return",
"true",
";",
"}",
"}",
")",
";",
"}",
"while",
"(",
"TokenUtils",
".",
"movePrevToken",
"(",
"ctx",
")",
")",
"{",
"if",
"(",
"ctx",
".",
"token",
".",
"type",
"===",
"\"tag bracket\"",
")",
"{",
"if",
"(",
"ctx",
".",
"token",
".",
"string",
"===",
"\"</\"",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"ctx",
".",
"token",
".",
"string",
".",
"indexOf",
"(",
"\">\"",
")",
">=",
"0",
"||",
"ctx",
".",
"token",
".",
"string",
"===",
"\"<\"",
")",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"ctx",
".",
"token",
".",
"type",
"===",
"\"attribute\"",
"&&",
"!",
"attrName",
")",
"{",
"attrName",
"=",
"ctx",
".",
"token",
".",
"string",
";",
"}",
"if",
"(",
"ctx",
".",
"token",
".",
"type",
"===",
"\"tag\"",
")",
"{",
"tagName",
"=",
"ctx",
".",
"token",
".",
"string",
";",
"if",
"(",
"TokenUtils",
".",
"movePrevToken",
"(",
"ctx",
")",
")",
"{",
"if",
"(",
"ctx",
".",
"token",
".",
"type",
"===",
"\"tag bracket\"",
"&&",
"ctx",
".",
"token",
".",
"string",
"===",
"\"<\"",
")",
"{",
"break",
";",
"}",
"return",
"null",
";",
"}",
"}",
"}",
"return",
"{",
"tagName",
":",
"tagName",
",",
"attrName",
":",
"attrName",
",",
"exclusionList",
":",
"exclusionList",
"}",
";",
"}"
] |
Return the tag name, attribute name and a list of options used by the attribute
@param {!Editor} editor An instance of active editor
@param {!{line: number, ch: number}} pos Position of cursor in the editor
@return {!{tagName: string, attrName: string, exclusionList: Array.<string>}}
|
[
"Return",
"the",
"tag",
"name",
"attribute",
"name",
"and",
"a",
"list",
"of",
"options",
"used",
"by",
"the",
"attribute"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/XMLUtils.js#L156-L220
|
train
|
adobe/brackets
|
src/language/XMLUtils.js
|
getTagInfo
|
function getTagInfo(editor, pos) {
var ctx, offset, tagAttrs, tagAttrValue;
ctx = TokenUtils.getInitialContext(editor._codeMirror, pos);
offset = TokenUtils.offsetInToken(ctx);
if (ctx.token && ctx.token.type === "tag bracket" && ctx.token.string === "<") {
// Returns tagInfo when an angle bracket is created.
return _createTagInfo(ctx.token, TOKEN_TAG);
} else if (ctx.token && ctx.token.type === "tag") {
// Return tagInfo when a tag is created.
if (TokenUtils.movePrevToken(ctx)) {
if (ctx.token.type === "tag bracket" && ctx.token.string === "<") {
TokenUtils.moveNextToken(ctx);
return _createTagInfo(ctx.token, TOKEN_TAG, offset);
}
}
} else if (ctx.token && (ctx.token.type === "attribute" ||
(ctx.token.type === null && regexWhitespace.test(ctx.token.string)))) {
// Return tagInfo when an attribute is created.
tagAttrs = _getTagAttributes(editor, pos);
if (tagAttrs && tagAttrs.tagName) {
return _createTagInfo(ctx.token, TOKEN_ATTR, offset, tagAttrs.exclusionList, tagAttrs.tagName, null, tagAttrs.shouldReplace);
}
} else if (ctx.token && ((ctx.token.type === null && ctx.token.string === "=") ||
(ctx.token.type === "string" && /^['"]$/.test(ctx.token.string.charAt(0))))) {
// Return tag info when an attribute value is created.
// Allow no hints if the cursor is outside the value.
if (ctx.token.type === "string" &&
/^['"]$/.test(ctx.token.string.substr(-1, 1)) &&
ctx.token.string.length !== 1 &&
ctx.token.end === pos.ch) {
return _createTagInfo();
}
tagAttrValue = _getTagAttributeValue(editor, pos);
if (tagAttrValue && tagAttrValue.tagName && tagAttrValue.attrName) {
return _createTagInfo(ctx.token, TOKEN_VALUE, offset, tagAttrValue.exclusionList, tagAttrValue.tagName, tagAttrValue.attrName);
}
}
return _createTagInfo();
}
|
javascript
|
function getTagInfo(editor, pos) {
var ctx, offset, tagAttrs, tagAttrValue;
ctx = TokenUtils.getInitialContext(editor._codeMirror, pos);
offset = TokenUtils.offsetInToken(ctx);
if (ctx.token && ctx.token.type === "tag bracket" && ctx.token.string === "<") {
// Returns tagInfo when an angle bracket is created.
return _createTagInfo(ctx.token, TOKEN_TAG);
} else if (ctx.token && ctx.token.type === "tag") {
// Return tagInfo when a tag is created.
if (TokenUtils.movePrevToken(ctx)) {
if (ctx.token.type === "tag bracket" && ctx.token.string === "<") {
TokenUtils.moveNextToken(ctx);
return _createTagInfo(ctx.token, TOKEN_TAG, offset);
}
}
} else if (ctx.token && (ctx.token.type === "attribute" ||
(ctx.token.type === null && regexWhitespace.test(ctx.token.string)))) {
// Return tagInfo when an attribute is created.
tagAttrs = _getTagAttributes(editor, pos);
if (tagAttrs && tagAttrs.tagName) {
return _createTagInfo(ctx.token, TOKEN_ATTR, offset, tagAttrs.exclusionList, tagAttrs.tagName, null, tagAttrs.shouldReplace);
}
} else if (ctx.token && ((ctx.token.type === null && ctx.token.string === "=") ||
(ctx.token.type === "string" && /^['"]$/.test(ctx.token.string.charAt(0))))) {
// Return tag info when an attribute value is created.
// Allow no hints if the cursor is outside the value.
if (ctx.token.type === "string" &&
/^['"]$/.test(ctx.token.string.substr(-1, 1)) &&
ctx.token.string.length !== 1 &&
ctx.token.end === pos.ch) {
return _createTagInfo();
}
tagAttrValue = _getTagAttributeValue(editor, pos);
if (tagAttrValue && tagAttrValue.tagName && tagAttrValue.attrName) {
return _createTagInfo(ctx.token, TOKEN_VALUE, offset, tagAttrValue.exclusionList, tagAttrValue.tagName, tagAttrValue.attrName);
}
}
return _createTagInfo();
}
|
[
"function",
"getTagInfo",
"(",
"editor",
",",
"pos",
")",
"{",
"var",
"ctx",
",",
"offset",
",",
"tagAttrs",
",",
"tagAttrValue",
";",
"ctx",
"=",
"TokenUtils",
".",
"getInitialContext",
"(",
"editor",
".",
"_codeMirror",
",",
"pos",
")",
";",
"offset",
"=",
"TokenUtils",
".",
"offsetInToken",
"(",
"ctx",
")",
";",
"if",
"(",
"ctx",
".",
"token",
"&&",
"ctx",
".",
"token",
".",
"type",
"===",
"\"tag bracket\"",
"&&",
"ctx",
".",
"token",
".",
"string",
"===",
"\"<\"",
")",
"{",
"return",
"_createTagInfo",
"(",
"ctx",
".",
"token",
",",
"TOKEN_TAG",
")",
";",
"}",
"else",
"if",
"(",
"ctx",
".",
"token",
"&&",
"ctx",
".",
"token",
".",
"type",
"===",
"\"tag\"",
")",
"{",
"if",
"(",
"TokenUtils",
".",
"movePrevToken",
"(",
"ctx",
")",
")",
"{",
"if",
"(",
"ctx",
".",
"token",
".",
"type",
"===",
"\"tag bracket\"",
"&&",
"ctx",
".",
"token",
".",
"string",
"===",
"\"<\"",
")",
"{",
"TokenUtils",
".",
"moveNextToken",
"(",
"ctx",
")",
";",
"return",
"_createTagInfo",
"(",
"ctx",
".",
"token",
",",
"TOKEN_TAG",
",",
"offset",
")",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"ctx",
".",
"token",
"&&",
"(",
"ctx",
".",
"token",
".",
"type",
"===",
"\"attribute\"",
"||",
"(",
"ctx",
".",
"token",
".",
"type",
"===",
"null",
"&&",
"regexWhitespace",
".",
"test",
"(",
"ctx",
".",
"token",
".",
"string",
")",
")",
")",
")",
"{",
"tagAttrs",
"=",
"_getTagAttributes",
"(",
"editor",
",",
"pos",
")",
";",
"if",
"(",
"tagAttrs",
"&&",
"tagAttrs",
".",
"tagName",
")",
"{",
"return",
"_createTagInfo",
"(",
"ctx",
".",
"token",
",",
"TOKEN_ATTR",
",",
"offset",
",",
"tagAttrs",
".",
"exclusionList",
",",
"tagAttrs",
".",
"tagName",
",",
"null",
",",
"tagAttrs",
".",
"shouldReplace",
")",
";",
"}",
"}",
"else",
"if",
"(",
"ctx",
".",
"token",
"&&",
"(",
"(",
"ctx",
".",
"token",
".",
"type",
"===",
"null",
"&&",
"ctx",
".",
"token",
".",
"string",
"===",
"\"=\"",
")",
"||",
"(",
"ctx",
".",
"token",
".",
"type",
"===",
"\"string\"",
"&&",
"/",
"^['\"]$",
"/",
".",
"test",
"(",
"ctx",
".",
"token",
".",
"string",
".",
"charAt",
"(",
"0",
")",
")",
")",
")",
")",
"{",
"if",
"(",
"ctx",
".",
"token",
".",
"type",
"===",
"\"string\"",
"&&",
"/",
"^['\"]$",
"/",
".",
"test",
"(",
"ctx",
".",
"token",
".",
"string",
".",
"substr",
"(",
"-",
"1",
",",
"1",
")",
")",
"&&",
"ctx",
".",
"token",
".",
"string",
".",
"length",
"!==",
"1",
"&&",
"ctx",
".",
"token",
".",
"end",
"===",
"pos",
".",
"ch",
")",
"{",
"return",
"_createTagInfo",
"(",
")",
";",
"}",
"tagAttrValue",
"=",
"_getTagAttributeValue",
"(",
"editor",
",",
"pos",
")",
";",
"if",
"(",
"tagAttrValue",
"&&",
"tagAttrValue",
".",
"tagName",
"&&",
"tagAttrValue",
".",
"attrName",
")",
"{",
"return",
"_createTagInfo",
"(",
"ctx",
".",
"token",
",",
"TOKEN_VALUE",
",",
"offset",
",",
"tagAttrValue",
".",
"exclusionList",
",",
"tagAttrValue",
".",
"tagName",
",",
"tagAttrValue",
".",
"attrName",
")",
";",
"}",
"}",
"return",
"_createTagInfo",
"(",
")",
";",
"}"
] |
Return the tag info at a given position in the active editor
@param {!Editor} editor Instance of active editor
@param {!{line: number, ch: number}} pos Position of cursor in the editor
@return {!{token: Object, tokenType: number, offset: number, exclusionList: Array.<string>, tagName: string, attrName: string, shouldReplace: boolean}}
|
[
"Return",
"the",
"tag",
"info",
"at",
"a",
"given",
"position",
"in",
"the",
"active",
"editor"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/XMLUtils.js#L229-L270
|
train
|
adobe/brackets
|
src/language/XMLUtils.js
|
getValueQuery
|
function getValueQuery(tagInfo) {
var query;
if (tagInfo.token.string === "=") {
return "";
}
// Remove quotation marks in query.
query = tagInfo.token.string.substr(1, tagInfo.offset - 1);
// Get the last option to use as a query to support multiple options.
return query.split(/\s+/).slice(-1)[0];
}
|
javascript
|
function getValueQuery(tagInfo) {
var query;
if (tagInfo.token.string === "=") {
return "";
}
// Remove quotation marks in query.
query = tagInfo.token.string.substr(1, tagInfo.offset - 1);
// Get the last option to use as a query to support multiple options.
return query.split(/\s+/).slice(-1)[0];
}
|
[
"function",
"getValueQuery",
"(",
"tagInfo",
")",
"{",
"var",
"query",
";",
"if",
"(",
"tagInfo",
".",
"token",
".",
"string",
"===",
"\"=\"",
")",
"{",
"return",
"\"\"",
";",
"}",
"query",
"=",
"tagInfo",
".",
"token",
".",
"string",
".",
"substr",
"(",
"1",
",",
"tagInfo",
".",
"offset",
"-",
"1",
")",
";",
"return",
"query",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
".",
"slice",
"(",
"-",
"1",
")",
"[",
"0",
"]",
";",
"}"
] |
Return the query text of a value.
@param {!{token: Object, tokenType: number, offset: number, exclusionList: Array.<string>, tagName: string, attrName: string, shouldReplace: boolean}}
@return {string} The query to use to matching hints.
|
[
"Return",
"the",
"query",
"text",
"of",
"a",
"value",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/XMLUtils.js#L278-L288
|
train
|
adobe/brackets
|
src/utils/ExtensionUtils.js
|
isAbsolutePathOrUrl
|
function isAbsolutePathOrUrl(pathOrUrl) {
return brackets.platform === "win" ? PathUtils.isAbsoluteUrl(pathOrUrl) : FileSystem.isAbsolutePath(pathOrUrl);
}
|
javascript
|
function isAbsolutePathOrUrl(pathOrUrl) {
return brackets.platform === "win" ? PathUtils.isAbsoluteUrl(pathOrUrl) : FileSystem.isAbsolutePath(pathOrUrl);
}
|
[
"function",
"isAbsolutePathOrUrl",
"(",
"pathOrUrl",
")",
"{",
"return",
"brackets",
".",
"platform",
"===",
"\"win\"",
"?",
"PathUtils",
".",
"isAbsoluteUrl",
"(",
"pathOrUrl",
")",
":",
"FileSystem",
".",
"isAbsolutePath",
"(",
"pathOrUrl",
")",
";",
"}"
] |
getModuleUrl returns different urls for win platform
so that's why we need a different check here
@see #getModuleUrl
@param {!string} pathOrUrl that should be checked if it's absolute
@return {!boolean} returns true if pathOrUrl is absolute url on win platform
or when it's absolute path on other platforms
|
[
"getModuleUrl",
"returns",
"different",
"urls",
"for",
"win",
"platform",
"so",
"that",
"s",
"why",
"we",
"need",
"a",
"different",
"check",
"here"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ExtensionUtils.js#L81-L83
|
train
|
adobe/brackets
|
src/utils/ExtensionUtils.js
|
parseLessCode
|
function parseLessCode(code, url) {
var result = new $.Deferred(),
options;
if (url) {
var dir = url.slice(0, url.lastIndexOf("/") + 1);
options = {
filename: url,
rootpath: dir
};
if (isAbsolutePathOrUrl(url)) {
options.currentFileInfo = {
currentDirectory: dir,
entryPath: dir,
filename: url,
rootFilename: url,
rootpath: dir
};
}
}
less.render(code, options, function onParse(err, tree) {
if (err) {
result.reject(err);
} else {
result.resolve(tree.css);
}
});
return result.promise();
}
|
javascript
|
function parseLessCode(code, url) {
var result = new $.Deferred(),
options;
if (url) {
var dir = url.slice(0, url.lastIndexOf("/") + 1);
options = {
filename: url,
rootpath: dir
};
if (isAbsolutePathOrUrl(url)) {
options.currentFileInfo = {
currentDirectory: dir,
entryPath: dir,
filename: url,
rootFilename: url,
rootpath: dir
};
}
}
less.render(code, options, function onParse(err, tree) {
if (err) {
result.reject(err);
} else {
result.resolve(tree.css);
}
});
return result.promise();
}
|
[
"function",
"parseLessCode",
"(",
"code",
",",
"url",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
",",
"options",
";",
"if",
"(",
"url",
")",
"{",
"var",
"dir",
"=",
"url",
".",
"slice",
"(",
"0",
",",
"url",
".",
"lastIndexOf",
"(",
"\"/\"",
")",
"+",
"1",
")",
";",
"options",
"=",
"{",
"filename",
":",
"url",
",",
"rootpath",
":",
"dir",
"}",
";",
"if",
"(",
"isAbsolutePathOrUrl",
"(",
"url",
")",
")",
"{",
"options",
".",
"currentFileInfo",
"=",
"{",
"currentDirectory",
":",
"dir",
",",
"entryPath",
":",
"dir",
",",
"filename",
":",
"url",
",",
"rootFilename",
":",
"url",
",",
"rootpath",
":",
"dir",
"}",
";",
"}",
"}",
"less",
".",
"render",
"(",
"code",
",",
"options",
",",
"function",
"onParse",
"(",
"err",
",",
"tree",
")",
"{",
"if",
"(",
"err",
")",
"{",
"result",
".",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"result",
".",
"resolve",
"(",
"tree",
".",
"css",
")",
";",
"}",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Parses LESS code and returns a promise that resolves with plain CSS code.
Pass the {@link url} argument to resolve relative URLs contained in the code.
Make sure URLs in the code are wrapped in quotes, like so:
background-image: url("image.png");
@param {!string} code LESS code to parse
@param {?string} url URL to the file containing the code
@return {!$.Promise} A promise object that is resolved with CSS code if the LESS code can be parsed
|
[
"Parses",
"LESS",
"code",
"and",
"returns",
"a",
"promise",
"that",
"resolves",
"with",
"plain",
"CSS",
"code",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ExtensionUtils.js#L96-L128
|
train
|
adobe/brackets
|
src/utils/ExtensionUtils.js
|
getModulePath
|
function getModulePath(module, path) {
var modulePath = module.uri.substr(0, module.uri.lastIndexOf("/") + 1);
if (path) {
modulePath += path;
}
return modulePath;
}
|
javascript
|
function getModulePath(module, path) {
var modulePath = module.uri.substr(0, module.uri.lastIndexOf("/") + 1);
if (path) {
modulePath += path;
}
return modulePath;
}
|
[
"function",
"getModulePath",
"(",
"module",
",",
"path",
")",
"{",
"var",
"modulePath",
"=",
"module",
".",
"uri",
".",
"substr",
"(",
"0",
",",
"module",
".",
"uri",
".",
"lastIndexOf",
"(",
"\"/\"",
")",
"+",
"1",
")",
";",
"if",
"(",
"path",
")",
"{",
"modulePath",
"+=",
"path",
";",
"}",
"return",
"modulePath",
";",
"}"
] |
Returns a path to an extension module.
@param {!module} module Module provided by RequireJS
@param {?string} path Relative path from the extension folder to a file
@return {!string} The path to the module's folder
|
[
"Returns",
"a",
"path",
"to",
"an",
"extension",
"module",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ExtensionUtils.js#L137-L144
|
train
|
adobe/brackets
|
src/utils/ExtensionUtils.js
|
getModuleUrl
|
function getModuleUrl(module, path) {
var url = encodeURI(getModulePath(module, path));
// On Windows, $.get() fails if the url is a full pathname. To work around this,
// prepend "file:///". On the Mac, $.get() works fine if the url is a full pathname,
// but *doesn't* work if it is prepended with "file://". Go figure.
// However, the prefix "file://localhost" does work.
if (brackets.platform === "win" && url.indexOf(":") !== -1) {
url = "file:///" + url;
}
return url;
}
|
javascript
|
function getModuleUrl(module, path) {
var url = encodeURI(getModulePath(module, path));
// On Windows, $.get() fails if the url is a full pathname. To work around this,
// prepend "file:///". On the Mac, $.get() works fine if the url is a full pathname,
// but *doesn't* work if it is prepended with "file://". Go figure.
// However, the prefix "file://localhost" does work.
if (brackets.platform === "win" && url.indexOf(":") !== -1) {
url = "file:///" + url;
}
return url;
}
|
[
"function",
"getModuleUrl",
"(",
"module",
",",
"path",
")",
"{",
"var",
"url",
"=",
"encodeURI",
"(",
"getModulePath",
"(",
"module",
",",
"path",
")",
")",
";",
"if",
"(",
"brackets",
".",
"platform",
"===",
"\"win\"",
"&&",
"url",
".",
"indexOf",
"(",
"\":\"",
")",
"!==",
"-",
"1",
")",
"{",
"url",
"=",
"\"file:///\"",
"+",
"url",
";",
"}",
"return",
"url",
";",
"}"
] |
Returns a URL to an extension module.
@param {!module} module Module provided by RequireJS
@param {?string} path Relative path from the extension folder to a file
@return {!string} The URL to the module's folder
|
[
"Returns",
"a",
"URL",
"to",
"an",
"extension",
"module",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ExtensionUtils.js#L153-L165
|
train
|
adobe/brackets
|
src/utils/ExtensionUtils.js
|
loadFile
|
function loadFile(module, path) {
var url = PathUtils.isAbsoluteUrl(path) ? path : getModuleUrl(module, path),
promise = $.get(url);
return promise;
}
|
javascript
|
function loadFile(module, path) {
var url = PathUtils.isAbsoluteUrl(path) ? path : getModuleUrl(module, path),
promise = $.get(url);
return promise;
}
|
[
"function",
"loadFile",
"(",
"module",
",",
"path",
")",
"{",
"var",
"url",
"=",
"PathUtils",
".",
"isAbsoluteUrl",
"(",
"path",
")",
"?",
"path",
":",
"getModuleUrl",
"(",
"module",
",",
"path",
")",
",",
"promise",
"=",
"$",
".",
"get",
"(",
"url",
")",
";",
"return",
"promise",
";",
"}"
] |
Performs a GET request using a path relative to an extension module.
The resulting URL can be retrieved in the resolve callback by accessing
@param {!module} module Module provided by RequireJS
@param {!string} path Relative path from the extension folder to a file
@return {!$.Promise} A promise object that is resolved with the contents of the requested file
|
[
"Performs",
"a",
"GET",
"request",
"using",
"a",
"path",
"relative",
"to",
"an",
"extension",
"module",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ExtensionUtils.js#L176-L181
|
train
|
adobe/brackets
|
src/utils/ExtensionUtils.js
|
loadMetadata
|
function loadMetadata(folder) {
var packageJSONFile = FileSystem.getFileForPath(folder + "/package.json"),
disabledFile = FileSystem.getFileForPath(folder + "/.disabled"),
baseName = FileUtils.getBaseName(folder),
result = new $.Deferred(),
jsonPromise = new $.Deferred(),
disabledPromise = new $.Deferred(),
json,
disabled;
FileUtils.readAsText(packageJSONFile)
.then(function (text) {
try {
json = JSON.parse(text);
jsonPromise.resolve();
} catch (e) {
jsonPromise.reject();
}
})
.fail(jsonPromise.reject);
disabledFile.exists(function (err, exists) {
if (err) {
disabled = false;
} else {
disabled = exists;
}
var defaultDisabled = PreferencesManager.get("extensions.default.disabled");
if (Array.isArray(defaultDisabled) && defaultDisabled.indexOf(folder) !== -1) {
console.warn("Default extension has been disabled on startup: " + baseName);
disabled = true;
}
disabledPromise.resolve();
});
Async.waitForAll([jsonPromise, disabledPromise])
.always(function () {
if (!json) {
// if we don't have any metadata for the extension
// we should still create an empty one, so we can attach
// disabled property on it in case it's disabled
json = {
name: baseName
};
}
json.disabled = disabled;
result.resolve(json);
});
return result.promise();
}
|
javascript
|
function loadMetadata(folder) {
var packageJSONFile = FileSystem.getFileForPath(folder + "/package.json"),
disabledFile = FileSystem.getFileForPath(folder + "/.disabled"),
baseName = FileUtils.getBaseName(folder),
result = new $.Deferred(),
jsonPromise = new $.Deferred(),
disabledPromise = new $.Deferred(),
json,
disabled;
FileUtils.readAsText(packageJSONFile)
.then(function (text) {
try {
json = JSON.parse(text);
jsonPromise.resolve();
} catch (e) {
jsonPromise.reject();
}
})
.fail(jsonPromise.reject);
disabledFile.exists(function (err, exists) {
if (err) {
disabled = false;
} else {
disabled = exists;
}
var defaultDisabled = PreferencesManager.get("extensions.default.disabled");
if (Array.isArray(defaultDisabled) && defaultDisabled.indexOf(folder) !== -1) {
console.warn("Default extension has been disabled on startup: " + baseName);
disabled = true;
}
disabledPromise.resolve();
});
Async.waitForAll([jsonPromise, disabledPromise])
.always(function () {
if (!json) {
// if we don't have any metadata for the extension
// we should still create an empty one, so we can attach
// disabled property on it in case it's disabled
json = {
name: baseName
};
}
json.disabled = disabled;
result.resolve(json);
});
return result.promise();
}
|
[
"function",
"loadMetadata",
"(",
"folder",
")",
"{",
"var",
"packageJSONFile",
"=",
"FileSystem",
".",
"getFileForPath",
"(",
"folder",
"+",
"\"/package.json\"",
")",
",",
"disabledFile",
"=",
"FileSystem",
".",
"getFileForPath",
"(",
"folder",
"+",
"\"/.disabled\"",
")",
",",
"baseName",
"=",
"FileUtils",
".",
"getBaseName",
"(",
"folder",
")",
",",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
",",
"jsonPromise",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
",",
"disabledPromise",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
",",
"json",
",",
"disabled",
";",
"FileUtils",
".",
"readAsText",
"(",
"packageJSONFile",
")",
".",
"then",
"(",
"function",
"(",
"text",
")",
"{",
"try",
"{",
"json",
"=",
"JSON",
".",
"parse",
"(",
"text",
")",
";",
"jsonPromise",
".",
"resolve",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"jsonPromise",
".",
"reject",
"(",
")",
";",
"}",
"}",
")",
".",
"fail",
"(",
"jsonPromise",
".",
"reject",
")",
";",
"disabledFile",
".",
"exists",
"(",
"function",
"(",
"err",
",",
"exists",
")",
"{",
"if",
"(",
"err",
")",
"{",
"disabled",
"=",
"false",
";",
"}",
"else",
"{",
"disabled",
"=",
"exists",
";",
"}",
"var",
"defaultDisabled",
"=",
"PreferencesManager",
".",
"get",
"(",
"\"extensions.default.disabled\"",
")",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"defaultDisabled",
")",
"&&",
"defaultDisabled",
".",
"indexOf",
"(",
"folder",
")",
"!==",
"-",
"1",
")",
"{",
"console",
".",
"warn",
"(",
"\"Default extension has been disabled on startup: \"",
"+",
"baseName",
")",
";",
"disabled",
"=",
"true",
";",
"}",
"disabledPromise",
".",
"resolve",
"(",
")",
";",
"}",
")",
";",
"Async",
".",
"waitForAll",
"(",
"[",
"jsonPromise",
",",
"disabledPromise",
"]",
")",
".",
"always",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"json",
")",
"{",
"json",
"=",
"{",
"name",
":",
"baseName",
"}",
";",
"}",
"json",
".",
"disabled",
"=",
"disabled",
";",
"result",
".",
"resolve",
"(",
"json",
")",
";",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Loads the package.json file in the given extension folder as well as any additional
metadata.
If there's a .disabled file in the extension directory, then the content of package.json
will be augmented with disabled property set to true. It will override whatever value of
disabled might be set.
@param {string} folder The extension folder.
@return {$.Promise} A promise object that is resolved with the parsed contents of the package.json file,
or rejected if there is no package.json with the boolean indicating whether .disabled file exists.
|
[
"Loads",
"the",
"package",
".",
"json",
"file",
"in",
"the",
"given",
"extension",
"folder",
"as",
"well",
"as",
"any",
"additional",
"metadata",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ExtensionUtils.js#L241-L289
|
train
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation.js
|
_markTags
|
function _markTags(cm, node) {
node.children.forEach(function (childNode) {
if (childNode.isElement()) {
_markTags(cm, childNode);
}
});
var mark = cm.markText(node.startPos, node.endPos);
mark.tagID = node.tagID;
}
|
javascript
|
function _markTags(cm, node) {
node.children.forEach(function (childNode) {
if (childNode.isElement()) {
_markTags(cm, childNode);
}
});
var mark = cm.markText(node.startPos, node.endPos);
mark.tagID = node.tagID;
}
|
[
"function",
"_markTags",
"(",
"cm",
",",
"node",
")",
"{",
"node",
".",
"children",
".",
"forEach",
"(",
"function",
"(",
"childNode",
")",
"{",
"if",
"(",
"childNode",
".",
"isElement",
"(",
")",
")",
"{",
"_markTags",
"(",
"cm",
",",
"childNode",
")",
";",
"}",
"}",
")",
";",
"var",
"mark",
"=",
"cm",
".",
"markText",
"(",
"node",
".",
"startPos",
",",
"node",
".",
"endPos",
")",
";",
"mark",
".",
"tagID",
"=",
"node",
".",
"tagID",
";",
"}"
] |
Recursively walks the SimpleDOM starting at node and marking
all tags in the CodeMirror instance. The more useful interface
is the _markTextFromDOM function which clears existing marks
before calling this function to create new ones.
@param {CodeMirror} cm CodeMirror instance in which to mark tags
@param {Object} node SimpleDOM node to use as the root for marking
|
[
"Recursively",
"walks",
"the",
"SimpleDOM",
"starting",
"at",
"node",
"and",
"marking",
"all",
"tags",
"in",
"the",
"CodeMirror",
"instance",
".",
"The",
"more",
"useful",
"interface",
"is",
"the",
"_markTextFromDOM",
"function",
"which",
"clears",
"existing",
"marks",
"before",
"calling",
"this",
"function",
"to",
"create",
"new",
"ones",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation.js#L192-L200
|
train
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation.js
|
_markTextFromDOM
|
function _markTextFromDOM(editor, dom) {
var cm = editor._codeMirror;
// Remove existing marks
var marks = cm.getAllMarks();
cm.operation(function () {
marks.forEach(function (mark) {
if (mark.hasOwnProperty("tagID")) {
mark.clear();
}
});
});
// Mark
_markTags(cm, dom);
}
|
javascript
|
function _markTextFromDOM(editor, dom) {
var cm = editor._codeMirror;
// Remove existing marks
var marks = cm.getAllMarks();
cm.operation(function () {
marks.forEach(function (mark) {
if (mark.hasOwnProperty("tagID")) {
mark.clear();
}
});
});
// Mark
_markTags(cm, dom);
}
|
[
"function",
"_markTextFromDOM",
"(",
"editor",
",",
"dom",
")",
"{",
"var",
"cm",
"=",
"editor",
".",
"_codeMirror",
";",
"var",
"marks",
"=",
"cm",
".",
"getAllMarks",
"(",
")",
";",
"cm",
".",
"operation",
"(",
"function",
"(",
")",
"{",
"marks",
".",
"forEach",
"(",
"function",
"(",
"mark",
")",
"{",
"if",
"(",
"mark",
".",
"hasOwnProperty",
"(",
"\"tagID\"",
")",
")",
"{",
"mark",
".",
"clear",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"_markTags",
"(",
"cm",
",",
"dom",
")",
";",
"}"
] |
Clears the marks from the document and creates new ones.
@param {Editor} editor Editor object holding this document
@param {Object} dom SimpleDOM root object that contains the parsed structure
|
[
"Clears",
"the",
"marks",
"from",
"the",
"document",
"and",
"creates",
"new",
"ones",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation.js#L208-L223
|
train
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation.js
|
scanDocument
|
function scanDocument(doc) {
if (!_cachedValues.hasOwnProperty(doc.file.fullPath)) {
// TODO: this doesn't seem to be correct any more. The DOM should never be "dirty" (i.e., out of sync
// with the editor) unless the doc is invalid.
// $(doc).on("change.htmlInstrumentation", function () {
// if (_cachedValues[doc.file.fullPath]) {
// _cachedValues[doc.file.fullPath].dirty = true;
// }
// });
// Assign to cache, but don't set a value yet
_cachedValues[doc.file.fullPath] = null;
}
var cachedValue = _cachedValues[doc.file.fullPath];
// TODO: No longer look at doc or cached value "dirty" settings, because even if the doc is dirty, the dom
// should generally be up to date unless the HTML is invalid. (However, the node offsets will be dirty of
// the dom was incrementally updated - we should note that somewhere.)
if (cachedValue && !cachedValue.invalid && cachedValue.timestamp === doc.diskTimestamp) {
return cachedValue.dom;
}
var text = doc.getText(),
dom = HTMLSimpleDOM.build(text);
if (dom) {
// Cache results
_cachedValues[doc.file.fullPath] = {
timestamp: doc.diskTimestamp,
dom: dom,
dirty: false
};
// Note that this was a full build, so we know that we can trust the node start/end offsets.
dom.fullBuild = true;
}
return dom;
}
|
javascript
|
function scanDocument(doc) {
if (!_cachedValues.hasOwnProperty(doc.file.fullPath)) {
// TODO: this doesn't seem to be correct any more. The DOM should never be "dirty" (i.e., out of sync
// with the editor) unless the doc is invalid.
// $(doc).on("change.htmlInstrumentation", function () {
// if (_cachedValues[doc.file.fullPath]) {
// _cachedValues[doc.file.fullPath].dirty = true;
// }
// });
// Assign to cache, but don't set a value yet
_cachedValues[doc.file.fullPath] = null;
}
var cachedValue = _cachedValues[doc.file.fullPath];
// TODO: No longer look at doc or cached value "dirty" settings, because even if the doc is dirty, the dom
// should generally be up to date unless the HTML is invalid. (However, the node offsets will be dirty of
// the dom was incrementally updated - we should note that somewhere.)
if (cachedValue && !cachedValue.invalid && cachedValue.timestamp === doc.diskTimestamp) {
return cachedValue.dom;
}
var text = doc.getText(),
dom = HTMLSimpleDOM.build(text);
if (dom) {
// Cache results
_cachedValues[doc.file.fullPath] = {
timestamp: doc.diskTimestamp,
dom: dom,
dirty: false
};
// Note that this was a full build, so we know that we can trust the node start/end offsets.
dom.fullBuild = true;
}
return dom;
}
|
[
"function",
"scanDocument",
"(",
"doc",
")",
"{",
"if",
"(",
"!",
"_cachedValues",
".",
"hasOwnProperty",
"(",
"doc",
".",
"file",
".",
"fullPath",
")",
")",
"{",
"_cachedValues",
"[",
"doc",
".",
"file",
".",
"fullPath",
"]",
"=",
"null",
";",
"}",
"var",
"cachedValue",
"=",
"_cachedValues",
"[",
"doc",
".",
"file",
".",
"fullPath",
"]",
";",
"if",
"(",
"cachedValue",
"&&",
"!",
"cachedValue",
".",
"invalid",
"&&",
"cachedValue",
".",
"timestamp",
"===",
"doc",
".",
"diskTimestamp",
")",
"{",
"return",
"cachedValue",
".",
"dom",
";",
"}",
"var",
"text",
"=",
"doc",
".",
"getText",
"(",
")",
",",
"dom",
"=",
"HTMLSimpleDOM",
".",
"build",
"(",
"text",
")",
";",
"if",
"(",
"dom",
")",
"{",
"_cachedValues",
"[",
"doc",
".",
"file",
".",
"fullPath",
"]",
"=",
"{",
"timestamp",
":",
"doc",
".",
"diskTimestamp",
",",
"dom",
":",
"dom",
",",
"dirty",
":",
"false",
"}",
";",
"dom",
".",
"fullBuild",
"=",
"true",
";",
"}",
"return",
"dom",
";",
"}"
] |
Parses the document, returning an HTMLSimpleDOM structure and caching it as the
initial state of the document. Will return a cached copy of the DOM if the
document hasn't changed since the last time scanDocument was called.
This is called by generateInstrumentedHTML(), but it can be useful to call it
ahead of time so the DOM is cached and doesn't need to be rescanned when the
instrumented HTML is requested by the browser.
@param {Document} doc The doc to scan.
@return {Object} Root DOM node of the document.
|
[
"Parses",
"the",
"document",
"returning",
"an",
"HTMLSimpleDOM",
"structure",
"and",
"caching",
"it",
"as",
"the",
"initial",
"state",
"of",
"the",
"document",
".",
"Will",
"return",
"a",
"cached",
"copy",
"of",
"the",
"DOM",
"if",
"the",
"document",
"hasn",
"t",
"changed",
"since",
"the",
"last",
"time",
"scanDocument",
"was",
"called",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation.js#L677-L714
|
train
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation.js
|
walk
|
function walk(node) {
if (node.tag) {
var attrText = " data-brackets-id='" + node.tagID + "'";
// If the dom was fully rebuilt, use its offsets. Otherwise, use the marks in the
// associated editor, since they'll be more up to date.
var startOffset;
if (dom.fullBuild) {
startOffset = node.start;
} else {
var mark = markCache[node.tagID];
if (mark) {
startOffset = editor._codeMirror.indexFromPos(mark.range.from);
} else {
console.warn("generateInstrumentedHTML(): couldn't find existing mark for tagID " + node.tagID);
startOffset = node.start;
}
}
// Insert the attribute as the first attribute in the tag.
var insertIndex = startOffset + node.tag.length + 1;
gen += orig.substr(lastIndex, insertIndex - lastIndex) + attrText;
lastIndex = insertIndex;
// If we have a script to inject and this is the head tag, inject it immediately
// after the open tag.
if (remoteScript && !remoteScriptInserted && node.tag === "head") {
insertIndex = node.openEnd;
gen += orig.substr(lastIndex, insertIndex - lastIndex) + remoteScript;
lastIndex = insertIndex;
remoteScriptInserted = true;
}
}
if (node.isElement()) {
node.children.forEach(walk);
}
}
|
javascript
|
function walk(node) {
if (node.tag) {
var attrText = " data-brackets-id='" + node.tagID + "'";
// If the dom was fully rebuilt, use its offsets. Otherwise, use the marks in the
// associated editor, since they'll be more up to date.
var startOffset;
if (dom.fullBuild) {
startOffset = node.start;
} else {
var mark = markCache[node.tagID];
if (mark) {
startOffset = editor._codeMirror.indexFromPos(mark.range.from);
} else {
console.warn("generateInstrumentedHTML(): couldn't find existing mark for tagID " + node.tagID);
startOffset = node.start;
}
}
// Insert the attribute as the first attribute in the tag.
var insertIndex = startOffset + node.tag.length + 1;
gen += orig.substr(lastIndex, insertIndex - lastIndex) + attrText;
lastIndex = insertIndex;
// If we have a script to inject and this is the head tag, inject it immediately
// after the open tag.
if (remoteScript && !remoteScriptInserted && node.tag === "head") {
insertIndex = node.openEnd;
gen += orig.substr(lastIndex, insertIndex - lastIndex) + remoteScript;
lastIndex = insertIndex;
remoteScriptInserted = true;
}
}
if (node.isElement()) {
node.children.forEach(walk);
}
}
|
[
"function",
"walk",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"tag",
")",
"{",
"var",
"attrText",
"=",
"\" data-brackets-id='\"",
"+",
"node",
".",
"tagID",
"+",
"\"'\"",
";",
"var",
"startOffset",
";",
"if",
"(",
"dom",
".",
"fullBuild",
")",
"{",
"startOffset",
"=",
"node",
".",
"start",
";",
"}",
"else",
"{",
"var",
"mark",
"=",
"markCache",
"[",
"node",
".",
"tagID",
"]",
";",
"if",
"(",
"mark",
")",
"{",
"startOffset",
"=",
"editor",
".",
"_codeMirror",
".",
"indexFromPos",
"(",
"mark",
".",
"range",
".",
"from",
")",
";",
"}",
"else",
"{",
"console",
".",
"warn",
"(",
"\"generateInstrumentedHTML(): couldn't find existing mark for tagID \"",
"+",
"node",
".",
"tagID",
")",
";",
"startOffset",
"=",
"node",
".",
"start",
";",
"}",
"}",
"var",
"insertIndex",
"=",
"startOffset",
"+",
"node",
".",
"tag",
".",
"length",
"+",
"1",
";",
"gen",
"+=",
"orig",
".",
"substr",
"(",
"lastIndex",
",",
"insertIndex",
"-",
"lastIndex",
")",
"+",
"attrText",
";",
"lastIndex",
"=",
"insertIndex",
";",
"if",
"(",
"remoteScript",
"&&",
"!",
"remoteScriptInserted",
"&&",
"node",
".",
"tag",
"===",
"\"head\"",
")",
"{",
"insertIndex",
"=",
"node",
".",
"openEnd",
";",
"gen",
"+=",
"orig",
".",
"substr",
"(",
"lastIndex",
",",
"insertIndex",
"-",
"lastIndex",
")",
"+",
"remoteScript",
";",
"lastIndex",
"=",
"insertIndex",
";",
"remoteScriptInserted",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"node",
".",
"isElement",
"(",
")",
")",
"{",
"node",
".",
"children",
".",
"forEach",
"(",
"walk",
")",
";",
"}",
"}"
] |
Walk through the dom nodes and insert the 'data-brackets-id' attribute at the end of the open tag
|
[
"Walk",
"through",
"the",
"dom",
"nodes",
"and",
"insert",
"the",
"data",
"-",
"brackets",
"-",
"id",
"attribute",
"at",
"the",
"end",
"of",
"the",
"open",
"tag"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation.js#L762-L799
|
train
|
adobe/brackets
|
src/extensions/default/JavaScriptCodeHints/main.js
|
setCachedHintContext
|
function setCachedHintContext(hints, cursor, type, token) {
cachedHints = hints;
cachedCursor = cursor;
cachedType = type;
cachedToken = token;
}
|
javascript
|
function setCachedHintContext(hints, cursor, type, token) {
cachedHints = hints;
cachedCursor = cursor;
cachedType = type;
cachedToken = token;
}
|
[
"function",
"setCachedHintContext",
"(",
"hints",
",",
"cursor",
",",
"type",
",",
"token",
")",
"{",
"cachedHints",
"=",
"hints",
";",
"cachedCursor",
"=",
"cursor",
";",
"cachedType",
"=",
"type",
";",
"cachedToken",
"=",
"token",
";",
"}"
] |
Cache the hints and the hint's context.
@param {Array.<string>} hints - array of hints
@param {{line:number, ch:number}} cursor - the location where the hints
were created.
@param {{property: boolean,
showFunctionType:boolean,
context: string,
functionCallPos: {line:number, ch:number}}} type -
type information about the hints
@param {Object} token - CodeMirror token
|
[
"Cache",
"the",
"hints",
"and",
"the",
"hint",
"s",
"context",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptCodeHints/main.js#L325-L330
|
train
|
adobe/brackets
|
src/extensions/default/JavaScriptCodeHints/main.js
|
getSessionHints
|
function getSessionHints(query, cursor, type, token, $deferredHints) {
var hintResults = session.getHints(query, getStringMatcher());
if (hintResults.needGuesses) {
var guessesResponse = ScopeManager.requestGuesses(session,
session.editor.document);
if (!$deferredHints) {
$deferredHints = $.Deferred();
}
guessesResponse.done(function () {
if (hintsArePending($deferredHints)) {
hintResults = session.getHints(query, getStringMatcher());
setCachedHintContext(hintResults.hints, cursor, type, token);
var hintResponse = getHintResponse(cachedHints, query, type);
$deferredHints.resolveWith(null, [hintResponse]);
}
}).fail(function () {
if (hintsArePending($deferredHints)) {
$deferredHints.reject();
}
});
return $deferredHints;
} else if (hintsArePending($deferredHints)) {
setCachedHintContext(hintResults.hints, cursor, type, token);
var hintResponse = getHintResponse(cachedHints, query, type);
$deferredHints.resolveWith(null, [hintResponse]);
return null;
} else {
setCachedHintContext(hintResults.hints, cursor, type, token);
return getHintResponse(cachedHints, query, type);
}
}
|
javascript
|
function getSessionHints(query, cursor, type, token, $deferredHints) {
var hintResults = session.getHints(query, getStringMatcher());
if (hintResults.needGuesses) {
var guessesResponse = ScopeManager.requestGuesses(session,
session.editor.document);
if (!$deferredHints) {
$deferredHints = $.Deferred();
}
guessesResponse.done(function () {
if (hintsArePending($deferredHints)) {
hintResults = session.getHints(query, getStringMatcher());
setCachedHintContext(hintResults.hints, cursor, type, token);
var hintResponse = getHintResponse(cachedHints, query, type);
$deferredHints.resolveWith(null, [hintResponse]);
}
}).fail(function () {
if (hintsArePending($deferredHints)) {
$deferredHints.reject();
}
});
return $deferredHints;
} else if (hintsArePending($deferredHints)) {
setCachedHintContext(hintResults.hints, cursor, type, token);
var hintResponse = getHintResponse(cachedHints, query, type);
$deferredHints.resolveWith(null, [hintResponse]);
return null;
} else {
setCachedHintContext(hintResults.hints, cursor, type, token);
return getHintResponse(cachedHints, query, type);
}
}
|
[
"function",
"getSessionHints",
"(",
"query",
",",
"cursor",
",",
"type",
",",
"token",
",",
"$deferredHints",
")",
"{",
"var",
"hintResults",
"=",
"session",
".",
"getHints",
"(",
"query",
",",
"getStringMatcher",
"(",
")",
")",
";",
"if",
"(",
"hintResults",
".",
"needGuesses",
")",
"{",
"var",
"guessesResponse",
"=",
"ScopeManager",
".",
"requestGuesses",
"(",
"session",
",",
"session",
".",
"editor",
".",
"document",
")",
";",
"if",
"(",
"!",
"$deferredHints",
")",
"{",
"$deferredHints",
"=",
"$",
".",
"Deferred",
"(",
")",
";",
"}",
"guessesResponse",
".",
"done",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"hintsArePending",
"(",
"$deferredHints",
")",
")",
"{",
"hintResults",
"=",
"session",
".",
"getHints",
"(",
"query",
",",
"getStringMatcher",
"(",
")",
")",
";",
"setCachedHintContext",
"(",
"hintResults",
".",
"hints",
",",
"cursor",
",",
"type",
",",
"token",
")",
";",
"var",
"hintResponse",
"=",
"getHintResponse",
"(",
"cachedHints",
",",
"query",
",",
"type",
")",
";",
"$deferredHints",
".",
"resolveWith",
"(",
"null",
",",
"[",
"hintResponse",
"]",
")",
";",
"}",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"hintsArePending",
"(",
"$deferredHints",
")",
")",
"{",
"$deferredHints",
".",
"reject",
"(",
")",
";",
"}",
"}",
")",
";",
"return",
"$deferredHints",
";",
"}",
"else",
"if",
"(",
"hintsArePending",
"(",
"$deferredHints",
")",
")",
"{",
"setCachedHintContext",
"(",
"hintResults",
".",
"hints",
",",
"cursor",
",",
"type",
",",
"token",
")",
";",
"var",
"hintResponse",
"=",
"getHintResponse",
"(",
"cachedHints",
",",
"query",
",",
"type",
")",
";",
"$deferredHints",
".",
"resolveWith",
"(",
"null",
",",
"[",
"hintResponse",
"]",
")",
";",
"return",
"null",
";",
"}",
"else",
"{",
"setCachedHintContext",
"(",
"hintResults",
".",
"hints",
",",
"cursor",
",",
"type",
",",
"token",
")",
";",
"return",
"getHintResponse",
"(",
"cachedHints",
",",
"query",
",",
"type",
")",
";",
"}",
"}"
] |
Common code to get the session hints. Will get guesses if there were
no completions for the query.
@param {string} query - user text to search hints with
@param {{line:number, ch:number}} cursor - the location where the hints
were created.
@param {{property: boolean,
showFunctionType:boolean,
context: string,
functionCallPos: {line:number, ch:number}}} type -
type information about the hints
@param {Object} token - CodeMirror token
@param {jQuery.Deferred=} $deferredHints - existing Deferred we need to
resolve (optional). If not supplied a new Deferred will be created if
needed.
@return {Object + jQuery.Deferred} - hint response (immediate or
deferred) as defined by the CodeHintManager API
|
[
"Common",
"code",
"to",
"get",
"the",
"session",
"hints",
".",
"Will",
"get",
"guesses",
"if",
"there",
"were",
"no",
"completions",
"for",
"the",
"query",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptCodeHints/main.js#L442-L476
|
train
|
adobe/brackets
|
src/extensions/default/JavaScriptCodeHints/main.js
|
requestJumpToDef
|
function requestJumpToDef(session, offset) {
var response = ScopeManager.requestJumptoDef(session, session.editor.document, offset);
if (response.hasOwnProperty("promise")) {
response.promise.done(handleJumpResponse).fail(function () {
result.reject();
});
}
}
|
javascript
|
function requestJumpToDef(session, offset) {
var response = ScopeManager.requestJumptoDef(session, session.editor.document, offset);
if (response.hasOwnProperty("promise")) {
response.promise.done(handleJumpResponse).fail(function () {
result.reject();
});
}
}
|
[
"function",
"requestJumpToDef",
"(",
"session",
",",
"offset",
")",
"{",
"var",
"response",
"=",
"ScopeManager",
".",
"requestJumptoDef",
"(",
"session",
",",
"session",
".",
"editor",
".",
"document",
",",
"offset",
")",
";",
"if",
"(",
"response",
".",
"hasOwnProperty",
"(",
"\"promise\"",
")",
")",
"{",
"response",
".",
"promise",
".",
"done",
"(",
"handleJumpResponse",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"}",
"}"
] |
Make a jump-to-def request based on the session and offset passed in.
@param {Session} session - the session
@param {number} offset - the offset of where to jump from
|
[
"Make",
"a",
"jump",
"-",
"to",
"-",
"def",
"request",
"based",
"on",
"the",
"session",
"and",
"offset",
"passed",
"in",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptCodeHints/main.js#L753-L761
|
train
|
adobe/brackets
|
src/extensions/default/JavaScriptCodeHints/main.js
|
setJumpSelection
|
function setJumpSelection(start, end, isFunction) {
/**
* helper function to decide if the tokens on the RHS of an assignment
* look like an identifier, or member expr.
*/
function validIdOrProp(token) {
if (!token) {
return false;
}
if (token.string === ".") {
return true;
}
var type = token.type;
if (type === "variable-2" || type === "variable" || type === "property") {
return true;
}
return false;
}
var madeNewRequest = false;
if (isFunction) {
// When jumping to function defs, follow the chain back
// to get to the original function def
var cursor = {line: end.line, ch: end.ch},
prev = session._getPreviousToken(cursor),
next,
offset;
// see if the selection is preceded by a '.', indicating we're in a member expr
if (prev.string === ".") {
cursor = {line: end.line, ch: end.ch};
next = session.getNextToken(cursor, true);
// check if the next token indicates an assignment
if (next && next.string === "=") {
next = session.getNextToken(cursor, true);
// find the last token of the identifier, or member expr
while (validIdOrProp(next)) {
offset = session.getOffsetFromCursor({line: cursor.line, ch: next.end});
next = session.getNextToken(cursor, false);
}
if (offset) {
// trigger another jump to def based on the offset of the RHS
requestJumpToDef(session, offset);
madeNewRequest = true;
}
}
}
}
// We didn't make a new jump-to-def request, so we can resolve the promise
// and set the selection
if (!madeNewRequest) {
// set the selection
session.editor.setSelection(start, end, true);
result.resolve(true);
}
}
|
javascript
|
function setJumpSelection(start, end, isFunction) {
/**
* helper function to decide if the tokens on the RHS of an assignment
* look like an identifier, or member expr.
*/
function validIdOrProp(token) {
if (!token) {
return false;
}
if (token.string === ".") {
return true;
}
var type = token.type;
if (type === "variable-2" || type === "variable" || type === "property") {
return true;
}
return false;
}
var madeNewRequest = false;
if (isFunction) {
// When jumping to function defs, follow the chain back
// to get to the original function def
var cursor = {line: end.line, ch: end.ch},
prev = session._getPreviousToken(cursor),
next,
offset;
// see if the selection is preceded by a '.', indicating we're in a member expr
if (prev.string === ".") {
cursor = {line: end.line, ch: end.ch};
next = session.getNextToken(cursor, true);
// check if the next token indicates an assignment
if (next && next.string === "=") {
next = session.getNextToken(cursor, true);
// find the last token of the identifier, or member expr
while (validIdOrProp(next)) {
offset = session.getOffsetFromCursor({line: cursor.line, ch: next.end});
next = session.getNextToken(cursor, false);
}
if (offset) {
// trigger another jump to def based on the offset of the RHS
requestJumpToDef(session, offset);
madeNewRequest = true;
}
}
}
}
// We didn't make a new jump-to-def request, so we can resolve the promise
// and set the selection
if (!madeNewRequest) {
// set the selection
session.editor.setSelection(start, end, true);
result.resolve(true);
}
}
|
[
"function",
"setJumpSelection",
"(",
"start",
",",
"end",
",",
"isFunction",
")",
"{",
"function",
"validIdOrProp",
"(",
"token",
")",
"{",
"if",
"(",
"!",
"token",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"token",
".",
"string",
"===",
"\".\"",
")",
"{",
"return",
"true",
";",
"}",
"var",
"type",
"=",
"token",
".",
"type",
";",
"if",
"(",
"type",
"===",
"\"variable-2\"",
"||",
"type",
"===",
"\"variable\"",
"||",
"type",
"===",
"\"property\"",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
"var",
"madeNewRequest",
"=",
"false",
";",
"if",
"(",
"isFunction",
")",
"{",
"var",
"cursor",
"=",
"{",
"line",
":",
"end",
".",
"line",
",",
"ch",
":",
"end",
".",
"ch",
"}",
",",
"prev",
"=",
"session",
".",
"_getPreviousToken",
"(",
"cursor",
")",
",",
"next",
",",
"offset",
";",
"if",
"(",
"prev",
".",
"string",
"===",
"\".\"",
")",
"{",
"cursor",
"=",
"{",
"line",
":",
"end",
".",
"line",
",",
"ch",
":",
"end",
".",
"ch",
"}",
";",
"next",
"=",
"session",
".",
"getNextToken",
"(",
"cursor",
",",
"true",
")",
";",
"if",
"(",
"next",
"&&",
"next",
".",
"string",
"===",
"\"=\"",
")",
"{",
"next",
"=",
"session",
".",
"getNextToken",
"(",
"cursor",
",",
"true",
")",
";",
"while",
"(",
"validIdOrProp",
"(",
"next",
")",
")",
"{",
"offset",
"=",
"session",
".",
"getOffsetFromCursor",
"(",
"{",
"line",
":",
"cursor",
".",
"line",
",",
"ch",
":",
"next",
".",
"end",
"}",
")",
";",
"next",
"=",
"session",
".",
"getNextToken",
"(",
"cursor",
",",
"false",
")",
";",
"}",
"if",
"(",
"offset",
")",
"{",
"requestJumpToDef",
"(",
"session",
",",
"offset",
")",
";",
"madeNewRequest",
"=",
"true",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"!",
"madeNewRequest",
")",
"{",
"session",
".",
"editor",
".",
"setSelection",
"(",
"start",
",",
"end",
",",
"true",
")",
";",
"result",
".",
"resolve",
"(",
"true",
")",
";",
"}",
"}"
] |
Sets the selection to move the cursor to the result position.
Assumes that the editor has already changed files, if necessary.
Additionally, this will check to see if the selection looks like an
assignment to a member expression - if it is, and the type is a function,
then we will attempt to jump to the RHS of the expression.
'exports.foo = foo'
if the selection is 'foo' in 'exports.foo', then we will attempt to jump to def
on the rhs of the assignment.
@param {number} start - the start of the selection
@param {number} end - the end of the selection
@param {boolean} isFunction - true if we are jumping to the source of a function def
|
[
"Sets",
"the",
"selection",
"to",
"move",
"the",
"cursor",
"to",
"the",
"result",
"position",
".",
"Assumes",
"that",
"the",
"editor",
"has",
"already",
"changed",
"files",
"if",
"necessary",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptCodeHints/main.js#L781-L839
|
train
|
adobe/brackets
|
src/extensions/default/JavaScriptCodeHints/main.js
|
validIdOrProp
|
function validIdOrProp(token) {
if (!token) {
return false;
}
if (token.string === ".") {
return true;
}
var type = token.type;
if (type === "variable-2" || type === "variable" || type === "property") {
return true;
}
return false;
}
|
javascript
|
function validIdOrProp(token) {
if (!token) {
return false;
}
if (token.string === ".") {
return true;
}
var type = token.type;
if (type === "variable-2" || type === "variable" || type === "property") {
return true;
}
return false;
}
|
[
"function",
"validIdOrProp",
"(",
"token",
")",
"{",
"if",
"(",
"!",
"token",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"token",
".",
"string",
"===",
"\".\"",
")",
"{",
"return",
"true",
";",
"}",
"var",
"type",
"=",
"token",
".",
"type",
";",
"if",
"(",
"type",
"===",
"\"variable-2\"",
"||",
"type",
"===",
"\"variable\"",
"||",
"type",
"===",
"\"property\"",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
helper function to decide if the tokens on the RHS of an assignment
look like an identifier, or member expr.
|
[
"helper",
"function",
"to",
"decide",
"if",
"the",
"tokens",
"on",
"the",
"RHS",
"of",
"an",
"assignment",
"look",
"like",
"an",
"identifier",
"or",
"member",
"expr",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptCodeHints/main.js#L787-L800
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/GotoAgent.js
|
_urlWithoutQueryString
|
function _urlWithoutQueryString(url) {
var index = url.search(/[#\?]/);
if (index >= 0) {
url = url.substr(0, index);
}
return url;
}
|
javascript
|
function _urlWithoutQueryString(url) {
var index = url.search(/[#\?]/);
if (index >= 0) {
url = url.substr(0, index);
}
return url;
}
|
[
"function",
"_urlWithoutQueryString",
"(",
"url",
")",
"{",
"var",
"index",
"=",
"url",
".",
"search",
"(",
"/",
"[#\\?]",
"/",
")",
";",
"if",
"(",
"index",
">=",
"0",
")",
"{",
"url",
"=",
"url",
".",
"substr",
"(",
"0",
",",
"index",
")",
";",
"}",
"return",
"url",
";",
"}"
] |
Return the URL without the query string
@param {string} URL
|
[
"Return",
"the",
"URL",
"without",
"the",
"query",
"string"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/GotoAgent.js#L47-L53
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/GotoAgent.js
|
_makeHTMLTarget
|
function _makeHTMLTarget(targets, node) {
if (node.location) {
var url = DOMAgent.url;
var location = node.location;
if (node.canHaveChildren()) {
location += node.length;
}
url += ":" + location;
var name = "<" + node.name + ">";
var file = _fileFromURL(url);
targets.push({"type": "html", "url": url, "name": name, "file": file});
}
}
|
javascript
|
function _makeHTMLTarget(targets, node) {
if (node.location) {
var url = DOMAgent.url;
var location = node.location;
if (node.canHaveChildren()) {
location += node.length;
}
url += ":" + location;
var name = "<" + node.name + ">";
var file = _fileFromURL(url);
targets.push({"type": "html", "url": url, "name": name, "file": file});
}
}
|
[
"function",
"_makeHTMLTarget",
"(",
"targets",
",",
"node",
")",
"{",
"if",
"(",
"node",
".",
"location",
")",
"{",
"var",
"url",
"=",
"DOMAgent",
".",
"url",
";",
"var",
"location",
"=",
"node",
".",
"location",
";",
"if",
"(",
"node",
".",
"canHaveChildren",
"(",
")",
")",
"{",
"location",
"+=",
"node",
".",
"length",
";",
"}",
"url",
"+=",
"\":\"",
"+",
"location",
";",
"var",
"name",
"=",
"\"<\"",
"+",
"node",
".",
"name",
"+",
"\">\"",
";",
"var",
"file",
"=",
"_fileFromURL",
"(",
"url",
")",
";",
"targets",
".",
"push",
"(",
"{",
"\"type\"",
":",
"\"html\"",
",",
"\"url\"",
":",
"url",
",",
"\"name\"",
":",
"name",
",",
"\"file\"",
":",
"file",
"}",
")",
";",
"}",
"}"
] |
Make the given node a target for goto
@param [] targets array
@param {DOMNode} node
|
[
"Make",
"the",
"given",
"node",
"a",
"target",
"for",
"goto"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/GotoAgent.js#L67-L79
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/GotoAgent.js
|
_makeCSSTarget
|
function _makeCSSTarget(targets, rule) {
if (rule.sourceURL) {
var url = rule.sourceURL;
url += ":" + rule.style.range.start;
var name = rule.selectorList.text;
var file = _fileFromURL(url);
targets.push({"type": "css", "url": url, "name": name, "file": file});
}
}
|
javascript
|
function _makeCSSTarget(targets, rule) {
if (rule.sourceURL) {
var url = rule.sourceURL;
url += ":" + rule.style.range.start;
var name = rule.selectorList.text;
var file = _fileFromURL(url);
targets.push({"type": "css", "url": url, "name": name, "file": file});
}
}
|
[
"function",
"_makeCSSTarget",
"(",
"targets",
",",
"rule",
")",
"{",
"if",
"(",
"rule",
".",
"sourceURL",
")",
"{",
"var",
"url",
"=",
"rule",
".",
"sourceURL",
";",
"url",
"+=",
"\":\"",
"+",
"rule",
".",
"style",
".",
"range",
".",
"start",
";",
"var",
"name",
"=",
"rule",
".",
"selectorList",
".",
"text",
";",
"var",
"file",
"=",
"_fileFromURL",
"(",
"url",
")",
";",
"targets",
".",
"push",
"(",
"{",
"\"type\"",
":",
"\"css\"",
",",
"\"url\"",
":",
"url",
",",
"\"name\"",
":",
"name",
",",
"\"file\"",
":",
"file",
"}",
")",
";",
"}",
"}"
] |
Make the given css rule a target for goto
@param [] targets array
@param {CSS.Rule} node
|
[
"Make",
"the",
"given",
"css",
"rule",
"a",
"target",
"for",
"goto"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/GotoAgent.js#L85-L93
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/GotoAgent.js
|
_makeJSTarget
|
function _makeJSTarget(targets, callFrame) {
var script = ScriptAgent.scriptWithId(callFrame.location.scriptId);
if (script && script.url) {
var url = script.url;
url += ":" + callFrame.location.lineNumber + "," + callFrame.location.columnNumber;
var name = callFrame.functionName;
if (name === "") {
name = "anonymous function";
}
var file = _fileFromURL(url);
targets.push({"type": "js", "url": url, "name": name, "file": file});
}
}
|
javascript
|
function _makeJSTarget(targets, callFrame) {
var script = ScriptAgent.scriptWithId(callFrame.location.scriptId);
if (script && script.url) {
var url = script.url;
url += ":" + callFrame.location.lineNumber + "," + callFrame.location.columnNumber;
var name = callFrame.functionName;
if (name === "") {
name = "anonymous function";
}
var file = _fileFromURL(url);
targets.push({"type": "js", "url": url, "name": name, "file": file});
}
}
|
[
"function",
"_makeJSTarget",
"(",
"targets",
",",
"callFrame",
")",
"{",
"var",
"script",
"=",
"ScriptAgent",
".",
"scriptWithId",
"(",
"callFrame",
".",
"location",
".",
"scriptId",
")",
";",
"if",
"(",
"script",
"&&",
"script",
".",
"url",
")",
"{",
"var",
"url",
"=",
"script",
".",
"url",
";",
"url",
"+=",
"\":\"",
"+",
"callFrame",
".",
"location",
".",
"lineNumber",
"+",
"\",\"",
"+",
"callFrame",
".",
"location",
".",
"columnNumber",
";",
"var",
"name",
"=",
"callFrame",
".",
"functionName",
";",
"if",
"(",
"name",
"===",
"\"\"",
")",
"{",
"name",
"=",
"\"anonymous function\"",
";",
"}",
"var",
"file",
"=",
"_fileFromURL",
"(",
"url",
")",
";",
"targets",
".",
"push",
"(",
"{",
"\"type\"",
":",
"\"js\"",
",",
"\"url\"",
":",
"url",
",",
"\"name\"",
":",
"name",
",",
"\"file\"",
":",
"file",
"}",
")",
";",
"}",
"}"
] |
Make the given javascript callFrame the target for goto
@param [] targets array
@param {Debugger.CallFrame} node
|
[
"Make",
"the",
"given",
"javascript",
"callFrame",
"the",
"target",
"for",
"goto"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/GotoAgent.js#L99-L111
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/GotoAgent.js
|
_onRemoteShowGoto
|
function _onRemoteShowGoto(event, res) {
// res = {nodeId, name, value}
var node = DOMAgent.nodeWithId(res.nodeId);
// get all css rules that apply to the given node
Inspector.CSS.getMatchedStylesForNode(node.nodeId, function onMatchedStyles(res) {
var i, targets = [];
_makeHTMLTarget(targets, node);
for (i in node.trace) {
_makeJSTarget(targets, node.trace[i]);
}
for (i in node.events) {
var trace = node.events[i];
_makeJSTarget(targets, trace.callFrames[0]);
}
for (i in res.matchedCSSRules.reverse()) {
_makeCSSTarget(targets, res.matchedCSSRules[i].rule);
}
RemoteAgent.call("showGoto", targets);
});
}
|
javascript
|
function _onRemoteShowGoto(event, res) {
// res = {nodeId, name, value}
var node = DOMAgent.nodeWithId(res.nodeId);
// get all css rules that apply to the given node
Inspector.CSS.getMatchedStylesForNode(node.nodeId, function onMatchedStyles(res) {
var i, targets = [];
_makeHTMLTarget(targets, node);
for (i in node.trace) {
_makeJSTarget(targets, node.trace[i]);
}
for (i in node.events) {
var trace = node.events[i];
_makeJSTarget(targets, trace.callFrames[0]);
}
for (i in res.matchedCSSRules.reverse()) {
_makeCSSTarget(targets, res.matchedCSSRules[i].rule);
}
RemoteAgent.call("showGoto", targets);
});
}
|
[
"function",
"_onRemoteShowGoto",
"(",
"event",
",",
"res",
")",
"{",
"var",
"node",
"=",
"DOMAgent",
".",
"nodeWithId",
"(",
"res",
".",
"nodeId",
")",
";",
"Inspector",
".",
"CSS",
".",
"getMatchedStylesForNode",
"(",
"node",
".",
"nodeId",
",",
"function",
"onMatchedStyles",
"(",
"res",
")",
"{",
"var",
"i",
",",
"targets",
"=",
"[",
"]",
";",
"_makeHTMLTarget",
"(",
"targets",
",",
"node",
")",
";",
"for",
"(",
"i",
"in",
"node",
".",
"trace",
")",
"{",
"_makeJSTarget",
"(",
"targets",
",",
"node",
".",
"trace",
"[",
"i",
"]",
")",
";",
"}",
"for",
"(",
"i",
"in",
"node",
".",
"events",
")",
"{",
"var",
"trace",
"=",
"node",
".",
"events",
"[",
"i",
"]",
";",
"_makeJSTarget",
"(",
"targets",
",",
"trace",
".",
"callFrames",
"[",
"0",
"]",
")",
";",
"}",
"for",
"(",
"i",
"in",
"res",
".",
"matchedCSSRules",
".",
"reverse",
"(",
")",
")",
"{",
"_makeCSSTarget",
"(",
"targets",
",",
"res",
".",
"matchedCSSRules",
"[",
"i",
"]",
".",
"rule",
")",
";",
"}",
"RemoteAgent",
".",
"call",
"(",
"\"showGoto\"",
",",
"targets",
")",
";",
"}",
")",
";",
"}"
] |
Gather options where to go to from the given source node
|
[
"Gather",
"options",
"where",
"to",
"go",
"to",
"from",
"the",
"given",
"source",
"node"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/GotoAgent.js#L114-L134
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.