monaco.contribution.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import '../../editor/editor.api.js';
  2. /*---------------------------------------------------------------------------------------------
  3. * Copyright (c) Microsoft Corporation. All rights reserved.
  4. * Licensed under the MIT License. See License.txt in the project root for license information.
  5. *--------------------------------------------------------------------------------------------*/
  6. import { Emitter, languages } from './fillers/monaco-editor-core.js';
  7. var LanguageServiceDefaultsImpl = /** @class */ (function () {
  8. function LanguageServiceDefaultsImpl(languageId, diagnosticsOptions, modeConfiguration) {
  9. this._onDidChange = new Emitter();
  10. this._languageId = languageId;
  11. this.setDiagnosticsOptions(diagnosticsOptions);
  12. this.setModeConfiguration(modeConfiguration);
  13. }
  14. Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "onDidChange", {
  15. get: function () {
  16. return this._onDidChange.event;
  17. },
  18. enumerable: false,
  19. configurable: true
  20. });
  21. Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "languageId", {
  22. get: function () {
  23. return this._languageId;
  24. },
  25. enumerable: false,
  26. configurable: true
  27. });
  28. Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "modeConfiguration", {
  29. get: function () {
  30. return this._modeConfiguration;
  31. },
  32. enumerable: false,
  33. configurable: true
  34. });
  35. Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "diagnosticsOptions", {
  36. get: function () {
  37. return this._diagnosticsOptions;
  38. },
  39. enumerable: false,
  40. configurable: true
  41. });
  42. LanguageServiceDefaultsImpl.prototype.setDiagnosticsOptions = function (options) {
  43. this._diagnosticsOptions = options || Object.create(null);
  44. this._onDidChange.fire(this);
  45. };
  46. LanguageServiceDefaultsImpl.prototype.setModeConfiguration = function (modeConfiguration) {
  47. this._modeConfiguration = modeConfiguration || Object.create(null);
  48. this._onDidChange.fire(this);
  49. };
  50. return LanguageServiceDefaultsImpl;
  51. }());
  52. var diagnosticDefault = {
  53. validate: true,
  54. allowComments: true,
  55. schemas: [],
  56. enableSchemaRequest: false,
  57. schemaRequest: 'warning',
  58. schemaValidation: 'warning',
  59. comments: 'error',
  60. trailingCommas: 'error'
  61. };
  62. var modeConfigurationDefault = {
  63. documentFormattingEdits: true,
  64. documentRangeFormattingEdits: true,
  65. completionItems: true,
  66. hovers: true,
  67. documentSymbols: true,
  68. tokens: true,
  69. colors: true,
  70. foldingRanges: true,
  71. diagnostics: true,
  72. selectionRanges: true
  73. };
  74. export var jsonDefaults = new LanguageServiceDefaultsImpl('json', diagnosticDefault, modeConfigurationDefault);
  75. // export to the global based API
  76. languages.json = { jsonDefaults: jsonDefaults };
  77. // --- Registration to monaco editor ---
  78. function getMode() {
  79. return import('./jsonMode.js');
  80. }
  81. languages.register({
  82. id: 'json',
  83. extensions: ['.json', '.bowerrc', '.jshintrc', '.jscsrc', '.eslintrc', '.babelrc', '.har'],
  84. aliases: ['JSON', 'json'],
  85. mimetypes: ['application/json']
  86. });
  87. languages.onLanguage('json', function () {
  88. getMode().then(function (mode) { return mode.setupMode(jsonDefaults); });
  89. });