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

Commit

Permalink
Merge pull request #2980 from adobe/jasonsanjose-dk/language-api
Browse files Browse the repository at this point in the history
Continued Language API work
  • Loading branch information
peterflynn committed Mar 1, 2013
2 parents d4d81e3 + 6fce307 commit 4e44a07
Show file tree
Hide file tree
Showing 10 changed files with 427 additions and 264 deletions.
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 @@ -181,55 +182,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 () {
// 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

0 comments on commit 4e44a07

Please sign in to comment.