Skip to main content

LanguageManager

Import :​

const LanguageManager = brackets.getModule("language/LanguageManager")

Language​

Kind: global class

new Language()​

Model for a language.

language.getId() ⇒ string​

Returns the identifier for this language.

Kind: instance method of Language
Returns: string - The identifier

language.getName() ⇒ string​

Returns the human-readable name of this language.

Kind: instance method of Language
Returns: string - The name

language.getMode() ⇒ string​

Returns the CodeMirror mode for this language.

Kind: instance method of Language
Returns: string - The mode

language.getFileExtensions() ⇒ Array.<string>​

Returns an array of file extensions for this language.

Kind: instance method of Language
Returns: Array.<string> - File extensions used by this language

language.getFileNames() ⇒ Array.<string>​

Returns an array of file names for extensionless files that use this language.

Kind: instance method of Language
Returns: Array.<string> - Extensionless file names used by this language

language.addFileExtension(extension)​

Adds one or more file extensions to this language.

Kind: instance method of Language

ParamTypeDescription
extensionstring | Array.<string>A file extension (or array thereof) used by this language

language.removeFileExtension(extension)​

Unregisters one or more file extensions from this language.

Kind: instance method of Language

ParamTypeDescription
extensionstring | Array.<string>File extension (or array thereof) to stop using for this language

language.addFileName(extension)​

Adds one or more file names to the language which is used to match files that don't have extensions like "Makefile" for example.

Kind: instance method of Language

ParamTypeDescription
extensionstring | Array.<string>An extensionless file name (or array thereof) used by this language

language.removeFileName(extension)​

Unregisters one or more file names from this language.

Kind: instance method of Language

ParamTypeDescription
extensionstring | Array.<string>An extensionless file name (or array thereof) used by this language

language.hasLineCommentSyntax() ⇒ boolean​

Returns whether the line comment syntax is defined for this language.

Kind: instance method of Language
Returns: boolean - Whether line comments are supported

language.getLineCommentPrefixes() ⇒ Array.<string>​

Returns an array of prefixes to use for line comments.

Kind: instance method of Language
Returns: Array.<string> - The prefixes

language.setLineCommentSyntax(prefix) ⇒ boolean​

Sets the prefixes to use for line comments in this language or prints an error to the console.

Kind: instance method of Language
Returns: boolean - Whether the syntax was valid and set or not

ParamTypeDescription
prefixstring | Array.<string>Prefix string or an array of prefix strings to use for line comments (e.g. "//" or ["//", "#"])

language.hasBlockCommentSyntax() ⇒ boolean​

Returns whether the block comment syntax is defined for this language.

Kind: instance method of Language
Returns: boolean - Whether block comments are supported

language.getBlockCommentPrefix() ⇒ string​

Returns the prefix to use for block comments.

Kind: instance method of Language
Returns: string - The prefix

language.getBlockCommentSuffix() ⇒ string​

Returns the suffix to use for block comments.

Kind: instance method of Language
Returns: string - The suffix

language.setBlockCommentSyntax(prefix, suffix) ⇒ boolean​

Sets the prefix and suffix to use for blocks comments in this language or prints an error to the console.

Kind: instance method of Language
Returns: boolean - Whether the syntax was valid and set or not

ParamTypeDescription
prefixstringPrefix string to use for block comments (e.g. "< !--")
suffixstringSuffix string to use for block comments (e.g. "-->")

language.getLanguageForMode(mode) ⇒ Language​

Returns either a language associated with the mode or the fallback language. Used to disambiguate modes used by multiple languages.

Kind: instance method of Language
Returns: Language - This language if it uses the mode, or whatever #_getLanguageForMode returns

ParamTypeDescription
modestringThe mode to associate the language with

language.isFallbackLanguage() ⇒ boolean​

Determines whether this is the fallback language or not

Kind: instance method of Language
Returns: boolean - True if this is the fallback language, false otherwise

language.isBinary() ⇒ boolean​

Indicates whether or not the language is binary (e.g., image or audio).

Kind: instance method of Language

getLanguage(id) ⇒ Language​

Resolves a language ID to a Language object. File names have a higher priority than file extensions.

Kind: global function
Returns: Language - The language with the provided identifier or undefined

ParamTypeDescription
idstringIdentifier for this language: lowercase letters, digits, and _ separators (e.g. "cpp", "foo_bar", "c99")

getLanguageForExtension(extension) ⇒ Language​

Resolves a file extension to a Language object. Warning: it is almost always better to use getLanguageForPath(), since Language can depend on file name and even full path. Use this API only if no relevant file/path exists.

Kind: global function
Returns: Language - The language for the provided extension or null if none exists

ParamTypeDescription
extensionstringExtension that language should be resolved for

getLanguageForPath(path, [ignoreOverride]) ⇒ Language​

Resolves a file path to a Language object.

Kind: global function
Returns: Language - The language for the provided file type or the fallback language

ParamTypeDescription
pathstringPath to the file to find a language for
[ignoreOverride]booleanIf set to true will cause the lookup to ignore any overrides and return default binding. By default override is not ignored.

getLanguages() ⇒ Object.<string, Language>​

Returns a map of all the languages currently defined in the LanguageManager. The key to the map is the language id and the value is the language object.

Kind: global function
Returns: Object.<string, Language> - A map containing all of the languages currently defined.

setLanguageOverrideForPath(fullPath, language)​

Adds a language mapping for the specified fullPath. If language is falsy (null or undefined), the mapping is removed. The override is NOT persisted across Brackets sessions.

Kind: global function

ParamTypeDescription
fullPathfullPathabsolute path of the file
languageobjectlanguage to associate the file with or falsy value to remove any existing override

getCompoundFileExtension(fullPath) ⇒ string​

Get the file extension (excluding ".") given a path OR a bare filename. Returns "" for names with no extension. If the only . in the file is the first character, returns "" as this is not considered an extension. This method considers known extensions which include . in them.

Kind: global function
Returns: string - Returns the extension of a filename or empty string if the argument is a directory or a filename with no extension

ParamTypeDescription
fullPathstringfull path to a file or directory

defineLanguage(id, definition) ⇒ $.Promise​

Defines a language.

Kind: global function
Returns: $.Promise - A promise object that will be resolved with a Language object

ParamTypeDescription
idstringUnique identifier for this language: lowercase letters, digits, and _ separators (e.g. "cpp", "foo_bar", "c99")
definitionObjectAn object describing the language
definition.namestringHuman-readable name of the language, as it's commonly referred to (e.g. "C++")
definition.fileExtensionsArray.<string>List of file extensions used by this language (e.g. ["php", "php3"] or ["coffee.md"] - may contain dots)
definition.fileNamesArray.<string>List of exact file names (e.g. ["Makefile"] or ["package.json]). Higher precedence than file extension.
definition.blockCommentArray.<string>Array with two entries defining the block comment prefix and suffix (e.g. ["< !--", "-->"])
definition.lineCommentstring | Array.<string>Line comment prefixes (e.g. "//" or ["//", "#"])
definition.modestring | Array.<string>CodeMirror mode (e.g. "htmlmixed"), optionally with a MIME mode defined by that mode ["clike", "text/x-c++src"] Unless the mode is located in thirdparty/CodeMirror/mode/"name"/"name".js, you need to first load it yourself.