GitHub PullRequestReviewCommentEvent at 2014-04-29 21:41:04
Repository: brackets
Actor: peterflynn
Payload: {"comment":{"url":"https://api.github.com/repos/adobe/brackets/pulls/comments/12118467","id":12118467,"diff_hunk":"@@ -655,14 +662,39 @@ define(function (require, exports, module) {\n     Document.prototype.getLanguage = function () {\n         return this.language;\n     };\n+    \n+    /**\n+     * Overrides the default language of this document and sets it to the given\n+     * language. This change is not persisted if the document is closed.\n+     * @param {?Language} language The language to be set for this document; if\n+     * null, the language will be set back to the default.\n+     */\n+    Document.prototype.setLanguageOverride = function (language) {\n+        if (language) {\n+            var oldLanguage = this.language;\n+            this._languageWasForced = true;\n+            if (oldLanguage !== language) {\n+                this.language = language;\n+                LanguageManager.setLanguageOverrideForPath(this.file.fullPath, this.language);\n+                $(this).triggerHandler(\"languageChanged\", [oldLanguage, this.language]);\n+            }\n+        } else { // if language was null, reset to default language\n+            this._languageWasForced = false;\n+            LanguageManager.setLanguageOverrideForPath(this.file.fullPath, null);\n+            this._updateLanguage();","path":"src/document/Document.js","position":37,"original_position":37,"commit_id":"8ebe1c2a1972e0dd7a193fcf90aa846dbec27aca","original_commit_id":"8ebe1c2a1972e0dd7a193fcf90aa846dbec27aca","user":{"login":"peterflynn","id":1197510,"avatar_url":"https://avatars.githubusercontent.com/u/1197510?","gravatar_id":"f8b97ac818aaa02413fe4f96325acdfd","url":"https://api.github.com/users/peterflynn","html_url":"https://github.com/peterflynn","followers_url":"https://api.github.com/users/peterflynn/followers","following_url":"https://api.github.com/users/peterflynn/following{/other_user}","gists_url":"https://api.github.com/users/peterflynn/gists{/gist_id}","starred_url":"https://api.github.com/users/peterflynn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterflynn/subscriptions","organizations_url":"https://api.github.com/users/peterflynn/orgs","repos_url":"https://api.github.com/users/peterflynn/repos","events_url":"https://api.github.com/users/peterflynn/events{/privacy}","received_events_url":"https://api.github.com/users/peterflynn/received_events","type":"User","site_admin":false},"body":"It seems like `setLanguageOverrideForPath()` should trigger some sort of event that we listen to in order to call `_updateLanguage()` -- otherwise, anyone else who calls that API is going to get broken behavior (Documents won't actually update to reflect it).  It seems like we'd want to add a new event, something like `\"languageMappingChanged\"`, that triggers all docs to recheck their language.  It actually seems like a bug in PR #7588 that we don't already have such an event -- it seems like editing the prefs to update the file extension -> language mapping doesn't send any sort of event that would update already-open files.  (@dangoor, is that true or did I miss something?)\r\n\r\nOTOH that's a bunch of extra work to bite off here.  A simpler alternative would be to leave this as-is and make `setLanguageOverrideForPath()` \"semi-private\" with an underscore prefix.  (And then spin off a bug for later if the PR #7588 problem is really true).","created_at":"2014-04-29T21:41:04Z","updated_at":"2014-04-29T21:41:04Z","html_url":"https://github.com/adobe/brackets/pull/6409#discussion_r12118467","pull_request_url":"https://api.github.com/repos/adobe/brackets/pulls/6409","_links":{"self":{"href":"https://api.github.com/repos/adobe/brackets/pulls/comments/12118467"},"html":{"href":"https://github.com/adobe/brackets/pull/6409#discussion_r12118467"},"pull_request":{"href":"https://api.github.com/repos/adobe/brackets/pulls/6409"}}}}