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

Continued Language API work #2980

Merged
merged 16 commits into from
Mar 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 48 additions & 44 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ define(function (require, exports, module) {
// Load dependent modules
var Global = require("utils/Global"),
AppInit = require("utils/AppInit"),
LanguageManager = require("language/LanguageManager"),
ProjectManager = require("project/ProjectManager"),
DocumentManager = require("document/DocumentManager"),
EditorManager = require("editor/EditorManager"),
Expand Down Expand Up @@ -179,55 +180,58 @@ define(function (require, exports, module) {

$testDiv.remove();
}

// Load all extensions. This promise will complete even if one or more
// extensions fail to load.
var extensionLoaderPromise = ExtensionLoader.init(params.get("extensions"));

// Load the initial project after extensions have loaded
extensionLoaderPromise.always(function () {
// Finish UI initialization
var initialProjectPath = ProjectManager.getInitialProjectPath();
ProjectManager.openProject(initialProjectPath).always(function () {
_initTest();

// If this is the first launch, and we have an index.html file in the project folder (which should be
// the samples folder on first launch), open it automatically. (We explicitly check for the
// samples folder in case this is the first time we're launching Brackets after upgrading from
// an old version that might not have set the "afterFirstLaunch" pref.)
var prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID),
deferred = new $.Deferred();
if (!params.get("skipSampleProjectLoad") && !prefs.getValue("afterFirstLaunch")) {
prefs.setValue("afterFirstLaunch", "true");
if (ProjectManager.isWelcomeProjectPath(initialProjectPath)) {
var dirEntry = new NativeFileSystem.DirectoryEntry(initialProjectPath);

dirEntry.getFile("index.html", {}, function (fileEntry) {
var promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, { fullPath: fileEntry.fullPath });
promise.pipe(deferred.resolve, deferred.reject);
}, deferred.reject);

// Load default languages
LanguageManager.ready.always(function () {
// Load all extensions. This promise will complete even if one or more
// extensions fail to load.
var extensionLoaderPromise = ExtensionLoader.init(params.get("extensions"));

// Load the initial project after extensions have loaded
extensionLoaderPromise.always(function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course thinking about it more, I realized there's a case this doesn't fix :-P The race condition still exists for any new modes added by extensions -- we begin project loading (including opening editors) after the extension itself has loaded but potentially before its mode has... So we should probably still leave #2962 open at a lower priority to try to come up with a more robust fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about I close #2962 and file a new bug specifically for the extension use case?

// Finish UI initialization
var initialProjectPath = ProjectManager.getInitialProjectPath();
ProjectManager.openProject(initialProjectPath).always(function () {
_initTest();

// If this is the first launch, and we have an index.html file in the project folder (which should be
// the samples folder on first launch), open it automatically. (We explicitly check for the
// samples folder in case this is the first time we're launching Brackets after upgrading from
// an old version that might not have set the "afterFirstLaunch" pref.)
var prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID),
deferred = new $.Deferred();
if (!params.get("skipSampleProjectLoad") && !prefs.getValue("afterFirstLaunch")) {
prefs.setValue("afterFirstLaunch", "true");
if (ProjectManager.isWelcomeProjectPath(initialProjectPath)) {
var dirEntry = new NativeFileSystem.DirectoryEntry(initialProjectPath);

dirEntry.getFile("index.html", {}, function (fileEntry) {
var promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, { fullPath: fileEntry.fullPath });
promise.pipe(deferred.resolve, deferred.reject);
}, deferred.reject);
} else {
deferred.resolve();
}
} else {
deferred.resolve();
}
} else {
deferred.resolve();
}

deferred.always(function () {
// Signal that Brackets is loaded
AppInit._dispatchReady(AppInit.APP_READY);

PerfUtils.addMeasurement("Application Startup");
});

// See if any startup files were passed to the application
if (brackets.app.getPendingFilesToOpen) {
brackets.app.getPendingFilesToOpen(function (err, files) {
files.forEach(function (filename) {
CommandManager.execute(Commands.FILE_OPEN, { fullPath: filename });
});
deferred.always(function () {
// Signal that Brackets is loaded
AppInit._dispatchReady(AppInit.APP_READY);

PerfUtils.addMeasurement("Application Startup");
});
}

// See if any startup files were passed to the application
if (brackets.app.getPendingFilesToOpen) {
brackets.app.getPendingFilesToOpen(function (err, files) {
files.forEach(function (filename) {
CommandManager.execute(Commands.FILE_OPEN, { fullPath: filename });
});
});
}
});
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ define(function (require, exports, module) {
// We'd like undefined/null/"" to mean plain text mode. CodeMirror defaults to plaintext for any
// unrecognized mode, but it complains on the console in that fallback case: so, convert
// here so we're always explicit, avoiding console noise.
return this.document.getLanguage().mode || "text/plain";
return this.document.getLanguage().getMode() || "text/plain";
};


Expand Down Expand Up @@ -1208,7 +1208,7 @@ define(function (require, exports, module) {
*
* @return {?(Object|string)} Name of syntax-highlighting mode, or object containing a "name" property
* naming the mode along with configuration options required by the mode.
* See {@link Languages#getLanguageForFileExtension()} and {@link Language#mode}.
* See {@link LanguageManager#getLanguageForFileExtension()} and {@link Language#getMode()}.
*/
Editor.prototype.getModeForSelection = function () {
// Check for mixed mode info
Expand Down Expand Up @@ -1241,7 +1241,7 @@ define(function (require, exports, module) {
/**
* Gets the syntax-highlighting mode for the document.
*
* @return {Object|String} Object or Name of syntax-highlighting mode; see {@link Languages#getLanguageForFileExtension()} and {@link Language#mode}.
* @return {Object|String} Object or Name of syntax-highlighting mode; see {@link LanguageManager#getLanguageForFileExtension()} and {@link Language#getMode()}.
*/
Editor.prototype.getModeForDocument = function () {
return this._codeMirror.getOption("mode");
Expand Down
13 changes: 7 additions & 6 deletions src/editor/EditorCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,9 @@ define(function (require, exports, module) {

var language = editor.getLanguageForSelection();

if (language.blockComment) {
blockCommentPrefixSuffix(editor, language.blockComment.prefix, language.blockComment.suffix, language.lineComment ? language.lineComment.prefix : null);
if (language.hasBlockCommentSyntax()) {
// getLineCommentPrefix returns null if no line comment syntax is defined
blockCommentPrefixSuffix(editor, language.getBlockCommentPrefix(), language.getBlockCommentSuffix(), language.getLineCommentPrefix());
}
}

Expand All @@ -485,10 +486,10 @@ define(function (require, exports, module) {

var language = editor.getLanguageForSelection();

if (language.lineComment) {
lineCommentPrefix(editor, language.lineComment.prefix);
} else if (language.blockComment) {
lineCommentPrefixSuffix(editor, language.blockComment.prefix, language.blockComment.suffix);
if (language.hasLineCommentSyntax()) {
lineCommentPrefix(editor, language.getLineCommentPrefix());
} else if (language.hasBlockCommentSyntax()) {
lineCommentPrefixSuffix(editor, language.getBlockCommentPrefix(), language.getBlockCommentSuffix());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/extensions/default/JavaScriptCodeHints/ScopeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ define(function (require, exports, module) {
file = split.file;

if (file.indexOf(".") > 1) { // ignore /.dotfiles
var mode = LanguageManager.getLanguageForFileExtension(entry.fullPath).mode;
var mode = LanguageManager.getLanguageForFileExtension(entry.fullPath).getMode();
if (mode === HintUtils.MODE_NAME) {
DocumentManager.getDocumentForPath(path).done(function (document) {
refreshOuterScope(dir, file, document.getText());
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/default/LESSSupport/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ define(function (require, exports, module) {

var LanguageManager = brackets.getModule("language/LanguageManager");

var language = LanguageManager.defineLanguage("less", {
LanguageManager.defineLanguage("less", {
name: "LESS",
mode: "less",
fileExtensions: ["less"],
Expand Down
Loading