mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Allow preferences to be overridden by a configuration file.
src/extensions/default/JavaScriptCodeHints/Preferences.js
New class to parse JSON preferences object and store preferences.
src/extensions/default/JavaScriptCodeHints/ScopeManager.js
Look for preference file, .jscodehints, in the project root directory.
Remove obsolete "shouldPrimePump" parameter.
src/extensions/default/JavaScriptCodeHints/main.js
Remove obsolete "shouldPrimePump" parameter.
src/extensions/default/JavaScriptCodeHints/unittests.js
Add new preference tests.
Add new preference tests under unittest-files/preference-test-files
This commit is contained in:
1 parent
149461a8ca
commit
d65fbdcacf
12 files changed
+543
-59
No files matched your search
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
This class parses configuration values from a JSON object. The expected
|
||||
name of the file is “.jscodehints” but this class does not actually read
|
||||
the file, it just provides a constant, FILE_NAME.
|
||||
|
||||
The following properties are supported:
|
||||
|
||||
"excluded-directories" - An array of directory strings that match
|
||||
directories that will be excluded from analysis. Directories may be
|
||||
excluded if they contain automated tests that aren’t relevant for code hinting.
|
||||
The wildcards “*” and “?” are supported in strings.
|
||||
|
||||
"excluded-files" - An array of file strings that match files that will
|
||||
be excluded from analysis. Files are typically excluded because
|
||||
their API is in a JSON file or they are known to cause problems with either
|
||||
stability or performance. The wildcards “*” and “?” are supported in strings.
|
||||
|
||||
"max-file-count" - Limits the total number of files that can be processed for
|
||||
hints.
|
||||
|
||||
"max-file-size" - Files larger than this number of bytes will not be parsed.
|
||||
|
||||
The strings in "excluded-directories" or "excluded-files" will be treated as a
|
||||
regular expression if the first and last characters of the string are the '/'
|
||||
character. Note the '\' character in a regular expression needs to be escaped
|
||||
to be valid in a JSON formatted file. For example "/[\d]/" becomes "/[\\d]/".
|
||||
|
||||
Example file:
|
||||
|
||||
{
|
||||
"excluded-directories" : ["/ex[\\w]*ed/"],
|
||||
"excluded-files" : ["require.js", "jquery*.js", "less*.min.js", "ember*.js", "d2?.js", "d3*"],
|
||||
"max-file-count": 100,
|
||||
"max-file-size": 524288
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp: true */
|
||||
/*global define, brackets, $ */
|
||||
|
||||
define(function (require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var StringUtils = brackets.getModule("utils/StringUtils");
|
||||
|
||||
/**
|
||||
* Convert an array of strings with optional wildcards, to an equivalent
|
||||
* regular expression.
|
||||
*
|
||||
* @param {Array.<string|RegExp>} settings
|
||||
* @param {RegExp} defaultRegExp - default regular expression to use
|
||||
* if none if provided.
|
||||
* @return {RegExp} Regular expression that captures the array of string
|
||||
* with optional wildcards.
|
||||
*/
|
||||
function settingsToRegExp(settings, defaultRegExp) {
|
||||
var regExpString = "";
|
||||
|
||||
if (settings) {
|
||||
|
||||
// convert each string, with optional wildcards to an equivalent
|
||||
// string in a regular expression.
|
||||
settings.forEach(function (value, index) {
|
||||
|
||||
if (typeof value === "string") {
|
||||
var isRegExp = value[0] === '/' && value[value.length - 1] === '/';
|
||||
|
||||
if (isRegExp) {
|
||||
value = value.substring(1, value.length - 1);
|
||||
} else {
|
||||
value = StringUtils.regexEscape(value);
|
||||
|
||||
// convert user input wildcard, "*" or "?", to a regular
|
||||
// expression. We can just replace the escaped "*" or "?"
|
||||
// since we know it is a wildcard.
|
||||
value = value.replace("\\?", ".?");
|
||||
value = value.replace("\\*", ".*");
|
||||
}
|
||||
|
||||
if (index > 0) {
|
||||
regExpString += "|";
|
||||
}
|
||||
|
||||
// Add "^" and "$" to prevent matching in the middle of strings.
|
||||
regExpString = regExpString.concat("^" + value + "$");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!regExpString) {
|
||||
return defaultRegExp;
|
||||
}
|
||||
|
||||
return new RegExp(regExpString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor to create a default preference object.
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object=} prefs - preference object
|
||||
*/
|
||||
function Preferences(prefs) {
|
||||
var DEFAULT_EXCLUDED_DIRECTORIES = null, /* no exclusions */
|
||||
// exclude require and jquery since we have special knowledge of those
|
||||
// temporarily exclude less*min.js because it is causing instability in tern.
|
||||
// exclude ember*.js as it is currently causing problems
|
||||
DEFAULT_EXCLUDED_FILES = /^require.*\.js$|^jquery.*\.js$|^less.*\.min\.js$|^ember.*\.js$/,
|
||||
DEFAULT_MAX_FILE_COUNT = 100,
|
||||
DEFAULT_MAX_FILE_SIZE = 512 * 1024;
|
||||
|
||||
if (prefs) {
|
||||
this._excludedDirectories = settingsToRegExp(prefs["excluded-directories"],
|
||||
DEFAULT_EXCLUDED_DIRECTORIES);
|
||||
this._excludedFiles = settingsToRegExp(prefs["excluded-files"],
|
||||
DEFAULT_EXCLUDED_FILES);
|
||||
this._maxFileCount = prefs["max-file-count"];
|
||||
this._maxFileSize = prefs["max-file-size"];
|
||||
|
||||
// sanity check values
|
||||
if (!this._maxFileCount || this._maxFileCount < 0) {
|
||||
this._maxFileCount = DEFAULT_MAX_FILE_COUNT;
|
||||
}
|
||||
|
||||
if (!this._maxFileSize || this._maxFileSize < 0) {
|
||||
this._maxFileSize = DEFAULT_MAX_FILE_SIZE;
|
||||
}
|
||||
|
||||
} else {
|
||||
this._excludedDirectories = DEFAULT_EXCLUDED_DIRECTORIES;
|
||||
this._excludedFiles = DEFAULT_EXCLUDED_FILES;
|
||||
this._maxFileCount = DEFAULT_MAX_FILE_COUNT;
|
||||
this._maxFileSize = DEFAULT_MAX_FILE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
Preferences.FILE_NAME = ".jscodehints";
|
||||
|
||||
/**
|
||||
* Get the regular expression for excluded directories.
|
||||
*
|
||||
* @returns {?RegExp} Regular expression matching the directories that should
|
||||
* be excluded. Returns null if no directories are excluded.
|
||||
*/
|
||||
Preferences.prototype.getExcludedDirectories = function () {
|
||||
return this._excludedDirectories;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the regular expression for excluded files.
|
||||
*
|
||||
* @returns {?RegExp} Regular expression matching the files that should
|
||||
* be excluded. Returns null if no files are excluded.
|
||||
*/
|
||||
Preferences.prototype.getExcludedFiles = function () {
|
||||
return this._excludedFiles;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the maximum number of files that will be analyzed.
|
||||
*
|
||||
* @returns {number}
|
||||
*/
|
||||
Preferences.prototype.getMaxFileCount = function () {
|
||||
return this._maxFileCount;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the maximum size of a file that will be analyzed. Files that are
|
||||
* larger will be ignored.
|
||||
*
|
||||
* @returns {number}
|
||||
*/
|
||||
Preferences.prototype.getMaxFileSize = function () {
|
||||
return this._maxFileSize;
|
||||
};
|
||||
|
||||
module.exports = Preferences;
|
||||
|
||||
});
|
||||
|
||||
@@ -43,30 +43,24 @@ define(function (require, exports, module) {
|
||||
FileUtils = brackets.getModule("file/FileUtils"),
|
||||
FileIndexManager = brackets.getModule("project/FileIndexManager"),
|
||||
HintUtils = require("HintUtils"),
|
||||
MessageIds = require("MessageIds");
|
||||
MessageIds = require("MessageIds"),
|
||||
Preferences = require("Preferences");
|
||||
|
||||
var ternEnvironment = [],
|
||||
pendingTernRequests = {},
|
||||
builtinFiles = ["ecma5.json", "browser.json", "jquery.json"],
|
||||
builtinFiles = ["ecma5.json", "browser.json", "jquery.json"],
|
||||
builtinLibraryNames = [],
|
||||
// exclude require and jquery since we have special knowledge of those
|
||||
// temporarily exclude less*min.js because it is causing instability in tern.
|
||||
// exclude ember*.js as it is currently causing problems
|
||||
excludedFilesRegEx = /require\.js$|jquery[\w.\-]*\.js$|less[\w.\-]*\.min\.js$|ember[\w.\-]*\.js$/,
|
||||
isDocumentDirty = false,
|
||||
_hintCount = 0,
|
||||
_lastPrimePump = false,
|
||||
currentWorker = null,
|
||||
documentChanges = null; // bounds of document changes
|
||||
documentChanges = null, // bounds of document changes
|
||||
preferences = null,
|
||||
deferredPreferences = null;
|
||||
|
||||
var MAX_TEXT_LENGTH = 512 * 1024,
|
||||
MAX_FILES_IN_DIR = 100,
|
||||
MAX_FILES_IN_PROJECT = 100,
|
||||
// how often to reset the tern server
|
||||
MAX_HINTS = 30,
|
||||
LARGE_LINE_CHANGE = 100,
|
||||
LARGE_LINE_COUNT = 250,
|
||||
OFFSET_ZERO = {line: 0, ch: 0};
|
||||
var MAX_HINTS = 30, // how often to reset the tern server
|
||||
LARGE_LINE_CHANGE = 100,
|
||||
LARGE_LINE_COUNT = 250,
|
||||
OFFSET_ZERO = {line: 0, ch: 0};
|
||||
|
||||
/**
|
||||
* An array of library names that contain JavaScript builtins definitions.
|
||||
@@ -101,7 +95,66 @@ define(function (require, exports, module) {
|
||||
}
|
||||
|
||||
initTernEnv();
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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;
|
||||
|
||||
NativeFileSystem.resolveNativeFileSystemPath(path, function (fileEntry) {
|
||||
FileUtils.readAsText(fileEntry).done(function (text) {
|
||||
var configObj = null;
|
||||
try {
|
||||
configObj = JSON.parse(text);
|
||||
} catch (e) {
|
||||
// continue with null configObj which will result in
|
||||
// default settings.
|
||||
}
|
||||
preferences = new Preferences(configObj);
|
||||
deferredPreferences.resolve();
|
||||
}).fail(function (error) {
|
||||
preferences = new Preferences();
|
||||
deferredPreferences.resolve();
|
||||
});
|
||||
}, function (error) {
|
||||
preferences = new Preferences();
|
||||
deferredPreferences.resolve();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Will initialize preferences only if they do not exist.
|
||||
*
|
||||
*/
|
||||
function ensurePreferences() {
|
||||
if (!deferredPreferences) {
|
||||
initPreferences();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the tern worker - if the worker is being initialized,
|
||||
* the message will not be posted until initialization is complete
|
||||
@@ -132,7 +185,7 @@ define(function (require, exports, module) {
|
||||
var reader = dirEntry.createReader();
|
||||
|
||||
reader.readEntries(function (entries) {
|
||||
entries.slice(0, MAX_FILES_IN_DIR).forEach(function (entry) {
|
||||
entries.slice(0, preferences.getMaxFileCount()).forEach(function (entry) {
|
||||
var path = entry.fullPath,
|
||||
split = HintUtils.splitPath(path),
|
||||
file = split.file;
|
||||
@@ -167,6 +220,43 @@ define(function (require, exports, module) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the directory should be excluded from analysis.
|
||||
*
|
||||
* @param {!string} path - full directory path.
|
||||
* @returns {boolean} true if excluded, false otherwise.
|
||||
*/
|
||||
function isDirectoryExcluded(path) {
|
||||
var excludes = preferences.getExcludedDirectories();
|
||||
|
||||
if (!excludes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var testPath = ProjectManager.makeProjectRelativeIfPossible(path);
|
||||
testPath = FileUtils.canonicalizeFolderPath(testPath);
|
||||
|
||||
return excludes.test(testPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the file should be excluded from analysis.
|
||||
*
|
||||
* @param {!string} path - full directory path.
|
||||
* @returns {boolean} true if excluded, false otherwise.
|
||||
*/
|
||||
function isFileExcluded(path) {
|
||||
var excludes = preferences.getExcludedFiles();
|
||||
|
||||
if (!excludes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var file = HintUtils.splitPath(path).file;
|
||||
|
||||
return excludes.test(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of javascript files in a given directory.
|
||||
*
|
||||
@@ -192,7 +282,7 @@ define(function (require, exports, module) {
|
||||
* @param path - full path of file.
|
||||
*/
|
||||
function fileCallback(path) {
|
||||
if (!excludedFilesRegEx.test(path)) {
|
||||
if (!isFileExcluded(path)) {
|
||||
files.push(path);
|
||||
}
|
||||
}
|
||||
@@ -286,7 +376,7 @@ define(function (require, exports, module) {
|
||||
*/
|
||||
function filterText(text) {
|
||||
var newText = text;
|
||||
if (text.length > MAX_TEXT_LENGTH) {
|
||||
if (text.length > preferences.getMaxFileSize()) {
|
||||
newText = "";
|
||||
}
|
||||
return newText;
|
||||
@@ -296,6 +386,7 @@ define(function (require, exports, module) {
|
||||
* Get the text of a document, applying any size restrictions
|
||||
* if necessary
|
||||
* @param {Document} document - the document to get the text from
|
||||
* @return {string} the text, or the empty text if the original was too long
|
||||
*/
|
||||
function getTextFromDocument(document) {
|
||||
var text = document.getText();
|
||||
@@ -812,8 +903,9 @@ define(function (require, exports, module) {
|
||||
*/
|
||||
function addFilesToTern(files) {
|
||||
// limit the number of files added to tern.
|
||||
if (numResolvedFiles + numAddedFiles < MAX_FILES_IN_PROJECT) {
|
||||
var available = MAX_FILES_IN_PROJECT - numResolvedFiles - numAddedFiles;
|
||||
var maxFileCount = preferences.getMaxFileCount();
|
||||
if (numResolvedFiles + numAddedFiles < maxFileCount) {
|
||||
var available = maxFileCount - numResolvedFiles - numAddedFiles;
|
||||
|
||||
if (available < files.length) {
|
||||
files = files.slice(0, available);
|
||||
@@ -888,7 +980,7 @@ define(function (require, exports, module) {
|
||||
* @param path - full path of file.
|
||||
*/
|
||||
function fileCallback(path) {
|
||||
if (!excludedFilesRegEx.test(path)) {
|
||||
if (!isFileExcluded(path)) {
|
||||
files.push(path);
|
||||
}
|
||||
}
|
||||
@@ -899,7 +991,8 @@ define(function (require, exports, module) {
|
||||
* @param path
|
||||
*/
|
||||
function directoryCallback(path) {
|
||||
if (path !== rootTernDir) {
|
||||
if (!isDirectoryExcluded(path) &&
|
||||
path !== rootTernDir) {
|
||||
dirs.push(path);
|
||||
}
|
||||
}
|
||||
@@ -996,9 +1089,8 @@ define(function (require, exports, module) {
|
||||
* @param {Session} session - the active hinting session
|
||||
* @param {Document} document - the document the editor has changed to
|
||||
* @param {Document} previousDocument - the document the editor has changed from
|
||||
* @param {boolean} shouldPrimePump - true if the pump should be primed.
|
||||
*/
|
||||
function doEditorChange(session, document, previousDocument, shouldPrimePump) {
|
||||
function doEditorChange(session, document, previousDocument) {
|
||||
var path = document.file.fullPath,
|
||||
split = HintUtils.splitPath(path),
|
||||
dir = split.dir,
|
||||
@@ -1008,9 +1100,7 @@ define(function (require, exports, module) {
|
||||
|
||||
var addFilesDeferred = $.Deferred();
|
||||
|
||||
_lastPrimePump = shouldPrimePump;
|
||||
documentChanges = null;
|
||||
|
||||
addFilesPromise = addFilesDeferred.promise();
|
||||
pr = ProjectManager.getProjectRoot() ? ProjectManager.getProjectRoot().fullPath : null;
|
||||
|
||||
@@ -1034,12 +1124,13 @@ define(function (require, exports, module) {
|
||||
|
||||
isDocumentDirty = false;
|
||||
resolvedFiles = {};
|
||||
|
||||
projectRoot = pr;
|
||||
getFilesInDirectory(dir, function (files) {
|
||||
initTernServer(dir, files);
|
||||
|
||||
if (shouldPrimePump) {
|
||||
|
||||
ensurePreferences();
|
||||
deferredPreferences.done(function () {
|
||||
getFilesInDirectory(dir, function (files) {
|
||||
initTernServer(dir, files);
|
||||
|
||||
var hintsPromise = primePump(path);
|
||||
hintsPromise.done(function () {
|
||||
if (!usingModules()) {
|
||||
@@ -1056,7 +1147,7 @@ define(function (require, exports, module) {
|
||||
// prime the pump again but this time don't wait
|
||||
// for completion.
|
||||
primePump(path);
|
||||
|
||||
|
||||
addFilesDeferred.resolveWith(null, [_ternWorker]);
|
||||
});
|
||||
} else {
|
||||
@@ -1067,13 +1158,10 @@ define(function (require, exports, module) {
|
||||
addFilesDeferred.resolveWith(null, [_ternWorker]);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
addFilesDeferred.resolveWith(null, [_ternWorker]);
|
||||
}
|
||||
|
||||
}, function () {
|
||||
addFilesDeferred.resolveWith(null);
|
||||
});
|
||||
}, function () {
|
||||
addFilesDeferred.resolveWith(null);
|
||||
});
|
||||
}).fail(function () {});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1082,14 +1170,13 @@ define(function (require, exports, module) {
|
||||
* @param {Session} session - the active hinting session
|
||||
* @param {Document} document - the document of the editor that has changed
|
||||
* @param {Document} previousDocument - the document of the editor is changing from
|
||||
* @param {boolean} shouldPrimePump - true if the pump should be primed.
|
||||
*/
|
||||
function handleEditorChange(session, document, previousDocument, shouldPrimePump) {
|
||||
function handleEditorChange(session, document, previousDocument) {
|
||||
if (addFilesPromise === null) {
|
||||
doEditorChange(session, document, previousDocument, shouldPrimePump);
|
||||
doEditorChange(session, document, previousDocument);
|
||||
} else {
|
||||
addFilesPromise.done(function () {
|
||||
doEditorChange(session, document, previousDocument, shouldPrimePump);
|
||||
doEditorChange(session, document, previousDocument);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1154,7 +1241,7 @@ define(function (require, exports, module) {
|
||||
if (++_hintCount > MAX_HINTS) {
|
||||
reseting = true;
|
||||
newWorker = new TernWorker();
|
||||
newWorker.handleEditorChange(session, document, null, _lastPrimePump);
|
||||
newWorker.handleEditorChange(session, document, null);
|
||||
newWorker.whenReady(function () {
|
||||
// tell the old worker to shut down
|
||||
currentWorker.closeWorker();
|
||||
@@ -1267,14 +1354,13 @@ define(function (require, exports, module) {
|
||||
* @param {Session} session - the active hinting session
|
||||
* @param {Document} document - the document of the editor that has changed
|
||||
* @param {Document} previousDocument - the document of the editor is changing from
|
||||
* @param {boolean} shouldPrimePump - true if the pump should be primed.
|
||||
*/
|
||||
function handleEditorChange(session, document, previousDocument, shouldPrimePump) {
|
||||
function handleEditorChange(session, document, previousDocument) {
|
||||
|
||||
if (!currentWorker) {
|
||||
currentWorker = new TernWorker();
|
||||
}
|
||||
return currentWorker.handleEditorChange(session, document, previousDocument, shouldPrimePump);
|
||||
return currentWorker.handleEditorChange(session, document, previousDocument);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1290,6 +1376,17 @@ define(function (require, exports, module) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read in project preferences when a new project is opened.
|
||||
* Look in the project root directory for a preference file.
|
||||
*
|
||||
* @param {string=} projectRootPath - new project root path(optional).
|
||||
* Only needed for unit tests.
|
||||
*/
|
||||
function handleProjectOpen(projectRootPath) {
|
||||
initPreferences(projectRootPath);
|
||||
}
|
||||
|
||||
exports.getBuiltins = getBuiltins;
|
||||
exports.getResolvedPath = getResolvedPath;
|
||||
exports.getTernHints = getTernHints;
|
||||
@@ -1299,4 +1396,6 @@ define(function (require, exports, module) {
|
||||
exports.requestHints = requestHints;
|
||||
exports.requestJumptoDef = requestJumptoDef;
|
||||
exports.handleProjectClose = handleProjectClose;
|
||||
exports.handleProjectOpen = handleProjectOpen;
|
||||
|
||||
});
|
||||
@@ -552,13 +552,11 @@ define(function (require, exports, module) {
|
||||
*
|
||||
* @param {Editor} editor - editor context to be initialized.
|
||||
* @param {Editor} previousEditor - the previous editor.
|
||||
* @param {boolean} primePump - true if the pump should be primed.
|
||||
*/
|
||||
function initializeSession(editor, previousEditor, primePump) {
|
||||
function initializeSession(editor, previousEditor) {
|
||||
session = new Session(editor);
|
||||
ScopeManager.handleEditorChange(session, editor.document,
|
||||
previousEditor ? previousEditor.document : null,
|
||||
primePump);
|
||||
previousEditor ? previousEditor.document : null);
|
||||
cachedHints = null;
|
||||
}
|
||||
|
||||
@@ -574,7 +572,7 @@ define(function (require, exports, module) {
|
||||
resetCachedHintContext();
|
||||
|
||||
if (editor && HintUtils.isSupportedLanguage(LanguageManager.getLanguageForPath(editor.document.file.fullPath).getId())) {
|
||||
initializeSession(editor, previousEditor, true);
|
||||
initializeSession(editor, previousEditor);
|
||||
$(editor)
|
||||
.on(HintUtils.eventName("change"), function (event, editor, changeList) {
|
||||
if (!ignoreChange) {
|
||||
@@ -680,7 +678,11 @@ define(function (require, exports, module) {
|
||||
$(ProjectManager).on("beforeProjectClose", function () {
|
||||
ScopeManager.handleProjectClose();
|
||||
});
|
||||
|
||||
|
||||
$(ProjectManager).on("projectOpen", function () {
|
||||
ScopeManager.handleProjectOpen();
|
||||
});
|
||||
|
||||
// immediately install the current editor
|
||||
installEditorListeners(EditorManager.getActiveEditor());
|
||||
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"excluded-directories" : ["/ex[\\w]*ed/"],
|
||||
"excluded-files" : ["require.js", "jquery*.js", "less*.min.js", "ember*.js", "d2?.js", "d3*"],
|
||||
"max-file-count": 100,
|
||||
"max-file-size": 524288
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
|
||||
/*global */
|
||||
|
||||
var app = app || {};
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
app.d2 = 42;
|
||||
|
||||
}());
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
|
||||
/*global */
|
||||
|
||||
var app = app || {};
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
app.d23 = 423;
|
||||
|
||||
}());
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
|
||||
/*global */
|
||||
|
||||
var app = app || {};
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
app.d3Excluded = 43;
|
||||
|
||||
}());
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
|
||||
/*global */
|
||||
|
||||
var app = app || {};
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
app.e = 5;
|
||||
|
||||
}());
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"excluded-directories" : [],
|
||||
"excluded-files" : [],
|
||||
"max-file-count": -100,
|
||||
"max-file-size": 0
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"excluded-directories" : ["excluded-dir1", "/excluded-dir2-[\\d]/"],
|
||||
"excluded-files" : ["file1?.js", "file2*.js", "file3.js", "/file4[x|y|z]?.js/"],
|
||||
"max-file-count": 512,
|
||||
"max-file-size": 100000
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
|
||||
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50, regexp: true */
|
||||
/*global define, describe, it, xit, expect, beforeEach, afterEach, waitsFor, runs, $, brackets, waitsForDone */
|
||||
|
||||
define(function (require, exports, module) {
|
||||
@@ -29,13 +29,16 @@ define(function (require, exports, module) {
|
||||
|
||||
var Commands = brackets.getModule("command/Commands"),
|
||||
CommandManager = brackets.getModule("command/CommandManager"),
|
||||
DocumentManager = brackets.getModule("document/DocumentManager"),
|
||||
Editor = brackets.getModule("editor/Editor").Editor,
|
||||
EditorManager = brackets.getModule("editor/EditorManager"),
|
||||
FileUtils = brackets.getModule("file/FileUtils"),
|
||||
DocumentManager = brackets.getModule("document/DocumentManager"),
|
||||
NativeFileSystem = brackets.getModule("file/NativeFileSystem").NativeFileSystem,
|
||||
SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"),
|
||||
UnitTestReporter = brackets.getModule("test/UnitTestReporter"),
|
||||
JSCodeHints = require("main");
|
||||
JSCodeHints = require("main"),
|
||||
Preferences = require("Preferences"),
|
||||
ScopeManager = require("ScopeManager");
|
||||
|
||||
var extensionPath = FileUtils.getNativeModuleDirectoryPath(module),
|
||||
testPath = extensionPath + "/unittest-files/basic-test-files/file1.js",
|
||||
@@ -1213,7 +1216,7 @@ define(function (require, exports, module) {
|
||||
|
||||
describe("JavaScript Code Hinting without modules", function () {
|
||||
var testPath = extensionPath + "/unittest-files/non-module-test-files/app.js";
|
||||
|
||||
ScopeManager.handleProjectOpen(extensionPath + "/unittest-files/non-module-test-files/");
|
||||
beforeEach(function () {
|
||||
setupTest(testPath, true);
|
||||
});
|
||||
@@ -1335,5 +1338,115 @@ define(function (require, exports, module) {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("JavaScript Code Hinting preference tests", function () {
|
||||
var testPath = extensionPath + "/unittest-files/preference-test-files/",
|
||||
preferences;
|
||||
|
||||
function getText(path) {
|
||||
preferences = null;
|
||||
|
||||
NativeFileSystem.resolveNativeFileSystemPath(path, function (fileEntry) {
|
||||
FileUtils.readAsText(fileEntry).done(function (text) {
|
||||
var configObj = null;
|
||||
try {
|
||||
configObj = JSON.parse(text);
|
||||
} catch (e) {
|
||||
// continue with null configObj
|
||||
console.log(e);
|
||||
}
|
||||
preferences = new Preferences(configObj);
|
||||
}).fail(function (error) {
|
||||
preferences = new Preferences();
|
||||
});
|
||||
}, function (error) {
|
||||
preferences = new Preferences();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Test preferences file with no entries. Preferences should contain
|
||||
// default values.
|
||||
it("should handle reading an empty configuration file", function () {
|
||||
getText(testPath + "defaults-test/.jscodehints");
|
||||
waitsFor(function () {
|
||||
return preferences !== null;
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
expect(preferences.getExcludedDirectories()).toBeNull();
|
||||
expect(preferences.getExcludedFiles().source).
|
||||
toBe(/^require.*\.js$|^jquery.*\.js$|^less.*\.min\.js$|^ember.*\.js$/.source);
|
||||
expect(preferences.getMaxFileCount()).toBe(100);
|
||||
expect(preferences.getMaxFileSize()).toBe(512 * 1024);
|
||||
});
|
||||
});
|
||||
|
||||
// Test preferences file with empty or out of ranges values. Preferences
|
||||
// should contain default values.
|
||||
it("should handle reading an invalid configuration file", function () {
|
||||
getText(testPath + "negative-test/.jscodehints");
|
||||
waitsFor(function () {
|
||||
return preferences !== null;
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
expect(preferences.getExcludedDirectories()).toBeNull();
|
||||
expect(preferences.getExcludedFiles().source).
|
||||
toBe(/^require.*\.js$|^jquery.*\.js$|^less.*\.min\.js$|^ember.*\.js$/.source);
|
||||
expect(preferences.getMaxFileCount()).toBe(100);
|
||||
expect(preferences.getMaxFileSize()).toBe(512 * 1024);
|
||||
});
|
||||
});
|
||||
|
||||
// Positive test. Test pattern matching.
|
||||
it("should handle a valid configuration file", function () {
|
||||
getText(testPath + "positive-test/.jscodehints");
|
||||
waitsFor(function () {
|
||||
return preferences !== null;
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
var excludedDirs = preferences.getExcludedDirectories(),
|
||||
excludesFiles = preferences.getExcludedFiles();
|
||||
|
||||
// test "excluded-dir1"
|
||||
expect(excludedDirs.test("excluded-dir1")).toBeTruthy();
|
||||
expect(excludedDirs.test("xexcluded-dir1")).toBeFalsy();
|
||||
|
||||
// test "excluded-dir2-*"
|
||||
expect(excludedDirs.test("excluded-dir2-1")).toBeTruthy();
|
||||
expect(excludedDirs.test("excluded-dir2-12")).toBeFalsy();
|
||||
expect(excludedDirs.test("excluded-dir2-z")).toBeFalsy();
|
||||
expect(excludedDirs.test("excluded-dir2-")).toBeFalsy();
|
||||
expect(excludedDirs.test("xexcluded-dir2-1")).toBeFalsy();
|
||||
|
||||
// test "file1?.js"
|
||||
expect(excludesFiles.test("file1.js")).toBeTruthy();
|
||||
expect(excludesFiles.test("file12.js")).toBeTruthy();
|
||||
expect(excludesFiles.test("file123.js")).toBeFalsy();
|
||||
|
||||
// test "file2*.js"
|
||||
expect(excludesFiles.test("file2.js")).toBeTruthy();
|
||||
expect(excludesFiles.test("file2xxx.js")).toBeTruthy();
|
||||
expect(excludesFiles.test("filexxxx.js")).toBeFalsy();
|
||||
|
||||
// test "file3.js"
|
||||
expect(excludesFiles.test("file3.js")).toBeTruthy();
|
||||
expect(excludesFiles.test("xfile3.js")).toBeFalsy();
|
||||
|
||||
// test "/file4[x|y|z]?.js/"
|
||||
expect(excludesFiles.test("file4.js")).toBeTruthy();
|
||||
expect(excludesFiles.test("file4x.js")).toBeTruthy();
|
||||
expect(excludesFiles.test("file4y.js")).toBeTruthy();
|
||||
expect(excludesFiles.test("file4z.js")).toBeTruthy();
|
||||
expect(excludesFiles.test("file4b.js")).toBeFalsy();
|
||||
expect(excludesFiles.test("file4xyz.js")).toBeFalsy();
|
||||
|
||||
expect(preferences.getMaxFileCount()).toBe(512);
|
||||
expect(preferences.getMaxFileSize()).toBe(100000);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user