@@ -227,28 +227,6 @@ define(function (require, exports, module) {
227227 _modeToLanguageMap [ mode ] = language ;
228228 }
229229
230- /**
231- * Adds a language mapping for the specified fullPath. If language is falsy (null or undefined), the mapping
232- * is removed.
233- *
234- * @param {!fullPath } fullPath absolute path of the file
235- * @param {?object } language language to associate the file with or falsy value to remove the existing mapping
236- */
237- function _setLanguageOverrideForPath ( fullPath , language ) {
238- if ( ! language ) {
239- delete _filePathToLanguageMap [ fullPath ] ;
240- } else {
241- _filePathToLanguageMap [ fullPath ] = language ;
242- }
243- }
244-
245- /**
246- * Resets all the language overrides for file paths. Used by unit tests only.
247- */
248- function _resetLanguageOverrides ( ) {
249- _filePathToLanguageMap = { } ;
250- }
251-
252230 /**
253231 * Resolves a language ID to a Language object.
254232 * File names have a higher priority than file extensions.
@@ -260,7 +238,9 @@ define(function (require, exports, module) {
260238 }
261239
262240 /**
263- * Resolves a language to a file extension
241+ * Resolves a file extension to a Language object.
242+ * *Warning:* it is almost always better to use getLanguageForPath(), since Language can depend
243+ * on file name and even full path. Use this API only if no relevant file/path exists.
264244 * @param {!string } extension Extension that language should be resolved for
265245 * @return {?Language } The language for the provided extension or null if none exists
266246 */
@@ -383,6 +363,37 @@ define(function (require, exports, module) {
383363 $ ( exports ) . triggerHandler ( "languageModified" , [ language ] ) ;
384364 }
385365
366+ /**
367+ * Adds a language mapping for the specified fullPath. If language is falsy (null or undefined), the mapping
368+ * is removed. The override is NOT persisted across Brackets sessions.
369+ *
370+ * @param {!fullPath } fullPath absolute path of the file
371+ * @param {?object } language language to associate the file with or falsy value to remove any existing override
372+ */
373+ function setLanguageOverrideForPath ( fullPath , language ) {
374+ var oldLang = getLanguageForPath ( fullPath ) ;
375+ if ( ! language ) {
376+ delete _filePathToLanguageMap [ fullPath ] ;
377+ } else {
378+ _filePathToLanguageMap [ fullPath ] = language ;
379+ }
380+ var newLang = getLanguageForPath ( fullPath ) ;
381+
382+ // Old language changed since this path is no longer mapped to it
383+ _triggerLanguageModified ( oldLang ) ;
384+ // New language changed since a path is now mapped to it that wasn't before
385+ _triggerLanguageModified ( newLang ) ;
386+ }
387+
388+ /**
389+ * Resets all the language overrides for file paths. Used by unit tests only.
390+ */
391+ function _resetPathLanguageOverrides ( ) {
392+ _filePathToLanguageMap = { } ;
393+ }
394+
395+
396+
386397
387398 /**
388399 * Model for a language.
@@ -1100,11 +1111,7 @@ define(function (require, exports, module) {
11001111 // Private for unit tests
11011112 exports . _EXTENSION_MAP_PREF = _EXTENSION_MAP_PREF ;
11021113 exports . _NAME_MAP_PREF = _NAME_MAP_PREF ;
1103- exports . _resetLanguageOverrides = _resetLanguageOverrides ;
1104- // Internal use only
1105- // _setLanguageOverrideForPath is used by Document to help LanguageManager keeping track of
1106- // in-document language overrides
1107- exports . _setLanguageOverrideForPath = _setLanguageOverrideForPath ;
1114+ exports . _resetPathLanguageOverrides = _resetPathLanguageOverrides ;
11081115
11091116 // Public methods
11101117 exports . ready = _ready ;
@@ -1113,4 +1120,5 @@ define(function (require, exports, module) {
11131120 exports . getLanguageForExtension = getLanguageForExtension ;
11141121 exports . getLanguageForPath = getLanguageForPath ;
11151122 exports . getLanguages = getLanguages ;
1123+ exports . setLanguageOverrideForPath = setLanguageOverrideForPath ;
11161124} ) ;
0 commit comments