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/language/CSSUtils.js
|
_findMatchingRulesInCSSFiles
|
function _findMatchingRulesInCSSFiles(selector, resultSelectors) {
var result = new $.Deferred();
// Load one CSS file and search its contents
function _loadFileAndScan(fullPath, selector) {
var oneFileResult = new $.Deferred();
DocumentManager.getDocumentForPath(fullPath)
.done(function (doc) {
// Find all matching rules for the given CSS file's content, and add them to the
// overall search result
var oneCSSFileMatches = _findAllMatchingSelectorsInText(doc.getText(), selector, doc.getLanguage().getMode());
_addSelectorsToResults(resultSelectors, oneCSSFileMatches, doc, 0);
oneFileResult.resolve();
})
.fail(function (error) {
console.warn("Unable to read " + fullPath + " during CSS rule search:", error);
oneFileResult.resolve(); // still resolve, so the overall result doesn't reject
});
return oneFileResult.promise();
}
ProjectManager.getAllFiles(ProjectManager.getLanguageFilter(["css", "less", "scss"]))
.done(function (cssFiles) {
// Load index of all CSS files; then process each CSS file in turn (see above)
Async.doInParallel(cssFiles, function (fileInfo, number) {
return _loadFileAndScan(fileInfo.fullPath, selector);
})
.then(result.resolve, result.reject);
});
return result.promise();
}
|
javascript
|
function _findMatchingRulesInCSSFiles(selector, resultSelectors) {
var result = new $.Deferred();
// Load one CSS file and search its contents
function _loadFileAndScan(fullPath, selector) {
var oneFileResult = new $.Deferred();
DocumentManager.getDocumentForPath(fullPath)
.done(function (doc) {
// Find all matching rules for the given CSS file's content, and add them to the
// overall search result
var oneCSSFileMatches = _findAllMatchingSelectorsInText(doc.getText(), selector, doc.getLanguage().getMode());
_addSelectorsToResults(resultSelectors, oneCSSFileMatches, doc, 0);
oneFileResult.resolve();
})
.fail(function (error) {
console.warn("Unable to read " + fullPath + " during CSS rule search:", error);
oneFileResult.resolve(); // still resolve, so the overall result doesn't reject
});
return oneFileResult.promise();
}
ProjectManager.getAllFiles(ProjectManager.getLanguageFilter(["css", "less", "scss"]))
.done(function (cssFiles) {
// Load index of all CSS files; then process each CSS file in turn (see above)
Async.doInParallel(cssFiles, function (fileInfo, number) {
return _loadFileAndScan(fileInfo.fullPath, selector);
})
.then(result.resolve, result.reject);
});
return result.promise();
}
|
[
"function",
"_findMatchingRulesInCSSFiles",
"(",
"selector",
",",
"resultSelectors",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"function",
"_loadFileAndScan",
"(",
"fullPath",
",",
"selector",
")",
"{",
"var",
"oneFileResult",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"DocumentManager",
".",
"getDocumentForPath",
"(",
"fullPath",
")",
".",
"done",
"(",
"function",
"(",
"doc",
")",
"{",
"var",
"oneCSSFileMatches",
"=",
"_findAllMatchingSelectorsInText",
"(",
"doc",
".",
"getText",
"(",
")",
",",
"selector",
",",
"doc",
".",
"getLanguage",
"(",
")",
".",
"getMode",
"(",
")",
")",
";",
"_addSelectorsToResults",
"(",
"resultSelectors",
",",
"oneCSSFileMatches",
",",
"doc",
",",
"0",
")",
";",
"oneFileResult",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"error",
")",
"{",
"console",
".",
"warn",
"(",
"\"Unable to read \"",
"+",
"fullPath",
"+",
"\" during CSS rule search:\"",
",",
"error",
")",
";",
"oneFileResult",
".",
"resolve",
"(",
")",
";",
"}",
")",
";",
"return",
"oneFileResult",
".",
"promise",
"(",
")",
";",
"}",
"ProjectManager",
".",
"getAllFiles",
"(",
"ProjectManager",
".",
"getLanguageFilter",
"(",
"[",
"\"css\"",
",",
"\"less\"",
",",
"\"scss\"",
"]",
")",
")",
".",
"done",
"(",
"function",
"(",
"cssFiles",
")",
"{",
"Async",
".",
"doInParallel",
"(",
"cssFiles",
",",
"function",
"(",
"fileInfo",
",",
"number",
")",
"{",
"return",
"_loadFileAndScan",
"(",
"fileInfo",
".",
"fullPath",
",",
"selector",
")",
";",
"}",
")",
".",
"then",
"(",
"result",
".",
"resolve",
",",
"result",
".",
"reject",
")",
";",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Finds matching selectors in CSS files; adds them to 'resultSelectors'
|
[
"Finds",
"matching",
"selectors",
"in",
"CSS",
"files",
";",
"adds",
"them",
"to",
"resultSelectors"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/CSSUtils.js#L1424-L1458
|
train
|
adobe/brackets
|
src/language/CSSUtils.js
|
_loadFileAndScan
|
function _loadFileAndScan(fullPath, selector) {
var oneFileResult = new $.Deferred();
DocumentManager.getDocumentForPath(fullPath)
.done(function (doc) {
// Find all matching rules for the given CSS file's content, and add them to the
// overall search result
var oneCSSFileMatches = _findAllMatchingSelectorsInText(doc.getText(), selector, doc.getLanguage().getMode());
_addSelectorsToResults(resultSelectors, oneCSSFileMatches, doc, 0);
oneFileResult.resolve();
})
.fail(function (error) {
console.warn("Unable to read " + fullPath + " during CSS rule search:", error);
oneFileResult.resolve(); // still resolve, so the overall result doesn't reject
});
return oneFileResult.promise();
}
|
javascript
|
function _loadFileAndScan(fullPath, selector) {
var oneFileResult = new $.Deferred();
DocumentManager.getDocumentForPath(fullPath)
.done(function (doc) {
// Find all matching rules for the given CSS file's content, and add them to the
// overall search result
var oneCSSFileMatches = _findAllMatchingSelectorsInText(doc.getText(), selector, doc.getLanguage().getMode());
_addSelectorsToResults(resultSelectors, oneCSSFileMatches, doc, 0);
oneFileResult.resolve();
})
.fail(function (error) {
console.warn("Unable to read " + fullPath + " during CSS rule search:", error);
oneFileResult.resolve(); // still resolve, so the overall result doesn't reject
});
return oneFileResult.promise();
}
|
[
"function",
"_loadFileAndScan",
"(",
"fullPath",
",",
"selector",
")",
"{",
"var",
"oneFileResult",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"DocumentManager",
".",
"getDocumentForPath",
"(",
"fullPath",
")",
".",
"done",
"(",
"function",
"(",
"doc",
")",
"{",
"var",
"oneCSSFileMatches",
"=",
"_findAllMatchingSelectorsInText",
"(",
"doc",
".",
"getText",
"(",
")",
",",
"selector",
",",
"doc",
".",
"getLanguage",
"(",
")",
".",
"getMode",
"(",
")",
")",
";",
"_addSelectorsToResults",
"(",
"resultSelectors",
",",
"oneCSSFileMatches",
",",
"doc",
",",
"0",
")",
";",
"oneFileResult",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"error",
")",
"{",
"console",
".",
"warn",
"(",
"\"Unable to read \"",
"+",
"fullPath",
"+",
"\" during CSS rule search:\"",
",",
"error",
")",
";",
"oneFileResult",
".",
"resolve",
"(",
")",
";",
"}",
")",
";",
"return",
"oneFileResult",
".",
"promise",
"(",
")",
";",
"}"
] |
Load one CSS file and search its contents
|
[
"Load",
"one",
"CSS",
"file",
"and",
"search",
"its",
"contents"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/CSSUtils.js#L1428-L1446
|
train
|
adobe/brackets
|
src/language/CSSUtils.js
|
_parseSelector
|
function _parseSelector(ctx) {
var selector = "";
// Skip over {
TokenUtils.movePrevToken(ctx);
while (true) {
if (ctx.token.type !== "comment") {
// Stop once we've reached a {, }, or ;
if (/[\{\}\;]/.test(ctx.token.string)) {
break;
}
// Stop once we've reached a <style ...> tag
if (ctx.token.string === "style" && ctx.token.type === "tag") {
// Remove everything up to end-of-tag from selector
var eotIndex = selector.indexOf(">");
if (eotIndex !== -1) {
selector = selector.substring(eotIndex + 1);
}
break;
}
selector = ctx.token.string + selector;
}
if (!TokenUtils.movePrevToken(ctx)) {
break;
}
}
return selector;
}
|
javascript
|
function _parseSelector(ctx) {
var selector = "";
// Skip over {
TokenUtils.movePrevToken(ctx);
while (true) {
if (ctx.token.type !== "comment") {
// Stop once we've reached a {, }, or ;
if (/[\{\}\;]/.test(ctx.token.string)) {
break;
}
// Stop once we've reached a <style ...> tag
if (ctx.token.string === "style" && ctx.token.type === "tag") {
// Remove everything up to end-of-tag from selector
var eotIndex = selector.indexOf(">");
if (eotIndex !== -1) {
selector = selector.substring(eotIndex + 1);
}
break;
}
selector = ctx.token.string + selector;
}
if (!TokenUtils.movePrevToken(ctx)) {
break;
}
}
return selector;
}
|
[
"function",
"_parseSelector",
"(",
"ctx",
")",
"{",
"var",
"selector",
"=",
"\"\"",
";",
"TokenUtils",
".",
"movePrevToken",
"(",
"ctx",
")",
";",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"ctx",
".",
"token",
".",
"type",
"!==",
"\"comment\"",
")",
"{",
"if",
"(",
"/",
"[\\{\\}\\;]",
"/",
".",
"test",
"(",
"ctx",
".",
"token",
".",
"string",
")",
")",
"{",
"break",
";",
"}",
"if",
"(",
"ctx",
".",
"token",
".",
"string",
"===",
"\"style\"",
"&&",
"ctx",
".",
"token",
".",
"type",
"===",
"\"tag\"",
")",
"{",
"var",
"eotIndex",
"=",
"selector",
".",
"indexOf",
"(",
"\">\"",
")",
";",
"if",
"(",
"eotIndex",
"!==",
"-",
"1",
")",
"{",
"selector",
"=",
"selector",
".",
"substring",
"(",
"eotIndex",
"+",
"1",
")",
";",
"}",
"break",
";",
"}",
"selector",
"=",
"ctx",
".",
"token",
".",
"string",
"+",
"selector",
";",
"}",
"if",
"(",
"!",
"TokenUtils",
".",
"movePrevToken",
"(",
"ctx",
")",
")",
"{",
"break",
";",
"}",
"}",
"return",
"selector",
";",
"}"
] |
Parse a selector. Assumes ctx is pointing at the opening { that is after the selector name.
|
[
"Parse",
"a",
"selector",
".",
"Assumes",
"ctx",
"is",
"pointing",
"at",
"the",
"opening",
"{",
"that",
"is",
"after",
"the",
"selector",
"name",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/CSSUtils.js#L1563-L1594
|
train
|
adobe/brackets
|
src/language/CSSUtils.js
|
extractAllNamedFlows
|
function extractAllNamedFlows(text) {
var namedFlowRegEx = /(?:flow\-(into|from)\:\s*)([\w\-]+)(?:\s*;)/gi,
result = [],
names = {},
thisMatch;
// Reduce the content so that matches
// inside strings and comments are ignored
text = reduceStyleSheetForRegExParsing(text);
// Find the first match
thisMatch = namedFlowRegEx.exec(text);
// Iterate over the matches and add them to result
while (thisMatch) {
var thisName = thisMatch[2];
if (IGNORED_FLOW_NAMES.indexOf(thisName) === -1 && !names.hasOwnProperty(thisName)) {
names[thisName] = result.push(thisName);
}
thisMatch = namedFlowRegEx.exec(text);
}
return result;
}
|
javascript
|
function extractAllNamedFlows(text) {
var namedFlowRegEx = /(?:flow\-(into|from)\:\s*)([\w\-]+)(?:\s*;)/gi,
result = [],
names = {},
thisMatch;
// Reduce the content so that matches
// inside strings and comments are ignored
text = reduceStyleSheetForRegExParsing(text);
// Find the first match
thisMatch = namedFlowRegEx.exec(text);
// Iterate over the matches and add them to result
while (thisMatch) {
var thisName = thisMatch[2];
if (IGNORED_FLOW_NAMES.indexOf(thisName) === -1 && !names.hasOwnProperty(thisName)) {
names[thisName] = result.push(thisName);
}
thisMatch = namedFlowRegEx.exec(text);
}
return result;
}
|
[
"function",
"extractAllNamedFlows",
"(",
"text",
")",
"{",
"var",
"namedFlowRegEx",
"=",
"/",
"(?:flow\\-(into|from)\\:\\s*)([\\w\\-]+)(?:\\s*;)",
"/",
"gi",
",",
"result",
"=",
"[",
"]",
",",
"names",
"=",
"{",
"}",
",",
"thisMatch",
";",
"text",
"=",
"reduceStyleSheetForRegExParsing",
"(",
"text",
")",
";",
"thisMatch",
"=",
"namedFlowRegEx",
".",
"exec",
"(",
"text",
")",
";",
"while",
"(",
"thisMatch",
")",
"{",
"var",
"thisName",
"=",
"thisMatch",
"[",
"2",
"]",
";",
"if",
"(",
"IGNORED_FLOW_NAMES",
".",
"indexOf",
"(",
"thisName",
")",
"===",
"-",
"1",
"&&",
"!",
"names",
".",
"hasOwnProperty",
"(",
"thisName",
")",
")",
"{",
"names",
"[",
"thisName",
"]",
"=",
"result",
".",
"push",
"(",
"thisName",
")",
";",
"}",
"thisMatch",
"=",
"namedFlowRegEx",
".",
"exec",
"(",
"text",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
Extracts all named flow instances
@param {!string} text to extract from
@return {Array.<string>} array of unique flow names found in the content (empty if none)
|
[
"Extracts",
"all",
"named",
"flow",
"instances"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/CSSUtils.js#L1729-L1753
|
train
|
adobe/brackets
|
src/document/ChangedDocumentTracker.js
|
ChangedDocumentTracker
|
function ChangedDocumentTracker() {
var self = this;
this._changedPaths = {};
this._windowFocus = true;
this._addListener = this._addListener.bind(this);
this._removeListener = this._removeListener.bind(this);
this._onChange = this._onChange.bind(this);
this._onWindowFocus = this._onWindowFocus.bind(this);
DocumentManager.on("afterDocumentCreate", function (event, doc) {
// Only track documents in the current project
if (ProjectManager.isWithinProject(doc.file.fullPath)) {
self._addListener(doc);
}
});
DocumentManager.on("beforeDocumentDelete", function (event, doc) {
// In case a document somehow remains loaded after its project
// has been closed, unconditionally attempt to remove the listener.
self._removeListener(doc);
});
$(window).focus(this._onWindowFocus);
}
|
javascript
|
function ChangedDocumentTracker() {
var self = this;
this._changedPaths = {};
this._windowFocus = true;
this._addListener = this._addListener.bind(this);
this._removeListener = this._removeListener.bind(this);
this._onChange = this._onChange.bind(this);
this._onWindowFocus = this._onWindowFocus.bind(this);
DocumentManager.on("afterDocumentCreate", function (event, doc) {
// Only track documents in the current project
if (ProjectManager.isWithinProject(doc.file.fullPath)) {
self._addListener(doc);
}
});
DocumentManager.on("beforeDocumentDelete", function (event, doc) {
// In case a document somehow remains loaded after its project
// has been closed, unconditionally attempt to remove the listener.
self._removeListener(doc);
});
$(window).focus(this._onWindowFocus);
}
|
[
"function",
"ChangedDocumentTracker",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"this",
".",
"_changedPaths",
"=",
"{",
"}",
";",
"this",
".",
"_windowFocus",
"=",
"true",
";",
"this",
".",
"_addListener",
"=",
"this",
".",
"_addListener",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_removeListener",
"=",
"this",
".",
"_removeListener",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_onChange",
"=",
"this",
".",
"_onChange",
".",
"bind",
"(",
"this",
")",
";",
"this",
".",
"_onWindowFocus",
"=",
"this",
".",
"_onWindowFocus",
".",
"bind",
"(",
"this",
")",
";",
"DocumentManager",
".",
"on",
"(",
"\"afterDocumentCreate\"",
",",
"function",
"(",
"event",
",",
"doc",
")",
"{",
"if",
"(",
"ProjectManager",
".",
"isWithinProject",
"(",
"doc",
".",
"file",
".",
"fullPath",
")",
")",
"{",
"self",
".",
"_addListener",
"(",
"doc",
")",
";",
"}",
"}",
")",
";",
"DocumentManager",
".",
"on",
"(",
"\"beforeDocumentDelete\"",
",",
"function",
"(",
"event",
",",
"doc",
")",
"{",
"self",
".",
"_removeListener",
"(",
"doc",
")",
";",
"}",
")",
";",
"$",
"(",
"window",
")",
".",
"focus",
"(",
"this",
".",
"_onWindowFocus",
")",
";",
"}"
] |
Tracks "change" events on opened Documents. Used to monitor changes
to documents in-memory and update caches. Assumes all documents have
changed when the Brackets window loses and regains focus. Does not
read timestamps of files on disk. Clients may optionally track file
timestamps on disk independently.
@constructor
|
[
"Tracks",
"change",
"events",
"on",
"opened",
"Documents",
".",
"Used",
"to",
"monitor",
"changes",
"to",
"documents",
"in",
"-",
"memory",
"and",
"update",
"caches",
".",
"Assumes",
"all",
"documents",
"have",
"changed",
"when",
"the",
"Brackets",
"window",
"loses",
"and",
"regains",
"focus",
".",
"Does",
"not",
"read",
"timestamps",
"of",
"files",
"on",
"disk",
".",
"Clients",
"may",
"optionally",
"track",
"file",
"timestamps",
"on",
"disk",
"independently",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/document/ChangedDocumentTracker.js#L41-L65
|
train
|
adobe/brackets
|
src/search/FindReplace.js
|
_findAllAndSelect
|
function _findAllAndSelect(editor) {
editor = editor || EditorManager.getActiveEditor();
if (!editor) {
return;
}
var sel = editor.getSelection(),
newSelections = [];
if (CodeMirror.cmpPos(sel.start, sel.end) === 0) {
sel = _getWordAt(editor, sel.start);
}
if (CodeMirror.cmpPos(sel.start, sel.end) !== 0) {
var searchStart = {line: 0, ch: 0},
state = getSearchState(editor._codeMirror),
nextMatch;
setQueryInfo(state, { query: editor.document.getRange(sel.start, sel.end), isCaseSensitive: false, isRegexp: false });
while ((nextMatch = _getNextMatch(editor, false, searchStart, false)) !== null) {
if (_selEq(sel, nextMatch)) {
nextMatch.primary = true;
}
newSelections.push(nextMatch);
searchStart = nextMatch.end;
}
// This should find at least the original selection, but just in case...
if (newSelections.length) {
// Don't change the scroll position.
editor.setSelections(newSelections, false);
}
}
}
|
javascript
|
function _findAllAndSelect(editor) {
editor = editor || EditorManager.getActiveEditor();
if (!editor) {
return;
}
var sel = editor.getSelection(),
newSelections = [];
if (CodeMirror.cmpPos(sel.start, sel.end) === 0) {
sel = _getWordAt(editor, sel.start);
}
if (CodeMirror.cmpPos(sel.start, sel.end) !== 0) {
var searchStart = {line: 0, ch: 0},
state = getSearchState(editor._codeMirror),
nextMatch;
setQueryInfo(state, { query: editor.document.getRange(sel.start, sel.end), isCaseSensitive: false, isRegexp: false });
while ((nextMatch = _getNextMatch(editor, false, searchStart, false)) !== null) {
if (_selEq(sel, nextMatch)) {
nextMatch.primary = true;
}
newSelections.push(nextMatch);
searchStart = nextMatch.end;
}
// This should find at least the original selection, but just in case...
if (newSelections.length) {
// Don't change the scroll position.
editor.setSelections(newSelections, false);
}
}
}
|
[
"function",
"_findAllAndSelect",
"(",
"editor",
")",
"{",
"editor",
"=",
"editor",
"||",
"EditorManager",
".",
"getActiveEditor",
"(",
")",
";",
"if",
"(",
"!",
"editor",
")",
"{",
"return",
";",
"}",
"var",
"sel",
"=",
"editor",
".",
"getSelection",
"(",
")",
",",
"newSelections",
"=",
"[",
"]",
";",
"if",
"(",
"CodeMirror",
".",
"cmpPos",
"(",
"sel",
".",
"start",
",",
"sel",
".",
"end",
")",
"===",
"0",
")",
"{",
"sel",
"=",
"_getWordAt",
"(",
"editor",
",",
"sel",
".",
"start",
")",
";",
"}",
"if",
"(",
"CodeMirror",
".",
"cmpPos",
"(",
"sel",
".",
"start",
",",
"sel",
".",
"end",
")",
"!==",
"0",
")",
"{",
"var",
"searchStart",
"=",
"{",
"line",
":",
"0",
",",
"ch",
":",
"0",
"}",
",",
"state",
"=",
"getSearchState",
"(",
"editor",
".",
"_codeMirror",
")",
",",
"nextMatch",
";",
"setQueryInfo",
"(",
"state",
",",
"{",
"query",
":",
"editor",
".",
"document",
".",
"getRange",
"(",
"sel",
".",
"start",
",",
"sel",
".",
"end",
")",
",",
"isCaseSensitive",
":",
"false",
",",
"isRegexp",
":",
"false",
"}",
")",
";",
"while",
"(",
"(",
"nextMatch",
"=",
"_getNextMatch",
"(",
"editor",
",",
"false",
",",
"searchStart",
",",
"false",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"_selEq",
"(",
"sel",
",",
"nextMatch",
")",
")",
"{",
"nextMatch",
".",
"primary",
"=",
"true",
";",
"}",
"newSelections",
".",
"push",
"(",
"nextMatch",
")",
";",
"searchStart",
"=",
"nextMatch",
".",
"end",
";",
"}",
"if",
"(",
"newSelections",
".",
"length",
")",
"{",
"editor",
".",
"setSelections",
"(",
"newSelections",
",",
"false",
")",
";",
"}",
"}",
"}"
] |
Takes the primary selection, expands it to a word range if necessary, then sets the selection to
include all instances of that range. Removes all other selections. Does nothing if the selection
is not a range after expansion.
|
[
"Takes",
"the",
"primary",
"selection",
"expands",
"it",
"to",
"a",
"word",
"range",
"if",
"necessary",
"then",
"sets",
"the",
"selection",
"to",
"include",
"all",
"instances",
"of",
"that",
"range",
".",
"Removes",
"all",
"other",
"selections",
".",
"Does",
"nothing",
"if",
"the",
"selection",
"is",
"not",
"a",
"range",
"after",
"expansion",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindReplace.js#L364-L395
|
train
|
adobe/brackets
|
src/search/FindReplace.js
|
clearCurrentMatchHighlight
|
function clearCurrentMatchHighlight(cm, state) {
if (state.markedCurrent) {
state.markedCurrent.clear();
ScrollTrackMarkers.markCurrent(-1);
}
}
|
javascript
|
function clearCurrentMatchHighlight(cm, state) {
if (state.markedCurrent) {
state.markedCurrent.clear();
ScrollTrackMarkers.markCurrent(-1);
}
}
|
[
"function",
"clearCurrentMatchHighlight",
"(",
"cm",
",",
"state",
")",
"{",
"if",
"(",
"state",
".",
"markedCurrent",
")",
"{",
"state",
".",
"markedCurrent",
".",
"clear",
"(",
")",
";",
"ScrollTrackMarkers",
".",
"markCurrent",
"(",
"-",
"1",
")",
";",
"}",
"}"
] |
Removes the current-match highlight, leaving all matches marked in the generic highlight style
|
[
"Removes",
"the",
"current",
"-",
"match",
"highlight",
"leaving",
"all",
"matches",
"marked",
"in",
"the",
"generic",
"highlight",
"style"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindReplace.js#L398-L403
|
train
|
adobe/brackets
|
src/search/FindReplace.js
|
clearHighlights
|
function clearHighlights(cm, state) {
cm.operation(function () {
state.marked.forEach(function (markedRange) {
markedRange.clear();
});
clearCurrentMatchHighlight(cm, state);
});
state.marked.length = 0;
state.markedCurrent = null;
ScrollTrackMarkers.clear();
state.resultSet = [];
state.matchIndex = -1;
}
|
javascript
|
function clearHighlights(cm, state) {
cm.operation(function () {
state.marked.forEach(function (markedRange) {
markedRange.clear();
});
clearCurrentMatchHighlight(cm, state);
});
state.marked.length = 0;
state.markedCurrent = null;
ScrollTrackMarkers.clear();
state.resultSet = [];
state.matchIndex = -1;
}
|
[
"function",
"clearHighlights",
"(",
"cm",
",",
"state",
")",
"{",
"cm",
".",
"operation",
"(",
"function",
"(",
")",
"{",
"state",
".",
"marked",
".",
"forEach",
"(",
"function",
"(",
"markedRange",
")",
"{",
"markedRange",
".",
"clear",
"(",
")",
";",
"}",
")",
";",
"clearCurrentMatchHighlight",
"(",
"cm",
",",
"state",
")",
";",
"}",
")",
";",
"state",
".",
"marked",
".",
"length",
"=",
"0",
";",
"state",
".",
"markedCurrent",
"=",
"null",
";",
"ScrollTrackMarkers",
".",
"clear",
"(",
")",
";",
"state",
".",
"resultSet",
"=",
"[",
"]",
";",
"state",
".",
"matchIndex",
"=",
"-",
"1",
";",
"}"
] |
Clears all match highlights, including the current match
|
[
"Clears",
"all",
"match",
"highlights",
"including",
"the",
"current",
"match"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindReplace.js#L451-L465
|
train
|
adobe/brackets
|
src/search/FindReplace.js
|
openSearchBar
|
function openSearchBar(editor, replace) {
var cm = editor._codeMirror,
state = getSearchState(cm);
// Use the selection start as the searchStartPos. This way if you
// start with a pre-populated search and enter an additional character,
// it will extend the initial selection instead of jumping to the next
// occurrence.
state.searchStartPos = editor.getCursorPos(false, "start");
// Prepopulate the search field
var initialQuery = FindBar.getInitialQuery(findBar, editor);
if (initialQuery.query === "" && editor.lastParsedQuery !== "") {
initialQuery.query = editor.lastParsedQuery;
}
// Close our previous find bar, if any. (The open() of the new findBar will
// take care of closing any other find bar instances.)
if (findBar) {
findBar.close();
}
// Create the search bar UI (closing any previous find bar in the process)
findBar = new FindBar({
multifile: false,
replace: replace,
initialQuery: initialQuery.query,
initialReplaceText: initialQuery.replaceText,
queryPlaceholder: Strings.FIND_QUERY_PLACEHOLDER
});
findBar.open();
findBar
.on("queryChange.FindReplace", function (e) {
handleQueryChange(editor, state);
})
.on("doFind.FindReplace", function (e, searchBackwards) {
findNext(editor, searchBackwards);
})
.on("close.FindReplace", function (e) {
editor.lastParsedQuery = state.parsedQuery;
// Clear highlights but leave search state in place so Find Next/Previous work after closing
clearHighlights(cm, state);
// Dispose highlighting UI (important to restore normal selection color as soon as focus goes back to the editor)
toggleHighlighting(editor, false);
findBar.off(".FindReplace");
findBar = null;
});
handleQueryChange(editor, state, true);
}
|
javascript
|
function openSearchBar(editor, replace) {
var cm = editor._codeMirror,
state = getSearchState(cm);
// Use the selection start as the searchStartPos. This way if you
// start with a pre-populated search and enter an additional character,
// it will extend the initial selection instead of jumping to the next
// occurrence.
state.searchStartPos = editor.getCursorPos(false, "start");
// Prepopulate the search field
var initialQuery = FindBar.getInitialQuery(findBar, editor);
if (initialQuery.query === "" && editor.lastParsedQuery !== "") {
initialQuery.query = editor.lastParsedQuery;
}
// Close our previous find bar, if any. (The open() of the new findBar will
// take care of closing any other find bar instances.)
if (findBar) {
findBar.close();
}
// Create the search bar UI (closing any previous find bar in the process)
findBar = new FindBar({
multifile: false,
replace: replace,
initialQuery: initialQuery.query,
initialReplaceText: initialQuery.replaceText,
queryPlaceholder: Strings.FIND_QUERY_PLACEHOLDER
});
findBar.open();
findBar
.on("queryChange.FindReplace", function (e) {
handleQueryChange(editor, state);
})
.on("doFind.FindReplace", function (e, searchBackwards) {
findNext(editor, searchBackwards);
})
.on("close.FindReplace", function (e) {
editor.lastParsedQuery = state.parsedQuery;
// Clear highlights but leave search state in place so Find Next/Previous work after closing
clearHighlights(cm, state);
// Dispose highlighting UI (important to restore normal selection color as soon as focus goes back to the editor)
toggleHighlighting(editor, false);
findBar.off(".FindReplace");
findBar = null;
});
handleQueryChange(editor, state, true);
}
|
[
"function",
"openSearchBar",
"(",
"editor",
",",
"replace",
")",
"{",
"var",
"cm",
"=",
"editor",
".",
"_codeMirror",
",",
"state",
"=",
"getSearchState",
"(",
"cm",
")",
";",
"state",
".",
"searchStartPos",
"=",
"editor",
".",
"getCursorPos",
"(",
"false",
",",
"\"start\"",
")",
";",
"var",
"initialQuery",
"=",
"FindBar",
".",
"getInitialQuery",
"(",
"findBar",
",",
"editor",
")",
";",
"if",
"(",
"initialQuery",
".",
"query",
"===",
"\"\"",
"&&",
"editor",
".",
"lastParsedQuery",
"!==",
"\"\"",
")",
"{",
"initialQuery",
".",
"query",
"=",
"editor",
".",
"lastParsedQuery",
";",
"}",
"if",
"(",
"findBar",
")",
"{",
"findBar",
".",
"close",
"(",
")",
";",
"}",
"findBar",
"=",
"new",
"FindBar",
"(",
"{",
"multifile",
":",
"false",
",",
"replace",
":",
"replace",
",",
"initialQuery",
":",
"initialQuery",
".",
"query",
",",
"initialReplaceText",
":",
"initialQuery",
".",
"replaceText",
",",
"queryPlaceholder",
":",
"Strings",
".",
"FIND_QUERY_PLACEHOLDER",
"}",
")",
";",
"findBar",
".",
"open",
"(",
")",
";",
"findBar",
".",
"on",
"(",
"\"queryChange.FindReplace\"",
",",
"function",
"(",
"e",
")",
"{",
"handleQueryChange",
"(",
"editor",
",",
"state",
")",
";",
"}",
")",
".",
"on",
"(",
"\"doFind.FindReplace\"",
",",
"function",
"(",
"e",
",",
"searchBackwards",
")",
"{",
"findNext",
"(",
"editor",
",",
"searchBackwards",
")",
";",
"}",
")",
".",
"on",
"(",
"\"close.FindReplace\"",
",",
"function",
"(",
"e",
")",
"{",
"editor",
".",
"lastParsedQuery",
"=",
"state",
".",
"parsedQuery",
";",
"clearHighlights",
"(",
"cm",
",",
"state",
")",
";",
"toggleHighlighting",
"(",
"editor",
",",
"false",
")",
";",
"findBar",
".",
"off",
"(",
"\".FindReplace\"",
")",
";",
"findBar",
"=",
"null",
";",
"}",
")",
";",
"handleQueryChange",
"(",
"editor",
",",
"state",
",",
"true",
")",
";",
"}"
] |
Creates a Find bar for the current search session.
@param {!Editor} editor
@param {boolean} replace Whether to show the Replace UI; default false
|
[
"Creates",
"a",
"Find",
"bar",
"for",
"the",
"current",
"search",
"session",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/FindReplace.js#L597-L649
|
train
|
adobe/brackets
|
src/extensions/default/JSLint/main.js
|
_getIndentSize
|
function _getIndentSize(fullPath) {
return Editor.getUseTabChar(fullPath) ? Editor.getTabSize(fullPath) : Editor.getSpaceUnits(fullPath);
}
|
javascript
|
function _getIndentSize(fullPath) {
return Editor.getUseTabChar(fullPath) ? Editor.getTabSize(fullPath) : Editor.getSpaceUnits(fullPath);
}
|
[
"function",
"_getIndentSize",
"(",
"fullPath",
")",
"{",
"return",
"Editor",
".",
"getUseTabChar",
"(",
"fullPath",
")",
"?",
"Editor",
".",
"getTabSize",
"(",
"fullPath",
")",
":",
"Editor",
".",
"getSpaceUnits",
"(",
"fullPath",
")",
";",
"}"
] |
gets indentation size depending whether the tabs or spaces are used
|
[
"gets",
"indentation",
"size",
"depending",
"whether",
"the",
"tabs",
"or",
"spaces",
"are",
"used"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JSLint/main.js#L210-L212
|
train
|
adobe/brackets
|
src/extensions/default/JSLint/main.js
|
lintOneFile
|
function lintOneFile(text, fullPath) {
// If a line contains only whitespace (here spaces or tabs), remove the whitespace
text = text.replace(/^[ \t]+$/gm, "");
var options = prefs.get("options");
_lastRunOptions = _.clone(options);
if (!options) {
options = {};
} else {
options = _.clone(options);
}
if (!options.indent) {
// default to using the same indentation value that the editor is using
options.indent = _getIndentSize(fullPath);
}
// If the user has not defined the environment, we use browser by default.
var hasEnvironment = _.some(ENVIRONMENTS, function (env) {
return options[env] !== undefined;
});
if (!hasEnvironment) {
options.browser = true;
}
var jslintResult = JSLINT(text, options);
if (!jslintResult) {
// Remove any trailing null placeholder (early-abort indicator)
var errors = JSLINT.errors.filter(function (err) { return err !== null; });
errors = errors.map(function (jslintError) {
return {
// JSLint returns 1-based line/col numbers
pos: { line: jslintError.line - 1, ch: jslintError.character - 1 },
message: jslintError.reason,
type: CodeInspection.Type.WARNING
};
});
var result = { errors: errors };
// If array terminated in a null it means there was a stop notice
if (errors.length !== JSLINT.errors.length) {
result.aborted = true;
errors[errors.length - 1].type = CodeInspection.Type.META;
}
return result;
}
return null;
}
|
javascript
|
function lintOneFile(text, fullPath) {
// If a line contains only whitespace (here spaces or tabs), remove the whitespace
text = text.replace(/^[ \t]+$/gm, "");
var options = prefs.get("options");
_lastRunOptions = _.clone(options);
if (!options) {
options = {};
} else {
options = _.clone(options);
}
if (!options.indent) {
// default to using the same indentation value that the editor is using
options.indent = _getIndentSize(fullPath);
}
// If the user has not defined the environment, we use browser by default.
var hasEnvironment = _.some(ENVIRONMENTS, function (env) {
return options[env] !== undefined;
});
if (!hasEnvironment) {
options.browser = true;
}
var jslintResult = JSLINT(text, options);
if (!jslintResult) {
// Remove any trailing null placeholder (early-abort indicator)
var errors = JSLINT.errors.filter(function (err) { return err !== null; });
errors = errors.map(function (jslintError) {
return {
// JSLint returns 1-based line/col numbers
pos: { line: jslintError.line - 1, ch: jslintError.character - 1 },
message: jslintError.reason,
type: CodeInspection.Type.WARNING
};
});
var result = { errors: errors };
// If array terminated in a null it means there was a stop notice
if (errors.length !== JSLINT.errors.length) {
result.aborted = true;
errors[errors.length - 1].type = CodeInspection.Type.META;
}
return result;
}
return null;
}
|
[
"function",
"lintOneFile",
"(",
"text",
",",
"fullPath",
")",
"{",
"text",
"=",
"text",
".",
"replace",
"(",
"/",
"^[ \\t]+$",
"/",
"gm",
",",
"\"\"",
")",
";",
"var",
"options",
"=",
"prefs",
".",
"get",
"(",
"\"options\"",
")",
";",
"_lastRunOptions",
"=",
"_",
".",
"clone",
"(",
"options",
")",
";",
"if",
"(",
"!",
"options",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"else",
"{",
"options",
"=",
"_",
".",
"clone",
"(",
"options",
")",
";",
"}",
"if",
"(",
"!",
"options",
".",
"indent",
")",
"{",
"options",
".",
"indent",
"=",
"_getIndentSize",
"(",
"fullPath",
")",
";",
"}",
"var",
"hasEnvironment",
"=",
"_",
".",
"some",
"(",
"ENVIRONMENTS",
",",
"function",
"(",
"env",
")",
"{",
"return",
"options",
"[",
"env",
"]",
"!==",
"undefined",
";",
"}",
")",
";",
"if",
"(",
"!",
"hasEnvironment",
")",
"{",
"options",
".",
"browser",
"=",
"true",
";",
"}",
"var",
"jslintResult",
"=",
"JSLINT",
"(",
"text",
",",
"options",
")",
";",
"if",
"(",
"!",
"jslintResult",
")",
"{",
"var",
"errors",
"=",
"JSLINT",
".",
"errors",
".",
"filter",
"(",
"function",
"(",
"err",
")",
"{",
"return",
"err",
"!==",
"null",
";",
"}",
")",
";",
"errors",
"=",
"errors",
".",
"map",
"(",
"function",
"(",
"jslintError",
")",
"{",
"return",
"{",
"pos",
":",
"{",
"line",
":",
"jslintError",
".",
"line",
"-",
"1",
",",
"ch",
":",
"jslintError",
".",
"character",
"-",
"1",
"}",
",",
"message",
":",
"jslintError",
".",
"reason",
",",
"type",
":",
"CodeInspection",
".",
"Type",
".",
"WARNING",
"}",
";",
"}",
")",
";",
"var",
"result",
"=",
"{",
"errors",
":",
"errors",
"}",
";",
"if",
"(",
"errors",
".",
"length",
"!==",
"JSLINT",
".",
"errors",
".",
"length",
")",
"{",
"result",
".",
"aborted",
"=",
"true",
";",
"errors",
"[",
"errors",
".",
"length",
"-",
"1",
"]",
".",
"type",
"=",
"CodeInspection",
".",
"Type",
".",
"META",
";",
"}",
"return",
"result",
";",
"}",
"return",
"null",
";",
"}"
] |
Run JSLint on the current document. Reports results to the main UI. Displays
a gold star when no errors are found.
|
[
"Run",
"JSLint",
"on",
"the",
"current",
"document",
".",
"Reports",
"results",
"to",
"the",
"main",
"UI",
".",
"Displays",
"a",
"gold",
"star",
"when",
"no",
"errors",
"are",
"found",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JSLint/main.js#L218-L272
|
train
|
adobe/brackets
|
src/extensions/default/InlineColorEditor/main.js
|
prepareEditorForProvider
|
function prepareEditorForProvider(hostEditor, pos) {
var colorRegEx, cursorLine, match, sel, start, end, endPos, marker;
sel = hostEditor.getSelection();
if (sel.start.line !== sel.end.line) {
return null;
}
colorRegEx = new RegExp(ColorUtils.COLOR_REGEX);
cursorLine = hostEditor.document.getLine(pos.line);
// Loop through each match of colorRegEx and stop when the one that contains pos is found.
do {
match = colorRegEx.exec(cursorLine);
if (match) {
start = match.index;
end = start + match[0].length;
}
} while (match && (pos.ch < start || pos.ch > end));
if (!match) {
return null;
}
// Adjust pos to the beginning of the match so that the inline editor won't get
// dismissed while we're updating the color with the new values from user's inline editing.
pos.ch = start;
endPos = {line: pos.line, ch: end};
marker = hostEditor._codeMirror.markText(pos, endPos);
hostEditor.setSelection(pos, endPos);
return {
color: match[0],
marker: marker
};
}
|
javascript
|
function prepareEditorForProvider(hostEditor, pos) {
var colorRegEx, cursorLine, match, sel, start, end, endPos, marker;
sel = hostEditor.getSelection();
if (sel.start.line !== sel.end.line) {
return null;
}
colorRegEx = new RegExp(ColorUtils.COLOR_REGEX);
cursorLine = hostEditor.document.getLine(pos.line);
// Loop through each match of colorRegEx and stop when the one that contains pos is found.
do {
match = colorRegEx.exec(cursorLine);
if (match) {
start = match.index;
end = start + match[0].length;
}
} while (match && (pos.ch < start || pos.ch > end));
if (!match) {
return null;
}
// Adjust pos to the beginning of the match so that the inline editor won't get
// dismissed while we're updating the color with the new values from user's inline editing.
pos.ch = start;
endPos = {line: pos.line, ch: end};
marker = hostEditor._codeMirror.markText(pos, endPos);
hostEditor.setSelection(pos, endPos);
return {
color: match[0],
marker: marker
};
}
|
[
"function",
"prepareEditorForProvider",
"(",
"hostEditor",
",",
"pos",
")",
"{",
"var",
"colorRegEx",
",",
"cursorLine",
",",
"match",
",",
"sel",
",",
"start",
",",
"end",
",",
"endPos",
",",
"marker",
";",
"sel",
"=",
"hostEditor",
".",
"getSelection",
"(",
")",
";",
"if",
"(",
"sel",
".",
"start",
".",
"line",
"!==",
"sel",
".",
"end",
".",
"line",
")",
"{",
"return",
"null",
";",
"}",
"colorRegEx",
"=",
"new",
"RegExp",
"(",
"ColorUtils",
".",
"COLOR_REGEX",
")",
";",
"cursorLine",
"=",
"hostEditor",
".",
"document",
".",
"getLine",
"(",
"pos",
".",
"line",
")",
";",
"do",
"{",
"match",
"=",
"colorRegEx",
".",
"exec",
"(",
"cursorLine",
")",
";",
"if",
"(",
"match",
")",
"{",
"start",
"=",
"match",
".",
"index",
";",
"end",
"=",
"start",
"+",
"match",
"[",
"0",
"]",
".",
"length",
";",
"}",
"}",
"while",
"(",
"match",
"&&",
"(",
"pos",
".",
"ch",
"<",
"start",
"||",
"pos",
".",
"ch",
">",
"end",
")",
")",
";",
"if",
"(",
"!",
"match",
")",
"{",
"return",
"null",
";",
"}",
"pos",
".",
"ch",
"=",
"start",
";",
"endPos",
"=",
"{",
"line",
":",
"pos",
".",
"line",
",",
"ch",
":",
"end",
"}",
";",
"marker",
"=",
"hostEditor",
".",
"_codeMirror",
".",
"markText",
"(",
"pos",
",",
"endPos",
")",
";",
"hostEditor",
".",
"setSelection",
"(",
"pos",
",",
"endPos",
")",
";",
"return",
"{",
"color",
":",
"match",
"[",
"0",
"]",
",",
"marker",
":",
"marker",
"}",
";",
"}"
] |
Prepare hostEditor for an InlineColorEditor at pos if possible. Return
editor context if so; otherwise null.
@param {Editor} hostEditor
@param {{line:Number, ch:Number}} pos
@return {?{color:String, marker:TextMarker}}
|
[
"Prepare",
"hostEditor",
"for",
"an",
"InlineColorEditor",
"at",
"pos",
"if",
"possible",
".",
"Return",
"editor",
"context",
"if",
"so",
";",
"otherwise",
"null",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineColorEditor/main.js#L41-L77
|
train
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/protocol/remote/LiveDevProtocolRemote.js
|
function (msg) {
var msgHandlers;
if (!msg.method) {
// no message type, ignoring it
// TODO: should we trigger a generic event?
console.log("[Brackets LiveDev] Received message without method.");
return;
}
// get handlers for msg.method
msgHandlers = this.handlers[msg.method];
if (msgHandlers && msgHandlers.length > 0) {
// invoke handlers with the received message
msgHandlers.forEach(function (handler) {
try {
// TODO: check which context should be used to call handlers here.
handler(msg);
return;
} catch (e) {
console.log("[Brackets LiveDev] Error executing a handler for " + msg.method);
console.log(e.stack);
return;
}
});
} else {
// no subscribers, ignore it.
// TODO: any other default handling? (eg. specific respond, trigger as a generic event, etc.);
console.log("[Brackets LiveDev] No subscribers for message " + msg.method);
return;
}
}
|
javascript
|
function (msg) {
var msgHandlers;
if (!msg.method) {
// no message type, ignoring it
// TODO: should we trigger a generic event?
console.log("[Brackets LiveDev] Received message without method.");
return;
}
// get handlers for msg.method
msgHandlers = this.handlers[msg.method];
if (msgHandlers && msgHandlers.length > 0) {
// invoke handlers with the received message
msgHandlers.forEach(function (handler) {
try {
// TODO: check which context should be used to call handlers here.
handler(msg);
return;
} catch (e) {
console.log("[Brackets LiveDev] Error executing a handler for " + msg.method);
console.log(e.stack);
return;
}
});
} else {
// no subscribers, ignore it.
// TODO: any other default handling? (eg. specific respond, trigger as a generic event, etc.);
console.log("[Brackets LiveDev] No subscribers for message " + msg.method);
return;
}
}
|
[
"function",
"(",
"msg",
")",
"{",
"var",
"msgHandlers",
";",
"if",
"(",
"!",
"msg",
".",
"method",
")",
"{",
"console",
".",
"log",
"(",
"\"[Brackets LiveDev] Received message without method.\"",
")",
";",
"return",
";",
"}",
"msgHandlers",
"=",
"this",
".",
"handlers",
"[",
"msg",
".",
"method",
"]",
";",
"if",
"(",
"msgHandlers",
"&&",
"msgHandlers",
".",
"length",
">",
"0",
")",
"{",
"msgHandlers",
".",
"forEach",
"(",
"function",
"(",
"handler",
")",
"{",
"try",
"{",
"handler",
"(",
"msg",
")",
";",
"return",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"\"[Brackets LiveDev] Error executing a handler for \"",
"+",
"msg",
".",
"method",
")",
";",
"console",
".",
"log",
"(",
"e",
".",
"stack",
")",
";",
"return",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"\"[Brackets LiveDev] No subscribers for message \"",
"+",
"msg",
".",
"method",
")",
";",
"return",
";",
"}",
"}"
] |
Dispatch messages to handlers according to msg.method value.
@param {Object} msg Message to be dispatched.
|
[
"Dispatch",
"messages",
"to",
"handlers",
"according",
"to",
"msg",
".",
"method",
"value",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/protocol/remote/LiveDevProtocolRemote.js#L60-L90
|
train
|
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/protocol/remote/LiveDevProtocolRemote.js
|
function (orig, response) {
if (!orig.id) {
console.log("[Brackets LiveDev] Trying to send a response for a message with no ID");
return;
}
response.id = orig.id;
this.send(response);
}
|
javascript
|
function (orig, response) {
if (!orig.id) {
console.log("[Brackets LiveDev] Trying to send a response for a message with no ID");
return;
}
response.id = orig.id;
this.send(response);
}
|
[
"function",
"(",
"orig",
",",
"response",
")",
"{",
"if",
"(",
"!",
"orig",
".",
"id",
")",
"{",
"console",
".",
"log",
"(",
"\"[Brackets LiveDev] Trying to send a response for a message with no ID\"",
")",
";",
"return",
";",
"}",
"response",
".",
"id",
"=",
"orig",
".",
"id",
";",
"this",
".",
"send",
"(",
"response",
")",
";",
"}"
] |
Send a response of a particular message to the Editor.
Original message must provide an 'id' property
@param {Object} orig Original message.
@param {Object} response Message to be sent as the response.
|
[
"Send",
"a",
"response",
"of",
"a",
"particular",
"message",
"to",
"the",
"Editor",
".",
"Original",
"message",
"must",
"provide",
"an",
"id",
"property"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/protocol/remote/LiveDevProtocolRemote.js#L98-L105
|
train
|
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/protocol/remote/LiveDevProtocolRemote.js
|
function (method, handler) {
if (!method || !handler) {
return;
}
if (!this.handlers[method]) {
//initialize array
this.handlers[method] = [];
}
// add handler to the stack
this.handlers[method].push(handler);
}
|
javascript
|
function (method, handler) {
if (!method || !handler) {
return;
}
if (!this.handlers[method]) {
//initialize array
this.handlers[method] = [];
}
// add handler to the stack
this.handlers[method].push(handler);
}
|
[
"function",
"(",
"method",
",",
"handler",
")",
"{",
"if",
"(",
"!",
"method",
"||",
"!",
"handler",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"this",
".",
"handlers",
"[",
"method",
"]",
")",
"{",
"this",
".",
"handlers",
"[",
"method",
"]",
"=",
"[",
"]",
";",
"}",
"this",
".",
"handlers",
"[",
"method",
"]",
".",
"push",
"(",
"handler",
")",
";",
"}"
] |
Subscribe handlers to specific messages.
@param {string} method Message type.
@param {function} handler.
TODO: add handler name or any identification mechanism to then implement 'off'?
|
[
"Subscribe",
"handlers",
"to",
"specific",
"messages",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/protocol/remote/LiveDevProtocolRemote.js#L113-L123
|
train
|
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/protocol/remote/LiveDevProtocolRemote.js
|
function (msg) {
console.log("Runtime.evaluate");
var result = eval(msg.params.expression);
MessageBroker.respond(msg, {
result: JSON.stringify(result) // TODO: in original protocol this is an object handle
});
}
|
javascript
|
function (msg) {
console.log("Runtime.evaluate");
var result = eval(msg.params.expression);
MessageBroker.respond(msg, {
result: JSON.stringify(result) // TODO: in original protocol this is an object handle
});
}
|
[
"function",
"(",
"msg",
")",
"{",
"console",
".",
"log",
"(",
"\"Runtime.evaluate\"",
")",
";",
"var",
"result",
"=",
"eval",
"(",
"msg",
".",
"params",
".",
"expression",
")",
";",
"MessageBroker",
".",
"respond",
"(",
"msg",
",",
"{",
"result",
":",
"JSON",
".",
"stringify",
"(",
"result",
")",
"}",
")",
";",
"}"
] |
Evaluate an expresion and return its result.
|
[
"Evaluate",
"an",
"expresion",
"and",
"return",
"its",
"result",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/protocol/remote/LiveDevProtocolRemote.js#L141-L147
|
train
|
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/protocol/remote/LiveDevProtocolRemote.js
|
function (msg) {
if (msg.params.url) {
// navigate to a new page.
window.location.replace(msg.params.url);
}
}
|
javascript
|
function (msg) {
if (msg.params.url) {
// navigate to a new page.
window.location.replace(msg.params.url);
}
}
|
[
"function",
"(",
"msg",
")",
"{",
"if",
"(",
"msg",
".",
"params",
".",
"url",
")",
"{",
"window",
".",
"location",
".",
"replace",
"(",
"msg",
".",
"params",
".",
"url",
")",
";",
"}",
"}"
] |
Navigate to a different page.
@param {Object} msg
|
[
"Navigate",
"to",
"a",
"different",
"page",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/protocol/remote/LiveDevProtocolRemote.js#L251-L256
|
train
|
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/protocol/remote/LiveDevProtocolRemote.js
|
function (msgStr) {
var msg;
try {
msg = JSON.parse(msgStr);
} catch (e) {
console.log("[Brackets LiveDev] Malformed message received: ", msgStr);
return;
}
// delegates handling/routing to MessageBroker.
MessageBroker.trigger(msg);
}
|
javascript
|
function (msgStr) {
var msg;
try {
msg = JSON.parse(msgStr);
} catch (e) {
console.log("[Brackets LiveDev] Malformed message received: ", msgStr);
return;
}
// delegates handling/routing to MessageBroker.
MessageBroker.trigger(msg);
}
|
[
"function",
"(",
"msgStr",
")",
"{",
"var",
"msg",
";",
"try",
"{",
"msg",
"=",
"JSON",
".",
"parse",
"(",
"msgStr",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"\"[Brackets LiveDev] Malformed message received: \"",
",",
"msgStr",
")",
";",
"return",
";",
"}",
"MessageBroker",
".",
"trigger",
"(",
"msg",
")",
";",
"}"
] |
Handles a message from the transport. Parses it as JSON and delegates
to MessageBroker who is in charge of routing them to handlers.
@param {string} msgStr The protocol message as stringified JSON.
|
[
"Handles",
"a",
"message",
"from",
"the",
"transport",
".",
"Parses",
"it",
"as",
"JSON",
"and",
"delegates",
"to",
"MessageBroker",
"who",
"is",
"in",
"charge",
"of",
"routing",
"them",
"to",
"handlers",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/protocol/remote/LiveDevProtocolRemote.js#L353-L363
|
train
|
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/protocol/remote/LiveDevProtocolRemote.js
|
onDocumentClick
|
function onDocumentClick(event) {
var element = event.target;
if (element && element.hasAttribute('data-brackets-id')) {
MessageBroker.send({"tagId": element.getAttribute('data-brackets-id')});
}
}
|
javascript
|
function onDocumentClick(event) {
var element = event.target;
if (element && element.hasAttribute('data-brackets-id')) {
MessageBroker.send({"tagId": element.getAttribute('data-brackets-id')});
}
}
|
[
"function",
"onDocumentClick",
"(",
"event",
")",
"{",
"var",
"element",
"=",
"event",
".",
"target",
";",
"if",
"(",
"element",
"&&",
"element",
".",
"hasAttribute",
"(",
"'data-brackets-id'",
")",
")",
"{",
"MessageBroker",
".",
"send",
"(",
"{",
"\"tagId\"",
":",
"element",
".",
"getAttribute",
"(",
"'data-brackets-id'",
")",
"}",
")",
";",
"}",
"}"
] |
Sends the message containing tagID which is being clicked
to the editor in order to change the cursor position to
the HTML tag corresponding to the clicked element.
|
[
"Sends",
"the",
"message",
"containing",
"tagID",
"which",
"is",
"being",
"clicked",
"to",
"the",
"editor",
"in",
"order",
"to",
"change",
"the",
"cursor",
"position",
"to",
"the",
"HTML",
"tag",
"corresponding",
"to",
"the",
"clicked",
"element",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/protocol/remote/LiveDevProtocolRemote.js#L385-L390
|
train
|
adobe/brackets
|
src/extensions/default/HealthData/HealthDataPreview.js
|
previewHealthData
|
function previewHealthData() {
var result = new $.Deferred();
HealthDataManager.getHealthData().done(function (healthDataObject) {
var combinedHealthAnalyticsData = HealthDataManager.getAnalyticsData(),
content;
combinedHealthAnalyticsData = [healthDataObject, combinedHealthAnalyticsData ];
content = JSON.stringify(combinedHealthAnalyticsData, null, 4);
content = _.escape(content);
content = content.replace(/ /g, " ");
content = content.replace(/(?:\r\n|\r|\n)/g, "<br />");
var hdPref = prefs.get("healthDataTracking"),
template = Mustache.render(HealthDataPreviewDialog, {Strings: Strings, content: content, hdPref: hdPref}),
$template = $(template);
Dialogs.addLinkTooltips($template);
Dialogs.showModalDialogUsingTemplate($template).done(function (id) {
if (id === "save") {
var newHDPref = $template.find("[data-target]:checkbox").is(":checked");
if (hdPref !== newHDPref) {
prefs.set("healthDataTracking", newHDPref);
}
}
});
return result.resolve();
});
return result.promise();
}
|
javascript
|
function previewHealthData() {
var result = new $.Deferred();
HealthDataManager.getHealthData().done(function (healthDataObject) {
var combinedHealthAnalyticsData = HealthDataManager.getAnalyticsData(),
content;
combinedHealthAnalyticsData = [healthDataObject, combinedHealthAnalyticsData ];
content = JSON.stringify(combinedHealthAnalyticsData, null, 4);
content = _.escape(content);
content = content.replace(/ /g, " ");
content = content.replace(/(?:\r\n|\r|\n)/g, "<br />");
var hdPref = prefs.get("healthDataTracking"),
template = Mustache.render(HealthDataPreviewDialog, {Strings: Strings, content: content, hdPref: hdPref}),
$template = $(template);
Dialogs.addLinkTooltips($template);
Dialogs.showModalDialogUsingTemplate($template).done(function (id) {
if (id === "save") {
var newHDPref = $template.find("[data-target]:checkbox").is(":checked");
if (hdPref !== newHDPref) {
prefs.set("healthDataTracking", newHDPref);
}
}
});
return result.resolve();
});
return result.promise();
}
|
[
"function",
"previewHealthData",
"(",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"HealthDataManager",
".",
"getHealthData",
"(",
")",
".",
"done",
"(",
"function",
"(",
"healthDataObject",
")",
"{",
"var",
"combinedHealthAnalyticsData",
"=",
"HealthDataManager",
".",
"getAnalyticsData",
"(",
")",
",",
"content",
";",
"combinedHealthAnalyticsData",
"=",
"[",
"healthDataObject",
",",
"combinedHealthAnalyticsData",
"]",
";",
"content",
"=",
"JSON",
".",
"stringify",
"(",
"combinedHealthAnalyticsData",
",",
"null",
",",
"4",
")",
";",
"content",
"=",
"_",
".",
"escape",
"(",
"content",
")",
";",
"content",
"=",
"content",
".",
"replace",
"(",
"/",
" ",
"/",
"g",
",",
"\" \"",
")",
";",
"content",
"=",
"content",
".",
"replace",
"(",
"/",
"(?:\\r\\n|\\r|\\n)",
"/",
"g",
",",
"\"<br />\"",
")",
";",
"var",
"hdPref",
"=",
"prefs",
".",
"get",
"(",
"\"healthDataTracking\"",
")",
",",
"template",
"=",
"Mustache",
".",
"render",
"(",
"HealthDataPreviewDialog",
",",
"{",
"Strings",
":",
"Strings",
",",
"content",
":",
"content",
",",
"hdPref",
":",
"hdPref",
"}",
")",
",",
"$template",
"=",
"$",
"(",
"template",
")",
";",
"Dialogs",
".",
"addLinkTooltips",
"(",
"$template",
")",
";",
"Dialogs",
".",
"showModalDialogUsingTemplate",
"(",
"$template",
")",
".",
"done",
"(",
"function",
"(",
"id",
")",
"{",
"if",
"(",
"id",
"===",
"\"save\"",
")",
"{",
"var",
"newHDPref",
"=",
"$template",
".",
"find",
"(",
"\"[data-target]:checkbox\"",
")",
".",
"is",
"(",
"\":checked\"",
")",
";",
"if",
"(",
"hdPref",
"!==",
"newHDPref",
")",
"{",
"prefs",
".",
"set",
"(",
"\"healthDataTracking\"",
",",
"newHDPref",
")",
";",
"}",
"}",
"}",
")",
";",
"return",
"result",
".",
"resolve",
"(",
")",
";",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Show the dialog for previewing the Health Data that will be sent.
|
[
"Show",
"the",
"dialog",
"for",
"previewing",
"the",
"Health",
"Data",
"that",
"will",
"be",
"sent",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/HealthData/HealthDataPreview.js#L44-L76
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
_openEditorForContext
|
function _openEditorForContext(contextData) {
// Open the file in the current active pane to prevent unwanted scenarios if we are not in split view, fallback
// to the persisted paneId when specified and we are in split view or unable to determine the paneid
var activePaneId = MainViewManager.getActivePaneId(),
targetPaneId = contextData.paneId; // Assume we are going to use the last associated paneID
// Detect if we are not in split mode
if (MainViewManager.getPaneCount() === 1) {
// Override the targetPaneId with activePaneId as we are not yet in split mode
targetPaneId = activePaneId;
}
// If hide of MROF list is a context parameter, hide the MROF list on successful file open
if (contextData.hideOnOpenFile) {
_hideMROFList();
}
return CommandManager
.execute(Commands.FILE_OPEN,
{ fullPath: contextData.path,
paneId: targetPaneId
}
)
.done(function () {
if (contextData.cursor) {
activeEditor = EditorManager.getActiveEditor();
activeEditor.setCursorPos(contextData.cursor);
activeEditor.centerOnCursor();
}
});
}
|
javascript
|
function _openEditorForContext(contextData) {
// Open the file in the current active pane to prevent unwanted scenarios if we are not in split view, fallback
// to the persisted paneId when specified and we are in split view or unable to determine the paneid
var activePaneId = MainViewManager.getActivePaneId(),
targetPaneId = contextData.paneId; // Assume we are going to use the last associated paneID
// Detect if we are not in split mode
if (MainViewManager.getPaneCount() === 1) {
// Override the targetPaneId with activePaneId as we are not yet in split mode
targetPaneId = activePaneId;
}
// If hide of MROF list is a context parameter, hide the MROF list on successful file open
if (contextData.hideOnOpenFile) {
_hideMROFList();
}
return CommandManager
.execute(Commands.FILE_OPEN,
{ fullPath: contextData.path,
paneId: targetPaneId
}
)
.done(function () {
if (contextData.cursor) {
activeEditor = EditorManager.getActiveEditor();
activeEditor.setCursorPos(contextData.cursor);
activeEditor.centerOnCursor();
}
});
}
|
[
"function",
"_openEditorForContext",
"(",
"contextData",
")",
"{",
"var",
"activePaneId",
"=",
"MainViewManager",
".",
"getActivePaneId",
"(",
")",
",",
"targetPaneId",
"=",
"contextData",
".",
"paneId",
";",
"if",
"(",
"MainViewManager",
".",
"getPaneCount",
"(",
")",
"===",
"1",
")",
"{",
"targetPaneId",
"=",
"activePaneId",
";",
"}",
"if",
"(",
"contextData",
".",
"hideOnOpenFile",
")",
"{",
"_hideMROFList",
"(",
")",
";",
"}",
"return",
"CommandManager",
".",
"execute",
"(",
"Commands",
".",
"FILE_OPEN",
",",
"{",
"fullPath",
":",
"contextData",
".",
"path",
",",
"paneId",
":",
"targetPaneId",
"}",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"contextData",
".",
"cursor",
")",
"{",
"activeEditor",
"=",
"EditorManager",
".",
"getActiveEditor",
"(",
")",
";",
"activeEditor",
".",
"setCursorPos",
"(",
"contextData",
".",
"cursor",
")",
";",
"activeEditor",
".",
"centerOnCursor",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Opens a full editor for the given context
@private
@param {Object.<path, paneId, cursor>} contextData - wrapper to provide the information required to open a full editor
@return {$.Promise} - from the commandmanager
|
[
"Opens",
"a",
"full",
"editor",
"for",
"the",
"given",
"context"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L99-L129
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
_makeMROFListEntry
|
function _makeMROFListEntry(path, pane, cursorPos) {
return {
file: path,
paneId: pane,
cursor: cursorPos
};
}
|
javascript
|
function _makeMROFListEntry(path, pane, cursorPos) {
return {
file: path,
paneId: pane,
cursor: cursorPos
};
}
|
[
"function",
"_makeMROFListEntry",
"(",
"path",
",",
"pane",
",",
"cursorPos",
")",
"{",
"return",
"{",
"file",
":",
"path",
",",
"paneId",
":",
"pane",
",",
"cursor",
":",
"cursorPos",
"}",
";",
"}"
] |
Creates an entry for MROF list
@private
@param {String} path - full path of a doc
@param {String} pane - the pane holding the editor for the doc
@param {Object} cursorPos - current cursor position
@return {Object} a frame containing file path, pane and last known cursor
|
[
"Creates",
"an",
"entry",
"for",
"MROF",
"list"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L139-L145
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
_syncWithFileSystem
|
function _syncWithFileSystem() {
_mrofList = _mrofList.filter(function (e) {return e; });
return Async.doSequentially(_mrofList, _checkExt, false);
}
|
javascript
|
function _syncWithFileSystem() {
_mrofList = _mrofList.filter(function (e) {return e; });
return Async.doSequentially(_mrofList, _checkExt, false);
}
|
[
"function",
"_syncWithFileSystem",
"(",
")",
"{",
"_mrofList",
"=",
"_mrofList",
".",
"filter",
"(",
"function",
"(",
"e",
")",
"{",
"return",
"e",
";",
"}",
")",
";",
"return",
"Async",
".",
"doSequentially",
"(",
"_mrofList",
",",
"_checkExt",
",",
"false",
")",
";",
"}"
] |
Checks whether entries in MROF list actually exists in fileSystem to prevent access to deleted files
@private
|
[
"Checks",
"whether",
"entries",
"in",
"MROF",
"list",
"actually",
"exists",
"in",
"fileSystem",
"to",
"prevent",
"access",
"to",
"deleted",
"files"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L190-L193
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
_createMROFList
|
function _createMROFList() {
var paneList = MainViewManager.getPaneIdList(),
mrofList = [],
fileList,
index;
var pane, file, mrofEntry, paneCount, fileCount;
// Iterate over the pane ID list
for (paneCount = 0; paneCount < paneList.length; paneCount++) {
pane = paneList[paneCount];
fileList = MainViewManager.getWorkingSet(pane);
// Iterate over the file list for this pane
for (fileCount = 0; fileCount < fileList.length; fileCount++) {
file = fileList[fileCount];
mrofEntry = _makeMROFListEntry(file.fullPath, pane, null);
// Add it in the MRU list order
index = MainViewManager.findInGlobalMRUList(pane, file);
mrofList[index] = mrofEntry;
}
}
return mrofList;
}
|
javascript
|
function _createMROFList() {
var paneList = MainViewManager.getPaneIdList(),
mrofList = [],
fileList,
index;
var pane, file, mrofEntry, paneCount, fileCount;
// Iterate over the pane ID list
for (paneCount = 0; paneCount < paneList.length; paneCount++) {
pane = paneList[paneCount];
fileList = MainViewManager.getWorkingSet(pane);
// Iterate over the file list for this pane
for (fileCount = 0; fileCount < fileList.length; fileCount++) {
file = fileList[fileCount];
mrofEntry = _makeMROFListEntry(file.fullPath, pane, null);
// Add it in the MRU list order
index = MainViewManager.findInGlobalMRUList(pane, file);
mrofList[index] = mrofEntry;
}
}
return mrofList;
}
|
[
"function",
"_createMROFList",
"(",
")",
"{",
"var",
"paneList",
"=",
"MainViewManager",
".",
"getPaneIdList",
"(",
")",
",",
"mrofList",
"=",
"[",
"]",
",",
"fileList",
",",
"index",
";",
"var",
"pane",
",",
"file",
",",
"mrofEntry",
",",
"paneCount",
",",
"fileCount",
";",
"for",
"(",
"paneCount",
"=",
"0",
";",
"paneCount",
"<",
"paneList",
".",
"length",
";",
"paneCount",
"++",
")",
"{",
"pane",
"=",
"paneList",
"[",
"paneCount",
"]",
";",
"fileList",
"=",
"MainViewManager",
".",
"getWorkingSet",
"(",
"pane",
")",
";",
"for",
"(",
"fileCount",
"=",
"0",
";",
"fileCount",
"<",
"fileList",
".",
"length",
";",
"fileCount",
"++",
")",
"{",
"file",
"=",
"fileList",
"[",
"fileCount",
"]",
";",
"mrofEntry",
"=",
"_makeMROFListEntry",
"(",
"file",
".",
"fullPath",
",",
"pane",
",",
"null",
")",
";",
"index",
"=",
"MainViewManager",
".",
"findInGlobalMRUList",
"(",
"pane",
",",
"file",
")",
";",
"mrofList",
"[",
"index",
"]",
"=",
"mrofEntry",
";",
"}",
"}",
"return",
"mrofList",
";",
"}"
] |
This function is used to create mrof when a project is opened for the firt time with the recent files feature
This routine acts as a logic to migrate existing viewlist to mrof structure
@private
|
[
"This",
"function",
"is",
"used",
"to",
"create",
"mrof",
"when",
"a",
"project",
"is",
"opened",
"for",
"the",
"firt",
"time",
"with",
"the",
"recent",
"files",
"feature",
"This",
"routine",
"acts",
"as",
"a",
"logic",
"to",
"migrate",
"existing",
"viewlist",
"to",
"mrof",
"structure"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L320-L343
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
_createMROFDisplayList
|
function _createMROFDisplayList(refresh) {
var $def = $.Deferred();
var $mrofList, $link, $newItem;
/**
* Clears the MROF list in memory and pop over but retains the working set entries
* @private
*/
function _purgeAllExceptWorkingSet() {
_mrofList = _createMROFList();
$mrofList.empty();
_createMROFDisplayList(true);
$currentContext = null;
PreferencesManager.setViewState(OPEN_FILES_VIEW_STATE, _mrofList, _getPrefsContext(), true);
}
if (!refresh) {
// Call hide first to make sure we are not creating duplicate lists
_hideMROFList();
$mrofContainer = $(Mustache.render(htmlTemplate, {Strings: Strings})).appendTo('body');
$("#mrof-list-close").one("click", _hideMROFList);
// Attach clear list handler to the 'Clear All' button
$("#mrof-container .footer > div#clear-mrof-list").on("click", _purgeAllExceptWorkingSet);
$(window).on("keydown", _handleArrowKeys);
$(window).on("keyup", _hideMROFListOnEscape);
}
$mrofList = $mrofContainer.find("#mrof-list");
/**
* Focus handler for the link in list item
* @private
*/
function _onFocus(event) {
var $scope = $(event.target).parent();
$("#mrof-container #mrof-list > li.highlight").removeClass("highlight");
$(event.target).parent().addClass("highlight");
$mrofContainer.find("#recent-file-path").text($scope.data("path"));
$mrofContainer.find("#recent-file-path").attr('title', ($scope.data("path")));
$currentContext = $scope;
}
/**
* Click handler for the link in list item
* @private
*/
function _onClick(event) {
var $scope = $(event.delegateTarget).parent();
_openEditorForContext({
path: $scope.data("path"),
paneId: $scope.data("paneId"),
cursor: $scope.data("cursor"),
hideOnOpenFile: true
});
}
var data, fileEntry;
_syncWithFileSystem().always(function () {
_mrofList = _mrofList.filter(function (e) {return e; });
_createFileEntries($mrofList);
var $fileLinks = $("#mrof-container #mrof-list > li > a.mroitem");
// Handlers for mouse events on the list items
$fileLinks.on("focus", _onFocus);
$fileLinks.on("click", _onClick);
$fileLinks.on("select", _onClick);
// Put focus on the Most recent file link in the list
$fileLinks.first().trigger("focus");
$def.resolve();
});
return $def.promise();
}
|
javascript
|
function _createMROFDisplayList(refresh) {
var $def = $.Deferred();
var $mrofList, $link, $newItem;
/**
* Clears the MROF list in memory and pop over but retains the working set entries
* @private
*/
function _purgeAllExceptWorkingSet() {
_mrofList = _createMROFList();
$mrofList.empty();
_createMROFDisplayList(true);
$currentContext = null;
PreferencesManager.setViewState(OPEN_FILES_VIEW_STATE, _mrofList, _getPrefsContext(), true);
}
if (!refresh) {
// Call hide first to make sure we are not creating duplicate lists
_hideMROFList();
$mrofContainer = $(Mustache.render(htmlTemplate, {Strings: Strings})).appendTo('body');
$("#mrof-list-close").one("click", _hideMROFList);
// Attach clear list handler to the 'Clear All' button
$("#mrof-container .footer > div#clear-mrof-list").on("click", _purgeAllExceptWorkingSet);
$(window).on("keydown", _handleArrowKeys);
$(window).on("keyup", _hideMROFListOnEscape);
}
$mrofList = $mrofContainer.find("#mrof-list");
/**
* Focus handler for the link in list item
* @private
*/
function _onFocus(event) {
var $scope = $(event.target).parent();
$("#mrof-container #mrof-list > li.highlight").removeClass("highlight");
$(event.target).parent().addClass("highlight");
$mrofContainer.find("#recent-file-path").text($scope.data("path"));
$mrofContainer.find("#recent-file-path").attr('title', ($scope.data("path")));
$currentContext = $scope;
}
/**
* Click handler for the link in list item
* @private
*/
function _onClick(event) {
var $scope = $(event.delegateTarget).parent();
_openEditorForContext({
path: $scope.data("path"),
paneId: $scope.data("paneId"),
cursor: $scope.data("cursor"),
hideOnOpenFile: true
});
}
var data, fileEntry;
_syncWithFileSystem().always(function () {
_mrofList = _mrofList.filter(function (e) {return e; });
_createFileEntries($mrofList);
var $fileLinks = $("#mrof-container #mrof-list > li > a.mroitem");
// Handlers for mouse events on the list items
$fileLinks.on("focus", _onFocus);
$fileLinks.on("click", _onClick);
$fileLinks.on("select", _onClick);
// Put focus on the Most recent file link in the list
$fileLinks.first().trigger("focus");
$def.resolve();
});
return $def.promise();
}
|
[
"function",
"_createMROFDisplayList",
"(",
"refresh",
")",
"{",
"var",
"$def",
"=",
"$",
".",
"Deferred",
"(",
")",
";",
"var",
"$mrofList",
",",
"$link",
",",
"$newItem",
";",
"function",
"_purgeAllExceptWorkingSet",
"(",
")",
"{",
"_mrofList",
"=",
"_createMROFList",
"(",
")",
";",
"$mrofList",
".",
"empty",
"(",
")",
";",
"_createMROFDisplayList",
"(",
"true",
")",
";",
"$currentContext",
"=",
"null",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"OPEN_FILES_VIEW_STATE",
",",
"_mrofList",
",",
"_getPrefsContext",
"(",
")",
",",
"true",
")",
";",
"}",
"if",
"(",
"!",
"refresh",
")",
"{",
"_hideMROFList",
"(",
")",
";",
"$mrofContainer",
"=",
"$",
"(",
"Mustache",
".",
"render",
"(",
"htmlTemplate",
",",
"{",
"Strings",
":",
"Strings",
"}",
")",
")",
".",
"appendTo",
"(",
"'body'",
")",
";",
"$",
"(",
"\"#mrof-list-close\"",
")",
".",
"one",
"(",
"\"click\"",
",",
"_hideMROFList",
")",
";",
"$",
"(",
"\"#mrof-container .footer > div#clear-mrof-list\"",
")",
".",
"on",
"(",
"\"click\"",
",",
"_purgeAllExceptWorkingSet",
")",
";",
"$",
"(",
"window",
")",
".",
"on",
"(",
"\"keydown\"",
",",
"_handleArrowKeys",
")",
";",
"$",
"(",
"window",
")",
".",
"on",
"(",
"\"keyup\"",
",",
"_hideMROFListOnEscape",
")",
";",
"}",
"$mrofList",
"=",
"$mrofContainer",
".",
"find",
"(",
"\"#mrof-list\"",
")",
";",
"function",
"_onFocus",
"(",
"event",
")",
"{",
"var",
"$scope",
"=",
"$",
"(",
"event",
".",
"target",
")",
".",
"parent",
"(",
")",
";",
"$",
"(",
"\"#mrof-container #mrof-list > li.highlight\"",
")",
".",
"removeClass",
"(",
"\"highlight\"",
")",
";",
"$",
"(",
"event",
".",
"target",
")",
".",
"parent",
"(",
")",
".",
"addClass",
"(",
"\"highlight\"",
")",
";",
"$mrofContainer",
".",
"find",
"(",
"\"#recent-file-path\"",
")",
".",
"text",
"(",
"$scope",
".",
"data",
"(",
"\"path\"",
")",
")",
";",
"$mrofContainer",
".",
"find",
"(",
"\"#recent-file-path\"",
")",
".",
"attr",
"(",
"'title'",
",",
"(",
"$scope",
".",
"data",
"(",
"\"path\"",
")",
")",
")",
";",
"$currentContext",
"=",
"$scope",
";",
"}",
"function",
"_onClick",
"(",
"event",
")",
"{",
"var",
"$scope",
"=",
"$",
"(",
"event",
".",
"delegateTarget",
")",
".",
"parent",
"(",
")",
";",
"_openEditorForContext",
"(",
"{",
"path",
":",
"$scope",
".",
"data",
"(",
"\"path\"",
")",
",",
"paneId",
":",
"$scope",
".",
"data",
"(",
"\"paneId\"",
")",
",",
"cursor",
":",
"$scope",
".",
"data",
"(",
"\"cursor\"",
")",
",",
"hideOnOpenFile",
":",
"true",
"}",
")",
";",
"}",
"var",
"data",
",",
"fileEntry",
";",
"_syncWithFileSystem",
"(",
")",
".",
"always",
"(",
"function",
"(",
")",
"{",
"_mrofList",
"=",
"_mrofList",
".",
"filter",
"(",
"function",
"(",
"e",
")",
"{",
"return",
"e",
";",
"}",
")",
";",
"_createFileEntries",
"(",
"$mrofList",
")",
";",
"var",
"$fileLinks",
"=",
"$",
"(",
"\"#mrof-container #mrof-list > li > a.mroitem\"",
")",
";",
"$fileLinks",
".",
"on",
"(",
"\"focus\"",
",",
"_onFocus",
")",
";",
"$fileLinks",
".",
"on",
"(",
"\"click\"",
",",
"_onClick",
")",
";",
"$fileLinks",
".",
"on",
"(",
"\"select\"",
",",
"_onClick",
")",
";",
"$fileLinks",
".",
"first",
"(",
")",
".",
"trigger",
"(",
"\"focus\"",
")",
";",
"$def",
".",
"resolve",
"(",
")",
";",
"}",
")",
";",
"return",
"$def",
".",
"promise",
"(",
")",
";",
"}"
] |
Shows the current MROF list
@private
|
[
"Shows",
"the",
"current",
"MROF",
"list"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L380-L455
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
_purgeAllExceptWorkingSet
|
function _purgeAllExceptWorkingSet() {
_mrofList = _createMROFList();
$mrofList.empty();
_createMROFDisplayList(true);
$currentContext = null;
PreferencesManager.setViewState(OPEN_FILES_VIEW_STATE, _mrofList, _getPrefsContext(), true);
}
|
javascript
|
function _purgeAllExceptWorkingSet() {
_mrofList = _createMROFList();
$mrofList.empty();
_createMROFDisplayList(true);
$currentContext = null;
PreferencesManager.setViewState(OPEN_FILES_VIEW_STATE, _mrofList, _getPrefsContext(), true);
}
|
[
"function",
"_purgeAllExceptWorkingSet",
"(",
")",
"{",
"_mrofList",
"=",
"_createMROFList",
"(",
")",
";",
"$mrofList",
".",
"empty",
"(",
")",
";",
"_createMROFDisplayList",
"(",
"true",
")",
";",
"$currentContext",
"=",
"null",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"OPEN_FILES_VIEW_STATE",
",",
"_mrofList",
",",
"_getPrefsContext",
"(",
")",
",",
"true",
")",
";",
"}"
] |
Clears the MROF list in memory and pop over but retains the working set entries
@private
|
[
"Clears",
"the",
"MROF",
"list",
"in",
"memory",
"and",
"pop",
"over",
"but",
"retains",
"the",
"working",
"set",
"entries"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L389-L395
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
_onFocus
|
function _onFocus(event) {
var $scope = $(event.target).parent();
$("#mrof-container #mrof-list > li.highlight").removeClass("highlight");
$(event.target).parent().addClass("highlight");
$mrofContainer.find("#recent-file-path").text($scope.data("path"));
$mrofContainer.find("#recent-file-path").attr('title', ($scope.data("path")));
$currentContext = $scope;
}
|
javascript
|
function _onFocus(event) {
var $scope = $(event.target).parent();
$("#mrof-container #mrof-list > li.highlight").removeClass("highlight");
$(event.target).parent().addClass("highlight");
$mrofContainer.find("#recent-file-path").text($scope.data("path"));
$mrofContainer.find("#recent-file-path").attr('title', ($scope.data("path")));
$currentContext = $scope;
}
|
[
"function",
"_onFocus",
"(",
"event",
")",
"{",
"var",
"$scope",
"=",
"$",
"(",
"event",
".",
"target",
")",
".",
"parent",
"(",
")",
";",
"$",
"(",
"\"#mrof-container #mrof-list > li.highlight\"",
")",
".",
"removeClass",
"(",
"\"highlight\"",
")",
";",
"$",
"(",
"event",
".",
"target",
")",
".",
"parent",
"(",
")",
".",
"addClass",
"(",
"\"highlight\"",
")",
";",
"$mrofContainer",
".",
"find",
"(",
"\"#recent-file-path\"",
")",
".",
"text",
"(",
"$scope",
".",
"data",
"(",
"\"path\"",
")",
")",
";",
"$mrofContainer",
".",
"find",
"(",
"\"#recent-file-path\"",
")",
".",
"attr",
"(",
"'title'",
",",
"(",
"$scope",
".",
"data",
"(",
"\"path\"",
")",
")",
")",
";",
"$currentContext",
"=",
"$scope",
";",
"}"
] |
Focus handler for the link in list item
@private
|
[
"Focus",
"handler",
"for",
"the",
"link",
"in",
"list",
"item"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L414-L421
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
_onClick
|
function _onClick(event) {
var $scope = $(event.delegateTarget).parent();
_openEditorForContext({
path: $scope.data("path"),
paneId: $scope.data("paneId"),
cursor: $scope.data("cursor"),
hideOnOpenFile: true
});
}
|
javascript
|
function _onClick(event) {
var $scope = $(event.delegateTarget).parent();
_openEditorForContext({
path: $scope.data("path"),
paneId: $scope.data("paneId"),
cursor: $scope.data("cursor"),
hideOnOpenFile: true
});
}
|
[
"function",
"_onClick",
"(",
"event",
")",
"{",
"var",
"$scope",
"=",
"$",
"(",
"event",
".",
"delegateTarget",
")",
".",
"parent",
"(",
")",
";",
"_openEditorForContext",
"(",
"{",
"path",
":",
"$scope",
".",
"data",
"(",
"\"path\"",
")",
",",
"paneId",
":",
"$scope",
".",
"data",
"(",
"\"paneId\"",
")",
",",
"cursor",
":",
"$scope",
".",
"data",
"(",
"\"cursor\"",
")",
",",
"hideOnOpenFile",
":",
"true",
"}",
")",
";",
"}"
] |
Click handler for the link in list item
@private
|
[
"Click",
"handler",
"for",
"the",
"link",
"in",
"list",
"item"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L427-L435
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
_moveNext
|
function _moveNext() {
var $context, $next;
$context = $currentContext || $("#mrof-container #mrof-list > li.highlight");
if ($context.length > 0) {
$next = $context.next();
if ($next.length === 0) {
$next = $("#mrof-container #mrof-list > li").first();
}
if ($next.length > 0) {
$currentContext = $next;
$next.find("a.mroitem").trigger("focus");
}
} else {
//WTF! (Worse than failure). We should not get here.
$("#mrof-container #mrof-list > li > a.mroitem:visited").last().trigger("focus");
}
}
|
javascript
|
function _moveNext() {
var $context, $next;
$context = $currentContext || $("#mrof-container #mrof-list > li.highlight");
if ($context.length > 0) {
$next = $context.next();
if ($next.length === 0) {
$next = $("#mrof-container #mrof-list > li").first();
}
if ($next.length > 0) {
$currentContext = $next;
$next.find("a.mroitem").trigger("focus");
}
} else {
//WTF! (Worse than failure). We should not get here.
$("#mrof-container #mrof-list > li > a.mroitem:visited").last().trigger("focus");
}
}
|
[
"function",
"_moveNext",
"(",
")",
"{",
"var",
"$context",
",",
"$next",
";",
"$context",
"=",
"$currentContext",
"||",
"$",
"(",
"\"#mrof-container #mrof-list > li.highlight\"",
")",
";",
"if",
"(",
"$context",
".",
"length",
">",
"0",
")",
"{",
"$next",
"=",
"$context",
".",
"next",
"(",
")",
";",
"if",
"(",
"$next",
".",
"length",
"===",
"0",
")",
"{",
"$next",
"=",
"$",
"(",
"\"#mrof-container #mrof-list > li\"",
")",
".",
"first",
"(",
")",
";",
"}",
"if",
"(",
"$next",
".",
"length",
">",
"0",
")",
"{",
"$currentContext",
"=",
"$next",
";",
"$next",
".",
"find",
"(",
"\"a.mroitem\"",
")",
".",
"trigger",
"(",
"\"focus\"",
")",
";",
"}",
"}",
"else",
"{",
"$",
"(",
"\"#mrof-container #mrof-list > li > a.mroitem:visited\"",
")",
".",
"last",
"(",
")",
".",
"trigger",
"(",
"\"focus\"",
")",
";",
"}",
"}"
] |
Opens the next item in MROF list if pop over is visible else displays the pop over
@private
|
[
"Opens",
"the",
"next",
"item",
"in",
"MROF",
"list",
"if",
"pop",
"over",
"is",
"visible",
"else",
"displays",
"the",
"pop",
"over"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L479-L496
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
_movePrev
|
function _movePrev() {
var $context, $prev;
$context = $currentContext || $("#mrof-container #mrof-list > li.highlight");
if ($context.length > 0) {
$prev = $context.prev();
if ($prev.length === 0) {
$prev = $("#mrof-container #mrof-list > li").last();
}
if ($prev.length > 0) {
$currentContext = $prev;
$prev.find("a.mroitem").trigger("focus");
}
} else {
//WTF! (Worse than failure). We should not get here.
$("#mrof-container #mrof-list > li > a.mroitem:visited").last().trigger("focus");
}
}
|
javascript
|
function _movePrev() {
var $context, $prev;
$context = $currentContext || $("#mrof-container #mrof-list > li.highlight");
if ($context.length > 0) {
$prev = $context.prev();
if ($prev.length === 0) {
$prev = $("#mrof-container #mrof-list > li").last();
}
if ($prev.length > 0) {
$currentContext = $prev;
$prev.find("a.mroitem").trigger("focus");
}
} else {
//WTF! (Worse than failure). We should not get here.
$("#mrof-container #mrof-list > li > a.mroitem:visited").last().trigger("focus");
}
}
|
[
"function",
"_movePrev",
"(",
")",
"{",
"var",
"$context",
",",
"$prev",
";",
"$context",
"=",
"$currentContext",
"||",
"$",
"(",
"\"#mrof-container #mrof-list > li.highlight\"",
")",
";",
"if",
"(",
"$context",
".",
"length",
">",
"0",
")",
"{",
"$prev",
"=",
"$context",
".",
"prev",
"(",
")",
";",
"if",
"(",
"$prev",
".",
"length",
"===",
"0",
")",
"{",
"$prev",
"=",
"$",
"(",
"\"#mrof-container #mrof-list > li\"",
")",
".",
"last",
"(",
")",
";",
"}",
"if",
"(",
"$prev",
".",
"length",
">",
"0",
")",
"{",
"$currentContext",
"=",
"$prev",
";",
"$prev",
".",
"find",
"(",
"\"a.mroitem\"",
")",
".",
"trigger",
"(",
"\"focus\"",
")",
";",
"}",
"}",
"else",
"{",
"$",
"(",
"\"#mrof-container #mrof-list > li > a.mroitem:visited\"",
")",
".",
"last",
"(",
")",
".",
"trigger",
"(",
"\"focus\"",
")",
";",
"}",
"}"
] |
Opens the previous item in MROF list if pop over is visible else displays the pop over
@private
|
[
"Opens",
"the",
"previous",
"item",
"in",
"MROF",
"list",
"if",
"pop",
"over",
"is",
"visible",
"else",
"displays",
"the",
"pop",
"over"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L519-L536
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
_addToMROFList
|
function _addToMROFList(file, paneId, cursorPos) {
var filePath = file.fullPath;
if (!paneId) { // Don't handle this if not a full view/editor
return;
}
// Check existing list for this doc path and pane entry
var index = _.findIndex(_mrofList, function (record) {
return (record && record.file === filePath && record.paneId === paneId);
});
var entry;
if (index !== -1) {
entry = _mrofList[index];
if (entry.cursor && !cursorPos) {
cursorPos = entry.cursor;
}
}
entry = _makeMROFListEntry(filePath, paneId, cursorPos);
// Check if the file is an InMemoryFile
if (file.constructor.name === "InMemoryFile") {
// Mark the entry as inMem, so that we can knock it off from the list when removed from working set
entry.inMem = true;
}
if (index !== -1) {
_mrofList.splice(index, 1);
}
// add it to the front of the list
_mrofList.unshift(entry);
PreferencesManager.setViewState(OPEN_FILES_VIEW_STATE, _mrofList, _getPrefsContext(), true);
}
|
javascript
|
function _addToMROFList(file, paneId, cursorPos) {
var filePath = file.fullPath;
if (!paneId) { // Don't handle this if not a full view/editor
return;
}
// Check existing list for this doc path and pane entry
var index = _.findIndex(_mrofList, function (record) {
return (record && record.file === filePath && record.paneId === paneId);
});
var entry;
if (index !== -1) {
entry = _mrofList[index];
if (entry.cursor && !cursorPos) {
cursorPos = entry.cursor;
}
}
entry = _makeMROFListEntry(filePath, paneId, cursorPos);
// Check if the file is an InMemoryFile
if (file.constructor.name === "InMemoryFile") {
// Mark the entry as inMem, so that we can knock it off from the list when removed from working set
entry.inMem = true;
}
if (index !== -1) {
_mrofList.splice(index, 1);
}
// add it to the front of the list
_mrofList.unshift(entry);
PreferencesManager.setViewState(OPEN_FILES_VIEW_STATE, _mrofList, _getPrefsContext(), true);
}
|
[
"function",
"_addToMROFList",
"(",
"file",
",",
"paneId",
",",
"cursorPos",
")",
"{",
"var",
"filePath",
"=",
"file",
".",
"fullPath",
";",
"if",
"(",
"!",
"paneId",
")",
"{",
"return",
";",
"}",
"var",
"index",
"=",
"_",
".",
"findIndex",
"(",
"_mrofList",
",",
"function",
"(",
"record",
")",
"{",
"return",
"(",
"record",
"&&",
"record",
".",
"file",
"===",
"filePath",
"&&",
"record",
".",
"paneId",
"===",
"paneId",
")",
";",
"}",
")",
";",
"var",
"entry",
";",
"if",
"(",
"index",
"!==",
"-",
"1",
")",
"{",
"entry",
"=",
"_mrofList",
"[",
"index",
"]",
";",
"if",
"(",
"entry",
".",
"cursor",
"&&",
"!",
"cursorPos",
")",
"{",
"cursorPos",
"=",
"entry",
".",
"cursor",
";",
"}",
"}",
"entry",
"=",
"_makeMROFListEntry",
"(",
"filePath",
",",
"paneId",
",",
"cursorPos",
")",
";",
"if",
"(",
"file",
".",
"constructor",
".",
"name",
"===",
"\"InMemoryFile\"",
")",
"{",
"entry",
".",
"inMem",
"=",
"true",
";",
"}",
"if",
"(",
"index",
"!==",
"-",
"1",
")",
"{",
"_mrofList",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"}",
"_mrofList",
".",
"unshift",
"(",
"entry",
")",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"OPEN_FILES_VIEW_STATE",
",",
"_mrofList",
",",
"_getPrefsContext",
"(",
")",
",",
"true",
")",
";",
"}"
] |
Adds an entry to MROF list
@private
@param {Editor} editor - editor to extract file information
|
[
"Adds",
"an",
"entry",
"to",
"MROF",
"list"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L579-L618
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
_handleWorkingSetMove
|
function _handleWorkingSetMove(event, file, sourcePaneId, destinationPaneId) {
// Check existing list for this doc path and source pane entry
var index = _.findIndex(_mrofList, function (record) {
return (record && record.file === file.fullPath && record.paneId === sourcePaneId);
}), tIndex;
// If an entry is found update the pane info
if (index >= 0) {
// But an entry with the target pane Id should not exist
tIndex = _.findIndex(_mrofList, function (record) {
return (record && record.file === file.fullPath && record.paneId === destinationPaneId);
});
if (tIndex === -1) {
_mrofList[index].paneId = destinationPaneId;
} else {
// Remove this entry as it has been moved.
_mrofList.splice(index, 1);
}
}
}
|
javascript
|
function _handleWorkingSetMove(event, file, sourcePaneId, destinationPaneId) {
// Check existing list for this doc path and source pane entry
var index = _.findIndex(_mrofList, function (record) {
return (record && record.file === file.fullPath && record.paneId === sourcePaneId);
}), tIndex;
// If an entry is found update the pane info
if (index >= 0) {
// But an entry with the target pane Id should not exist
tIndex = _.findIndex(_mrofList, function (record) {
return (record && record.file === file.fullPath && record.paneId === destinationPaneId);
});
if (tIndex === -1) {
_mrofList[index].paneId = destinationPaneId;
} else {
// Remove this entry as it has been moved.
_mrofList.splice(index, 1);
}
}
}
|
[
"function",
"_handleWorkingSetMove",
"(",
"event",
",",
"file",
",",
"sourcePaneId",
",",
"destinationPaneId",
")",
"{",
"var",
"index",
"=",
"_",
".",
"findIndex",
"(",
"_mrofList",
",",
"function",
"(",
"record",
")",
"{",
"return",
"(",
"record",
"&&",
"record",
".",
"file",
"===",
"file",
".",
"fullPath",
"&&",
"record",
".",
"paneId",
"===",
"sourcePaneId",
")",
";",
"}",
")",
",",
"tIndex",
";",
"if",
"(",
"index",
">=",
"0",
")",
"{",
"tIndex",
"=",
"_",
".",
"findIndex",
"(",
"_mrofList",
",",
"function",
"(",
"record",
")",
"{",
"return",
"(",
"record",
"&&",
"record",
".",
"file",
"===",
"file",
".",
"fullPath",
"&&",
"record",
".",
"paneId",
"===",
"destinationPaneId",
")",
";",
"}",
")",
";",
"if",
"(",
"tIndex",
"===",
"-",
"1",
")",
"{",
"_mrofList",
"[",
"index",
"]",
".",
"paneId",
"=",
"destinationPaneId",
";",
"}",
"else",
"{",
"_mrofList",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"}",
"}",
"}"
] |
To update existing entry if a move has happened
|
[
"To",
"update",
"existing",
"entry",
"if",
"a",
"move",
"has",
"happened"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L621-L639
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
_handlePaneMerge
|
function _handlePaneMerge(e, paneId) {
var index;
var targetPaneId = MainViewManager.FIRST_PANE;
$.each(_mrofList, function (itrIndex, value) {
if (value && value.paneId === paneId) { // We have got an entry which needs merge
// Before modifying the actual pane info check if an entry exists with same target pane
index = _.findIndex(_mrofList, function (record) {
return (record && record.file === value.file && record.paneId === targetPaneId);
});
if (index !== -1) { // A duplicate entry found, remove the current one instead of updating
_mrofList[index] = null;
} else { // Update with merged pane info
_mrofList[itrIndex].paneId = targetPaneId;
}
}
});
// Clean the null/undefined entries
_mrofList = _mrofList.filter(function (e) {return e; });
PreferencesManager.setViewState(OPEN_FILES_VIEW_STATE, _mrofList, _getPrefsContext(), true);
}
|
javascript
|
function _handlePaneMerge(e, paneId) {
var index;
var targetPaneId = MainViewManager.FIRST_PANE;
$.each(_mrofList, function (itrIndex, value) {
if (value && value.paneId === paneId) { // We have got an entry which needs merge
// Before modifying the actual pane info check if an entry exists with same target pane
index = _.findIndex(_mrofList, function (record) {
return (record && record.file === value.file && record.paneId === targetPaneId);
});
if (index !== -1) { // A duplicate entry found, remove the current one instead of updating
_mrofList[index] = null;
} else { // Update with merged pane info
_mrofList[itrIndex].paneId = targetPaneId;
}
}
});
// Clean the null/undefined entries
_mrofList = _mrofList.filter(function (e) {return e; });
PreferencesManager.setViewState(OPEN_FILES_VIEW_STATE, _mrofList, _getPrefsContext(), true);
}
|
[
"function",
"_handlePaneMerge",
"(",
"e",
",",
"paneId",
")",
"{",
"var",
"index",
";",
"var",
"targetPaneId",
"=",
"MainViewManager",
".",
"FIRST_PANE",
";",
"$",
".",
"each",
"(",
"_mrofList",
",",
"function",
"(",
"itrIndex",
",",
"value",
")",
"{",
"if",
"(",
"value",
"&&",
"value",
".",
"paneId",
"===",
"paneId",
")",
"{",
"index",
"=",
"_",
".",
"findIndex",
"(",
"_mrofList",
",",
"function",
"(",
"record",
")",
"{",
"return",
"(",
"record",
"&&",
"record",
".",
"file",
"===",
"value",
".",
"file",
"&&",
"record",
".",
"paneId",
"===",
"targetPaneId",
")",
";",
"}",
")",
";",
"if",
"(",
"index",
"!==",
"-",
"1",
")",
"{",
"_mrofList",
"[",
"index",
"]",
"=",
"null",
";",
"}",
"else",
"{",
"_mrofList",
"[",
"itrIndex",
"]",
".",
"paneId",
"=",
"targetPaneId",
";",
"}",
"}",
"}",
")",
";",
"_mrofList",
"=",
"_mrofList",
".",
"filter",
"(",
"function",
"(",
"e",
")",
"{",
"return",
"e",
";",
"}",
")",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"OPEN_FILES_VIEW_STATE",
",",
"_mrofList",
",",
"_getPrefsContext",
"(",
")",
",",
"true",
")",
";",
"}"
] |
Merges the entries to a single pane if split view have been merged Then purges duplicate entries in mrof list
|
[
"Merges",
"the",
"entries",
"to",
"a",
"single",
"pane",
"if",
"split",
"view",
"have",
"been",
"merged",
"Then",
"purges",
"duplicate",
"entries",
"in",
"mrof",
"list"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L701-L723
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
handleCurrentFileChange
|
function handleCurrentFileChange(e, newFile, newPaneId, oldFile) {
if (newFile) {
if (_mrofList.length === 0) {
_initRecentFilesList();
}
_addToMROFList(newFile, newPaneId);
}
}
|
javascript
|
function handleCurrentFileChange(e, newFile, newPaneId, oldFile) {
if (newFile) {
if (_mrofList.length === 0) {
_initRecentFilesList();
}
_addToMROFList(newFile, newPaneId);
}
}
|
[
"function",
"handleCurrentFileChange",
"(",
"e",
",",
"newFile",
",",
"newPaneId",
",",
"oldFile",
")",
"{",
"if",
"(",
"newFile",
")",
"{",
"if",
"(",
"_mrofList",
".",
"length",
"===",
"0",
")",
"{",
"_initRecentFilesList",
"(",
")",
";",
"}",
"_addToMROFList",
"(",
"newFile",
",",
"newPaneId",
")",
";",
"}",
"}"
] |
Handle current file change
|
[
"Handle",
"current",
"file",
"change"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L771-L779
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/main.js
|
_handleActiveEditorChange
|
function _handleActiveEditorChange(event, current, previous) {
if (current) { // Handle only full editors
if (_mrofList.length === 0) {
_initRecentFilesList();
}
var file = current.document.file;
var paneId = current._paneId;
_addToMROFList(file, paneId, current.getCursorPos(true, "first"));
}
if (previous) { // Capture the last know cursor position
_updateCursorPosition(previous.document.file.fullPath, previous._paneId, previous.getCursorPos(true, "first"));
}
}
|
javascript
|
function _handleActiveEditorChange(event, current, previous) {
if (current) { // Handle only full editors
if (_mrofList.length === 0) {
_initRecentFilesList();
}
var file = current.document.file;
var paneId = current._paneId;
_addToMROFList(file, paneId, current.getCursorPos(true, "first"));
}
if (previous) { // Capture the last know cursor position
_updateCursorPosition(previous.document.file.fullPath, previous._paneId, previous.getCursorPos(true, "first"));
}
}
|
[
"function",
"_handleActiveEditorChange",
"(",
"event",
",",
"current",
",",
"previous",
")",
"{",
"if",
"(",
"current",
")",
"{",
"if",
"(",
"_mrofList",
".",
"length",
"===",
"0",
")",
"{",
"_initRecentFilesList",
"(",
")",
";",
"}",
"var",
"file",
"=",
"current",
".",
"document",
".",
"file",
";",
"var",
"paneId",
"=",
"current",
".",
"_paneId",
";",
"_addToMROFList",
"(",
"file",
",",
"paneId",
",",
"current",
".",
"getCursorPos",
"(",
"true",
",",
"\"first\"",
")",
")",
";",
"}",
"if",
"(",
"previous",
")",
"{",
"_updateCursorPosition",
"(",
"previous",
".",
"document",
".",
"file",
".",
"fullPath",
",",
"previous",
".",
"_paneId",
",",
"previous",
".",
"getCursorPos",
"(",
"true",
",",
"\"first\"",
")",
")",
";",
"}",
"}"
] |
Handle Active Editor change to update mrof information
|
[
"Handle",
"Active",
"Editor",
"change",
"to",
"update",
"mrof",
"information"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/main.js#L782-L796
|
train
|
adobe/brackets
|
src/extensions/default/JavaScriptRefactoring/ExtractToFunction.js
|
handleExtractToFunction
|
function handleExtractToFunction() {
var editor = EditorManager.getActiveEditor();
var result = new $.Deferred(); // used only for testing purpose
if (editor.getSelections().length > 1) {
editor.displayErrorMessageAtCursor(Strings.ERROR_EXTRACTTO_FUNCTION_MULTICURSORS);
result.resolve(Strings.ERROR_EXTRACTTO_FUNCTION_MULTICURSORS);
return;
}
initializeSession(editor);
var selection = editor.getSelection(),
doc = editor.document,
retObj = RefactoringUtils.normalizeText(editor.getSelectedText(), editor.indexFromPos(selection.start), editor.indexFromPos(selection.end)),
text = retObj.text,
start = retObj.start,
end = retObj.end,
ast,
scopes,
expns,
inlineMenu;
RefactoringUtils.getScopeData(session, editor.posFromIndex(start)).done(function(scope) {
ast = RefactoringUtils.getAST(doc.getText());
var isExpression = false;
if (!RefactoringUtils.checkStatement(ast, start, end, doc.getText())) {
isExpression = RefactoringUtils.getExpression(ast, start, end, doc.getText());
if (!isExpression) {
editor.displayErrorMessageAtCursor(Strings.ERROR_EXTRACTTO_FUNCTION_NOT_VALID);
result.resolve(Strings.ERROR_EXTRACTTO_FUNCTION_NOT_VALID);
return;
}
}
scopes = RefactoringUtils.getAllScopes(ast, scope, doc.getText());
// if only one scope, extract without menu
if (scopes.length === 1) {
extract(ast, text, scopes, scopes[0], scopes[0], start, end, isExpression);
result.resolve();
return;
}
inlineMenu = new InlineMenu(editor, Strings.EXTRACTTO_FUNCTION_SELECT_SCOPE);
inlineMenu.open(scopes.filter(RefactoringUtils.isFnScope));
result.resolve(inlineMenu);
inlineMenu.onSelect(function (scopeId) {
extract(ast, text, scopes, scopes[0], scopes[scopeId], start, end, isExpression);
inlineMenu.close();
});
inlineMenu.onClose(function(){
inlineMenu.close();
});
}).fail(function() {
editor.displayErrorMessageAtCursor(Strings.ERROR_TERN_FAILED);
result.resolve(Strings.ERROR_TERN_FAILED);
});
return result.promise();
}
|
javascript
|
function handleExtractToFunction() {
var editor = EditorManager.getActiveEditor();
var result = new $.Deferred(); // used only for testing purpose
if (editor.getSelections().length > 1) {
editor.displayErrorMessageAtCursor(Strings.ERROR_EXTRACTTO_FUNCTION_MULTICURSORS);
result.resolve(Strings.ERROR_EXTRACTTO_FUNCTION_MULTICURSORS);
return;
}
initializeSession(editor);
var selection = editor.getSelection(),
doc = editor.document,
retObj = RefactoringUtils.normalizeText(editor.getSelectedText(), editor.indexFromPos(selection.start), editor.indexFromPos(selection.end)),
text = retObj.text,
start = retObj.start,
end = retObj.end,
ast,
scopes,
expns,
inlineMenu;
RefactoringUtils.getScopeData(session, editor.posFromIndex(start)).done(function(scope) {
ast = RefactoringUtils.getAST(doc.getText());
var isExpression = false;
if (!RefactoringUtils.checkStatement(ast, start, end, doc.getText())) {
isExpression = RefactoringUtils.getExpression(ast, start, end, doc.getText());
if (!isExpression) {
editor.displayErrorMessageAtCursor(Strings.ERROR_EXTRACTTO_FUNCTION_NOT_VALID);
result.resolve(Strings.ERROR_EXTRACTTO_FUNCTION_NOT_VALID);
return;
}
}
scopes = RefactoringUtils.getAllScopes(ast, scope, doc.getText());
// if only one scope, extract without menu
if (scopes.length === 1) {
extract(ast, text, scopes, scopes[0], scopes[0], start, end, isExpression);
result.resolve();
return;
}
inlineMenu = new InlineMenu(editor, Strings.EXTRACTTO_FUNCTION_SELECT_SCOPE);
inlineMenu.open(scopes.filter(RefactoringUtils.isFnScope));
result.resolve(inlineMenu);
inlineMenu.onSelect(function (scopeId) {
extract(ast, text, scopes, scopes[0], scopes[scopeId], start, end, isExpression);
inlineMenu.close();
});
inlineMenu.onClose(function(){
inlineMenu.close();
});
}).fail(function() {
editor.displayErrorMessageAtCursor(Strings.ERROR_TERN_FAILED);
result.resolve(Strings.ERROR_TERN_FAILED);
});
return result.promise();
}
|
[
"function",
"handleExtractToFunction",
"(",
")",
"{",
"var",
"editor",
"=",
"EditorManager",
".",
"getActiveEditor",
"(",
")",
";",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"if",
"(",
"editor",
".",
"getSelections",
"(",
")",
".",
"length",
">",
"1",
")",
"{",
"editor",
".",
"displayErrorMessageAtCursor",
"(",
"Strings",
".",
"ERROR_EXTRACTTO_FUNCTION_MULTICURSORS",
")",
";",
"result",
".",
"resolve",
"(",
"Strings",
".",
"ERROR_EXTRACTTO_FUNCTION_MULTICURSORS",
")",
";",
"return",
";",
"}",
"initializeSession",
"(",
"editor",
")",
";",
"var",
"selection",
"=",
"editor",
".",
"getSelection",
"(",
")",
",",
"doc",
"=",
"editor",
".",
"document",
",",
"retObj",
"=",
"RefactoringUtils",
".",
"normalizeText",
"(",
"editor",
".",
"getSelectedText",
"(",
")",
",",
"editor",
".",
"indexFromPos",
"(",
"selection",
".",
"start",
")",
",",
"editor",
".",
"indexFromPos",
"(",
"selection",
".",
"end",
")",
")",
",",
"text",
"=",
"retObj",
".",
"text",
",",
"start",
"=",
"retObj",
".",
"start",
",",
"end",
"=",
"retObj",
".",
"end",
",",
"ast",
",",
"scopes",
",",
"expns",
",",
"inlineMenu",
";",
"RefactoringUtils",
".",
"getScopeData",
"(",
"session",
",",
"editor",
".",
"posFromIndex",
"(",
"start",
")",
")",
".",
"done",
"(",
"function",
"(",
"scope",
")",
"{",
"ast",
"=",
"RefactoringUtils",
".",
"getAST",
"(",
"doc",
".",
"getText",
"(",
")",
")",
";",
"var",
"isExpression",
"=",
"false",
";",
"if",
"(",
"!",
"RefactoringUtils",
".",
"checkStatement",
"(",
"ast",
",",
"start",
",",
"end",
",",
"doc",
".",
"getText",
"(",
")",
")",
")",
"{",
"isExpression",
"=",
"RefactoringUtils",
".",
"getExpression",
"(",
"ast",
",",
"start",
",",
"end",
",",
"doc",
".",
"getText",
"(",
")",
")",
";",
"if",
"(",
"!",
"isExpression",
")",
"{",
"editor",
".",
"displayErrorMessageAtCursor",
"(",
"Strings",
".",
"ERROR_EXTRACTTO_FUNCTION_NOT_VALID",
")",
";",
"result",
".",
"resolve",
"(",
"Strings",
".",
"ERROR_EXTRACTTO_FUNCTION_NOT_VALID",
")",
";",
"return",
";",
"}",
"}",
"scopes",
"=",
"RefactoringUtils",
".",
"getAllScopes",
"(",
"ast",
",",
"scope",
",",
"doc",
".",
"getText",
"(",
")",
")",
";",
"if",
"(",
"scopes",
".",
"length",
"===",
"1",
")",
"{",
"extract",
"(",
"ast",
",",
"text",
",",
"scopes",
",",
"scopes",
"[",
"0",
"]",
",",
"scopes",
"[",
"0",
"]",
",",
"start",
",",
"end",
",",
"isExpression",
")",
";",
"result",
".",
"resolve",
"(",
")",
";",
"return",
";",
"}",
"inlineMenu",
"=",
"new",
"InlineMenu",
"(",
"editor",
",",
"Strings",
".",
"EXTRACTTO_FUNCTION_SELECT_SCOPE",
")",
";",
"inlineMenu",
".",
"open",
"(",
"scopes",
".",
"filter",
"(",
"RefactoringUtils",
".",
"isFnScope",
")",
")",
";",
"result",
".",
"resolve",
"(",
"inlineMenu",
")",
";",
"inlineMenu",
".",
"onSelect",
"(",
"function",
"(",
"scopeId",
")",
"{",
"extract",
"(",
"ast",
",",
"text",
",",
"scopes",
",",
"scopes",
"[",
"0",
"]",
",",
"scopes",
"[",
"scopeId",
"]",
",",
"start",
",",
"end",
",",
"isExpression",
")",
";",
"inlineMenu",
".",
"close",
"(",
")",
";",
"}",
")",
";",
"inlineMenu",
".",
"onClose",
"(",
"function",
"(",
")",
"{",
"inlineMenu",
".",
"close",
"(",
")",
";",
"}",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"editor",
".",
"displayErrorMessageAtCursor",
"(",
"Strings",
".",
"ERROR_TERN_FAILED",
")",
";",
"result",
".",
"resolve",
"(",
"Strings",
".",
"ERROR_TERN_FAILED",
")",
";",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Main function that handles extract to function
|
[
"Main",
"function",
"that",
"handles",
"extract",
"to",
"function"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptRefactoring/ExtractToFunction.js#L265-L328
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
initTernEnv
|
function initTernEnv() {
var path = [_absoluteModulePath, "node/node_modules/tern/defs/"].join("/"),
files = builtinFiles,
library;
files.forEach(function (i) {
FileSystem.resolve(path + i, function (err, file) {
if (!err) {
FileUtils.readAsText(file).done(function (text) {
library = JSON.parse(text);
builtinLibraryNames.push(library["!name"]);
ternEnvironment.push(library);
}).fail(function (error) {
console.log("failed to read tern config file " + i);
});
} else {
console.log("failed to read tern config file " + i);
}
});
});
}
|
javascript
|
function initTernEnv() {
var path = [_absoluteModulePath, "node/node_modules/tern/defs/"].join("/"),
files = builtinFiles,
library;
files.forEach(function (i) {
FileSystem.resolve(path + i, function (err, file) {
if (!err) {
FileUtils.readAsText(file).done(function (text) {
library = JSON.parse(text);
builtinLibraryNames.push(library["!name"]);
ternEnvironment.push(library);
}).fail(function (error) {
console.log("failed to read tern config file " + i);
});
} else {
console.log("failed to read tern config file " + i);
}
});
});
}
|
[
"function",
"initTernEnv",
"(",
")",
"{",
"var",
"path",
"=",
"[",
"_absoluteModulePath",
",",
"\"node/node_modules/tern/defs/\"",
"]",
".",
"join",
"(",
"\"/\"",
")",
",",
"files",
"=",
"builtinFiles",
",",
"library",
";",
"files",
".",
"forEach",
"(",
"function",
"(",
"i",
")",
"{",
"FileSystem",
".",
"resolve",
"(",
"path",
"+",
"i",
",",
"function",
"(",
"err",
",",
"file",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"FileUtils",
".",
"readAsText",
"(",
"file",
")",
".",
"done",
"(",
"function",
"(",
"text",
")",
"{",
"library",
"=",
"JSON",
".",
"parse",
"(",
"text",
")",
";",
"builtinLibraryNames",
".",
"push",
"(",
"library",
"[",
"\"!name\"",
"]",
")",
";",
"ternEnvironment",
".",
"push",
"(",
"library",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"error",
")",
"{",
"console",
".",
"log",
"(",
"\"failed to read tern config file \"",
"+",
"i",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"\"failed to read tern config file \"",
"+",
"i",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Read in the json files that have type information for the builtins, dom,etc
|
[
"Read",
"in",
"the",
"json",
"files",
"that",
"have",
"type",
"information",
"for",
"the",
"builtins",
"dom",
"etc"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L93-L113
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
initPreferences
|
function initPreferences(projectRootPath) {
// Reject the old preferences if they have not completed.
if (deferredPreferences && deferredPreferences.state() === "pending") {
deferredPreferences.reject();
}
deferredPreferences = $.Deferred();
var pr = ProjectManager.getProjectRoot();
// Open preferences relative to the project root
// Normally there is a project root, but for unit tests we need to
// pass in a project root.
if (pr) {
projectRootPath = pr.fullPath;
} else if (!projectRootPath) {
console.log("initPreferences: projectRootPath has no value");
}
var path = projectRootPath + Preferences.FILE_NAME;
FileSystem.resolve(path, function (err, file) {
if (!err) {
FileUtils.readAsText(file).done(function (text) {
var configObj = null;
try {
configObj = JSON.parse(text);
} catch (e) {
// continue with null configObj which will result in
// default settings.
console.log("Error parsing preference file: " + path);
if (e instanceof SyntaxError) {
console.log(e.message);
}
}
preferences = new Preferences(configObj);
deferredPreferences.resolve();
}).fail(function (error) {
preferences = new Preferences();
deferredPreferences.resolve();
});
} else {
preferences = new Preferences();
deferredPreferences.resolve();
}
});
}
|
javascript
|
function initPreferences(projectRootPath) {
// Reject the old preferences if they have not completed.
if (deferredPreferences && deferredPreferences.state() === "pending") {
deferredPreferences.reject();
}
deferredPreferences = $.Deferred();
var pr = ProjectManager.getProjectRoot();
// Open preferences relative to the project root
// Normally there is a project root, but for unit tests we need to
// pass in a project root.
if (pr) {
projectRootPath = pr.fullPath;
} else if (!projectRootPath) {
console.log("initPreferences: projectRootPath has no value");
}
var path = projectRootPath + Preferences.FILE_NAME;
FileSystem.resolve(path, function (err, file) {
if (!err) {
FileUtils.readAsText(file).done(function (text) {
var configObj = null;
try {
configObj = JSON.parse(text);
} catch (e) {
// continue with null configObj which will result in
// default settings.
console.log("Error parsing preference file: " + path);
if (e instanceof SyntaxError) {
console.log(e.message);
}
}
preferences = new Preferences(configObj);
deferredPreferences.resolve();
}).fail(function (error) {
preferences = new Preferences();
deferredPreferences.resolve();
});
} else {
preferences = new Preferences();
deferredPreferences.resolve();
}
});
}
|
[
"function",
"initPreferences",
"(",
"projectRootPath",
")",
"{",
"if",
"(",
"deferredPreferences",
"&&",
"deferredPreferences",
".",
"state",
"(",
")",
"===",
"\"pending\"",
")",
"{",
"deferredPreferences",
".",
"reject",
"(",
")",
";",
"}",
"deferredPreferences",
"=",
"$",
".",
"Deferred",
"(",
")",
";",
"var",
"pr",
"=",
"ProjectManager",
".",
"getProjectRoot",
"(",
")",
";",
"if",
"(",
"pr",
")",
"{",
"projectRootPath",
"=",
"pr",
".",
"fullPath",
";",
"}",
"else",
"if",
"(",
"!",
"projectRootPath",
")",
"{",
"console",
".",
"log",
"(",
"\"initPreferences: projectRootPath has no value\"",
")",
";",
"}",
"var",
"path",
"=",
"projectRootPath",
"+",
"Preferences",
".",
"FILE_NAME",
";",
"FileSystem",
".",
"resolve",
"(",
"path",
",",
"function",
"(",
"err",
",",
"file",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"FileUtils",
".",
"readAsText",
"(",
"file",
")",
".",
"done",
"(",
"function",
"(",
"text",
")",
"{",
"var",
"configObj",
"=",
"null",
";",
"try",
"{",
"configObj",
"=",
"JSON",
".",
"parse",
"(",
"text",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"\"Error parsing preference file: \"",
"+",
"path",
")",
";",
"if",
"(",
"e",
"instanceof",
"SyntaxError",
")",
"{",
"console",
".",
"log",
"(",
"e",
".",
"message",
")",
";",
"}",
"}",
"preferences",
"=",
"new",
"Preferences",
"(",
"configObj",
")",
";",
"deferredPreferences",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"error",
")",
"{",
"preferences",
"=",
"new",
"Preferences",
"(",
")",
";",
"deferredPreferences",
".",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"preferences",
"=",
"new",
"Preferences",
"(",
")",
";",
"deferredPreferences",
".",
"resolve",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Init preferences from a file in the project root or builtin
defaults if no file is found;
@param {string=} projectRootPath - new project root path. Only needed
for unit tests.
|
[
"Init",
"preferences",
"from",
"a",
"file",
"in",
"the",
"project",
"root",
"or",
"builtin",
"defaults",
"if",
"no",
"file",
"is",
"found",
";"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L124-L170
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
isDirectoryExcluded
|
function isDirectoryExcluded(path) {
var excludes = preferences.getExcludedDirectories();
if (!excludes) {
return false;
}
var testPath = ProjectManager.makeProjectRelativeIfPossible(path);
testPath = FileUtils.stripTrailingSlash(testPath);
return excludes.test(testPath);
}
|
javascript
|
function isDirectoryExcluded(path) {
var excludes = preferences.getExcludedDirectories();
if (!excludes) {
return false;
}
var testPath = ProjectManager.makeProjectRelativeIfPossible(path);
testPath = FileUtils.stripTrailingSlash(testPath);
return excludes.test(testPath);
}
|
[
"function",
"isDirectoryExcluded",
"(",
"path",
")",
"{",
"var",
"excludes",
"=",
"preferences",
".",
"getExcludedDirectories",
"(",
")",
";",
"if",
"(",
"!",
"excludes",
")",
"{",
"return",
"false",
";",
"}",
"var",
"testPath",
"=",
"ProjectManager",
".",
"makeProjectRelativeIfPossible",
"(",
"path",
")",
";",
"testPath",
"=",
"FileUtils",
".",
"stripTrailingSlash",
"(",
"testPath",
")",
";",
"return",
"excludes",
".",
"test",
"(",
"testPath",
")",
";",
"}"
] |
Test if the directory should be excluded from analysis.
@param {!string} path - full directory path.
@return {boolean} true if excluded, false otherwise.
|
[
"Test",
"if",
"the",
"directory",
"should",
"be",
"excluded",
"from",
"analysis",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L198-L209
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
isFileBeingEdited
|
function isFileBeingEdited(filePath) {
var currentEditor = EditorManager.getActiveEditor(),
currentDoc = currentEditor && currentEditor.document;
return (currentDoc && currentDoc.file.fullPath === filePath);
}
|
javascript
|
function isFileBeingEdited(filePath) {
var currentEditor = EditorManager.getActiveEditor(),
currentDoc = currentEditor && currentEditor.document;
return (currentDoc && currentDoc.file.fullPath === filePath);
}
|
[
"function",
"isFileBeingEdited",
"(",
"filePath",
")",
"{",
"var",
"currentEditor",
"=",
"EditorManager",
".",
"getActiveEditor",
"(",
")",
",",
"currentDoc",
"=",
"currentEditor",
"&&",
"currentEditor",
".",
"document",
";",
"return",
"(",
"currentDoc",
"&&",
"currentDoc",
".",
"file",
".",
"fullPath",
"===",
"filePath",
")",
";",
"}"
] |
Test if the file path is in current editor
@param {string} filePath file path to test for exclusion.
@return {boolean} true if in editor, false otherwise.
|
[
"Test",
"if",
"the",
"file",
"path",
"is",
"in",
"current",
"editor"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L217-L222
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
isFileExcludedInternal
|
function isFileExcludedInternal(path) {
// The detectedExclusions are files detected to be troublesome with current versions of Tern.
// detectedExclusions is an array of full paths.
var detectedExclusions = PreferencesManager.get("jscodehints.detectedExclusions") || [];
if (detectedExclusions && detectedExclusions.indexOf(path) !== -1) {
return true;
}
return false;
}
|
javascript
|
function isFileExcludedInternal(path) {
// The detectedExclusions are files detected to be troublesome with current versions of Tern.
// detectedExclusions is an array of full paths.
var detectedExclusions = PreferencesManager.get("jscodehints.detectedExclusions") || [];
if (detectedExclusions && detectedExclusions.indexOf(path) !== -1) {
return true;
}
return false;
}
|
[
"function",
"isFileExcludedInternal",
"(",
"path",
")",
"{",
"var",
"detectedExclusions",
"=",
"PreferencesManager",
".",
"get",
"(",
"\"jscodehints.detectedExclusions\"",
")",
"||",
"[",
"]",
";",
"if",
"(",
"detectedExclusions",
"&&",
"detectedExclusions",
".",
"indexOf",
"(",
"path",
")",
"!==",
"-",
"1",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Test if the file path is an internal exclusion.
@param {string} path file path to test for exclusion.
@return {boolean} true if excluded, false otherwise.
|
[
"Test",
"if",
"the",
"file",
"path",
"is",
"an",
"internal",
"exclusion",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L230-L239
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
isFileExcluded
|
function isFileExcluded(file) {
if (file.name[0] === ".") {
return true;
}
var languageID = LanguageManager.getLanguageForPath(file.fullPath).getId();
if (languageID !== HintUtils.LANGUAGE_ID) {
return true;
}
var excludes = preferences.getExcludedFiles();
if (excludes && excludes.test(file.name)) {
return true;
}
if (isFileExcludedInternal(file.fullPath)) {
return true;
}
return false;
}
|
javascript
|
function isFileExcluded(file) {
if (file.name[0] === ".") {
return true;
}
var languageID = LanguageManager.getLanguageForPath(file.fullPath).getId();
if (languageID !== HintUtils.LANGUAGE_ID) {
return true;
}
var excludes = preferences.getExcludedFiles();
if (excludes && excludes.test(file.name)) {
return true;
}
if (isFileExcludedInternal(file.fullPath)) {
return true;
}
return false;
}
|
[
"function",
"isFileExcluded",
"(",
"file",
")",
"{",
"if",
"(",
"file",
".",
"name",
"[",
"0",
"]",
"===",
"\".\"",
")",
"{",
"return",
"true",
";",
"}",
"var",
"languageID",
"=",
"LanguageManager",
".",
"getLanguageForPath",
"(",
"file",
".",
"fullPath",
")",
".",
"getId",
"(",
")",
";",
"if",
"(",
"languageID",
"!==",
"HintUtils",
".",
"LANGUAGE_ID",
")",
"{",
"return",
"true",
";",
"}",
"var",
"excludes",
"=",
"preferences",
".",
"getExcludedFiles",
"(",
")",
";",
"if",
"(",
"excludes",
"&&",
"excludes",
".",
"test",
"(",
"file",
".",
"name",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"isFileExcludedInternal",
"(",
"file",
".",
"fullPath",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Test if the file should be excluded from analysis.
@param {!File} file - file to test for exclusion.
@return {boolean} true if excluded, false otherwise.
|
[
"Test",
"if",
"the",
"file",
"should",
"be",
"excluded",
"from",
"analysis",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L247-L267
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
addPendingRequest
|
function addPendingRequest(file, offset, type) {
var requests,
key = file + "@" + offset.line + "@" + offset.ch,
$deferredRequest;
// Reject detected exclusions
if (isFileExcludedInternal(file)) {
return (new $.Deferred()).reject().promise();
}
if (_.has(pendingTernRequests, key)) {
requests = pendingTernRequests[key];
} else {
requests = {};
pendingTernRequests[key] = requests;
}
if (_.has(requests, type)) {
$deferredRequest = requests[type];
} else {
requests[type] = $deferredRequest = new $.Deferred();
}
return $deferredRequest.promise();
}
|
javascript
|
function addPendingRequest(file, offset, type) {
var requests,
key = file + "@" + offset.line + "@" + offset.ch,
$deferredRequest;
// Reject detected exclusions
if (isFileExcludedInternal(file)) {
return (new $.Deferred()).reject().promise();
}
if (_.has(pendingTernRequests, key)) {
requests = pendingTernRequests[key];
} else {
requests = {};
pendingTernRequests[key] = requests;
}
if (_.has(requests, type)) {
$deferredRequest = requests[type];
} else {
requests[type] = $deferredRequest = new $.Deferred();
}
return $deferredRequest.promise();
}
|
[
"function",
"addPendingRequest",
"(",
"file",
",",
"offset",
",",
"type",
")",
"{",
"var",
"requests",
",",
"key",
"=",
"file",
"+",
"\"@\"",
"+",
"offset",
".",
"line",
"+",
"\"@\"",
"+",
"offset",
".",
"ch",
",",
"$deferredRequest",
";",
"if",
"(",
"isFileExcludedInternal",
"(",
"file",
")",
")",
"{",
"return",
"(",
"new",
"$",
".",
"Deferred",
"(",
")",
")",
".",
"reject",
"(",
")",
".",
"promise",
"(",
")",
";",
"}",
"if",
"(",
"_",
".",
"has",
"(",
"pendingTernRequests",
",",
"key",
")",
")",
"{",
"requests",
"=",
"pendingTernRequests",
"[",
"key",
"]",
";",
"}",
"else",
"{",
"requests",
"=",
"{",
"}",
";",
"pendingTernRequests",
"[",
"key",
"]",
"=",
"requests",
";",
"}",
"if",
"(",
"_",
".",
"has",
"(",
"requests",
",",
"type",
")",
")",
"{",
"$deferredRequest",
"=",
"requests",
"[",
"type",
"]",
";",
"}",
"else",
"{",
"requests",
"[",
"type",
"]",
"=",
"$deferredRequest",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"}",
"return",
"$deferredRequest",
".",
"promise",
"(",
")",
";",
"}"
] |
Add a pending request waiting for the tern-module to complete.
If file is a detected exclusion, then reject request.
@param {string} file - the name of the file
@param {{line: number, ch: number}} offset - the offset into the file the request is for
@param {string} type - the type of request
@return {jQuery.Promise} - the promise for the request
|
[
"Add",
"a",
"pending",
"request",
"waiting",
"for",
"the",
"tern",
"-",
"module",
"to",
"complete",
".",
"If",
"file",
"is",
"a",
"detected",
"exclusion",
"then",
"reject",
"request",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L278-L301
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
getJumptoDef
|
function getJumptoDef(fileInfo, offset) {
postMessage({
type: MessageIds.TERN_JUMPTODEF_MSG,
fileInfo: fileInfo,
offset: offset
});
return addPendingRequest(fileInfo.name, offset, MessageIds.TERN_JUMPTODEF_MSG);
}
|
javascript
|
function getJumptoDef(fileInfo, offset) {
postMessage({
type: MessageIds.TERN_JUMPTODEF_MSG,
fileInfo: fileInfo,
offset: offset
});
return addPendingRequest(fileInfo.name, offset, MessageIds.TERN_JUMPTODEF_MSG);
}
|
[
"function",
"getJumptoDef",
"(",
"fileInfo",
",",
"offset",
")",
"{",
"postMessage",
"(",
"{",
"type",
":",
"MessageIds",
".",
"TERN_JUMPTODEF_MSG",
",",
"fileInfo",
":",
"fileInfo",
",",
"offset",
":",
"offset",
"}",
")",
";",
"return",
"addPendingRequest",
"(",
"fileInfo",
".",
"name",
",",
"offset",
",",
"MessageIds",
".",
"TERN_JUMPTODEF_MSG",
")",
";",
"}"
] |
Get a Promise for the definition from TernJS, for the file & offset passed in.
@param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
- type of update, name of file, and the text of the update.
For "full" updates, the whole text of the file is present. For "part" updates,
the changed portion of the text. For "empty" updates, the file has not been modified
and the text is empty.
@param {{line: number, ch: number}} offset - the offset in the file the hints should be calculate at
@return {jQuery.Promise} - a promise that will resolve to definition when
it is done
|
[
"Get",
"a",
"Promise",
"for",
"the",
"definition",
"from",
"TernJS",
"for",
"the",
"file",
"&",
"offset",
"passed",
"in",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L345-L353
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
filterText
|
function filterText(text) {
var newText = text;
if (text.length > preferences.getMaxFileSize()) {
newText = "";
}
return newText;
}
|
javascript
|
function filterText(text) {
var newText = text;
if (text.length > preferences.getMaxFileSize()) {
newText = "";
}
return newText;
}
|
[
"function",
"filterText",
"(",
"text",
")",
"{",
"var",
"newText",
"=",
"text",
";",
"if",
"(",
"text",
".",
"length",
">",
"preferences",
".",
"getMaxFileSize",
"(",
")",
")",
"{",
"newText",
"=",
"\"\"",
";",
"}",
"return",
"newText",
";",
"}"
] |
check to see if the text we are sending to Tern is too long.
@param {string} the text to check
@return {string} the text, or the empty text if the original was too long
|
[
"check",
"to",
"see",
"if",
"the",
"text",
"we",
"are",
"sending",
"to",
"Tern",
"is",
"too",
"long",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L360-L366
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
handleRename
|
function handleRename(response) {
if (response.error) {
EditorManager.getActiveEditor().displayErrorMessageAtCursor(response.error);
return;
}
var file = response.file,
offset = response.offset;
var $deferredFindRefs = getPendingRequest(file, offset, MessageIds.TERN_REFS);
if ($deferredFindRefs) {
$deferredFindRefs.resolveWith(null, [response]);
}
}
|
javascript
|
function handleRename(response) {
if (response.error) {
EditorManager.getActiveEditor().displayErrorMessageAtCursor(response.error);
return;
}
var file = response.file,
offset = response.offset;
var $deferredFindRefs = getPendingRequest(file, offset, MessageIds.TERN_REFS);
if ($deferredFindRefs) {
$deferredFindRefs.resolveWith(null, [response]);
}
}
|
[
"function",
"handleRename",
"(",
"response",
")",
"{",
"if",
"(",
"response",
".",
"error",
")",
"{",
"EditorManager",
".",
"getActiveEditor",
"(",
")",
".",
"displayErrorMessageAtCursor",
"(",
"response",
".",
"error",
")",
";",
"return",
";",
"}",
"var",
"file",
"=",
"response",
".",
"file",
",",
"offset",
"=",
"response",
".",
"offset",
";",
"var",
"$deferredFindRefs",
"=",
"getPendingRequest",
"(",
"file",
",",
"offset",
",",
"MessageIds",
".",
"TERN_REFS",
")",
";",
"if",
"(",
"$deferredFindRefs",
")",
"{",
"$deferredFindRefs",
".",
"resolveWith",
"(",
"null",
",",
"[",
"response",
"]",
")",
";",
"}",
"}"
] |
Handle the response from the tern node domain when
it responds with the references
@param response - the response from the node domain
|
[
"Handle",
"the",
"response",
"from",
"the",
"tern",
"node",
"domain",
"when",
"it",
"responds",
"with",
"the",
"references"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L386-L401
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
requestJumptoDef
|
function requestJumptoDef(session, document, offset) {
var path = document.file.fullPath,
fileInfo = {
type: MessageIds.TERN_FILE_INFO_TYPE_FULL,
name: path,
offsetLines: 0,
text: filterText(session.getJavascriptText())
};
var ternPromise = getJumptoDef(fileInfo, offset);
return {promise: ternPromise};
}
|
javascript
|
function requestJumptoDef(session, document, offset) {
var path = document.file.fullPath,
fileInfo = {
type: MessageIds.TERN_FILE_INFO_TYPE_FULL,
name: path,
offsetLines: 0,
text: filterText(session.getJavascriptText())
};
var ternPromise = getJumptoDef(fileInfo, offset);
return {promise: ternPromise};
}
|
[
"function",
"requestJumptoDef",
"(",
"session",
",",
"document",
",",
"offset",
")",
"{",
"var",
"path",
"=",
"document",
".",
"file",
".",
"fullPath",
",",
"fileInfo",
"=",
"{",
"type",
":",
"MessageIds",
".",
"TERN_FILE_INFO_TYPE_FULL",
",",
"name",
":",
"path",
",",
"offsetLines",
":",
"0",
",",
"text",
":",
"filterText",
"(",
"session",
".",
"getJavascriptText",
"(",
")",
")",
"}",
";",
"var",
"ternPromise",
"=",
"getJumptoDef",
"(",
"fileInfo",
",",
"offset",
")",
";",
"return",
"{",
"promise",
":",
"ternPromise",
"}",
";",
"}"
] |
Request Jump-To-Definition from Tern.
@param {session} session - the session
@param {Document} document - the document
@param {{line: number, ch: number}} offset - the offset into the document
@return {jQuery.Promise} - The promise will not complete until tern
has completed.
|
[
"Request",
"Jump",
"-",
"To",
"-",
"Definition",
"from",
"Tern",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L412-L424
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
handleJumptoDef
|
function handleJumptoDef(response) {
var file = response.file,
offset = response.offset;
var $deferredJump = getPendingRequest(file, offset, MessageIds.TERN_JUMPTODEF_MSG);
if ($deferredJump) {
response.fullPath = getResolvedPath(response.resultFile);
$deferredJump.resolveWith(null, [response]);
}
}
|
javascript
|
function handleJumptoDef(response) {
var file = response.file,
offset = response.offset;
var $deferredJump = getPendingRequest(file, offset, MessageIds.TERN_JUMPTODEF_MSG);
if ($deferredJump) {
response.fullPath = getResolvedPath(response.resultFile);
$deferredJump.resolveWith(null, [response]);
}
}
|
[
"function",
"handleJumptoDef",
"(",
"response",
")",
"{",
"var",
"file",
"=",
"response",
".",
"file",
",",
"offset",
"=",
"response",
".",
"offset",
";",
"var",
"$deferredJump",
"=",
"getPendingRequest",
"(",
"file",
",",
"offset",
",",
"MessageIds",
".",
"TERN_JUMPTODEF_MSG",
")",
";",
"if",
"(",
"$deferredJump",
")",
"{",
"response",
".",
"fullPath",
"=",
"getResolvedPath",
"(",
"response",
".",
"resultFile",
")",
";",
"$deferredJump",
".",
"resolveWith",
"(",
"null",
",",
"[",
"response",
"]",
")",
";",
"}",
"}"
] |
Handle the response from the tern node domain when
it responds with the definition
@param response - the response from the node domain
|
[
"Handle",
"the",
"response",
"from",
"the",
"tern",
"node",
"domain",
"when",
"it",
"responds",
"with",
"the",
"definition"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L432-L443
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
handleScopeData
|
function handleScopeData(response) {
var file = response.file,
offset = response.offset;
var $deferredJump = getPendingRequest(file, offset, MessageIds.TERN_SCOPEDATA_MSG);
if ($deferredJump) {
$deferredJump.resolveWith(null, [response]);
}
}
|
javascript
|
function handleScopeData(response) {
var file = response.file,
offset = response.offset;
var $deferredJump = getPendingRequest(file, offset, MessageIds.TERN_SCOPEDATA_MSG);
if ($deferredJump) {
$deferredJump.resolveWith(null, [response]);
}
}
|
[
"function",
"handleScopeData",
"(",
"response",
")",
"{",
"var",
"file",
"=",
"response",
".",
"file",
",",
"offset",
"=",
"response",
".",
"offset",
";",
"var",
"$deferredJump",
"=",
"getPendingRequest",
"(",
"file",
",",
"offset",
",",
"MessageIds",
".",
"TERN_SCOPEDATA_MSG",
")",
";",
"if",
"(",
"$deferredJump",
")",
"{",
"$deferredJump",
".",
"resolveWith",
"(",
"null",
",",
"[",
"response",
"]",
")",
";",
"}",
"}"
] |
Handle the response from the tern node domain when
it responds with the scope data
@param response - the response from the node domain
|
[
"Handle",
"the",
"response",
"from",
"the",
"tern",
"node",
"domain",
"when",
"it",
"responds",
"with",
"the",
"scope",
"data"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L451-L460
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
getTernHints
|
function getTernHints(fileInfo, offset, isProperty) {
/**
* If the document is large and we have modified a small portions of it that
* we are asking hints for, then send a partial document.
*/
postMessage({
type: MessageIds.TERN_COMPLETIONS_MSG,
fileInfo: fileInfo,
offset: offset,
isProperty: isProperty
});
return addPendingRequest(fileInfo.name, offset, MessageIds.TERN_COMPLETIONS_MSG);
}
|
javascript
|
function getTernHints(fileInfo, offset, isProperty) {
/**
* If the document is large and we have modified a small portions of it that
* we are asking hints for, then send a partial document.
*/
postMessage({
type: MessageIds.TERN_COMPLETIONS_MSG,
fileInfo: fileInfo,
offset: offset,
isProperty: isProperty
});
return addPendingRequest(fileInfo.name, offset, MessageIds.TERN_COMPLETIONS_MSG);
}
|
[
"function",
"getTernHints",
"(",
"fileInfo",
",",
"offset",
",",
"isProperty",
")",
"{",
"postMessage",
"(",
"{",
"type",
":",
"MessageIds",
".",
"TERN_COMPLETIONS_MSG",
",",
"fileInfo",
":",
"fileInfo",
",",
"offset",
":",
"offset",
",",
"isProperty",
":",
"isProperty",
"}",
")",
";",
"return",
"addPendingRequest",
"(",
"fileInfo",
".",
"name",
",",
"offset",
",",
"MessageIds",
".",
"TERN_COMPLETIONS_MSG",
")",
";",
"}"
] |
Get a Promise for the completions from TernJS, for the file & offset passed in.
@param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
- type of update, name of file, and the text of the update.
For "full" updates, the whole text of the file is present. For "part" updates,
the changed portion of the text. For "empty" updates, the file has not been modified
and the text is empty.
@param {{line: number, ch: number}} offset - the offset in the file the hints should be calculate at
@param {boolean} isProperty - true if getting a property hint,
otherwise getting an identifier hint.
@return {jQuery.Promise} - a promise that will resolve to an array of completions when
it is done
|
[
"Get",
"a",
"Promise",
"for",
"the",
"completions",
"from",
"TernJS",
"for",
"the",
"file",
"&",
"offset",
"passed",
"in",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L476-L490
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
getTernFunctionType
|
function getTernFunctionType(fileInfo, offset) {
postMessage({
type: MessageIds.TERN_CALLED_FUNC_TYPE_MSG,
fileInfo: fileInfo,
offset: offset
});
return addPendingRequest(fileInfo.name, offset, MessageIds.TERN_CALLED_FUNC_TYPE_MSG);
}
|
javascript
|
function getTernFunctionType(fileInfo, offset) {
postMessage({
type: MessageIds.TERN_CALLED_FUNC_TYPE_MSG,
fileInfo: fileInfo,
offset: offset
});
return addPendingRequest(fileInfo.name, offset, MessageIds.TERN_CALLED_FUNC_TYPE_MSG);
}
|
[
"function",
"getTernFunctionType",
"(",
"fileInfo",
",",
"offset",
")",
"{",
"postMessage",
"(",
"{",
"type",
":",
"MessageIds",
".",
"TERN_CALLED_FUNC_TYPE_MSG",
",",
"fileInfo",
":",
"fileInfo",
",",
"offset",
":",
"offset",
"}",
")",
";",
"return",
"addPendingRequest",
"(",
"fileInfo",
".",
"name",
",",
"offset",
",",
"MessageIds",
".",
"TERN_CALLED_FUNC_TYPE_MSG",
")",
";",
"}"
] |
Get a Promise for the function type from TernJS.
@param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
- type of update, name of file, and the text of the update.
For "full" updates, the whole text of the file is present. For "part" updates,
the changed portion of the text. For "empty" updates, the file has not been modified
and the text is empty.
@param {{line:number, ch:number}} offset - the line, column info for what we want the function type of.
@return {jQuery.Promise} - a promise that will resolve to the function type of the function being called.
|
[
"Get",
"a",
"Promise",
"for",
"the",
"function",
"type",
"from",
"TernJS",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L502-L510
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
getFragmentAround
|
function getFragmentAround(session, start) {
var minIndent = null,
minLine = null,
endLine,
cm = session.editor._codeMirror,
tabSize = cm.getOption("tabSize"),
document = session.editor.document,
p,
min,
indent,
line;
// expand range backwards
for (p = start.line - 1, min = Math.max(0, p - 100); p >= min; --p) {
line = session.getLine(p);
var fn = line.search(/\bfunction\b/);
if (fn >= 0) {
indent = CodeMirror.countColumn(line, null, tabSize);
if (minIndent === null || minIndent > indent) {
if (session.getToken({line: p, ch: fn + 1}).type === "keyword") {
minIndent = indent;
minLine = p;
}
}
}
}
if (minIndent === null) {
minIndent = 0;
}
if (minLine === null) {
minLine = min;
}
var max = Math.min(cm.lastLine(), start.line + 100),
endCh = 0;
for (endLine = start.line + 1; endLine < max; ++endLine) {
line = cm.getLine(endLine);
if (line.length > 0) {
indent = CodeMirror.countColumn(line, null, tabSize);
if (indent <= minIndent) {
endCh = line.length;
break;
}
}
}
var from = {line: minLine, ch: 0},
to = {line: endLine, ch: endCh};
return {type: MessageIds.TERN_FILE_INFO_TYPE_PART,
name: document.file.fullPath,
offsetLines: from.line,
text: document.getRange(from, to)};
}
|
javascript
|
function getFragmentAround(session, start) {
var minIndent = null,
minLine = null,
endLine,
cm = session.editor._codeMirror,
tabSize = cm.getOption("tabSize"),
document = session.editor.document,
p,
min,
indent,
line;
// expand range backwards
for (p = start.line - 1, min = Math.max(0, p - 100); p >= min; --p) {
line = session.getLine(p);
var fn = line.search(/\bfunction\b/);
if (fn >= 0) {
indent = CodeMirror.countColumn(line, null, tabSize);
if (minIndent === null || minIndent > indent) {
if (session.getToken({line: p, ch: fn + 1}).type === "keyword") {
minIndent = indent;
minLine = p;
}
}
}
}
if (minIndent === null) {
minIndent = 0;
}
if (minLine === null) {
minLine = min;
}
var max = Math.min(cm.lastLine(), start.line + 100),
endCh = 0;
for (endLine = start.line + 1; endLine < max; ++endLine) {
line = cm.getLine(endLine);
if (line.length > 0) {
indent = CodeMirror.countColumn(line, null, tabSize);
if (indent <= minIndent) {
endCh = line.length;
break;
}
}
}
var from = {line: minLine, ch: 0},
to = {line: endLine, ch: endCh};
return {type: MessageIds.TERN_FILE_INFO_TYPE_PART,
name: document.file.fullPath,
offsetLines: from.line,
text: document.getRange(from, to)};
}
|
[
"function",
"getFragmentAround",
"(",
"session",
",",
"start",
")",
"{",
"var",
"minIndent",
"=",
"null",
",",
"minLine",
"=",
"null",
",",
"endLine",
",",
"cm",
"=",
"session",
".",
"editor",
".",
"_codeMirror",
",",
"tabSize",
"=",
"cm",
".",
"getOption",
"(",
"\"tabSize\"",
")",
",",
"document",
"=",
"session",
".",
"editor",
".",
"document",
",",
"p",
",",
"min",
",",
"indent",
",",
"line",
";",
"for",
"(",
"p",
"=",
"start",
".",
"line",
"-",
"1",
",",
"min",
"=",
"Math",
".",
"max",
"(",
"0",
",",
"p",
"-",
"100",
")",
";",
"p",
">=",
"min",
";",
"--",
"p",
")",
"{",
"line",
"=",
"session",
".",
"getLine",
"(",
"p",
")",
";",
"var",
"fn",
"=",
"line",
".",
"search",
"(",
"/",
"\\bfunction\\b",
"/",
")",
";",
"if",
"(",
"fn",
">=",
"0",
")",
"{",
"indent",
"=",
"CodeMirror",
".",
"countColumn",
"(",
"line",
",",
"null",
",",
"tabSize",
")",
";",
"if",
"(",
"minIndent",
"===",
"null",
"||",
"minIndent",
">",
"indent",
")",
"{",
"if",
"(",
"session",
".",
"getToken",
"(",
"{",
"line",
":",
"p",
",",
"ch",
":",
"fn",
"+",
"1",
"}",
")",
".",
"type",
"===",
"\"keyword\"",
")",
"{",
"minIndent",
"=",
"indent",
";",
"minLine",
"=",
"p",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"minIndent",
"===",
"null",
")",
"{",
"minIndent",
"=",
"0",
";",
"}",
"if",
"(",
"minLine",
"===",
"null",
")",
"{",
"minLine",
"=",
"min",
";",
"}",
"var",
"max",
"=",
"Math",
".",
"min",
"(",
"cm",
".",
"lastLine",
"(",
")",
",",
"start",
".",
"line",
"+",
"100",
")",
",",
"endCh",
"=",
"0",
";",
"for",
"(",
"endLine",
"=",
"start",
".",
"line",
"+",
"1",
";",
"endLine",
"<",
"max",
";",
"++",
"endLine",
")",
"{",
"line",
"=",
"cm",
".",
"getLine",
"(",
"endLine",
")",
";",
"if",
"(",
"line",
".",
"length",
">",
"0",
")",
"{",
"indent",
"=",
"CodeMirror",
".",
"countColumn",
"(",
"line",
",",
"null",
",",
"tabSize",
")",
";",
"if",
"(",
"indent",
"<=",
"minIndent",
")",
"{",
"endCh",
"=",
"line",
".",
"length",
";",
"break",
";",
"}",
"}",
"}",
"var",
"from",
"=",
"{",
"line",
":",
"minLine",
",",
"ch",
":",
"0",
"}",
",",
"to",
"=",
"{",
"line",
":",
"endLine",
",",
"ch",
":",
"endCh",
"}",
";",
"return",
"{",
"type",
":",
"MessageIds",
".",
"TERN_FILE_INFO_TYPE_PART",
",",
"name",
":",
"document",
".",
"file",
".",
"fullPath",
",",
"offsetLines",
":",
"from",
".",
"line",
",",
"text",
":",
"document",
".",
"getRange",
"(",
"from",
",",
"to",
")",
"}",
";",
"}"
] |
Given a starting and ending position, get a code fragment that is self contained
enough to be compiled.
@param {!Session} session - the current session
@param {{line: number, ch: number}} start - the starting position of the changes
@return {{type: string, name: string, offsetLines: number, text: string}}
|
[
"Given",
"a",
"starting",
"and",
"ending",
"position",
"get",
"a",
"code",
"fragment",
"that",
"is",
"self",
"contained",
"enough",
"to",
"be",
"compiled",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L521-L579
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
getFileInfo
|
function getFileInfo(session, preventPartialUpdates) {
var start = session.getCursor(),
end = start,
document = session.editor.document,
path = document.file.fullPath,
isHtmlFile = LanguageManager.getLanguageForPath(path).getId() === "html",
result;
if (isHtmlFile) {
result = {type: MessageIds.TERN_FILE_INFO_TYPE_FULL,
name: path,
text: session.getJavascriptText()};
} else if (!documentChanges) {
result = {type: MessageIds.TERN_FILE_INFO_TYPE_EMPTY,
name: path,
text: ""};
} else if (!preventPartialUpdates && session.editor.lineCount() > LARGE_LINE_COUNT &&
(documentChanges.to - documentChanges.from < LARGE_LINE_CHANGE) &&
documentChanges.from <= start.line &&
documentChanges.to > end.line) {
result = getFragmentAround(session, start);
} else {
result = {type: MessageIds.TERN_FILE_INFO_TYPE_FULL,
name: path,
text: getTextFromDocument(document)};
}
documentChanges = null;
return result;
}
|
javascript
|
function getFileInfo(session, preventPartialUpdates) {
var start = session.getCursor(),
end = start,
document = session.editor.document,
path = document.file.fullPath,
isHtmlFile = LanguageManager.getLanguageForPath(path).getId() === "html",
result;
if (isHtmlFile) {
result = {type: MessageIds.TERN_FILE_INFO_TYPE_FULL,
name: path,
text: session.getJavascriptText()};
} else if (!documentChanges) {
result = {type: MessageIds.TERN_FILE_INFO_TYPE_EMPTY,
name: path,
text: ""};
} else if (!preventPartialUpdates && session.editor.lineCount() > LARGE_LINE_COUNT &&
(documentChanges.to - documentChanges.from < LARGE_LINE_CHANGE) &&
documentChanges.from <= start.line &&
documentChanges.to > end.line) {
result = getFragmentAround(session, start);
} else {
result = {type: MessageIds.TERN_FILE_INFO_TYPE_FULL,
name: path,
text: getTextFromDocument(document)};
}
documentChanges = null;
return result;
}
|
[
"function",
"getFileInfo",
"(",
"session",
",",
"preventPartialUpdates",
")",
"{",
"var",
"start",
"=",
"session",
".",
"getCursor",
"(",
")",
",",
"end",
"=",
"start",
",",
"document",
"=",
"session",
".",
"editor",
".",
"document",
",",
"path",
"=",
"document",
".",
"file",
".",
"fullPath",
",",
"isHtmlFile",
"=",
"LanguageManager",
".",
"getLanguageForPath",
"(",
"path",
")",
".",
"getId",
"(",
")",
"===",
"\"html\"",
",",
"result",
";",
"if",
"(",
"isHtmlFile",
")",
"{",
"result",
"=",
"{",
"type",
":",
"MessageIds",
".",
"TERN_FILE_INFO_TYPE_FULL",
",",
"name",
":",
"path",
",",
"text",
":",
"session",
".",
"getJavascriptText",
"(",
")",
"}",
";",
"}",
"else",
"if",
"(",
"!",
"documentChanges",
")",
"{",
"result",
"=",
"{",
"type",
":",
"MessageIds",
".",
"TERN_FILE_INFO_TYPE_EMPTY",
",",
"name",
":",
"path",
",",
"text",
":",
"\"\"",
"}",
";",
"}",
"else",
"if",
"(",
"!",
"preventPartialUpdates",
"&&",
"session",
".",
"editor",
".",
"lineCount",
"(",
")",
">",
"LARGE_LINE_COUNT",
"&&",
"(",
"documentChanges",
".",
"to",
"-",
"documentChanges",
".",
"from",
"<",
"LARGE_LINE_CHANGE",
")",
"&&",
"documentChanges",
".",
"from",
"<=",
"start",
".",
"line",
"&&",
"documentChanges",
".",
"to",
">",
"end",
".",
"line",
")",
"{",
"result",
"=",
"getFragmentAround",
"(",
"session",
",",
"start",
")",
";",
"}",
"else",
"{",
"result",
"=",
"{",
"type",
":",
"MessageIds",
".",
"TERN_FILE_INFO_TYPE_FULL",
",",
"name",
":",
"path",
",",
"text",
":",
"getTextFromDocument",
"(",
"document",
")",
"}",
";",
"}",
"documentChanges",
"=",
"null",
";",
"return",
"result",
";",
"}"
] |
Get an object that describes what tern needs to know about the updated
file to produce a hint. As a side-effect of this calls the document
changes are reset.
@param {!Session} session - the current session
@param {boolean=} preventPartialUpdates - if true, disallow partial updates.
Optional, defaults to false.
@return {{type: string, name: string, offsetLines: number, text: string}}
|
[
"Get",
"an",
"object",
"that",
"describes",
"what",
"tern",
"needs",
"to",
"know",
"about",
"the",
"updated",
"file",
"to",
"produce",
"a",
"hint",
".",
"As",
"a",
"side",
"-",
"effect",
"of",
"this",
"calls",
"the",
"document",
"changes",
"are",
"reset",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L592-L621
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
getOffset
|
function getOffset(session, fileInfo, offset) {
var newOffset;
if (offset) {
newOffset = {line: offset.line, ch: offset.ch};
} else {
newOffset = session.getCursor();
}
if (fileInfo.type === MessageIds.TERN_FILE_INFO_TYPE_PART) {
newOffset.line = Math.max(0, newOffset.line - fileInfo.offsetLines);
}
return newOffset;
}
|
javascript
|
function getOffset(session, fileInfo, offset) {
var newOffset;
if (offset) {
newOffset = {line: offset.line, ch: offset.ch};
} else {
newOffset = session.getCursor();
}
if (fileInfo.type === MessageIds.TERN_FILE_INFO_TYPE_PART) {
newOffset.line = Math.max(0, newOffset.line - fileInfo.offsetLines);
}
return newOffset;
}
|
[
"function",
"getOffset",
"(",
"session",
",",
"fileInfo",
",",
"offset",
")",
"{",
"var",
"newOffset",
";",
"if",
"(",
"offset",
")",
"{",
"newOffset",
"=",
"{",
"line",
":",
"offset",
".",
"line",
",",
"ch",
":",
"offset",
".",
"ch",
"}",
";",
"}",
"else",
"{",
"newOffset",
"=",
"session",
".",
"getCursor",
"(",
")",
";",
"}",
"if",
"(",
"fileInfo",
".",
"type",
"===",
"MessageIds",
".",
"TERN_FILE_INFO_TYPE_PART",
")",
"{",
"newOffset",
".",
"line",
"=",
"Math",
".",
"max",
"(",
"0",
",",
"newOffset",
".",
"line",
"-",
"fileInfo",
".",
"offsetLines",
")",
";",
"}",
"return",
"newOffset",
";",
"}"
] |
Get the current offset. The offset is adjusted for "part" updates.
@param {!Session} session - the current session
@param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
- type of update, name of file, and the text of the update.
For "full" updates, the whole text of the file is present. For "part" updates,
the changed portion of the text. For "empty" updates, the file has not been modified
and the text is empty.
@param {{line: number, ch: number}=} offset - the default offset (optional). Will
use the cursor if not provided.
@return {{line: number, ch: number}}
|
[
"Get",
"the",
"current",
"offset",
".",
"The",
"offset",
"is",
"adjusted",
"for",
"part",
"updates",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L636-L650
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
requestGuesses
|
function requestGuesses(session, document) {
var $deferred = $.Deferred(),
fileInfo = getFileInfo(session),
offset = getOffset(session, fileInfo);
postMessage({
type: MessageIds.TERN_GET_GUESSES_MSG,
fileInfo: fileInfo,
offset: offset
});
var promise = addPendingRequest(fileInfo.name, offset, MessageIds.TERN_GET_GUESSES_MSG);
promise.done(function (guesses) {
session.setGuesses(guesses);
$deferred.resolve();
}).fail(function () {
$deferred.reject();
});
return $deferred.promise();
}
|
javascript
|
function requestGuesses(session, document) {
var $deferred = $.Deferred(),
fileInfo = getFileInfo(session),
offset = getOffset(session, fileInfo);
postMessage({
type: MessageIds.TERN_GET_GUESSES_MSG,
fileInfo: fileInfo,
offset: offset
});
var promise = addPendingRequest(fileInfo.name, offset, MessageIds.TERN_GET_GUESSES_MSG);
promise.done(function (guesses) {
session.setGuesses(guesses);
$deferred.resolve();
}).fail(function () {
$deferred.reject();
});
return $deferred.promise();
}
|
[
"function",
"requestGuesses",
"(",
"session",
",",
"document",
")",
"{",
"var",
"$deferred",
"=",
"$",
".",
"Deferred",
"(",
")",
",",
"fileInfo",
"=",
"getFileInfo",
"(",
"session",
")",
",",
"offset",
"=",
"getOffset",
"(",
"session",
",",
"fileInfo",
")",
";",
"postMessage",
"(",
"{",
"type",
":",
"MessageIds",
".",
"TERN_GET_GUESSES_MSG",
",",
"fileInfo",
":",
"fileInfo",
",",
"offset",
":",
"offset",
"}",
")",
";",
"var",
"promise",
"=",
"addPendingRequest",
"(",
"fileInfo",
".",
"name",
",",
"offset",
",",
"MessageIds",
".",
"TERN_GET_GUESSES_MSG",
")",
";",
"promise",
".",
"done",
"(",
"function",
"(",
"guesses",
")",
"{",
"session",
".",
"setGuesses",
"(",
"guesses",
")",
";",
"$deferred",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"$deferred",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"return",
"$deferred",
".",
"promise",
"(",
")",
";",
"}"
] |
Get a Promise for all of the known properties from TernJS, for the directory and file.
The properties will be used as guesses in tern.
@param {Session} session - the active hinting session
@param {Document} document - the document for which scope info is
desired
@return {jQuery.Promise} - The promise will not complete until the tern
request has completed.
|
[
"Get",
"a",
"Promise",
"for",
"all",
"of",
"the",
"known",
"properties",
"from",
"TernJS",
"for",
"the",
"directory",
"and",
"file",
".",
"The",
"properties",
"will",
"be",
"used",
"as",
"guesses",
"in",
"tern",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L661-L681
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
handleTernCompletions
|
function handleTernCompletions(response) {
var file = response.file,
offset = response.offset,
completions = response.completions,
properties = response.properties,
fnType = response.fnType,
type = response.type,
error = response.error,
$deferredHints = getPendingRequest(file, offset, type);
if ($deferredHints) {
if (error) {
$deferredHints.reject();
} else if (completions) {
$deferredHints.resolveWith(null, [{completions: completions}]);
} else if (properties) {
$deferredHints.resolveWith(null, [{properties: properties}]);
} else if (fnType) {
$deferredHints.resolveWith(null, [fnType]);
}
}
}
|
javascript
|
function handleTernCompletions(response) {
var file = response.file,
offset = response.offset,
completions = response.completions,
properties = response.properties,
fnType = response.fnType,
type = response.type,
error = response.error,
$deferredHints = getPendingRequest(file, offset, type);
if ($deferredHints) {
if (error) {
$deferredHints.reject();
} else if (completions) {
$deferredHints.resolveWith(null, [{completions: completions}]);
} else if (properties) {
$deferredHints.resolveWith(null, [{properties: properties}]);
} else if (fnType) {
$deferredHints.resolveWith(null, [fnType]);
}
}
}
|
[
"function",
"handleTernCompletions",
"(",
"response",
")",
"{",
"var",
"file",
"=",
"response",
".",
"file",
",",
"offset",
"=",
"response",
".",
"offset",
",",
"completions",
"=",
"response",
".",
"completions",
",",
"properties",
"=",
"response",
".",
"properties",
",",
"fnType",
"=",
"response",
".",
"fnType",
",",
"type",
"=",
"response",
".",
"type",
",",
"error",
"=",
"response",
".",
"error",
",",
"$deferredHints",
"=",
"getPendingRequest",
"(",
"file",
",",
"offset",
",",
"type",
")",
";",
"if",
"(",
"$deferredHints",
")",
"{",
"if",
"(",
"error",
")",
"{",
"$deferredHints",
".",
"reject",
"(",
")",
";",
"}",
"else",
"if",
"(",
"completions",
")",
"{",
"$deferredHints",
".",
"resolveWith",
"(",
"null",
",",
"[",
"{",
"completions",
":",
"completions",
"}",
"]",
")",
";",
"}",
"else",
"if",
"(",
"properties",
")",
"{",
"$deferredHints",
".",
"resolveWith",
"(",
"null",
",",
"[",
"{",
"properties",
":",
"properties",
"}",
"]",
")",
";",
"}",
"else",
"if",
"(",
"fnType",
")",
"{",
"$deferredHints",
".",
"resolveWith",
"(",
"null",
",",
"[",
"fnType",
"]",
")",
";",
"}",
"}",
"}"
] |
Handle the response from the tern node domain when
it responds with the list of completions
@param {{file: string, offset: {line: number, ch: number}, completions:Array.<string>,
properties:Array.<string>}} response - the response from node domain
|
[
"Handle",
"the",
"response",
"from",
"the",
"tern",
"node",
"domain",
"when",
"it",
"responds",
"with",
"the",
"list",
"of",
"completions"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L690-L712
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
handleGetGuesses
|
function handleGetGuesses(response) {
var path = response.file,
type = response.type,
offset = response.offset,
$deferredHints = getPendingRequest(path, offset, type);
if ($deferredHints) {
$deferredHints.resolveWith(null, [response.properties]);
}
}
|
javascript
|
function handleGetGuesses(response) {
var path = response.file,
type = response.type,
offset = response.offset,
$deferredHints = getPendingRequest(path, offset, type);
if ($deferredHints) {
$deferredHints.resolveWith(null, [response.properties]);
}
}
|
[
"function",
"handleGetGuesses",
"(",
"response",
")",
"{",
"var",
"path",
"=",
"response",
".",
"file",
",",
"type",
"=",
"response",
".",
"type",
",",
"offset",
"=",
"response",
".",
"offset",
",",
"$deferredHints",
"=",
"getPendingRequest",
"(",
"path",
",",
"offset",
",",
"type",
")",
";",
"if",
"(",
"$deferredHints",
")",
"{",
"$deferredHints",
".",
"resolveWith",
"(",
"null",
",",
"[",
"response",
".",
"properties",
"]",
")",
";",
"}",
"}"
] |
Handle the response from the tern node domain when
it responds to the get guesses message.
@param {{file: string, type: string, offset: {line: number, ch: number},
properties: Array.<string>}} response -
the response from node domain contains the guesses for a
property lookup.
|
[
"Handle",
"the",
"response",
"from",
"the",
"tern",
"node",
"domain",
"when",
"it",
"responds",
"to",
"the",
"get",
"guesses",
"message",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L723-L732
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
handleUpdateFile
|
function handleUpdateFile(response) {
var path = response.path,
type = response.type,
$deferredHints = getPendingRequest(path, OFFSET_ZERO, type);
if ($deferredHints) {
$deferredHints.resolve();
}
}
|
javascript
|
function handleUpdateFile(response) {
var path = response.path,
type = response.type,
$deferredHints = getPendingRequest(path, OFFSET_ZERO, type);
if ($deferredHints) {
$deferredHints.resolve();
}
}
|
[
"function",
"handleUpdateFile",
"(",
"response",
")",
"{",
"var",
"path",
"=",
"response",
".",
"path",
",",
"type",
"=",
"response",
".",
"type",
",",
"$deferredHints",
"=",
"getPendingRequest",
"(",
"path",
",",
"OFFSET_ZERO",
",",
"type",
")",
";",
"if",
"(",
"$deferredHints",
")",
"{",
"$deferredHints",
".",
"resolve",
"(",
")",
";",
"}",
"}"
] |
Handle the response from the tern node domain when
it responds to the update file message.
@param {{path: string, type: string}} response - the response from node domain
|
[
"Handle",
"the",
"response",
"from",
"the",
"tern",
"node",
"domain",
"when",
"it",
"responds",
"to",
"the",
"update",
"file",
"message",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L740-L749
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
handleTimedOut
|
function handleTimedOut(response) {
var detectedExclusions = PreferencesManager.get("jscodehints.detectedExclusions") || [],
filePath = response.file;
// Don't exclude the file currently being edited
if (isFileBeingEdited(filePath)) {
return;
}
// Handle file that is already excluded
if (detectedExclusions.indexOf(filePath) !== -1) {
console.log("JavaScriptCodeHints.handleTimedOut: file already in detectedExclusions array timed out: " + filePath);
return;
}
// Save detected exclusion in project prefs so no further time is wasted on it
detectedExclusions.push(filePath);
PreferencesManager.set("jscodehints.detectedExclusions", detectedExclusions, { location: { scope: "project" } });
// Show informational dialog
Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_INFO,
Strings.DETECTED_EXCLUSION_TITLE,
StringUtils.format(
Strings.DETECTED_EXCLUSION_INFO,
StringUtils.breakableUrl(filePath)
),
[
{
className : Dialogs.DIALOG_BTN_CLASS_PRIMARY,
id : Dialogs.DIALOG_BTN_OK,
text : Strings.OK
}
]
);
}
|
javascript
|
function handleTimedOut(response) {
var detectedExclusions = PreferencesManager.get("jscodehints.detectedExclusions") || [],
filePath = response.file;
// Don't exclude the file currently being edited
if (isFileBeingEdited(filePath)) {
return;
}
// Handle file that is already excluded
if (detectedExclusions.indexOf(filePath) !== -1) {
console.log("JavaScriptCodeHints.handleTimedOut: file already in detectedExclusions array timed out: " + filePath);
return;
}
// Save detected exclusion in project prefs so no further time is wasted on it
detectedExclusions.push(filePath);
PreferencesManager.set("jscodehints.detectedExclusions", detectedExclusions, { location: { scope: "project" } });
// Show informational dialog
Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_INFO,
Strings.DETECTED_EXCLUSION_TITLE,
StringUtils.format(
Strings.DETECTED_EXCLUSION_INFO,
StringUtils.breakableUrl(filePath)
),
[
{
className : Dialogs.DIALOG_BTN_CLASS_PRIMARY,
id : Dialogs.DIALOG_BTN_OK,
text : Strings.OK
}
]
);
}
|
[
"function",
"handleTimedOut",
"(",
"response",
")",
"{",
"var",
"detectedExclusions",
"=",
"PreferencesManager",
".",
"get",
"(",
"\"jscodehints.detectedExclusions\"",
")",
"||",
"[",
"]",
",",
"filePath",
"=",
"response",
".",
"file",
";",
"if",
"(",
"isFileBeingEdited",
"(",
"filePath",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"detectedExclusions",
".",
"indexOf",
"(",
"filePath",
")",
"!==",
"-",
"1",
")",
"{",
"console",
".",
"log",
"(",
"\"JavaScriptCodeHints.handleTimedOut: file already in detectedExclusions array timed out: \"",
"+",
"filePath",
")",
";",
"return",
";",
"}",
"detectedExclusions",
".",
"push",
"(",
"filePath",
")",
";",
"PreferencesManager",
".",
"set",
"(",
"\"jscodehints.detectedExclusions\"",
",",
"detectedExclusions",
",",
"{",
"location",
":",
"{",
"scope",
":",
"\"project\"",
"}",
"}",
")",
";",
"Dialogs",
".",
"showModalDialog",
"(",
"DefaultDialogs",
".",
"DIALOG_ID_INFO",
",",
"Strings",
".",
"DETECTED_EXCLUSION_TITLE",
",",
"StringUtils",
".",
"format",
"(",
"Strings",
".",
"DETECTED_EXCLUSION_INFO",
",",
"StringUtils",
".",
"breakableUrl",
"(",
"filePath",
")",
")",
",",
"[",
"{",
"className",
":",
"Dialogs",
".",
"DIALOG_BTN_CLASS_PRIMARY",
",",
"id",
":",
"Dialogs",
".",
"DIALOG_BTN_OK",
",",
"text",
":",
"Strings",
".",
"OK",
"}",
"]",
")",
";",
"}"
] |
Handle timed out inference
@param {{path: string, type: string}} response - the response from node domain
|
[
"Handle",
"timed",
"out",
"inference"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L756-L792
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
postMessage
|
function postMessage(msg) {
addFilesPromise.done(function (ternModule) {
// If an error came up during file handling, bail out now
if (!_ternNodeDomain) {
return;
}
if (config.debug) {
console.debug("Sending message", msg);
}
_ternNodeDomain.exec("invokeTernCommand", msg);
});
}
|
javascript
|
function postMessage(msg) {
addFilesPromise.done(function (ternModule) {
// If an error came up during file handling, bail out now
if (!_ternNodeDomain) {
return;
}
if (config.debug) {
console.debug("Sending message", msg);
}
_ternNodeDomain.exec("invokeTernCommand", msg);
});
}
|
[
"function",
"postMessage",
"(",
"msg",
")",
"{",
"addFilesPromise",
".",
"done",
"(",
"function",
"(",
"ternModule",
")",
"{",
"if",
"(",
"!",
"_ternNodeDomain",
")",
"{",
"return",
";",
"}",
"if",
"(",
"config",
".",
"debug",
")",
"{",
"console",
".",
"debug",
"(",
"\"Sending message\"",
",",
"msg",
")",
";",
"}",
"_ternNodeDomain",
".",
"exec",
"(",
"\"invokeTernCommand\"",
",",
"msg",
")",
";",
"}",
")",
";",
"}"
] |
Send a message to the tern node domain - if the module is being initialized,
the message will not be posted until initialization is complete
|
[
"Send",
"a",
"message",
"to",
"the",
"tern",
"node",
"domain",
"-",
"if",
"the",
"module",
"is",
"being",
"initialized",
"the",
"message",
"will",
"not",
"be",
"posted",
"until",
"initialization",
"is",
"complete"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L852-L864
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
_postMessageByPass
|
function _postMessageByPass(msg) {
ternPromise.done(function (ternModule) {
if (config.debug) {
console.debug("Sending message", msg);
}
_ternNodeDomain.exec("invokeTernCommand", msg);
});
}
|
javascript
|
function _postMessageByPass(msg) {
ternPromise.done(function (ternModule) {
if (config.debug) {
console.debug("Sending message", msg);
}
_ternNodeDomain.exec("invokeTernCommand", msg);
});
}
|
[
"function",
"_postMessageByPass",
"(",
"msg",
")",
"{",
"ternPromise",
".",
"done",
"(",
"function",
"(",
"ternModule",
")",
"{",
"if",
"(",
"config",
".",
"debug",
")",
"{",
"console",
".",
"debug",
"(",
"\"Sending message\"",
",",
"msg",
")",
";",
"}",
"_ternNodeDomain",
".",
"exec",
"(",
"\"invokeTernCommand\"",
",",
"msg",
")",
";",
"}",
")",
";",
"}"
] |
Send a message to the tern node domain - this is only for messages that
need to be sent before and while the addFilesPromise is being resolved.
|
[
"Send",
"a",
"message",
"to",
"the",
"tern",
"node",
"domain",
"-",
"this",
"is",
"only",
"for",
"messages",
"that",
"need",
"to",
"be",
"sent",
"before",
"and",
"while",
"the",
"addFilesPromise",
"is",
"being",
"resolved",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L870-L877
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
updateTernFile
|
function updateTernFile(document) {
var path = document.file.fullPath;
_postMessageByPass({
type : MessageIds.TERN_UPDATE_FILE_MSG,
path : path,
text : getTextFromDocument(document)
});
return addPendingRequest(path, OFFSET_ZERO, MessageIds.TERN_UPDATE_FILE_MSG);
}
|
javascript
|
function updateTernFile(document) {
var path = document.file.fullPath;
_postMessageByPass({
type : MessageIds.TERN_UPDATE_FILE_MSG,
path : path,
text : getTextFromDocument(document)
});
return addPendingRequest(path, OFFSET_ZERO, MessageIds.TERN_UPDATE_FILE_MSG);
}
|
[
"function",
"updateTernFile",
"(",
"document",
")",
"{",
"var",
"path",
"=",
"document",
".",
"file",
".",
"fullPath",
";",
"_postMessageByPass",
"(",
"{",
"type",
":",
"MessageIds",
".",
"TERN_UPDATE_FILE_MSG",
",",
"path",
":",
"path",
",",
"text",
":",
"getTextFromDocument",
"(",
"document",
")",
"}",
")",
";",
"return",
"addPendingRequest",
"(",
"path",
",",
"OFFSET_ZERO",
",",
"MessageIds",
".",
"TERN_UPDATE_FILE_MSG",
")",
";",
"}"
] |
Update tern with the new contents of a given file.
@param {Document} document - the document to update
@return {jQuery.Promise} - the promise for the request
|
[
"Update",
"tern",
"with",
"the",
"new",
"contents",
"of",
"a",
"given",
"file",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L885-L895
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
handleTernGetFile
|
function handleTernGetFile(request) {
function replyWith(name, txt) {
_postMessageByPass({
type: MessageIds.TERN_GET_FILE_MSG,
file: name,
text: txt
});
}
var name = request.file;
/**
* Helper function to get the text of a given document and send it to tern.
* If DocumentManager successfully gets the file's text then we'll send it to the tern node domain.
* The Promise for getDocumentText() is returned so that custom fail functions can be used.
*
* @param {string} filePath - the path of the file to get the text of
* @return {jQuery.Promise} - the Promise returned from DocumentMangaer.getDocumentText()
*/
function getDocText(filePath) {
if (!FileSystem.isAbsolutePath(filePath) || // don't handle URLs
filePath.slice(0, 2) === "//") { // don't handle protocol-relative URLs like //example.com/main.js (see #10566)
return (new $.Deferred()).reject().promise();
}
var file = FileSystem.getFileForPath(filePath),
promise = DocumentManager.getDocumentText(file);
promise.done(function (docText) {
resolvedFiles[name] = filePath;
numResolvedFiles++;
replyWith(name, filterText(docText));
});
return promise;
}
/**
* Helper function to find any files in the project that end with the
* name we are looking for. This is so we can find requirejs modules
* when the baseUrl is unknown, or when the project root is not the same
* as the script root (e.g. if you open the 'brackets' dir instead of 'brackets/src' dir).
*/
function findNameInProject() {
// check for any files in project that end with the right path.
var fileName = name.substring(name.lastIndexOf("/") + 1);
function _fileFilter(entry) {
return entry.name === fileName;
}
ProjectManager.getAllFiles(_fileFilter).done(function (files) {
var file;
files = files.filter(function (file) {
var pos = file.fullPath.length - name.length;
return pos === file.fullPath.lastIndexOf(name);
});
if (files.length === 1) {
file = files[0];
}
if (file) {
getDocText(file.fullPath).fail(function () {
replyWith(name, "");
});
} else {
replyWith(name, "");
}
});
}
if (!isFileExcludedInternal(name)) {
getDocText(name).fail(function () {
getDocText(rootTernDir + name).fail(function () {
// check relative to project root
getDocText(projectRoot + name)
// last look for any files that end with the right path
// in the project
.fail(findNameInProject);
});
});
}
}
|
javascript
|
function handleTernGetFile(request) {
function replyWith(name, txt) {
_postMessageByPass({
type: MessageIds.TERN_GET_FILE_MSG,
file: name,
text: txt
});
}
var name = request.file;
/**
* Helper function to get the text of a given document and send it to tern.
* If DocumentManager successfully gets the file's text then we'll send it to the tern node domain.
* The Promise for getDocumentText() is returned so that custom fail functions can be used.
*
* @param {string} filePath - the path of the file to get the text of
* @return {jQuery.Promise} - the Promise returned from DocumentMangaer.getDocumentText()
*/
function getDocText(filePath) {
if (!FileSystem.isAbsolutePath(filePath) || // don't handle URLs
filePath.slice(0, 2) === "//") { // don't handle protocol-relative URLs like //example.com/main.js (see #10566)
return (new $.Deferred()).reject().promise();
}
var file = FileSystem.getFileForPath(filePath),
promise = DocumentManager.getDocumentText(file);
promise.done(function (docText) {
resolvedFiles[name] = filePath;
numResolvedFiles++;
replyWith(name, filterText(docText));
});
return promise;
}
/**
* Helper function to find any files in the project that end with the
* name we are looking for. This is so we can find requirejs modules
* when the baseUrl is unknown, or when the project root is not the same
* as the script root (e.g. if you open the 'brackets' dir instead of 'brackets/src' dir).
*/
function findNameInProject() {
// check for any files in project that end with the right path.
var fileName = name.substring(name.lastIndexOf("/") + 1);
function _fileFilter(entry) {
return entry.name === fileName;
}
ProjectManager.getAllFiles(_fileFilter).done(function (files) {
var file;
files = files.filter(function (file) {
var pos = file.fullPath.length - name.length;
return pos === file.fullPath.lastIndexOf(name);
});
if (files.length === 1) {
file = files[0];
}
if (file) {
getDocText(file.fullPath).fail(function () {
replyWith(name, "");
});
} else {
replyWith(name, "");
}
});
}
if (!isFileExcludedInternal(name)) {
getDocText(name).fail(function () {
getDocText(rootTernDir + name).fail(function () {
// check relative to project root
getDocText(projectRoot + name)
// last look for any files that end with the right path
// in the project
.fail(findNameInProject);
});
});
}
}
|
[
"function",
"handleTernGetFile",
"(",
"request",
")",
"{",
"function",
"replyWith",
"(",
"name",
",",
"txt",
")",
"{",
"_postMessageByPass",
"(",
"{",
"type",
":",
"MessageIds",
".",
"TERN_GET_FILE_MSG",
",",
"file",
":",
"name",
",",
"text",
":",
"txt",
"}",
")",
";",
"}",
"var",
"name",
"=",
"request",
".",
"file",
";",
"function",
"getDocText",
"(",
"filePath",
")",
"{",
"if",
"(",
"!",
"FileSystem",
".",
"isAbsolutePath",
"(",
"filePath",
")",
"||",
"filePath",
".",
"slice",
"(",
"0",
",",
"2",
")",
"===",
"\"//\"",
")",
"{",
"return",
"(",
"new",
"$",
".",
"Deferred",
"(",
")",
")",
".",
"reject",
"(",
")",
".",
"promise",
"(",
")",
";",
"}",
"var",
"file",
"=",
"FileSystem",
".",
"getFileForPath",
"(",
"filePath",
")",
",",
"promise",
"=",
"DocumentManager",
".",
"getDocumentText",
"(",
"file",
")",
";",
"promise",
".",
"done",
"(",
"function",
"(",
"docText",
")",
"{",
"resolvedFiles",
"[",
"name",
"]",
"=",
"filePath",
";",
"numResolvedFiles",
"++",
";",
"replyWith",
"(",
"name",
",",
"filterText",
"(",
"docText",
")",
")",
";",
"}",
")",
";",
"return",
"promise",
";",
"}",
"function",
"findNameInProject",
"(",
")",
"{",
"var",
"fileName",
"=",
"name",
".",
"substring",
"(",
"name",
".",
"lastIndexOf",
"(",
"\"/\"",
")",
"+",
"1",
")",
";",
"function",
"_fileFilter",
"(",
"entry",
")",
"{",
"return",
"entry",
".",
"name",
"===",
"fileName",
";",
"}",
"ProjectManager",
".",
"getAllFiles",
"(",
"_fileFilter",
")",
".",
"done",
"(",
"function",
"(",
"files",
")",
"{",
"var",
"file",
";",
"files",
"=",
"files",
".",
"filter",
"(",
"function",
"(",
"file",
")",
"{",
"var",
"pos",
"=",
"file",
".",
"fullPath",
".",
"length",
"-",
"name",
".",
"length",
";",
"return",
"pos",
"===",
"file",
".",
"fullPath",
".",
"lastIndexOf",
"(",
"name",
")",
";",
"}",
")",
";",
"if",
"(",
"files",
".",
"length",
"===",
"1",
")",
"{",
"file",
"=",
"files",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"file",
")",
"{",
"getDocText",
"(",
"file",
".",
"fullPath",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"replyWith",
"(",
"name",
",",
"\"\"",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"replyWith",
"(",
"name",
",",
"\"\"",
")",
";",
"}",
"}",
")",
";",
"}",
"if",
"(",
"!",
"isFileExcludedInternal",
"(",
"name",
")",
")",
"{",
"getDocText",
"(",
"name",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"getDocText",
"(",
"rootTernDir",
"+",
"name",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"getDocText",
"(",
"projectRoot",
"+",
"name",
")",
".",
"fail",
"(",
"findNameInProject",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"}"
] |
Handle a request from the tern node domain for text of a file
@param {{file:string}} request - the request from the tern node domain. Should be an Object containing the name
of the file tern wants the contents of
|
[
"Handle",
"a",
"request",
"from",
"the",
"tern",
"node",
"domain",
"for",
"text",
"of",
"a",
"file"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L903-L985
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
primePump
|
function primePump(path, isUntitledDoc) {
_postMessageByPass({
type : MessageIds.TERN_PRIME_PUMP_MSG,
path : path,
isUntitledDoc : isUntitledDoc
});
return addPendingRequest(path, OFFSET_ZERO, MessageIds.TERN_PRIME_PUMP_MSG);
}
|
javascript
|
function primePump(path, isUntitledDoc) {
_postMessageByPass({
type : MessageIds.TERN_PRIME_PUMP_MSG,
path : path,
isUntitledDoc : isUntitledDoc
});
return addPendingRequest(path, OFFSET_ZERO, MessageIds.TERN_PRIME_PUMP_MSG);
}
|
[
"function",
"primePump",
"(",
"path",
",",
"isUntitledDoc",
")",
"{",
"_postMessageByPass",
"(",
"{",
"type",
":",
"MessageIds",
".",
"TERN_PRIME_PUMP_MSG",
",",
"path",
":",
"path",
",",
"isUntitledDoc",
":",
"isUntitledDoc",
"}",
")",
";",
"return",
"addPendingRequest",
"(",
"path",
",",
"OFFSET_ZERO",
",",
"MessageIds",
".",
"TERN_PRIME_PUMP_MSG",
")",
";",
"}"
] |
Prime the pump for a fast first lookup.
@param {string} path - full path of file
@return {jQuery.Promise} - the promise for the request
|
[
"Prime",
"the",
"pump",
"for",
"a",
"fast",
"first",
"lookup",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L993-L1001
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
handlePrimePumpCompletion
|
function handlePrimePumpCompletion(response) {
var path = response.path,
type = response.type,
$deferredHints = getPendingRequest(path, OFFSET_ZERO, type);
if ($deferredHints) {
$deferredHints.resolve();
}
}
|
javascript
|
function handlePrimePumpCompletion(response) {
var path = response.path,
type = response.type,
$deferredHints = getPendingRequest(path, OFFSET_ZERO, type);
if ($deferredHints) {
$deferredHints.resolve();
}
}
|
[
"function",
"handlePrimePumpCompletion",
"(",
"response",
")",
"{",
"var",
"path",
"=",
"response",
".",
"path",
",",
"type",
"=",
"response",
".",
"type",
",",
"$deferredHints",
"=",
"getPendingRequest",
"(",
"path",
",",
"OFFSET_ZERO",
",",
"type",
")",
";",
"if",
"(",
"$deferredHints",
")",
"{",
"$deferredHints",
".",
"resolve",
"(",
")",
";",
"}",
"}"
] |
Handle the response from the tern node domain when
it responds to the prime pump message.
@param {{path: string, type: string}} response - the response from node domain
|
[
"Handle",
"the",
"response",
"from",
"the",
"tern",
"node",
"domain",
"when",
"it",
"responds",
"to",
"the",
"prime",
"pump",
"message",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L1009-L1018
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
addFilesToTern
|
function addFilesToTern(files) {
// limit the number of files added to tern.
var maxFileCount = preferences.getMaxFileCount();
if (numResolvedFiles + numAddedFiles < maxFileCount) {
var available = maxFileCount - numResolvedFiles - numAddedFiles;
if (available < files.length) {
files = files.slice(0, available);
}
numAddedFiles += files.length;
ternPromise.done(function (ternModule) {
var msg = {
type : MessageIds.TERN_ADD_FILES_MSG,
files : files
};
if (config.debug) {
console.debug("Sending message", msg);
}
_ternNodeDomain.exec("invokeTernCommand", msg);
});
} else {
stopAddingFiles = true;
}
return stopAddingFiles;
}
|
javascript
|
function addFilesToTern(files) {
// limit the number of files added to tern.
var maxFileCount = preferences.getMaxFileCount();
if (numResolvedFiles + numAddedFiles < maxFileCount) {
var available = maxFileCount - numResolvedFiles - numAddedFiles;
if (available < files.length) {
files = files.slice(0, available);
}
numAddedFiles += files.length;
ternPromise.done(function (ternModule) {
var msg = {
type : MessageIds.TERN_ADD_FILES_MSG,
files : files
};
if (config.debug) {
console.debug("Sending message", msg);
}
_ternNodeDomain.exec("invokeTernCommand", msg);
});
} else {
stopAddingFiles = true;
}
return stopAddingFiles;
}
|
[
"function",
"addFilesToTern",
"(",
"files",
")",
"{",
"var",
"maxFileCount",
"=",
"preferences",
".",
"getMaxFileCount",
"(",
")",
";",
"if",
"(",
"numResolvedFiles",
"+",
"numAddedFiles",
"<",
"maxFileCount",
")",
"{",
"var",
"available",
"=",
"maxFileCount",
"-",
"numResolvedFiles",
"-",
"numAddedFiles",
";",
"if",
"(",
"available",
"<",
"files",
".",
"length",
")",
"{",
"files",
"=",
"files",
".",
"slice",
"(",
"0",
",",
"available",
")",
";",
"}",
"numAddedFiles",
"+=",
"files",
".",
"length",
";",
"ternPromise",
".",
"done",
"(",
"function",
"(",
"ternModule",
")",
"{",
"var",
"msg",
"=",
"{",
"type",
":",
"MessageIds",
".",
"TERN_ADD_FILES_MSG",
",",
"files",
":",
"files",
"}",
";",
"if",
"(",
"config",
".",
"debug",
")",
"{",
"console",
".",
"debug",
"(",
"\"Sending message\"",
",",
"msg",
")",
";",
"}",
"_ternNodeDomain",
".",
"exec",
"(",
"\"invokeTernCommand\"",
",",
"msg",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"stopAddingFiles",
"=",
"true",
";",
"}",
"return",
"stopAddingFiles",
";",
"}"
] |
Add new files to tern, keeping any previous files.
The tern server must be initialized before making
this call.
@param {Array.<string>} files - array of file to add to tern.
@return {boolean} - true if more files may be added, false if maximum has been reached.
|
[
"Add",
"new",
"files",
"to",
"tern",
"keeping",
"any",
"previous",
"files",
".",
"The",
"tern",
"server",
"must",
"be",
"initialized",
"before",
"making",
"this",
"call",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L1028-L1056
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
addAllFilesAndSubdirectories
|
function addAllFilesAndSubdirectories(dir, doneCallback) {
FileSystem.resolve(dir, function (err, directory) {
function visitor(entry) {
if (entry.isFile) {
if (!isFileExcluded(entry)) { // ignore .dotfiles and non-.js files
addFilesToTern([entry.fullPath]);
}
} else {
return !isDirectoryExcluded(entry.fullPath) &&
entry.name.indexOf(".") !== 0 &&
!stopAddingFiles;
}
}
if (err) {
return;
}
if (dir === FileSystem.getDirectoryForPath(rootTernDir)) {
doneCallback();
return;
}
directory.visit(visitor, doneCallback);
});
}
|
javascript
|
function addAllFilesAndSubdirectories(dir, doneCallback) {
FileSystem.resolve(dir, function (err, directory) {
function visitor(entry) {
if (entry.isFile) {
if (!isFileExcluded(entry)) { // ignore .dotfiles and non-.js files
addFilesToTern([entry.fullPath]);
}
} else {
return !isDirectoryExcluded(entry.fullPath) &&
entry.name.indexOf(".") !== 0 &&
!stopAddingFiles;
}
}
if (err) {
return;
}
if (dir === FileSystem.getDirectoryForPath(rootTernDir)) {
doneCallback();
return;
}
directory.visit(visitor, doneCallback);
});
}
|
[
"function",
"addAllFilesAndSubdirectories",
"(",
"dir",
",",
"doneCallback",
")",
"{",
"FileSystem",
".",
"resolve",
"(",
"dir",
",",
"function",
"(",
"err",
",",
"directory",
")",
"{",
"function",
"visitor",
"(",
"entry",
")",
"{",
"if",
"(",
"entry",
".",
"isFile",
")",
"{",
"if",
"(",
"!",
"isFileExcluded",
"(",
"entry",
")",
")",
"{",
"addFilesToTern",
"(",
"[",
"entry",
".",
"fullPath",
"]",
")",
";",
"}",
"}",
"else",
"{",
"return",
"!",
"isDirectoryExcluded",
"(",
"entry",
".",
"fullPath",
")",
"&&",
"entry",
".",
"name",
".",
"indexOf",
"(",
"\".\"",
")",
"!==",
"0",
"&&",
"!",
"stopAddingFiles",
";",
"}",
"}",
"if",
"(",
"err",
")",
"{",
"return",
";",
"}",
"if",
"(",
"dir",
"===",
"FileSystem",
".",
"getDirectoryForPath",
"(",
"rootTernDir",
")",
")",
"{",
"doneCallback",
"(",
")",
";",
"return",
";",
"}",
"directory",
".",
"visit",
"(",
"visitor",
",",
"doneCallback",
")",
";",
"}",
")",
";",
"}"
] |
Add the files in the directory and subdirectories of a given directory
to tern.
@param {string} dir - the root directory to add.
@param {function ()} doneCallback - called when all files have been
added to tern.
|
[
"Add",
"the",
"files",
"in",
"the",
"directory",
"and",
"subdirectories",
"of",
"a",
"given",
"directory",
"to",
"tern",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L1066-L1091
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
initTernModule
|
function initTernModule() {
var moduleDeferred = $.Deferred();
ternPromise = moduleDeferred.promise();
function prepareTern() {
_ternNodeDomain.exec("setInterface", {
messageIds : MessageIds
});
_ternNodeDomain.exec("invokeTernCommand", {
type: MessageIds.SET_CONFIG,
config: config
});
moduleDeferred.resolveWith(null, [_ternNodeDomain]);
}
if (_ternNodeDomain) {
_ternNodeDomain.exec("resetTernServer");
moduleDeferred.resolveWith(null, [_ternNodeDomain]);
} else {
_ternNodeDomain = new NodeDomain("TernNodeDomain", _domainPath);
_ternNodeDomain.on("data", function (evt, data) {
if (config.debug) {
console.log("Message received", data.type);
}
var response = data,
type = response.type;
if (type === MessageIds.TERN_COMPLETIONS_MSG ||
type === MessageIds.TERN_CALLED_FUNC_TYPE_MSG) {
// handle any completions the tern server calculated
handleTernCompletions(response);
} else if (type === MessageIds.TERN_GET_FILE_MSG) {
// handle a request for the contents of a file
handleTernGetFile(response);
} else if (type === MessageIds.TERN_JUMPTODEF_MSG) {
handleJumptoDef(response);
} else if (type === MessageIds.TERN_SCOPEDATA_MSG) {
handleScopeData(response);
} else if (type === MessageIds.TERN_REFS) {
handleRename(response);
} else if (type === MessageIds.TERN_PRIME_PUMP_MSG) {
handlePrimePumpCompletion(response);
} else if (type === MessageIds.TERN_GET_GUESSES_MSG) {
handleGetGuesses(response);
} else if (type === MessageIds.TERN_UPDATE_FILE_MSG) {
handleUpdateFile(response);
} else if (type === MessageIds.TERN_INFERENCE_TIMEDOUT) {
handleTimedOut(response);
} else if (type === MessageIds.TERN_WORKER_READY) {
moduleDeferred.resolveWith(null, [_ternNodeDomain]);
} else if (type === "RE_INIT_TERN") {
// Ensure the request is because of a node restart
if (currentModule) {
prepareTern();
// Mark the module with resetForced, then creation of TernModule will
// happen again as part of '_maybeReset' call
currentModule.resetForced = true;
}
} else {
console.log("Tern Module: " + (response.log || response));
}
});
_ternNodeDomain.promise().done(prepareTern);
}
}
|
javascript
|
function initTernModule() {
var moduleDeferred = $.Deferred();
ternPromise = moduleDeferred.promise();
function prepareTern() {
_ternNodeDomain.exec("setInterface", {
messageIds : MessageIds
});
_ternNodeDomain.exec("invokeTernCommand", {
type: MessageIds.SET_CONFIG,
config: config
});
moduleDeferred.resolveWith(null, [_ternNodeDomain]);
}
if (_ternNodeDomain) {
_ternNodeDomain.exec("resetTernServer");
moduleDeferred.resolveWith(null, [_ternNodeDomain]);
} else {
_ternNodeDomain = new NodeDomain("TernNodeDomain", _domainPath);
_ternNodeDomain.on("data", function (evt, data) {
if (config.debug) {
console.log("Message received", data.type);
}
var response = data,
type = response.type;
if (type === MessageIds.TERN_COMPLETIONS_MSG ||
type === MessageIds.TERN_CALLED_FUNC_TYPE_MSG) {
// handle any completions the tern server calculated
handleTernCompletions(response);
} else if (type === MessageIds.TERN_GET_FILE_MSG) {
// handle a request for the contents of a file
handleTernGetFile(response);
} else if (type === MessageIds.TERN_JUMPTODEF_MSG) {
handleJumptoDef(response);
} else if (type === MessageIds.TERN_SCOPEDATA_MSG) {
handleScopeData(response);
} else if (type === MessageIds.TERN_REFS) {
handleRename(response);
} else if (type === MessageIds.TERN_PRIME_PUMP_MSG) {
handlePrimePumpCompletion(response);
} else if (type === MessageIds.TERN_GET_GUESSES_MSG) {
handleGetGuesses(response);
} else if (type === MessageIds.TERN_UPDATE_FILE_MSG) {
handleUpdateFile(response);
} else if (type === MessageIds.TERN_INFERENCE_TIMEDOUT) {
handleTimedOut(response);
} else if (type === MessageIds.TERN_WORKER_READY) {
moduleDeferred.resolveWith(null, [_ternNodeDomain]);
} else if (type === "RE_INIT_TERN") {
// Ensure the request is because of a node restart
if (currentModule) {
prepareTern();
// Mark the module with resetForced, then creation of TernModule will
// happen again as part of '_maybeReset' call
currentModule.resetForced = true;
}
} else {
console.log("Tern Module: " + (response.log || response));
}
});
_ternNodeDomain.promise().done(prepareTern);
}
}
|
[
"function",
"initTernModule",
"(",
")",
"{",
"var",
"moduleDeferred",
"=",
"$",
".",
"Deferred",
"(",
")",
";",
"ternPromise",
"=",
"moduleDeferred",
".",
"promise",
"(",
")",
";",
"function",
"prepareTern",
"(",
")",
"{",
"_ternNodeDomain",
".",
"exec",
"(",
"\"setInterface\"",
",",
"{",
"messageIds",
":",
"MessageIds",
"}",
")",
";",
"_ternNodeDomain",
".",
"exec",
"(",
"\"invokeTernCommand\"",
",",
"{",
"type",
":",
"MessageIds",
".",
"SET_CONFIG",
",",
"config",
":",
"config",
"}",
")",
";",
"moduleDeferred",
".",
"resolveWith",
"(",
"null",
",",
"[",
"_ternNodeDomain",
"]",
")",
";",
"}",
"if",
"(",
"_ternNodeDomain",
")",
"{",
"_ternNodeDomain",
".",
"exec",
"(",
"\"resetTernServer\"",
")",
";",
"moduleDeferred",
".",
"resolveWith",
"(",
"null",
",",
"[",
"_ternNodeDomain",
"]",
")",
";",
"}",
"else",
"{",
"_ternNodeDomain",
"=",
"new",
"NodeDomain",
"(",
"\"TernNodeDomain\"",
",",
"_domainPath",
")",
";",
"_ternNodeDomain",
".",
"on",
"(",
"\"data\"",
",",
"function",
"(",
"evt",
",",
"data",
")",
"{",
"if",
"(",
"config",
".",
"debug",
")",
"{",
"console",
".",
"log",
"(",
"\"Message received\"",
",",
"data",
".",
"type",
")",
";",
"}",
"var",
"response",
"=",
"data",
",",
"type",
"=",
"response",
".",
"type",
";",
"if",
"(",
"type",
"===",
"MessageIds",
".",
"TERN_COMPLETIONS_MSG",
"||",
"type",
"===",
"MessageIds",
".",
"TERN_CALLED_FUNC_TYPE_MSG",
")",
"{",
"handleTernCompletions",
"(",
"response",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"MessageIds",
".",
"TERN_GET_FILE_MSG",
")",
"{",
"handleTernGetFile",
"(",
"response",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"MessageIds",
".",
"TERN_JUMPTODEF_MSG",
")",
"{",
"handleJumptoDef",
"(",
"response",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"MessageIds",
".",
"TERN_SCOPEDATA_MSG",
")",
"{",
"handleScopeData",
"(",
"response",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"MessageIds",
".",
"TERN_REFS",
")",
"{",
"handleRename",
"(",
"response",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"MessageIds",
".",
"TERN_PRIME_PUMP_MSG",
")",
"{",
"handlePrimePumpCompletion",
"(",
"response",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"MessageIds",
".",
"TERN_GET_GUESSES_MSG",
")",
"{",
"handleGetGuesses",
"(",
"response",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"MessageIds",
".",
"TERN_UPDATE_FILE_MSG",
")",
"{",
"handleUpdateFile",
"(",
"response",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"MessageIds",
".",
"TERN_INFERENCE_TIMEDOUT",
")",
"{",
"handleTimedOut",
"(",
"response",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"MessageIds",
".",
"TERN_WORKER_READY",
")",
"{",
"moduleDeferred",
".",
"resolveWith",
"(",
"null",
",",
"[",
"_ternNodeDomain",
"]",
")",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"\"RE_INIT_TERN\"",
")",
"{",
"if",
"(",
"currentModule",
")",
"{",
"prepareTern",
"(",
")",
";",
"currentModule",
".",
"resetForced",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"\"Tern Module: \"",
"+",
"(",
"response",
".",
"log",
"||",
"response",
")",
")",
";",
"}",
"}",
")",
";",
"_ternNodeDomain",
".",
"promise",
"(",
")",
".",
"done",
"(",
"prepareTern",
")",
";",
"}",
"}"
] |
Init the Tern module that does all the code hinting work.
|
[
"Init",
"the",
"Tern",
"module",
"that",
"does",
"all",
"the",
"code",
"hinting",
"work",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L1096-L1163
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
doEditorChange
|
function doEditorChange(session, document, previousDocument) {
var file = document.file,
path = file.fullPath,
dir = file.parentPath,
pr;
var addFilesDeferred = $.Deferred();
documentChanges = null;
addFilesPromise = addFilesDeferred.promise();
pr = ProjectManager.getProjectRoot() ? ProjectManager.getProjectRoot().fullPath : null;
// avoid re-initializing tern if possible.
if (canSkipTernInitialization(path)) {
// update the previous document in tern to prevent stale files.
if (isDocumentDirty && previousDocument) {
var updateFilePromise = updateTernFile(previousDocument);
updateFilePromise.done(function () {
primePump(path, document.isUntitled());
addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
});
} else {
addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
}
isDocumentDirty = false;
return;
}
if (previousDocument && previousDocument.isDirty) {
updateTernFile(previousDocument);
}
isDocumentDirty = false;
resolvedFiles = {};
projectRoot = pr;
ensurePreferences();
deferredPreferences.done(function () {
if (file instanceof InMemoryFile) {
initTernServer(pr, []);
var hintsPromise = primePump(path, true);
hintsPromise.done(function () {
addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
});
return;
}
FileSystem.resolve(dir, function (err, directory) {
if (err) {
console.error("Error resolving", dir);
addFilesDeferred.resolveWith(null);
return;
}
directory.getContents(function (err, contents) {
if (err) {
console.error("Error getting contents for", directory);
addFilesDeferred.resolveWith(null);
return;
}
var files = contents
.filter(function (entry) {
return entry.isFile && !isFileExcluded(entry);
})
.map(function (entry) {
return entry.fullPath;
});
initTernServer(dir, files);
var hintsPromise = primePump(path, false);
hintsPromise.done(function () {
if (!usingModules()) {
// Read the subdirectories of the new file's directory.
// Read them first in case there are too many files to
// read in the project.
addAllFilesAndSubdirectories(dir, function () {
// If the file is in the project root, then read
// all the files under the project root.
var currentDir = (dir + "/");
if (projectRoot && currentDir !== projectRoot &&
currentDir.indexOf(projectRoot) === 0) {
addAllFilesAndSubdirectories(projectRoot, function () {
// prime the pump again but this time don't wait
// for completion.
primePump(path, false);
addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
});
} else {
addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
}
});
} else {
addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
}
});
});
});
});
}
|
javascript
|
function doEditorChange(session, document, previousDocument) {
var file = document.file,
path = file.fullPath,
dir = file.parentPath,
pr;
var addFilesDeferred = $.Deferred();
documentChanges = null;
addFilesPromise = addFilesDeferred.promise();
pr = ProjectManager.getProjectRoot() ? ProjectManager.getProjectRoot().fullPath : null;
// avoid re-initializing tern if possible.
if (canSkipTernInitialization(path)) {
// update the previous document in tern to prevent stale files.
if (isDocumentDirty && previousDocument) {
var updateFilePromise = updateTernFile(previousDocument);
updateFilePromise.done(function () {
primePump(path, document.isUntitled());
addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
});
} else {
addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
}
isDocumentDirty = false;
return;
}
if (previousDocument && previousDocument.isDirty) {
updateTernFile(previousDocument);
}
isDocumentDirty = false;
resolvedFiles = {};
projectRoot = pr;
ensurePreferences();
deferredPreferences.done(function () {
if (file instanceof InMemoryFile) {
initTernServer(pr, []);
var hintsPromise = primePump(path, true);
hintsPromise.done(function () {
addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
});
return;
}
FileSystem.resolve(dir, function (err, directory) {
if (err) {
console.error("Error resolving", dir);
addFilesDeferred.resolveWith(null);
return;
}
directory.getContents(function (err, contents) {
if (err) {
console.error("Error getting contents for", directory);
addFilesDeferred.resolveWith(null);
return;
}
var files = contents
.filter(function (entry) {
return entry.isFile && !isFileExcluded(entry);
})
.map(function (entry) {
return entry.fullPath;
});
initTernServer(dir, files);
var hintsPromise = primePump(path, false);
hintsPromise.done(function () {
if (!usingModules()) {
// Read the subdirectories of the new file's directory.
// Read them first in case there are too many files to
// read in the project.
addAllFilesAndSubdirectories(dir, function () {
// If the file is in the project root, then read
// all the files under the project root.
var currentDir = (dir + "/");
if (projectRoot && currentDir !== projectRoot &&
currentDir.indexOf(projectRoot) === 0) {
addAllFilesAndSubdirectories(projectRoot, function () {
// prime the pump again but this time don't wait
// for completion.
primePump(path, false);
addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
});
} else {
addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
}
});
} else {
addFilesDeferred.resolveWith(null, [_ternNodeDomain]);
}
});
});
});
});
}
|
[
"function",
"doEditorChange",
"(",
"session",
",",
"document",
",",
"previousDocument",
")",
"{",
"var",
"file",
"=",
"document",
".",
"file",
",",
"path",
"=",
"file",
".",
"fullPath",
",",
"dir",
"=",
"file",
".",
"parentPath",
",",
"pr",
";",
"var",
"addFilesDeferred",
"=",
"$",
".",
"Deferred",
"(",
")",
";",
"documentChanges",
"=",
"null",
";",
"addFilesPromise",
"=",
"addFilesDeferred",
".",
"promise",
"(",
")",
";",
"pr",
"=",
"ProjectManager",
".",
"getProjectRoot",
"(",
")",
"?",
"ProjectManager",
".",
"getProjectRoot",
"(",
")",
".",
"fullPath",
":",
"null",
";",
"if",
"(",
"canSkipTernInitialization",
"(",
"path",
")",
")",
"{",
"if",
"(",
"isDocumentDirty",
"&&",
"previousDocument",
")",
"{",
"var",
"updateFilePromise",
"=",
"updateTernFile",
"(",
"previousDocument",
")",
";",
"updateFilePromise",
".",
"done",
"(",
"function",
"(",
")",
"{",
"primePump",
"(",
"path",
",",
"document",
".",
"isUntitled",
"(",
")",
")",
";",
"addFilesDeferred",
".",
"resolveWith",
"(",
"null",
",",
"[",
"_ternNodeDomain",
"]",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"addFilesDeferred",
".",
"resolveWith",
"(",
"null",
",",
"[",
"_ternNodeDomain",
"]",
")",
";",
"}",
"isDocumentDirty",
"=",
"false",
";",
"return",
";",
"}",
"if",
"(",
"previousDocument",
"&&",
"previousDocument",
".",
"isDirty",
")",
"{",
"updateTernFile",
"(",
"previousDocument",
")",
";",
"}",
"isDocumentDirty",
"=",
"false",
";",
"resolvedFiles",
"=",
"{",
"}",
";",
"projectRoot",
"=",
"pr",
";",
"ensurePreferences",
"(",
")",
";",
"deferredPreferences",
".",
"done",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"file",
"instanceof",
"InMemoryFile",
")",
"{",
"initTernServer",
"(",
"pr",
",",
"[",
"]",
")",
";",
"var",
"hintsPromise",
"=",
"primePump",
"(",
"path",
",",
"true",
")",
";",
"hintsPromise",
".",
"done",
"(",
"function",
"(",
")",
"{",
"addFilesDeferred",
".",
"resolveWith",
"(",
"null",
",",
"[",
"_ternNodeDomain",
"]",
")",
";",
"}",
")",
";",
"return",
";",
"}",
"FileSystem",
".",
"resolve",
"(",
"dir",
",",
"function",
"(",
"err",
",",
"directory",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"\"Error resolving\"",
",",
"dir",
")",
";",
"addFilesDeferred",
".",
"resolveWith",
"(",
"null",
")",
";",
"return",
";",
"}",
"directory",
".",
"getContents",
"(",
"function",
"(",
"err",
",",
"contents",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"\"Error getting contents for\"",
",",
"directory",
")",
";",
"addFilesDeferred",
".",
"resolveWith",
"(",
"null",
")",
";",
"return",
";",
"}",
"var",
"files",
"=",
"contents",
".",
"filter",
"(",
"function",
"(",
"entry",
")",
"{",
"return",
"entry",
".",
"isFile",
"&&",
"!",
"isFileExcluded",
"(",
"entry",
")",
";",
"}",
")",
".",
"map",
"(",
"function",
"(",
"entry",
")",
"{",
"return",
"entry",
".",
"fullPath",
";",
"}",
")",
";",
"initTernServer",
"(",
"dir",
",",
"files",
")",
";",
"var",
"hintsPromise",
"=",
"primePump",
"(",
"path",
",",
"false",
")",
";",
"hintsPromise",
".",
"done",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"usingModules",
"(",
")",
")",
"{",
"addAllFilesAndSubdirectories",
"(",
"dir",
",",
"function",
"(",
")",
"{",
"var",
"currentDir",
"=",
"(",
"dir",
"+",
"\"/\"",
")",
";",
"if",
"(",
"projectRoot",
"&&",
"currentDir",
"!==",
"projectRoot",
"&&",
"currentDir",
".",
"indexOf",
"(",
"projectRoot",
")",
"===",
"0",
")",
"{",
"addAllFilesAndSubdirectories",
"(",
"projectRoot",
",",
"function",
"(",
")",
"{",
"primePump",
"(",
"path",
",",
"false",
")",
";",
"addFilesDeferred",
".",
"resolveWith",
"(",
"null",
",",
"[",
"_ternNodeDomain",
"]",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"addFilesDeferred",
".",
"resolveWith",
"(",
"null",
",",
"[",
"_ternNodeDomain",
"]",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"addFilesDeferred",
".",
"resolveWith",
"(",
"null",
",",
"[",
"_ternNodeDomain",
"]",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Do the work to initialize a code hinting session.
@param {Session} session - the active hinting session (TODO: currently unused)
@param {!Document} document - the document the editor has changed to
@param {?Document} previousDocument - the document the editor has changed from
|
[
"Do",
"the",
"work",
"to",
"initialize",
"a",
"code",
"hinting",
"session",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L1208-L1310
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
resetModule
|
function resetModule() {
function resetTernServer() {
if (_ternNodeDomain.ready()) {
_ternNodeDomain.exec('resetTernServer');
}
}
if (_ternNodeDomain) {
if (addFilesPromise) {
// If we're in the middle of added files, don't reset
// until we're done
addFilesPromise.done(resetTernServer).fail(resetTernServer);
} else {
resetTernServer();
}
}
}
|
javascript
|
function resetModule() {
function resetTernServer() {
if (_ternNodeDomain.ready()) {
_ternNodeDomain.exec('resetTernServer');
}
}
if (_ternNodeDomain) {
if (addFilesPromise) {
// If we're in the middle of added files, don't reset
// until we're done
addFilesPromise.done(resetTernServer).fail(resetTernServer);
} else {
resetTernServer();
}
}
}
|
[
"function",
"resetModule",
"(",
")",
"{",
"function",
"resetTernServer",
"(",
")",
"{",
"if",
"(",
"_ternNodeDomain",
".",
"ready",
"(",
")",
")",
"{",
"_ternNodeDomain",
".",
"exec",
"(",
"'resetTernServer'",
")",
";",
"}",
"}",
"if",
"(",
"_ternNodeDomain",
")",
"{",
"if",
"(",
"addFilesPromise",
")",
"{",
"addFilesPromise",
".",
"done",
"(",
"resetTernServer",
")",
".",
"fail",
"(",
"resetTernServer",
")",
";",
"}",
"else",
"{",
"resetTernServer",
"(",
")",
";",
"}",
"}",
"}"
] |
Do some cleanup when a project is closed.
We can clean up the node tern server we use to calculate hints now, since
we know we will need to re-init it in any new project that is opened.
|
[
"Do",
"some",
"cleanup",
"when",
"a",
"project",
"is",
"closed",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L1335-L1351
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
_maybeReset
|
function _maybeReset(session, document, force) {
var newTernModule;
// if we're in the middle of a reset, don't have to check
// the new module will be online soon
if (!resettingDeferred) {
// We don't reset if the debugging flag is set
// because it's easier to debug if the module isn't
// getting reset all the time.
if (currentModule.resetForced || force || (!config.noReset && ++_hintCount > MAX_HINTS)) {
if (config.debug) {
console.debug("Resetting tern module");
}
resettingDeferred = new $.Deferred();
newTernModule = new TernModule();
newTernModule.handleEditorChange(session, document, null);
newTernModule.whenReady(function () {
// reset the old module
currentModule.resetModule();
currentModule = newTernModule;
resettingDeferred.resolve(currentModule);
// all done reseting
resettingDeferred = null;
});
_hintCount = 0;
} else {
var d = new $.Deferred();
d.resolve(currentModule);
return d.promise();
}
}
return resettingDeferred.promise();
}
|
javascript
|
function _maybeReset(session, document, force) {
var newTernModule;
// if we're in the middle of a reset, don't have to check
// the new module will be online soon
if (!resettingDeferred) {
// We don't reset if the debugging flag is set
// because it's easier to debug if the module isn't
// getting reset all the time.
if (currentModule.resetForced || force || (!config.noReset && ++_hintCount > MAX_HINTS)) {
if (config.debug) {
console.debug("Resetting tern module");
}
resettingDeferred = new $.Deferred();
newTernModule = new TernModule();
newTernModule.handleEditorChange(session, document, null);
newTernModule.whenReady(function () {
// reset the old module
currentModule.resetModule();
currentModule = newTernModule;
resettingDeferred.resolve(currentModule);
// all done reseting
resettingDeferred = null;
});
_hintCount = 0;
} else {
var d = new $.Deferred();
d.resolve(currentModule);
return d.promise();
}
}
return resettingDeferred.promise();
}
|
[
"function",
"_maybeReset",
"(",
"session",
",",
"document",
",",
"force",
")",
"{",
"var",
"newTernModule",
";",
"if",
"(",
"!",
"resettingDeferred",
")",
"{",
"if",
"(",
"currentModule",
".",
"resetForced",
"||",
"force",
"||",
"(",
"!",
"config",
".",
"noReset",
"&&",
"++",
"_hintCount",
">",
"MAX_HINTS",
")",
")",
"{",
"if",
"(",
"config",
".",
"debug",
")",
"{",
"console",
".",
"debug",
"(",
"\"Resetting tern module\"",
")",
";",
"}",
"resettingDeferred",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"newTernModule",
"=",
"new",
"TernModule",
"(",
")",
";",
"newTernModule",
".",
"handleEditorChange",
"(",
"session",
",",
"document",
",",
"null",
")",
";",
"newTernModule",
".",
"whenReady",
"(",
"function",
"(",
")",
"{",
"currentModule",
".",
"resetModule",
"(",
")",
";",
"currentModule",
"=",
"newTernModule",
";",
"resettingDeferred",
".",
"resolve",
"(",
"currentModule",
")",
";",
"resettingDeferred",
"=",
"null",
";",
"}",
")",
";",
"_hintCount",
"=",
"0",
";",
"}",
"else",
"{",
"var",
"d",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"d",
".",
"resolve",
"(",
"currentModule",
")",
";",
"return",
"d",
".",
"promise",
"(",
")",
";",
"}",
"}",
"return",
"resettingDeferred",
".",
"promise",
"(",
")",
";",
"}"
] |
reset the tern module, if necessary.
During debugging, you can turn this automatic resetting behavior off
by running this in the console:
brackets._configureJSCodeHints({ noReset: true })
This function is also used in unit testing with the "force" flag to
reset the module for each test to start with a clean environment.
@param {Session} session
@param {Document} document
@param {boolean} force true to force a reset regardless of how long since the last one
@return {Promise} Promise resolved when the module is ready.
The new (or current, if there was no reset) module is passed to the callback.
|
[
"reset",
"the",
"tern",
"module",
"if",
"necessary",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L1384-L1418
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
requestParameterHint
|
function requestParameterHint(session, functionOffset) {
var $deferredHints = $.Deferred(),
fileInfo = getFileInfo(session, true),
offset = getOffset(session, fileInfo, functionOffset),
fnTypePromise = getTernFunctionType(fileInfo, offset);
$.when(fnTypePromise).done(
function (fnType) {
session.setFnType(fnType);
session.setFunctionCallPos(functionOffset);
$deferredHints.resolveWith(null, [fnType]);
}
).fail(function () {
$deferredHints.reject();
});
return $deferredHints.promise();
}
|
javascript
|
function requestParameterHint(session, functionOffset) {
var $deferredHints = $.Deferred(),
fileInfo = getFileInfo(session, true),
offset = getOffset(session, fileInfo, functionOffset),
fnTypePromise = getTernFunctionType(fileInfo, offset);
$.when(fnTypePromise).done(
function (fnType) {
session.setFnType(fnType);
session.setFunctionCallPos(functionOffset);
$deferredHints.resolveWith(null, [fnType]);
}
).fail(function () {
$deferredHints.reject();
});
return $deferredHints.promise();
}
|
[
"function",
"requestParameterHint",
"(",
"session",
",",
"functionOffset",
")",
"{",
"var",
"$deferredHints",
"=",
"$",
".",
"Deferred",
"(",
")",
",",
"fileInfo",
"=",
"getFileInfo",
"(",
"session",
",",
"true",
")",
",",
"offset",
"=",
"getOffset",
"(",
"session",
",",
"fileInfo",
",",
"functionOffset",
")",
",",
"fnTypePromise",
"=",
"getTernFunctionType",
"(",
"fileInfo",
",",
"offset",
")",
";",
"$",
".",
"when",
"(",
"fnTypePromise",
")",
".",
"done",
"(",
"function",
"(",
"fnType",
")",
"{",
"session",
".",
"setFnType",
"(",
"fnType",
")",
";",
"session",
".",
"setFunctionCallPos",
"(",
"functionOffset",
")",
";",
"$deferredHints",
".",
"resolveWith",
"(",
"null",
",",
"[",
"fnType",
"]",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"$deferredHints",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"return",
"$deferredHints",
".",
"promise",
"(",
")",
";",
"}"
] |
Request a parameter hint from Tern.
@param {Session} session - the active hinting session
@param {{line: number, ch: number}} functionOffset - the offset of the function call.
@return {jQuery.Promise} - The promise will not complete until the
hint has completed.
|
[
"Request",
"a",
"parameter",
"hint",
"from",
"Tern",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L1428-L1445
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
requestHints
|
function requestHints(session, document) {
var $deferredHints = $.Deferred(),
hintPromise,
sessionType = session.getType(),
fileInfo = getFileInfo(session),
offset = getOffset(session, fileInfo, null);
_maybeReset(session, document);
hintPromise = getTernHints(fileInfo, offset, sessionType.property);
$.when(hintPromise).done(
function (completions, fnType) {
if (completions.completions) {
session.setTernHints(completions.completions);
session.setGuesses(null);
} else {
session.setTernHints([]);
session.setGuesses(completions.properties);
}
$deferredHints.resolveWith(null);
}
).fail(function () {
$deferredHints.reject();
});
return $deferredHints.promise();
}
|
javascript
|
function requestHints(session, document) {
var $deferredHints = $.Deferred(),
hintPromise,
sessionType = session.getType(),
fileInfo = getFileInfo(session),
offset = getOffset(session, fileInfo, null);
_maybeReset(session, document);
hintPromise = getTernHints(fileInfo, offset, sessionType.property);
$.when(hintPromise).done(
function (completions, fnType) {
if (completions.completions) {
session.setTernHints(completions.completions);
session.setGuesses(null);
} else {
session.setTernHints([]);
session.setGuesses(completions.properties);
}
$deferredHints.resolveWith(null);
}
).fail(function () {
$deferredHints.reject();
});
return $deferredHints.promise();
}
|
[
"function",
"requestHints",
"(",
"session",
",",
"document",
")",
"{",
"var",
"$deferredHints",
"=",
"$",
".",
"Deferred",
"(",
")",
",",
"hintPromise",
",",
"sessionType",
"=",
"session",
".",
"getType",
"(",
")",
",",
"fileInfo",
"=",
"getFileInfo",
"(",
"session",
")",
",",
"offset",
"=",
"getOffset",
"(",
"session",
",",
"fileInfo",
",",
"null",
")",
";",
"_maybeReset",
"(",
"session",
",",
"document",
")",
";",
"hintPromise",
"=",
"getTernHints",
"(",
"fileInfo",
",",
"offset",
",",
"sessionType",
".",
"property",
")",
";",
"$",
".",
"when",
"(",
"hintPromise",
")",
".",
"done",
"(",
"function",
"(",
"completions",
",",
"fnType",
")",
"{",
"if",
"(",
"completions",
".",
"completions",
")",
"{",
"session",
".",
"setTernHints",
"(",
"completions",
".",
"completions",
")",
";",
"session",
".",
"setGuesses",
"(",
"null",
")",
";",
"}",
"else",
"{",
"session",
".",
"setTernHints",
"(",
"[",
"]",
")",
";",
"session",
".",
"setGuesses",
"(",
"completions",
".",
"properties",
")",
";",
"}",
"$deferredHints",
".",
"resolveWith",
"(",
"null",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"$deferredHints",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"return",
"$deferredHints",
".",
"promise",
"(",
")",
";",
"}"
] |
Request hints from Tern.
Note that successive calls to getScope may return the same objects, so
clients that wish to modify those objects (e.g., by annotating them based
on some temporary context) should copy them first. See, e.g.,
Session.getHints().
@param {Session} session - the active hinting session
@param {Document} document - the document for which scope info is
desired
@return {jQuery.Promise} - The promise will not complete until the tern
hints have completed.
|
[
"Request",
"hints",
"from",
"Tern",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L1461-L1489
|
train
|
adobe/brackets
|
src/JSUtils/ScopeManager.js
|
trackChange
|
function trackChange(changeList) {
var changed = documentChanges, i;
if (changed === null) {
documentChanges = changed = {from: changeList[0].from.line, to: changeList[0].from.line};
if (config.debug) {
console.debug("ScopeManager: document has changed");
}
}
for (i = 0; i < changeList.length; i++) {
var thisChange = changeList[i],
end = thisChange.from.line + (thisChange.text.length - 1);
if (thisChange.from.line < changed.to) {
changed.to = changed.to - (thisChange.to.line - end);
}
if (end >= changed.to) {
changed.to = end + 1;
}
if (changed.from > thisChange.from.line) {
changed.from = thisChange.from.line;
}
}
}
|
javascript
|
function trackChange(changeList) {
var changed = documentChanges, i;
if (changed === null) {
documentChanges = changed = {from: changeList[0].from.line, to: changeList[0].from.line};
if (config.debug) {
console.debug("ScopeManager: document has changed");
}
}
for (i = 0; i < changeList.length; i++) {
var thisChange = changeList[i],
end = thisChange.from.line + (thisChange.text.length - 1);
if (thisChange.from.line < changed.to) {
changed.to = changed.to - (thisChange.to.line - end);
}
if (end >= changed.to) {
changed.to = end + 1;
}
if (changed.from > thisChange.from.line) {
changed.from = thisChange.from.line;
}
}
}
|
[
"function",
"trackChange",
"(",
"changeList",
")",
"{",
"var",
"changed",
"=",
"documentChanges",
",",
"i",
";",
"if",
"(",
"changed",
"===",
"null",
")",
"{",
"documentChanges",
"=",
"changed",
"=",
"{",
"from",
":",
"changeList",
"[",
"0",
"]",
".",
"from",
".",
"line",
",",
"to",
":",
"changeList",
"[",
"0",
"]",
".",
"from",
".",
"line",
"}",
";",
"if",
"(",
"config",
".",
"debug",
")",
"{",
"console",
".",
"debug",
"(",
"\"ScopeManager: document has changed\"",
")",
";",
"}",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"changeList",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"thisChange",
"=",
"changeList",
"[",
"i",
"]",
",",
"end",
"=",
"thisChange",
".",
"from",
".",
"line",
"+",
"(",
"thisChange",
".",
"text",
".",
"length",
"-",
"1",
")",
";",
"if",
"(",
"thisChange",
".",
"from",
".",
"line",
"<",
"changed",
".",
"to",
")",
"{",
"changed",
".",
"to",
"=",
"changed",
".",
"to",
"-",
"(",
"thisChange",
".",
"to",
".",
"line",
"-",
"end",
")",
";",
"}",
"if",
"(",
"end",
">=",
"changed",
".",
"to",
")",
"{",
"changed",
".",
"to",
"=",
"end",
"+",
"1",
";",
"}",
"if",
"(",
"changed",
".",
"from",
">",
"thisChange",
".",
"from",
".",
"line",
")",
"{",
"changed",
".",
"from",
"=",
"thisChange",
".",
"from",
".",
"line",
";",
"}",
"}",
"}"
] |
Track the update area of the current document so we can tell if we can send
partial updates to tern or not.
@param {Array.<{from: {line:number, ch: number}, to: {line:number, ch: number},
text: Array<string>}>} changeList - the document changes from the current change event
|
[
"Track",
"the",
"update",
"area",
"of",
"the",
"current",
"document",
"so",
"we",
"can",
"tell",
"if",
"we",
"can",
"send",
"partial",
"updates",
"to",
"tern",
"or",
"not",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/ScopeManager.js#L1498-L1522
|
train
|
adobe/brackets
|
src/extensibility/node/ExtensionManagerDomain.js
|
_removeFailedInstallation
|
function _removeFailedInstallation(installDirectory) {
fs.remove(installDirectory, function (err) {
if (err) {
console.error("Error while removing directory after failed installation", installDirectory, err);
}
});
}
|
javascript
|
function _removeFailedInstallation(installDirectory) {
fs.remove(installDirectory, function (err) {
if (err) {
console.error("Error while removing directory after failed installation", installDirectory, err);
}
});
}
|
[
"function",
"_removeFailedInstallation",
"(",
"installDirectory",
")",
"{",
"fs",
".",
"remove",
"(",
"installDirectory",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"\"Error while removing directory after failed installation\"",
",",
"installDirectory",
",",
"err",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Private function to remove the installation directory if the installation fails.
This does not call any callbacks. It's assumed that the callback has already been called
and this cleanup routine will do its best to complete in the background. If there's
a problem here, it is simply logged with console.error.
@param {string} installDirectory Directory to remove
|
[
"Private",
"function",
"to",
"remove",
"the",
"installation",
"directory",
"if",
"the",
"installation",
"fails",
".",
"This",
"does",
"not",
"call",
"any",
"callbacks",
".",
"It",
"s",
"assumed",
"that",
"the",
"callback",
"has",
"already",
"been",
"called",
"and",
"this",
"cleanup",
"routine",
"will",
"do",
"its",
"best",
"to",
"complete",
"in",
"the",
"background",
".",
"If",
"there",
"s",
"a",
"problem",
"here",
"it",
"is",
"simply",
"logged",
"with",
"console",
".",
"error",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/ExtensionManagerDomain.js#L74-L80
|
train
|
adobe/brackets
|
src/extensibility/node/ExtensionManagerDomain.js
|
_performInstall
|
function _performInstall(packagePath, installDirectory, validationResult, callback) {
validationResult.installedTo = installDirectory;
function fail(err) {
_removeFailedInstallation(installDirectory);
callback(err, null);
}
function finish() {
// The status may have already been set previously (as in the
// DISABLED case.
if (!validationResult.installationStatus) {
validationResult.installationStatus = Statuses.INSTALLED;
}
callback(null, validationResult);
}
fs.mkdirs(installDirectory, function (err) {
if (err) {
callback(err);
return;
}
var sourceDir = path.join(validationResult.extractDir, validationResult.commonPrefix);
fs.copy(sourceDir, installDirectory, function (err) {
if (err) {
return fail(err);
}
finish();
});
});
}
|
javascript
|
function _performInstall(packagePath, installDirectory, validationResult, callback) {
validationResult.installedTo = installDirectory;
function fail(err) {
_removeFailedInstallation(installDirectory);
callback(err, null);
}
function finish() {
// The status may have already been set previously (as in the
// DISABLED case.
if (!validationResult.installationStatus) {
validationResult.installationStatus = Statuses.INSTALLED;
}
callback(null, validationResult);
}
fs.mkdirs(installDirectory, function (err) {
if (err) {
callback(err);
return;
}
var sourceDir = path.join(validationResult.extractDir, validationResult.commonPrefix);
fs.copy(sourceDir, installDirectory, function (err) {
if (err) {
return fail(err);
}
finish();
});
});
}
|
[
"function",
"_performInstall",
"(",
"packagePath",
",",
"installDirectory",
",",
"validationResult",
",",
"callback",
")",
"{",
"validationResult",
".",
"installedTo",
"=",
"installDirectory",
";",
"function",
"fail",
"(",
"err",
")",
"{",
"_removeFailedInstallation",
"(",
"installDirectory",
")",
";",
"callback",
"(",
"err",
",",
"null",
")",
";",
"}",
"function",
"finish",
"(",
")",
"{",
"if",
"(",
"!",
"validationResult",
".",
"installationStatus",
")",
"{",
"validationResult",
".",
"installationStatus",
"=",
"Statuses",
".",
"INSTALLED",
";",
"}",
"callback",
"(",
"null",
",",
"validationResult",
")",
";",
"}",
"fs",
".",
"mkdirs",
"(",
"installDirectory",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"return",
";",
"}",
"var",
"sourceDir",
"=",
"path",
".",
"join",
"(",
"validationResult",
".",
"extractDir",
",",
"validationResult",
".",
"commonPrefix",
")",
";",
"fs",
".",
"copy",
"(",
"sourceDir",
",",
"installDirectory",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"fail",
"(",
"err",
")",
";",
"}",
"finish",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Private function to unzip to the correct directory.
@param {string} Absolute path to the package zip file
@param {string} Absolute path to the destination directory for unzipping
@param {Object} the return value with the useful information for the client
@param {Function} callback function that is called at the end of the unzipping
|
[
"Private",
"function",
"to",
"unzip",
"to",
"the",
"correct",
"directory",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/ExtensionManagerDomain.js#L90-L121
|
train
|
adobe/brackets
|
src/extensibility/node/ExtensionManagerDomain.js
|
_removeAndInstall
|
function _removeAndInstall(packagePath, installDirectory, validationResult, callback) {
// If this extension was previously installed but disabled, we will overwrite the
// previous installation in that directory.
fs.remove(installDirectory, function (err) {
if (err) {
callback(err);
return;
}
_performInstall(packagePath, installDirectory, validationResult, callback);
});
}
|
javascript
|
function _removeAndInstall(packagePath, installDirectory, validationResult, callback) {
// If this extension was previously installed but disabled, we will overwrite the
// previous installation in that directory.
fs.remove(installDirectory, function (err) {
if (err) {
callback(err);
return;
}
_performInstall(packagePath, installDirectory, validationResult, callback);
});
}
|
[
"function",
"_removeAndInstall",
"(",
"packagePath",
",",
"installDirectory",
",",
"validationResult",
",",
"callback",
")",
"{",
"fs",
".",
"remove",
"(",
"installDirectory",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"return",
";",
"}",
"_performInstall",
"(",
"packagePath",
",",
"installDirectory",
",",
"validationResult",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
] |
Private function to remove the target directory and then install.
@param {string} Absolute path to the package zip file
@param {string} Absolute path to the destination directory for unzipping
@param {Object} the return value with the useful information for the client
@param {Function} callback function that is called at the end of the unzipping
|
[
"Private",
"function",
"to",
"remove",
"the",
"target",
"directory",
"and",
"then",
"install",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/ExtensionManagerDomain.js#L131-L141
|
train
|
adobe/brackets
|
src/extensibility/node/ExtensionManagerDomain.js
|
legacyPackageCheck
|
function legacyPackageCheck(legacyDirectory) {
return fs.existsSync(legacyDirectory) && !fs.existsSync(path.join(legacyDirectory, "package.json"));
}
|
javascript
|
function legacyPackageCheck(legacyDirectory) {
return fs.existsSync(legacyDirectory) && !fs.existsSync(path.join(legacyDirectory, "package.json"));
}
|
[
"function",
"legacyPackageCheck",
"(",
"legacyDirectory",
")",
"{",
"return",
"fs",
".",
"existsSync",
"(",
"legacyDirectory",
")",
"&&",
"!",
"fs",
".",
"existsSync",
"(",
"path",
".",
"join",
"(",
"legacyDirectory",
",",
"\"package.json\"",
")",
")",
";",
"}"
] |
A "legacy package" is an extension that was installed based on the GitHub name without
a package.json file. Checking for the presence of these legacy extensions will help
users upgrade if the extension developer puts a different name in package.json than
the name of the GitHub project.
@param {string} legacyDirectory directory to check for old-style extension.
|
[
"A",
"legacy",
"package",
"is",
"an",
"extension",
"that",
"was",
"installed",
"based",
"on",
"the",
"GitHub",
"name",
"without",
"a",
"package",
".",
"json",
"file",
".",
"Checking",
"for",
"the",
"presence",
"of",
"these",
"legacy",
"extensions",
"will",
"help",
"users",
"upgrade",
"if",
"the",
"extension",
"developer",
"puts",
"a",
"different",
"name",
"in",
"package",
".",
"json",
"than",
"the",
"name",
"of",
"the",
"GitHub",
"project",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/ExtensionManagerDomain.js#L185-L187
|
train
|
adobe/brackets
|
src/extensibility/node/ExtensionManagerDomain.js
|
_cmdInstall
|
function _cmdInstall(packagePath, destinationDirectory, options, callback, pCallback, _doUpdate) {
if (!options || !options.disabledDirectory || !options.apiVersion || !options.systemExtensionDirectory) {
callback(new Error(Errors.MISSING_REQUIRED_OPTIONS), null);
return;
}
function validateCallback(err, validationResult) {
validationResult.localPath = packagePath;
// This is a wrapper for the callback that will delete the temporary
// directory to which the package was unzipped.
function deleteTempAndCallback(err) {
if (validationResult.extractDir) {
fs.remove(validationResult.extractDir);
delete validationResult.extractDir;
}
callback(err, validationResult);
}
// If there was trouble at the validation stage, we stop right away.
if (err || validationResult.errors.length > 0) {
validationResult.installationStatus = Statuses.FAILED;
deleteTempAndCallback(err);
return;
}
// Prefers the package.json name field, but will take the zip
// file's name if that's all that's available.
var extensionName, guessedName;
if (options.nameHint) {
guessedName = path.basename(options.nameHint, ".zip");
} else {
guessedName = path.basename(packagePath, ".zip");
}
if (validationResult.metadata) {
extensionName = validationResult.metadata.name;
} else {
extensionName = guessedName;
}
validationResult.name = extensionName;
var installDirectory = path.join(destinationDirectory, extensionName),
legacyDirectory = path.join(destinationDirectory, guessedName),
systemInstallDirectory = path.join(options.systemExtensionDirectory, extensionName);
if (validationResult.metadata && validationResult.metadata.engines &&
validationResult.metadata.engines.brackets) {
var compatible = semver.satisfies(options.apiVersion,
validationResult.metadata.engines.brackets);
if (!compatible) {
installDirectory = path.join(options.disabledDirectory, extensionName);
validationResult.installationStatus = Statuses.DISABLED;
validationResult.disabledReason = Errors.API_NOT_COMPATIBLE;
_removeAndInstall(packagePath, installDirectory, validationResult, deleteTempAndCallback);
return;
}
}
// The "legacy" stuff should go away after all of the commonly used extensions
// have been upgraded with package.json files.
var hasLegacyPackage = validationResult.metadata && legacyPackageCheck(legacyDirectory);
// If the extension is already there, we signal to the front end that it's already installed
// unless the front end has signaled an intent to update.
if (hasLegacyPackage || fs.existsSync(installDirectory) || fs.existsSync(systemInstallDirectory)) {
if (_doUpdate === true) {
if (hasLegacyPackage) {
// When there's a legacy installed extension, remove it first,
// then also remove any new-style directory the user may have.
// This helps clean up if the user is in a state where they have
// both legacy and new extensions installed.
fs.remove(legacyDirectory, function (err) {
if (err) {
deleteTempAndCallback(err);
return;
}
_removeAndInstall(packagePath, installDirectory, validationResult, deleteTempAndCallback);
});
} else {
_removeAndInstall(packagePath, installDirectory, validationResult, deleteTempAndCallback);
}
} else if (hasLegacyPackage) {
validationResult.installationStatus = Statuses.NEEDS_UPDATE;
validationResult.name = guessedName;
deleteTempAndCallback(null);
} else {
_checkExistingInstallation(validationResult, installDirectory, systemInstallDirectory, deleteTempAndCallback);
}
} else {
// Regular installation with no conflicts.
validationResult.disabledReason = null;
_performInstall(packagePath, installDirectory, validationResult, deleteTempAndCallback);
}
}
validate(packagePath, options, validateCallback);
}
|
javascript
|
function _cmdInstall(packagePath, destinationDirectory, options, callback, pCallback, _doUpdate) {
if (!options || !options.disabledDirectory || !options.apiVersion || !options.systemExtensionDirectory) {
callback(new Error(Errors.MISSING_REQUIRED_OPTIONS), null);
return;
}
function validateCallback(err, validationResult) {
validationResult.localPath = packagePath;
// This is a wrapper for the callback that will delete the temporary
// directory to which the package was unzipped.
function deleteTempAndCallback(err) {
if (validationResult.extractDir) {
fs.remove(validationResult.extractDir);
delete validationResult.extractDir;
}
callback(err, validationResult);
}
// If there was trouble at the validation stage, we stop right away.
if (err || validationResult.errors.length > 0) {
validationResult.installationStatus = Statuses.FAILED;
deleteTempAndCallback(err);
return;
}
// Prefers the package.json name field, but will take the zip
// file's name if that's all that's available.
var extensionName, guessedName;
if (options.nameHint) {
guessedName = path.basename(options.nameHint, ".zip");
} else {
guessedName = path.basename(packagePath, ".zip");
}
if (validationResult.metadata) {
extensionName = validationResult.metadata.name;
} else {
extensionName = guessedName;
}
validationResult.name = extensionName;
var installDirectory = path.join(destinationDirectory, extensionName),
legacyDirectory = path.join(destinationDirectory, guessedName),
systemInstallDirectory = path.join(options.systemExtensionDirectory, extensionName);
if (validationResult.metadata && validationResult.metadata.engines &&
validationResult.metadata.engines.brackets) {
var compatible = semver.satisfies(options.apiVersion,
validationResult.metadata.engines.brackets);
if (!compatible) {
installDirectory = path.join(options.disabledDirectory, extensionName);
validationResult.installationStatus = Statuses.DISABLED;
validationResult.disabledReason = Errors.API_NOT_COMPATIBLE;
_removeAndInstall(packagePath, installDirectory, validationResult, deleteTempAndCallback);
return;
}
}
// The "legacy" stuff should go away after all of the commonly used extensions
// have been upgraded with package.json files.
var hasLegacyPackage = validationResult.metadata && legacyPackageCheck(legacyDirectory);
// If the extension is already there, we signal to the front end that it's already installed
// unless the front end has signaled an intent to update.
if (hasLegacyPackage || fs.existsSync(installDirectory) || fs.existsSync(systemInstallDirectory)) {
if (_doUpdate === true) {
if (hasLegacyPackage) {
// When there's a legacy installed extension, remove it first,
// then also remove any new-style directory the user may have.
// This helps clean up if the user is in a state where they have
// both legacy and new extensions installed.
fs.remove(legacyDirectory, function (err) {
if (err) {
deleteTempAndCallback(err);
return;
}
_removeAndInstall(packagePath, installDirectory, validationResult, deleteTempAndCallback);
});
} else {
_removeAndInstall(packagePath, installDirectory, validationResult, deleteTempAndCallback);
}
} else if (hasLegacyPackage) {
validationResult.installationStatus = Statuses.NEEDS_UPDATE;
validationResult.name = guessedName;
deleteTempAndCallback(null);
} else {
_checkExistingInstallation(validationResult, installDirectory, systemInstallDirectory, deleteTempAndCallback);
}
} else {
// Regular installation with no conflicts.
validationResult.disabledReason = null;
_performInstall(packagePath, installDirectory, validationResult, deleteTempAndCallback);
}
}
validate(packagePath, options, validateCallback);
}
|
[
"function",
"_cmdInstall",
"(",
"packagePath",
",",
"destinationDirectory",
",",
"options",
",",
"callback",
",",
"pCallback",
",",
"_doUpdate",
")",
"{",
"if",
"(",
"!",
"options",
"||",
"!",
"options",
".",
"disabledDirectory",
"||",
"!",
"options",
".",
"apiVersion",
"||",
"!",
"options",
".",
"systemExtensionDirectory",
")",
"{",
"callback",
"(",
"new",
"Error",
"(",
"Errors",
".",
"MISSING_REQUIRED_OPTIONS",
")",
",",
"null",
")",
";",
"return",
";",
"}",
"function",
"validateCallback",
"(",
"err",
",",
"validationResult",
")",
"{",
"validationResult",
".",
"localPath",
"=",
"packagePath",
";",
"function",
"deleteTempAndCallback",
"(",
"err",
")",
"{",
"if",
"(",
"validationResult",
".",
"extractDir",
")",
"{",
"fs",
".",
"remove",
"(",
"validationResult",
".",
"extractDir",
")",
";",
"delete",
"validationResult",
".",
"extractDir",
";",
"}",
"callback",
"(",
"err",
",",
"validationResult",
")",
";",
"}",
"if",
"(",
"err",
"||",
"validationResult",
".",
"errors",
".",
"length",
">",
"0",
")",
"{",
"validationResult",
".",
"installationStatus",
"=",
"Statuses",
".",
"FAILED",
";",
"deleteTempAndCallback",
"(",
"err",
")",
";",
"return",
";",
"}",
"var",
"extensionName",
",",
"guessedName",
";",
"if",
"(",
"options",
".",
"nameHint",
")",
"{",
"guessedName",
"=",
"path",
".",
"basename",
"(",
"options",
".",
"nameHint",
",",
"\".zip\"",
")",
";",
"}",
"else",
"{",
"guessedName",
"=",
"path",
".",
"basename",
"(",
"packagePath",
",",
"\".zip\"",
")",
";",
"}",
"if",
"(",
"validationResult",
".",
"metadata",
")",
"{",
"extensionName",
"=",
"validationResult",
".",
"metadata",
".",
"name",
";",
"}",
"else",
"{",
"extensionName",
"=",
"guessedName",
";",
"}",
"validationResult",
".",
"name",
"=",
"extensionName",
";",
"var",
"installDirectory",
"=",
"path",
".",
"join",
"(",
"destinationDirectory",
",",
"extensionName",
")",
",",
"legacyDirectory",
"=",
"path",
".",
"join",
"(",
"destinationDirectory",
",",
"guessedName",
")",
",",
"systemInstallDirectory",
"=",
"path",
".",
"join",
"(",
"options",
".",
"systemExtensionDirectory",
",",
"extensionName",
")",
";",
"if",
"(",
"validationResult",
".",
"metadata",
"&&",
"validationResult",
".",
"metadata",
".",
"engines",
"&&",
"validationResult",
".",
"metadata",
".",
"engines",
".",
"brackets",
")",
"{",
"var",
"compatible",
"=",
"semver",
".",
"satisfies",
"(",
"options",
".",
"apiVersion",
",",
"validationResult",
".",
"metadata",
".",
"engines",
".",
"brackets",
")",
";",
"if",
"(",
"!",
"compatible",
")",
"{",
"installDirectory",
"=",
"path",
".",
"join",
"(",
"options",
".",
"disabledDirectory",
",",
"extensionName",
")",
";",
"validationResult",
".",
"installationStatus",
"=",
"Statuses",
".",
"DISABLED",
";",
"validationResult",
".",
"disabledReason",
"=",
"Errors",
".",
"API_NOT_COMPATIBLE",
";",
"_removeAndInstall",
"(",
"packagePath",
",",
"installDirectory",
",",
"validationResult",
",",
"deleteTempAndCallback",
")",
";",
"return",
";",
"}",
"}",
"var",
"hasLegacyPackage",
"=",
"validationResult",
".",
"metadata",
"&&",
"legacyPackageCheck",
"(",
"legacyDirectory",
")",
";",
"if",
"(",
"hasLegacyPackage",
"||",
"fs",
".",
"existsSync",
"(",
"installDirectory",
")",
"||",
"fs",
".",
"existsSync",
"(",
"systemInstallDirectory",
")",
")",
"{",
"if",
"(",
"_doUpdate",
"===",
"true",
")",
"{",
"if",
"(",
"hasLegacyPackage",
")",
"{",
"fs",
".",
"remove",
"(",
"legacyDirectory",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"deleteTempAndCallback",
"(",
"err",
")",
";",
"return",
";",
"}",
"_removeAndInstall",
"(",
"packagePath",
",",
"installDirectory",
",",
"validationResult",
",",
"deleteTempAndCallback",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"_removeAndInstall",
"(",
"packagePath",
",",
"installDirectory",
",",
"validationResult",
",",
"deleteTempAndCallback",
")",
";",
"}",
"}",
"else",
"if",
"(",
"hasLegacyPackage",
")",
"{",
"validationResult",
".",
"installationStatus",
"=",
"Statuses",
".",
"NEEDS_UPDATE",
";",
"validationResult",
".",
"name",
"=",
"guessedName",
";",
"deleteTempAndCallback",
"(",
"null",
")",
";",
"}",
"else",
"{",
"_checkExistingInstallation",
"(",
"validationResult",
",",
"installDirectory",
",",
"systemInstallDirectory",
",",
"deleteTempAndCallback",
")",
";",
"}",
"}",
"else",
"{",
"validationResult",
".",
"disabledReason",
"=",
"null",
";",
"_performInstall",
"(",
"packagePath",
",",
"installDirectory",
",",
"validationResult",
",",
"deleteTempAndCallback",
")",
";",
"}",
"}",
"validate",
"(",
"packagePath",
",",
"options",
",",
"validateCallback",
")",
";",
"}"
] |
Implements the "install" command in the "extensions" domain.
There is no need to call validate independently. Validation is the first
thing that is done here.
After the extension is validated, it is installed in destinationDirectory
unless the extension is already present there. If it is already present,
a determination is made about whether the package being installed is
an update. If it does appear to be an update, then result.installationStatus
is set to NEEDS_UPDATE. If not, then it's set to ALREADY_INSTALLED.
If the installation succeeds, then result.installationStatus is set to INSTALLED.
The extension is unzipped into a directory in destinationDirectory with
the name of the extension (the name is derived either from package.json
or the name of the zip file).
The destinationDirectory will be created if it does not exist.
@param {string} Absolute path to the package zip file
@param {string} the destination directory
@param {{disabledDirectory: !string, apiVersion: !string, nameHint: ?string,
systemExtensionDirectory: !string}} additional settings to control the installation
@param {function} callback (err, result)
@param {function} pCallback (msg) callback for notifications about operation progress
@param {boolean} _doUpdate private argument to signal that an update should be performed
|
[
"Implements",
"the",
"install",
"command",
"in",
"the",
"extensions",
"domain",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/ExtensionManagerDomain.js#L217-L313
|
train
|
adobe/brackets
|
src/extensibility/node/ExtensionManagerDomain.js
|
deleteTempAndCallback
|
function deleteTempAndCallback(err) {
if (validationResult.extractDir) {
fs.remove(validationResult.extractDir);
delete validationResult.extractDir;
}
callback(err, validationResult);
}
|
javascript
|
function deleteTempAndCallback(err) {
if (validationResult.extractDir) {
fs.remove(validationResult.extractDir);
delete validationResult.extractDir;
}
callback(err, validationResult);
}
|
[
"function",
"deleteTempAndCallback",
"(",
"err",
")",
"{",
"if",
"(",
"validationResult",
".",
"extractDir",
")",
"{",
"fs",
".",
"remove",
"(",
"validationResult",
".",
"extractDir",
")",
";",
"delete",
"validationResult",
".",
"extractDir",
";",
"}",
"callback",
"(",
"err",
",",
"validationResult",
")",
";",
"}"
] |
This is a wrapper for the callback that will delete the temporary directory to which the package was unzipped.
|
[
"This",
"is",
"a",
"wrapper",
"for",
"the",
"callback",
"that",
"will",
"delete",
"the",
"temporary",
"directory",
"to",
"which",
"the",
"package",
"was",
"unzipped",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/ExtensionManagerDomain.js#L228-L234
|
train
|
adobe/brackets
|
src/extensibility/node/ExtensionManagerDomain.js
|
_cmdUpdate
|
function _cmdUpdate(packagePath, destinationDirectory, options, callback, pCallback) {
_cmdInstall(packagePath, destinationDirectory, options, callback, pCallback, true);
}
|
javascript
|
function _cmdUpdate(packagePath, destinationDirectory, options, callback, pCallback) {
_cmdInstall(packagePath, destinationDirectory, options, callback, pCallback, true);
}
|
[
"function",
"_cmdUpdate",
"(",
"packagePath",
",",
"destinationDirectory",
",",
"options",
",",
"callback",
",",
"pCallback",
")",
"{",
"_cmdInstall",
"(",
"packagePath",
",",
"destinationDirectory",
",",
"options",
",",
"callback",
",",
"pCallback",
",",
"true",
")",
";",
"}"
] |
Implements the "update" command in the "extensions" domain.
Currently, this just wraps _cmdInstall, but will remove the existing directory
first.
There is no need to call validate independently. Validation is the first
thing that is done here.
After the extension is validated, it is installed in destinationDirectory
unless the extension is already present there. If it is already present,
a determination is made about whether the package being installed is
an update. If it does appear to be an update, then result.installationStatus
is set to NEEDS_UPDATE. If not, then it's set to ALREADY_INSTALLED.
If the installation succeeds, then result.installationStatus is set to INSTALLED.
The extension is unzipped into a directory in destinationDirectory with
the name of the extension (the name is derived either from package.json
or the name of the zip file).
The destinationDirectory will be created if it does not exist.
@param {string} Absolute path to the package zip file
@param {string} the destination directory
@param {{disabledDirectory: !string, apiVersion: !string, nameHint: ?string,
systemExtensionDirectory: !string}} additional settings to control the installation
@param {function} callback (err, result)
@param {function} pCallback (msg) callback for notifications about operation progress
|
[
"Implements",
"the",
"update",
"command",
"in",
"the",
"extensions",
"domain",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/ExtensionManagerDomain.js#L345-L347
|
train
|
adobe/brackets
|
src/extensibility/node/ExtensionManagerDomain.js
|
_cmdDownloadFile
|
function _cmdDownloadFile(downloadId, url, proxy, callback, pCallback) {
// Backwards compatibility check, added in 0.37
if (typeof proxy === "function") {
callback = proxy;
proxy = undefined;
}
if (pendingDownloads[downloadId]) {
callback(Errors.DOWNLOAD_ID_IN_USE, null);
return;
}
var req = request.get({
url: url,
encoding: null,
proxy: proxy
},
// Note: we could use the traditional "response"/"data"/"end" events too if we wanted to stream data
// incrementally, limit download size, etc. - but the simple callback is good enough for our needs.
function (error, response, body) {
if (error) {
// Usually means we never got a response - server is down, no DNS entry, etc.
_endDownload(downloadId, Errors.NO_SERVER_RESPONSE);
return;
}
if (response.statusCode !== 200) {
_endDownload(downloadId, [Errors.BAD_HTTP_STATUS, response.statusCode]);
return;
}
var stream = temp.createWriteStream("brackets");
if (!stream) {
_endDownload(downloadId, Errors.CANNOT_WRITE_TEMP);
return;
}
pendingDownloads[downloadId].localPath = stream.path;
pendingDownloads[downloadId].outStream = stream;
stream.write(body);
_endDownload(downloadId);
});
pendingDownloads[downloadId] = { request: req, callback: callback };
}
|
javascript
|
function _cmdDownloadFile(downloadId, url, proxy, callback, pCallback) {
// Backwards compatibility check, added in 0.37
if (typeof proxy === "function") {
callback = proxy;
proxy = undefined;
}
if (pendingDownloads[downloadId]) {
callback(Errors.DOWNLOAD_ID_IN_USE, null);
return;
}
var req = request.get({
url: url,
encoding: null,
proxy: proxy
},
// Note: we could use the traditional "response"/"data"/"end" events too if we wanted to stream data
// incrementally, limit download size, etc. - but the simple callback is good enough for our needs.
function (error, response, body) {
if (error) {
// Usually means we never got a response - server is down, no DNS entry, etc.
_endDownload(downloadId, Errors.NO_SERVER_RESPONSE);
return;
}
if (response.statusCode !== 200) {
_endDownload(downloadId, [Errors.BAD_HTTP_STATUS, response.statusCode]);
return;
}
var stream = temp.createWriteStream("brackets");
if (!stream) {
_endDownload(downloadId, Errors.CANNOT_WRITE_TEMP);
return;
}
pendingDownloads[downloadId].localPath = stream.path;
pendingDownloads[downloadId].outStream = stream;
stream.write(body);
_endDownload(downloadId);
});
pendingDownloads[downloadId] = { request: req, callback: callback };
}
|
[
"function",
"_cmdDownloadFile",
"(",
"downloadId",
",",
"url",
",",
"proxy",
",",
"callback",
",",
"pCallback",
")",
"{",
"if",
"(",
"typeof",
"proxy",
"===",
"\"function\"",
")",
"{",
"callback",
"=",
"proxy",
";",
"proxy",
"=",
"undefined",
";",
"}",
"if",
"(",
"pendingDownloads",
"[",
"downloadId",
"]",
")",
"{",
"callback",
"(",
"Errors",
".",
"DOWNLOAD_ID_IN_USE",
",",
"null",
")",
";",
"return",
";",
"}",
"var",
"req",
"=",
"request",
".",
"get",
"(",
"{",
"url",
":",
"url",
",",
"encoding",
":",
"null",
",",
"proxy",
":",
"proxy",
"}",
",",
"function",
"(",
"error",
",",
"response",
",",
"body",
")",
"{",
"if",
"(",
"error",
")",
"{",
"_endDownload",
"(",
"downloadId",
",",
"Errors",
".",
"NO_SERVER_RESPONSE",
")",
";",
"return",
";",
"}",
"if",
"(",
"response",
".",
"statusCode",
"!==",
"200",
")",
"{",
"_endDownload",
"(",
"downloadId",
",",
"[",
"Errors",
".",
"BAD_HTTP_STATUS",
",",
"response",
".",
"statusCode",
"]",
")",
";",
"return",
";",
"}",
"var",
"stream",
"=",
"temp",
".",
"createWriteStream",
"(",
"\"brackets\"",
")",
";",
"if",
"(",
"!",
"stream",
")",
"{",
"_endDownload",
"(",
"downloadId",
",",
"Errors",
".",
"CANNOT_WRITE_TEMP",
")",
";",
"return",
";",
"}",
"pendingDownloads",
"[",
"downloadId",
"]",
".",
"localPath",
"=",
"stream",
".",
"path",
";",
"pendingDownloads",
"[",
"downloadId",
"]",
".",
"outStream",
"=",
"stream",
";",
"stream",
".",
"write",
"(",
"body",
")",
";",
"_endDownload",
"(",
"downloadId",
")",
";",
"}",
")",
";",
"pendingDownloads",
"[",
"downloadId",
"]",
"=",
"{",
"request",
":",
"req",
",",
"callback",
":",
"callback",
"}",
";",
"}"
] |
Implements "downloadFile" command, asynchronously.
|
[
"Implements",
"downloadFile",
"command",
"asynchronously",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/ExtensionManagerDomain.js#L386-L429
|
train
|
adobe/brackets
|
src/extensibility/node/ExtensionManagerDomain.js
|
_cmdAbortDownload
|
function _cmdAbortDownload(downloadId) {
if (!pendingDownloads[downloadId]) {
// This may mean the download already completed
return false;
} else {
_endDownload(downloadId, Errors.CANCELED);
return true;
}
}
|
javascript
|
function _cmdAbortDownload(downloadId) {
if (!pendingDownloads[downloadId]) {
// This may mean the download already completed
return false;
} else {
_endDownload(downloadId, Errors.CANCELED);
return true;
}
}
|
[
"function",
"_cmdAbortDownload",
"(",
"downloadId",
")",
"{",
"if",
"(",
"!",
"pendingDownloads",
"[",
"downloadId",
"]",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"_endDownload",
"(",
"downloadId",
",",
"Errors",
".",
"CANCELED",
")",
";",
"return",
"true",
";",
"}",
"}"
] |
Implements "abortDownload" command, synchronously.
|
[
"Implements",
"abortDownload",
"command",
"synchronously",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/ExtensionManagerDomain.js#L434-L442
|
train
|
adobe/brackets
|
src/extensibility/node/ExtensionManagerDomain.js
|
_cmdRemove
|
function _cmdRemove(extensionDir, callback, pCallback) {
fs.remove(extensionDir, function (err) {
if (err) {
callback(err);
} else {
callback(null);
}
});
}
|
javascript
|
function _cmdRemove(extensionDir, callback, pCallback) {
fs.remove(extensionDir, function (err) {
if (err) {
callback(err);
} else {
callback(null);
}
});
}
|
[
"function",
"_cmdRemove",
"(",
"extensionDir",
",",
"callback",
",",
"pCallback",
")",
"{",
"fs",
".",
"remove",
"(",
"extensionDir",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"null",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Implements the remove extension command.
|
[
"Implements",
"the",
"remove",
"extension",
"command",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/ExtensionManagerDomain.js#L447-L455
|
train
|
adobe/brackets
|
src/filesystem/FileSystem.js
|
registerProtocolAdapter
|
function registerProtocolAdapter(protocol, adapter) {
var adapters;
if (protocol) {
adapters = _fileProtocolPlugins[protocol] || [];
adapters.push(adapter);
// We will keep a sorted adapter list on 'priority'
// If priority is not provided a default of '0' is assumed
adapters.sort(function (a, b) {
return (b.priority || 0) - (a.priority || 0);
});
_fileProtocolPlugins[protocol] = adapters;
}
}
|
javascript
|
function registerProtocolAdapter(protocol, adapter) {
var adapters;
if (protocol) {
adapters = _fileProtocolPlugins[protocol] || [];
adapters.push(adapter);
// We will keep a sorted adapter list on 'priority'
// If priority is not provided a default of '0' is assumed
adapters.sort(function (a, b) {
return (b.priority || 0) - (a.priority || 0);
});
_fileProtocolPlugins[protocol] = adapters;
}
}
|
[
"function",
"registerProtocolAdapter",
"(",
"protocol",
",",
"adapter",
")",
"{",
"var",
"adapters",
";",
"if",
"(",
"protocol",
")",
"{",
"adapters",
"=",
"_fileProtocolPlugins",
"[",
"protocol",
"]",
"||",
"[",
"]",
";",
"adapters",
".",
"push",
"(",
"adapter",
")",
";",
"adapters",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"(",
"b",
".",
"priority",
"||",
"0",
")",
"-",
"(",
"a",
".",
"priority",
"||",
"0",
")",
";",
"}",
")",
";",
"_fileProtocolPlugins",
"[",
"protocol",
"]",
"=",
"adapters",
";",
"}",
"}"
] |
Typical signature of a file protocol adapter.
@typedef {Object} FileProtocol~Adapter
@property {Number} priority - Indicates the priority.
@property {Object} fileImpl - Handle for the custom file implementation prototype.
@property {function} canRead - To check if this impl can read a file for a given path.
FileSystem hook to register file protocol adapter
@param {string} protocol ex: "https:"|"http:"|"ftp:"|"file:"
@param {...FileProtocol~Adapter} adapter wrapper over file implementation
|
[
"Typical",
"signature",
"of",
"a",
"file",
"protocol",
"adapter",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/FileSystem.js#L118-L132
|
train
|
adobe/brackets
|
src/extensibility/ExtensionManager.js
|
downloadRegistry
|
function downloadRegistry() {
if (pendingDownloadRegistry) {
return pendingDownloadRegistry.promise();
}
pendingDownloadRegistry = new $.Deferred();
$.ajax({
url: brackets.config.extension_registry,
dataType: "json",
cache: false
})
.done(function (data) {
exports.hasDownloadedRegistry = true;
Object.keys(data).forEach(function (id) {
if (!extensions[id]) {
extensions[id] = {};
}
extensions[id].registryInfo = data[id];
synchronizeEntry(id);
});
exports.trigger("registryDownload");
pendingDownloadRegistry.resolve();
})
.fail(function () {
pendingDownloadRegistry.reject();
})
.always(function () {
// Make sure to clean up the pending registry so that new requests can be made.
pendingDownloadRegistry = null;
});
return pendingDownloadRegistry.promise();
}
|
javascript
|
function downloadRegistry() {
if (pendingDownloadRegistry) {
return pendingDownloadRegistry.promise();
}
pendingDownloadRegistry = new $.Deferred();
$.ajax({
url: brackets.config.extension_registry,
dataType: "json",
cache: false
})
.done(function (data) {
exports.hasDownloadedRegistry = true;
Object.keys(data).forEach(function (id) {
if (!extensions[id]) {
extensions[id] = {};
}
extensions[id].registryInfo = data[id];
synchronizeEntry(id);
});
exports.trigger("registryDownload");
pendingDownloadRegistry.resolve();
})
.fail(function () {
pendingDownloadRegistry.reject();
})
.always(function () {
// Make sure to clean up the pending registry so that new requests can be made.
pendingDownloadRegistry = null;
});
return pendingDownloadRegistry.promise();
}
|
[
"function",
"downloadRegistry",
"(",
")",
"{",
"if",
"(",
"pendingDownloadRegistry",
")",
"{",
"return",
"pendingDownloadRegistry",
".",
"promise",
"(",
")",
";",
"}",
"pendingDownloadRegistry",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"$",
".",
"ajax",
"(",
"{",
"url",
":",
"brackets",
".",
"config",
".",
"extension_registry",
",",
"dataType",
":",
"\"json\"",
",",
"cache",
":",
"false",
"}",
")",
".",
"done",
"(",
"function",
"(",
"data",
")",
"{",
"exports",
".",
"hasDownloadedRegistry",
"=",
"true",
";",
"Object",
".",
"keys",
"(",
"data",
")",
".",
"forEach",
"(",
"function",
"(",
"id",
")",
"{",
"if",
"(",
"!",
"extensions",
"[",
"id",
"]",
")",
"{",
"extensions",
"[",
"id",
"]",
"=",
"{",
"}",
";",
"}",
"extensions",
"[",
"id",
"]",
".",
"registryInfo",
"=",
"data",
"[",
"id",
"]",
";",
"synchronizeEntry",
"(",
"id",
")",
";",
"}",
")",
";",
"exports",
".",
"trigger",
"(",
"\"registryDownload\"",
")",
";",
"pendingDownloadRegistry",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"pendingDownloadRegistry",
".",
"reject",
"(",
")",
";",
"}",
")",
".",
"always",
"(",
"function",
"(",
")",
"{",
"pendingDownloadRegistry",
"=",
"null",
";",
"}",
")",
";",
"return",
"pendingDownloadRegistry",
".",
"promise",
"(",
")",
";",
"}"
] |
Downloads the registry of Brackets extensions and stores the information in our
extension info.
@return {$.Promise} a promise that's resolved with the registry JSON data
or rejected if the server can't be reached.
|
[
"Downloads",
"the",
"registry",
"of",
"Brackets",
"extensions",
"and",
"stores",
"the",
"information",
"in",
"our",
"extension",
"info",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/ExtensionManager.js#L205-L238
|
train
|
adobe/brackets
|
src/extensibility/ExtensionManager.js
|
getCompatibilityInfo
|
function getCompatibilityInfo(entry, apiVersion) {
if (!entry.versions) {
var fallback = getCompatibilityInfoForVersion(entry.metadata, apiVersion);
if (fallback.isCompatible) {
fallback.isLatestVersion = true;
}
return fallback;
}
var i = entry.versions.length - 1,
latestInfo = getCompatibilityInfoForVersion(entry.versions[i], apiVersion);
if (latestInfo.isCompatible) {
latestInfo.isLatestVersion = true;
return latestInfo;
} else {
// Look at earlier versions (skipping very latest version since we already checked it)
for (i--; i >= 0; i--) {
var compatInfo = getCompatibilityInfoForVersion(entry.versions[i], apiVersion);
if (compatInfo.isCompatible) {
compatInfo.isLatestVersion = false;
compatInfo.requiresNewer = latestInfo.requiresNewer;
return compatInfo;
}
}
// No version is compatible, so just return info for the latest version
return latestInfo;
}
}
|
javascript
|
function getCompatibilityInfo(entry, apiVersion) {
if (!entry.versions) {
var fallback = getCompatibilityInfoForVersion(entry.metadata, apiVersion);
if (fallback.isCompatible) {
fallback.isLatestVersion = true;
}
return fallback;
}
var i = entry.versions.length - 1,
latestInfo = getCompatibilityInfoForVersion(entry.versions[i], apiVersion);
if (latestInfo.isCompatible) {
latestInfo.isLatestVersion = true;
return latestInfo;
} else {
// Look at earlier versions (skipping very latest version since we already checked it)
for (i--; i >= 0; i--) {
var compatInfo = getCompatibilityInfoForVersion(entry.versions[i], apiVersion);
if (compatInfo.isCompatible) {
compatInfo.isLatestVersion = false;
compatInfo.requiresNewer = latestInfo.requiresNewer;
return compatInfo;
}
}
// No version is compatible, so just return info for the latest version
return latestInfo;
}
}
|
[
"function",
"getCompatibilityInfo",
"(",
"entry",
",",
"apiVersion",
")",
"{",
"if",
"(",
"!",
"entry",
".",
"versions",
")",
"{",
"var",
"fallback",
"=",
"getCompatibilityInfoForVersion",
"(",
"entry",
".",
"metadata",
",",
"apiVersion",
")",
";",
"if",
"(",
"fallback",
".",
"isCompatible",
")",
"{",
"fallback",
".",
"isLatestVersion",
"=",
"true",
";",
"}",
"return",
"fallback",
";",
"}",
"var",
"i",
"=",
"entry",
".",
"versions",
".",
"length",
"-",
"1",
",",
"latestInfo",
"=",
"getCompatibilityInfoForVersion",
"(",
"entry",
".",
"versions",
"[",
"i",
"]",
",",
"apiVersion",
")",
";",
"if",
"(",
"latestInfo",
".",
"isCompatible",
")",
"{",
"latestInfo",
".",
"isLatestVersion",
"=",
"true",
";",
"return",
"latestInfo",
";",
"}",
"else",
"{",
"for",
"(",
"i",
"--",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"compatInfo",
"=",
"getCompatibilityInfoForVersion",
"(",
"entry",
".",
"versions",
"[",
"i",
"]",
",",
"apiVersion",
")",
";",
"if",
"(",
"compatInfo",
".",
"isCompatible",
")",
"{",
"compatInfo",
".",
"isLatestVersion",
"=",
"false",
";",
"compatInfo",
".",
"requiresNewer",
"=",
"latestInfo",
".",
"requiresNewer",
";",
"return",
"compatInfo",
";",
"}",
"}",
"return",
"latestInfo",
";",
"}",
"}"
] |
Finds the newest version of the entry that is compatible with the given Brackets API version, if any.
@param {Object} entry The registry entry to check.
@param {string} apiVersion The Brackets API version to check against.
@return {{isCompatible: boolean, requiresNewer: ?boolean, compatibleVersion: ?string, isLatestVersion: boolean}}
Result contains an "isCompatible" member saying whether it's compatible. If compatible, "compatibleVersion"
specifies the newest version that is compatible and "isLatestVersion" indicates if this is the absolute
latest version of the extension or not. If !isCompatible or !isLatestVersion, "requiresNewer" says whether
the latest version is incompatible due to requiring a newer (vs. older) version of Brackets.
|
[
"Finds",
"the",
"newest",
"version",
"of",
"the",
"entry",
"that",
"is",
"compatible",
"with",
"the",
"given",
"Brackets",
"API",
"version",
"if",
"any",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/ExtensionManager.js#L348-L377
|
train
|
adobe/brackets
|
src/extensibility/ExtensionManager.js
|
getExtensionURL
|
function getExtensionURL(id, version) {
return StringUtils.format(brackets.config.extension_url, id, version);
}
|
javascript
|
function getExtensionURL(id, version) {
return StringUtils.format(brackets.config.extension_url, id, version);
}
|
[
"function",
"getExtensionURL",
"(",
"id",
",",
"version",
")",
"{",
"return",
"StringUtils",
".",
"format",
"(",
"brackets",
".",
"config",
".",
"extension_url",
",",
"id",
",",
"version",
")",
";",
"}"
] |
Given an extension id and version number, returns the URL for downloading that extension from
the repository. Does not guarantee that the extension exists at that URL.
@param {string} id The extension's name from the metadata.
@param {string} version The version to download.
@return {string} The URL to download the extension from.
|
[
"Given",
"an",
"extension",
"id",
"and",
"version",
"number",
"returns",
"the",
"URL",
"for",
"downloading",
"that",
"extension",
"from",
"the",
"repository",
".",
"Does",
"not",
"guarantee",
"that",
"the",
"extension",
"exists",
"at",
"that",
"URL",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/ExtensionManager.js#L386-L388
|
train
|
adobe/brackets
|
src/extensibility/ExtensionManager.js
|
remove
|
function remove(id) {
var result = new $.Deferred();
if (extensions[id] && extensions[id].installInfo) {
Package.remove(extensions[id].installInfo.path)
.done(function () {
extensions[id].installInfo = null;
result.resolve();
exports.trigger("statusChange", id);
})
.fail(function (err) {
result.reject(err);
});
} else {
result.reject(StringUtils.format(Strings.EXTENSION_NOT_INSTALLED, id));
}
return result.promise();
}
|
javascript
|
function remove(id) {
var result = new $.Deferred();
if (extensions[id] && extensions[id].installInfo) {
Package.remove(extensions[id].installInfo.path)
.done(function () {
extensions[id].installInfo = null;
result.resolve();
exports.trigger("statusChange", id);
})
.fail(function (err) {
result.reject(err);
});
} else {
result.reject(StringUtils.format(Strings.EXTENSION_NOT_INSTALLED, id));
}
return result.promise();
}
|
[
"function",
"remove",
"(",
"id",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"if",
"(",
"extensions",
"[",
"id",
"]",
"&&",
"extensions",
"[",
"id",
"]",
".",
"installInfo",
")",
"{",
"Package",
".",
"remove",
"(",
"extensions",
"[",
"id",
"]",
".",
"installInfo",
".",
"path",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"extensions",
"[",
"id",
"]",
".",
"installInfo",
"=",
"null",
";",
"result",
".",
"resolve",
"(",
")",
";",
"exports",
".",
"trigger",
"(",
"\"statusChange\"",
",",
"id",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"err",
")",
"{",
"result",
".",
"reject",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"result",
".",
"reject",
"(",
"StringUtils",
".",
"format",
"(",
"Strings",
".",
"EXTENSION_NOT_INSTALLED",
",",
"id",
")",
")",
";",
"}",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Removes the installed extension with the given id.
@param {string} id The id of the extension to remove.
@return {$.Promise} A promise that's resolved when the extension is removed or
rejected with an error if there's a problem with the removal.
|
[
"Removes",
"the",
"installed",
"extension",
"with",
"the",
"given",
"id",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/ExtensionManager.js#L396-L412
|
train
|
adobe/brackets
|
src/extensibility/ExtensionManager.js
|
update
|
function update(id, packagePath, keepFile) {
return Package.installUpdate(packagePath, id).done(function () {
if (!keepFile) {
FileSystem.getFileForPath(packagePath).unlink();
}
});
}
|
javascript
|
function update(id, packagePath, keepFile) {
return Package.installUpdate(packagePath, id).done(function () {
if (!keepFile) {
FileSystem.getFileForPath(packagePath).unlink();
}
});
}
|
[
"function",
"update",
"(",
"id",
",",
"packagePath",
",",
"keepFile",
")",
"{",
"return",
"Package",
".",
"installUpdate",
"(",
"packagePath",
",",
"id",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"keepFile",
")",
"{",
"FileSystem",
".",
"getFileForPath",
"(",
"packagePath",
")",
".",
"unlink",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Updates an installed extension with the given package file.
@param {string} id of the extension
@param {string} packagePath path to the package file
@param {boolean=} keepFile Flag to keep extension package file, default=false
@return {$.Promise} A promise that's resolved when the extension is updated or
rejected with an error if there's a problem with the update.
|
[
"Updates",
"an",
"installed",
"extension",
"with",
"the",
"given",
"package",
"file",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/ExtensionManager.js#L474-L480
|
train
|
adobe/brackets
|
src/extensibility/ExtensionManager.js
|
cleanupUpdates
|
function cleanupUpdates() {
Object.keys(_idsToUpdate).forEach(function (id) {
var installResult = _idsToUpdate[id],
keepFile = installResult.keepFile,
filename = installResult.localPath;
if (filename && !keepFile) {
FileSystem.getFileForPath(filename).unlink();
}
});
_idsToUpdate = {};
}
|
javascript
|
function cleanupUpdates() {
Object.keys(_idsToUpdate).forEach(function (id) {
var installResult = _idsToUpdate[id],
keepFile = installResult.keepFile,
filename = installResult.localPath;
if (filename && !keepFile) {
FileSystem.getFileForPath(filename).unlink();
}
});
_idsToUpdate = {};
}
|
[
"function",
"cleanupUpdates",
"(",
")",
"{",
"Object",
".",
"keys",
"(",
"_idsToUpdate",
")",
".",
"forEach",
"(",
"function",
"(",
"id",
")",
"{",
"var",
"installResult",
"=",
"_idsToUpdate",
"[",
"id",
"]",
",",
"keepFile",
"=",
"installResult",
".",
"keepFile",
",",
"filename",
"=",
"installResult",
".",
"localPath",
";",
"if",
"(",
"filename",
"&&",
"!",
"keepFile",
")",
"{",
"FileSystem",
".",
"getFileForPath",
"(",
"filename",
")",
".",
"unlink",
"(",
")",
";",
"}",
"}",
")",
";",
"_idsToUpdate",
"=",
"{",
"}",
";",
"}"
] |
Deletes any temporary files left behind by extensions that
were marked for update.
|
[
"Deletes",
"any",
"temporary",
"files",
"left",
"behind",
"by",
"extensions",
"that",
"were",
"marked",
"for",
"update",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/ExtensionManager.js#L486-L497
|
train
|
adobe/brackets
|
src/extensibility/ExtensionManager.js
|
markForRemoval
|
function markForRemoval(id, mark) {
if (mark) {
_idsToRemove[id] = true;
} else {
delete _idsToRemove[id];
}
exports.trigger("statusChange", id);
}
|
javascript
|
function markForRemoval(id, mark) {
if (mark) {
_idsToRemove[id] = true;
} else {
delete _idsToRemove[id];
}
exports.trigger("statusChange", id);
}
|
[
"function",
"markForRemoval",
"(",
"id",
",",
"mark",
")",
"{",
"if",
"(",
"mark",
")",
"{",
"_idsToRemove",
"[",
"id",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"delete",
"_idsToRemove",
"[",
"id",
"]",
";",
"}",
"exports",
".",
"trigger",
"(",
"\"statusChange\"",
",",
"id",
")",
";",
"}"
] |
Marks an extension for later removal, or unmarks an extension previously marked.
@param {string} id The id of the extension to mark for removal.
@param {boolean} mark Whether to mark or unmark it.
|
[
"Marks",
"an",
"extension",
"for",
"later",
"removal",
"or",
"unmarks",
"an",
"extension",
"previously",
"marked",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/ExtensionManager.js#L511-L518
|
train
|
adobe/brackets
|
src/extensibility/ExtensionManager.js
|
markForDisabling
|
function markForDisabling(id, mark) {
if (mark) {
_idsToDisable[id] = true;
} else {
delete _idsToDisable[id];
}
exports.trigger("statusChange", id);
}
|
javascript
|
function markForDisabling(id, mark) {
if (mark) {
_idsToDisable[id] = true;
} else {
delete _idsToDisable[id];
}
exports.trigger("statusChange", id);
}
|
[
"function",
"markForDisabling",
"(",
"id",
",",
"mark",
")",
"{",
"if",
"(",
"mark",
")",
"{",
"_idsToDisable",
"[",
"id",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"delete",
"_idsToDisable",
"[",
"id",
"]",
";",
"}",
"exports",
".",
"trigger",
"(",
"\"statusChange\"",
",",
"id",
")",
";",
"}"
] |
Marks an extension for disabling later, or unmarks an extension previously marked.
@param {string} id The id of the extension
@param {boolean} mark Whether to mark or unmark the extension.
|
[
"Marks",
"an",
"extension",
"for",
"disabling",
"later",
"or",
"unmarks",
"an",
"extension",
"previously",
"marked",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/ExtensionManager.js#L543-L550
|
train
|
adobe/brackets
|
src/extensibility/ExtensionManager.js
|
updateFromDownload
|
function updateFromDownload(installationResult) {
if (installationResult.keepFile === undefined) {
installationResult.keepFile = false;
}
var installationStatus = installationResult.installationStatus;
if (installationStatus === Package.InstallationStatuses.ALREADY_INSTALLED ||
installationStatus === Package.InstallationStatuses.NEEDS_UPDATE ||
installationStatus === Package.InstallationStatuses.SAME_VERSION ||
installationStatus === Package.InstallationStatuses.OLDER_VERSION) {
var id = installationResult.name;
delete _idsToRemove[id];
_idsToUpdate[id] = installationResult;
exports.trigger("statusChange", id);
}
}
|
javascript
|
function updateFromDownload(installationResult) {
if (installationResult.keepFile === undefined) {
installationResult.keepFile = false;
}
var installationStatus = installationResult.installationStatus;
if (installationStatus === Package.InstallationStatuses.ALREADY_INSTALLED ||
installationStatus === Package.InstallationStatuses.NEEDS_UPDATE ||
installationStatus === Package.InstallationStatuses.SAME_VERSION ||
installationStatus === Package.InstallationStatuses.OLDER_VERSION) {
var id = installationResult.name;
delete _idsToRemove[id];
_idsToUpdate[id] = installationResult;
exports.trigger("statusChange", id);
}
}
|
[
"function",
"updateFromDownload",
"(",
"installationResult",
")",
"{",
"if",
"(",
"installationResult",
".",
"keepFile",
"===",
"undefined",
")",
"{",
"installationResult",
".",
"keepFile",
"=",
"false",
";",
"}",
"var",
"installationStatus",
"=",
"installationResult",
".",
"installationStatus",
";",
"if",
"(",
"installationStatus",
"===",
"Package",
".",
"InstallationStatuses",
".",
"ALREADY_INSTALLED",
"||",
"installationStatus",
"===",
"Package",
".",
"InstallationStatuses",
".",
"NEEDS_UPDATE",
"||",
"installationStatus",
"===",
"Package",
".",
"InstallationStatuses",
".",
"SAME_VERSION",
"||",
"installationStatus",
"===",
"Package",
".",
"InstallationStatuses",
".",
"OLDER_VERSION",
")",
"{",
"var",
"id",
"=",
"installationResult",
".",
"name",
";",
"delete",
"_idsToRemove",
"[",
"id",
"]",
";",
"_idsToUpdate",
"[",
"id",
"]",
"=",
"installationResult",
";",
"exports",
".",
"trigger",
"(",
"\"statusChange\"",
",",
"id",
")",
";",
"}",
"}"
] |
If a downloaded package appears to be an update, mark the extension for update.
If an extension was previously marked for removal, marking for update will
turn off the removal mark.
@param {Object} installationResult info about the install provided by the Package.download function
|
[
"If",
"a",
"downloaded",
"package",
"appears",
"to",
"be",
"an",
"update",
"mark",
"the",
"extension",
"for",
"update",
".",
"If",
"an",
"extension",
"was",
"previously",
"marked",
"for",
"removal",
"marking",
"for",
"update",
"will",
"turn",
"off",
"the",
"removal",
"mark",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/ExtensionManager.js#L583-L598
|
train
|
adobe/brackets
|
src/extensibility/ExtensionManager.js
|
removeUpdate
|
function removeUpdate(id) {
var installationResult = _idsToUpdate[id];
if (!installationResult) {
return;
}
if (installationResult.localPath && !installationResult.keepFile) {
FileSystem.getFileForPath(installationResult.localPath).unlink();
}
delete _idsToUpdate[id];
exports.trigger("statusChange", id);
}
|
javascript
|
function removeUpdate(id) {
var installationResult = _idsToUpdate[id];
if (!installationResult) {
return;
}
if (installationResult.localPath && !installationResult.keepFile) {
FileSystem.getFileForPath(installationResult.localPath).unlink();
}
delete _idsToUpdate[id];
exports.trigger("statusChange", id);
}
|
[
"function",
"removeUpdate",
"(",
"id",
")",
"{",
"var",
"installationResult",
"=",
"_idsToUpdate",
"[",
"id",
"]",
";",
"if",
"(",
"!",
"installationResult",
")",
"{",
"return",
";",
"}",
"if",
"(",
"installationResult",
".",
"localPath",
"&&",
"!",
"installationResult",
".",
"keepFile",
")",
"{",
"FileSystem",
".",
"getFileForPath",
"(",
"installationResult",
".",
"localPath",
")",
".",
"unlink",
"(",
")",
";",
"}",
"delete",
"_idsToUpdate",
"[",
"id",
"]",
";",
"exports",
".",
"trigger",
"(",
"\"statusChange\"",
",",
"id",
")",
";",
"}"
] |
Removes the mark for an extension to be updated on restart. Also deletes the
downloaded package file.
@param {string} id The id of the extension for which the update is being removed
|
[
"Removes",
"the",
"mark",
"for",
"an",
"extension",
"to",
"be",
"updated",
"on",
"restart",
".",
"Also",
"deletes",
"the",
"downloaded",
"package",
"file",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/ExtensionManager.js#L605-L615
|
train
|
adobe/brackets
|
src/extensibility/ExtensionManager.js
|
updateExtensions
|
function updateExtensions() {
return Async.doInParallel_aggregateErrors(
Object.keys(_idsToUpdate),
function (id) {
var installationResult = _idsToUpdate[id];
return update(installationResult.name, installationResult.localPath, installationResult.keepFile);
}
);
}
|
javascript
|
function updateExtensions() {
return Async.doInParallel_aggregateErrors(
Object.keys(_idsToUpdate),
function (id) {
var installationResult = _idsToUpdate[id];
return update(installationResult.name, installationResult.localPath, installationResult.keepFile);
}
);
}
|
[
"function",
"updateExtensions",
"(",
")",
"{",
"return",
"Async",
".",
"doInParallel_aggregateErrors",
"(",
"Object",
".",
"keys",
"(",
"_idsToUpdate",
")",
",",
"function",
"(",
"id",
")",
"{",
"var",
"installationResult",
"=",
"_idsToUpdate",
"[",
"id",
"]",
";",
"return",
"update",
"(",
"installationResult",
".",
"name",
",",
"installationResult",
".",
"localPath",
",",
"installationResult",
".",
"keepFile",
")",
";",
"}",
")",
";",
"}"
] |
Updates extensions previously marked for update.
@return {$.Promise} A promise that's resolved when all extensions are updated, or rejected
if one or more extensions can't be updated. When rejected, the argument will be an
array of error objects, each of which contains an "item" property with the id of the
failed extension and an "error" property with the actual error.
|
[
"Updates",
"extensions",
"previously",
"marked",
"for",
"update",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/ExtensionManager.js#L676-L684
|
train
|
adobe/brackets
|
src/extensibility/ExtensionManager.js
|
getAvailableUpdates
|
function getAvailableUpdates() {
var result = [];
Object.keys(extensions).forEach(function (extensionId) {
var extensionInfo = extensions[extensionId];
// skip extensions that are not installed or are not in the registry
if (!extensionInfo.installInfo || !extensionInfo.registryInfo) {
return;
}
if (extensionInfo.registryInfo.updateCompatible) {
result.push({
id: extensionId,
installVersion: extensionInfo.installInfo.metadata.version,
registryVersion: extensionInfo.registryInfo.lastCompatibleVersion
});
}
});
return result;
}
|
javascript
|
function getAvailableUpdates() {
var result = [];
Object.keys(extensions).forEach(function (extensionId) {
var extensionInfo = extensions[extensionId];
// skip extensions that are not installed or are not in the registry
if (!extensionInfo.installInfo || !extensionInfo.registryInfo) {
return;
}
if (extensionInfo.registryInfo.updateCompatible) {
result.push({
id: extensionId,
installVersion: extensionInfo.installInfo.metadata.version,
registryVersion: extensionInfo.registryInfo.lastCompatibleVersion
});
}
});
return result;
}
|
[
"function",
"getAvailableUpdates",
"(",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"Object",
".",
"keys",
"(",
"extensions",
")",
".",
"forEach",
"(",
"function",
"(",
"extensionId",
")",
"{",
"var",
"extensionInfo",
"=",
"extensions",
"[",
"extensionId",
"]",
";",
"if",
"(",
"!",
"extensionInfo",
".",
"installInfo",
"||",
"!",
"extensionInfo",
".",
"registryInfo",
")",
"{",
"return",
";",
"}",
"if",
"(",
"extensionInfo",
".",
"registryInfo",
".",
"updateCompatible",
")",
"{",
"result",
".",
"push",
"(",
"{",
"id",
":",
"extensionId",
",",
"installVersion",
":",
"extensionInfo",
".",
"installInfo",
".",
"metadata",
".",
"version",
",",
"registryVersion",
":",
"extensionInfo",
".",
"registryInfo",
".",
"lastCompatibleVersion",
"}",
")",
";",
"}",
"}",
")",
";",
"return",
"result",
";",
"}"
] |
Gets an array of extensions that are currently installed and can be updated to a new version
@return {Array.<{id: string, installVersion: string, registryVersion: string}>}
where id = extensionId
installVersion = currently installed version of extension
registryVersion = latest version compatible with current Brackets
|
[
"Gets",
"an",
"array",
"of",
"extensions",
"that",
"are",
"currently",
"installed",
"and",
"can",
"be",
"updated",
"to",
"a",
"new",
"version"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/ExtensionManager.js#L693-L710
|
train
|
adobe/brackets
|
src/extensions/default/JavaScriptRefactoring/ExtractToVariable.js
|
extract
|
function extract(scopes, parentStatement, expns, text, insertPosition) {
var varType = "var",
varName = RefactoringUtils.getUniqueIdentifierName(scopes, "extracted"),
varDeclaration = varType + " " + varName + " = " + text + ";\n",
parentStatementStartPos = session.editor.posFromIndex(parentStatement.start),
insertStartPos = insertPosition || parentStatementStartPos,
selections = [],
doc = session.editor.document,
replaceExpnIndex = 0,
posToIndent,
edits = [];
// If parent statement is expression statement, then just append var declaration
// Ex: "add(1, 2)" will become "var extracted = add(1, 2)"
if (parentStatement.type === "ExpressionStatement" &&
RefactoringUtils.isEqual(parentStatement.expression, expns[0]) &&
insertStartPos.line === parentStatementStartPos.line &&
insertStartPos.ch === parentStatementStartPos.ch) {
varDeclaration = varType + " " + varName + " = ";
replaceExpnIndex = 1;
}
posToIndent = doc.adjustPosForChange(insertStartPos, varDeclaration.split("\n"), insertStartPos, insertStartPos);
// adjust pos for change
for (var i = replaceExpnIndex; i < expns.length; ++i) {
expns[i].start = session.editor.posFromIndex(expns[i].start);
expns[i].end = session.editor.posFromIndex(expns[i].end);
expns[i].start = doc.adjustPosForChange(expns[i].start, varDeclaration.split("\n"), insertStartPos, insertStartPos);
expns[i].end = doc.adjustPosForChange(expns[i].end, varDeclaration.split("\n"), insertStartPos, insertStartPos);
edits.push({
edit: {
text: varName,
start: expns[i].start,
end: expns[i].end
},
selection: {
start: expns[i].start,
end: {line: expns[i].start.line, ch: expns[i].start.ch + varName.length}
}
});
}
// Replace and multi-select
doc.batchOperation(function() {
doc.replaceRange(varDeclaration, insertStartPos);
selections = doc.doMultipleEdits(edits);
selections.push({
start: {line: insertStartPos.line, ch: insertStartPos.ch + varType.length + 1},
end: {line: insertStartPos.line, ch: insertStartPos.ch + varType.length + varName.length + 1},
primary: true
});
session.editor.setSelections(selections);
session.editor._codeMirror.indentLine(posToIndent.line, "smart");
});
}
|
javascript
|
function extract(scopes, parentStatement, expns, text, insertPosition) {
var varType = "var",
varName = RefactoringUtils.getUniqueIdentifierName(scopes, "extracted"),
varDeclaration = varType + " " + varName + " = " + text + ";\n",
parentStatementStartPos = session.editor.posFromIndex(parentStatement.start),
insertStartPos = insertPosition || parentStatementStartPos,
selections = [],
doc = session.editor.document,
replaceExpnIndex = 0,
posToIndent,
edits = [];
// If parent statement is expression statement, then just append var declaration
// Ex: "add(1, 2)" will become "var extracted = add(1, 2)"
if (parentStatement.type === "ExpressionStatement" &&
RefactoringUtils.isEqual(parentStatement.expression, expns[0]) &&
insertStartPos.line === parentStatementStartPos.line &&
insertStartPos.ch === parentStatementStartPos.ch) {
varDeclaration = varType + " " + varName + " = ";
replaceExpnIndex = 1;
}
posToIndent = doc.adjustPosForChange(insertStartPos, varDeclaration.split("\n"), insertStartPos, insertStartPos);
// adjust pos for change
for (var i = replaceExpnIndex; i < expns.length; ++i) {
expns[i].start = session.editor.posFromIndex(expns[i].start);
expns[i].end = session.editor.posFromIndex(expns[i].end);
expns[i].start = doc.adjustPosForChange(expns[i].start, varDeclaration.split("\n"), insertStartPos, insertStartPos);
expns[i].end = doc.adjustPosForChange(expns[i].end, varDeclaration.split("\n"), insertStartPos, insertStartPos);
edits.push({
edit: {
text: varName,
start: expns[i].start,
end: expns[i].end
},
selection: {
start: expns[i].start,
end: {line: expns[i].start.line, ch: expns[i].start.ch + varName.length}
}
});
}
// Replace and multi-select
doc.batchOperation(function() {
doc.replaceRange(varDeclaration, insertStartPos);
selections = doc.doMultipleEdits(edits);
selections.push({
start: {line: insertStartPos.line, ch: insertStartPos.ch + varType.length + 1},
end: {line: insertStartPos.line, ch: insertStartPos.ch + varType.length + varName.length + 1},
primary: true
});
session.editor.setSelections(selections);
session.editor._codeMirror.indentLine(posToIndent.line, "smart");
});
}
|
[
"function",
"extract",
"(",
"scopes",
",",
"parentStatement",
",",
"expns",
",",
"text",
",",
"insertPosition",
")",
"{",
"var",
"varType",
"=",
"\"var\"",
",",
"varName",
"=",
"RefactoringUtils",
".",
"getUniqueIdentifierName",
"(",
"scopes",
",",
"\"extracted\"",
")",
",",
"varDeclaration",
"=",
"varType",
"+",
"\" \"",
"+",
"varName",
"+",
"\" = \"",
"+",
"text",
"+",
"\";\\n\"",
",",
"\\n",
",",
"parentStatementStartPos",
"=",
"session",
".",
"editor",
".",
"posFromIndex",
"(",
"parentStatement",
".",
"start",
")",
",",
"insertStartPos",
"=",
"insertPosition",
"||",
"parentStatementStartPos",
",",
"selections",
"=",
"[",
"]",
",",
"doc",
"=",
"session",
".",
"editor",
".",
"document",
",",
"replaceExpnIndex",
"=",
"0",
",",
"posToIndent",
";",
"edits",
"=",
"[",
"]",
"if",
"(",
"parentStatement",
".",
"type",
"===",
"\"ExpressionStatement\"",
"&&",
"RefactoringUtils",
".",
"isEqual",
"(",
"parentStatement",
".",
"expression",
",",
"expns",
"[",
"0",
"]",
")",
"&&",
"insertStartPos",
".",
"line",
"===",
"parentStatementStartPos",
".",
"line",
"&&",
"insertStartPos",
".",
"ch",
"===",
"parentStatementStartPos",
".",
"ch",
")",
"{",
"varDeclaration",
"=",
"varType",
"+",
"\" \"",
"+",
"varName",
"+",
"\" = \"",
";",
"replaceExpnIndex",
"=",
"1",
";",
"}",
"posToIndent",
"=",
"doc",
".",
"adjustPosForChange",
"(",
"insertStartPos",
",",
"varDeclaration",
".",
"split",
"(",
"\"\\n\"",
")",
",",
"\\n",
",",
"insertStartPos",
")",
";",
"insertStartPos",
"}"
] |
Does the actual extraction. i.e Replacing the text, Creating a variable
and multi select variable names
|
[
"Does",
"the",
"actual",
"extraction",
".",
"i",
".",
"e",
"Replacing",
"the",
"text",
"Creating",
"a",
"variable",
"and",
"multi",
"select",
"variable",
"names"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptRefactoring/ExtractToVariable.js#L40-L97
|
train
|
adobe/brackets
|
src/extensions/default/JavaScriptRefactoring/ExtractToVariable.js
|
findAllExpressions
|
function findAllExpressions(parentBlockStatement, expn, text) {
var doc = session.editor.document,
obj = {},
expns = [];
// find all references of the expression
obj[expn.type] = function(node) {
if (text === doc.getText().substr(node.start, node.end - node.start)) {
expns.push(node);
}
};
ASTWalker.simple(parentBlockStatement, obj);
return expns;
}
|
javascript
|
function findAllExpressions(parentBlockStatement, expn, text) {
var doc = session.editor.document,
obj = {},
expns = [];
// find all references of the expression
obj[expn.type] = function(node) {
if (text === doc.getText().substr(node.start, node.end - node.start)) {
expns.push(node);
}
};
ASTWalker.simple(parentBlockStatement, obj);
return expns;
}
|
[
"function",
"findAllExpressions",
"(",
"parentBlockStatement",
",",
"expn",
",",
"text",
")",
"{",
"var",
"doc",
"=",
"session",
".",
"editor",
".",
"document",
",",
"obj",
"=",
"{",
"}",
",",
"expns",
"=",
"[",
"]",
";",
"obj",
"[",
"expn",
".",
"type",
"]",
"=",
"function",
"(",
"node",
")",
"{",
"if",
"(",
"text",
"===",
"doc",
".",
"getText",
"(",
")",
".",
"substr",
"(",
"node",
".",
"start",
",",
"node",
".",
"end",
"-",
"node",
".",
"start",
")",
")",
"{",
"expns",
".",
"push",
"(",
"node",
")",
";",
"}",
"}",
";",
"ASTWalker",
".",
"simple",
"(",
"parentBlockStatement",
",",
"obj",
")",
";",
"return",
"expns",
";",
"}"
] |
Find all expressions in the parentBlockStatement that are same as expn
@param {!ASTNode} parentBlockStatement
@param {!ASTNode} expn
@param {!string} text - text of the expression
@return {!Array.<ASTNode>}
|
[
"Find",
"all",
"expressions",
"in",
"the",
"parentBlockStatement",
"that",
"are",
"same",
"as",
"expn"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptRefactoring/ExtractToVariable.js#L106-L120
|
train
|
adobe/brackets
|
src/extensions/default/JavaScriptRefactoring/ExtractToVariable.js
|
getExpressions
|
function getExpressions(ast, start, end) {
var expns = [],
s = start,
e = end,
expn;
while (true) {
expn = RefactoringUtils.findSurroundExpression(ast, {start: s, end: e});
if (!expn) {
break;
}
expns.push(expn);
s = expn.start - 1;
}
s = start;
e = end;
function checkExpnEquality(e) {
return e.start === expn.start && e.end === expn.end;
}
while (true) {
expn = RefactoringUtils.findSurroundExpression(ast, {start: s, end: e});
if (!expn) {
break;
}
e = expn.end + 1;
// if expn already added, continue
if (expns.find(checkExpnEquality)) {
continue;
}
expns.push(expn);
}
return expns;
}
|
javascript
|
function getExpressions(ast, start, end) {
var expns = [],
s = start,
e = end,
expn;
while (true) {
expn = RefactoringUtils.findSurroundExpression(ast, {start: s, end: e});
if (!expn) {
break;
}
expns.push(expn);
s = expn.start - 1;
}
s = start;
e = end;
function checkExpnEquality(e) {
return e.start === expn.start && e.end === expn.end;
}
while (true) {
expn = RefactoringUtils.findSurroundExpression(ast, {start: s, end: e});
if (!expn) {
break;
}
e = expn.end + 1;
// if expn already added, continue
if (expns.find(checkExpnEquality)) {
continue;
}
expns.push(expn);
}
return expns;
}
|
[
"function",
"getExpressions",
"(",
"ast",
",",
"start",
",",
"end",
")",
"{",
"var",
"expns",
"=",
"[",
"]",
",",
"s",
"=",
"start",
",",
"e",
"=",
"end",
",",
"expn",
";",
"while",
"(",
"true",
")",
"{",
"expn",
"=",
"RefactoringUtils",
".",
"findSurroundExpression",
"(",
"ast",
",",
"{",
"start",
":",
"s",
",",
"end",
":",
"e",
"}",
")",
";",
"if",
"(",
"!",
"expn",
")",
"{",
"break",
";",
"}",
"expns",
".",
"push",
"(",
"expn",
")",
";",
"s",
"=",
"expn",
".",
"start",
"-",
"1",
";",
"}",
"s",
"=",
"start",
";",
"e",
"=",
"end",
";",
"function",
"checkExpnEquality",
"(",
"e",
")",
"{",
"return",
"e",
".",
"start",
"===",
"expn",
".",
"start",
"&&",
"e",
".",
"end",
"===",
"expn",
".",
"end",
";",
"}",
"while",
"(",
"true",
")",
"{",
"expn",
"=",
"RefactoringUtils",
".",
"findSurroundExpression",
"(",
"ast",
",",
"{",
"start",
":",
"s",
",",
"end",
":",
"e",
"}",
")",
";",
"if",
"(",
"!",
"expn",
")",
"{",
"break",
";",
"}",
"e",
"=",
"expn",
".",
"end",
"+",
"1",
";",
"if",
"(",
"expns",
".",
"find",
"(",
"checkExpnEquality",
")",
")",
"{",
"continue",
";",
"}",
"expns",
".",
"push",
"(",
"expn",
")",
";",
"}",
"return",
"expns",
";",
"}"
] |
Gets the surrounding expressions of start and end offset
@param {!ASTNode} ast - the ast of the complete file
@param {!number} start - the start offset
@param {!number} end - the end offset
@return {!Array.<ASTNode>}
|
[
"Gets",
"the",
"surrounding",
"expressions",
"of",
"start",
"and",
"end",
"offset"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptRefactoring/ExtractToVariable.js#L129-L167
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.