modesRegistry.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import * as nls from '../../../nls.js';
  6. import { Emitter } from '../../../base/common/event.js';
  7. import { LanguageConfigurationRegistry } from './languageConfigurationRegistry.js';
  8. import { Registry } from '../../../platform/registry/common/platform.js';
  9. import { Mimes } from '../../../base/common/mime.js';
  10. import { Extensions as ConfigurationExtensions } from '../../../platform/configuration/common/configurationRegistry.js';
  11. // Define extension point ids
  12. export const Extensions = {
  13. ModesRegistry: 'editor.modesRegistry'
  14. };
  15. export class EditorModesRegistry {
  16. constructor() {
  17. this._onDidChangeLanguages = new Emitter();
  18. this.onDidChangeLanguages = this._onDidChangeLanguages.event;
  19. this._languages = [];
  20. this._dynamicLanguages = [];
  21. }
  22. // --- languages
  23. registerLanguage(def) {
  24. this._languages.push(def);
  25. this._onDidChangeLanguages.fire(undefined);
  26. return {
  27. dispose: () => {
  28. for (let i = 0, len = this._languages.length; i < len; i++) {
  29. if (this._languages[i] === def) {
  30. this._languages.splice(i, 1);
  31. return;
  32. }
  33. }
  34. }
  35. };
  36. }
  37. getLanguages() {
  38. return [].concat(this._languages).concat(this._dynamicLanguages);
  39. }
  40. }
  41. export const ModesRegistry = new EditorModesRegistry();
  42. Registry.add(Extensions.ModesRegistry, ModesRegistry);
  43. export const PLAINTEXT_MODE_ID = 'plaintext';
  44. export const PLAINTEXT_EXTENSION = '.txt';
  45. ModesRegistry.registerLanguage({
  46. id: PLAINTEXT_MODE_ID,
  47. extensions: [PLAINTEXT_EXTENSION],
  48. aliases: [nls.localize('plainText.alias', "Plain Text"), 'text'],
  49. mimetypes: [Mimes.text]
  50. });
  51. LanguageConfigurationRegistry.register(PLAINTEXT_MODE_ID, {
  52. brackets: [
  53. ['(', ')'],
  54. ['[', ']'],
  55. ['{', '}'],
  56. ],
  57. surroundingPairs: [
  58. { open: '{', close: '}' },
  59. { open: '[', close: ']' },
  60. { open: '(', close: ')' },
  61. { open: '<', close: '>' },
  62. { open: '\"', close: '\"' },
  63. { open: '\'', close: '\'' },
  64. { open: '`', close: '`' },
  65. ],
  66. colorizedBracketPairs: [],
  67. folding: {
  68. offSide: true
  69. }
  70. }, 0);
  71. Registry.as(ConfigurationExtensions.Configuration)
  72. .registerDefaultConfigurations([{
  73. overrides: {
  74. '[plaintext]': {
  75. 'editor.unicodeHighlight.ambiguousCharacters': false
  76. }
  77. }
  78. }]);