monaco.contribution.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 { languages, Emitter } from './fillers/monaco-editor-core.js';
  7. // --- CSS configuration and defaults ---------
  8. var LanguageServiceDefaultsImpl = /** @class */ (function () {
  9. function LanguageServiceDefaultsImpl(languageId, options, modeConfiguration) {
  10. this._onDidChange = new Emitter();
  11. this._languageId = languageId;
  12. this.setOptions(options);
  13. this.setModeConfiguration(modeConfiguration);
  14. }
  15. Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "onDidChange", {
  16. get: function () {
  17. return this._onDidChange.event;
  18. },
  19. enumerable: false,
  20. configurable: true
  21. });
  22. Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "languageId", {
  23. get: function () {
  24. return this._languageId;
  25. },
  26. enumerable: false,
  27. configurable: true
  28. });
  29. Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "modeConfiguration", {
  30. get: function () {
  31. return this._modeConfiguration;
  32. },
  33. enumerable: false,
  34. configurable: true
  35. });
  36. Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "diagnosticsOptions", {
  37. get: function () {
  38. return this.options;
  39. },
  40. enumerable: false,
  41. configurable: true
  42. });
  43. Object.defineProperty(LanguageServiceDefaultsImpl.prototype, "options", {
  44. get: function () {
  45. return this._options;
  46. },
  47. enumerable: false,
  48. configurable: true
  49. });
  50. LanguageServiceDefaultsImpl.prototype.setOptions = function (options) {
  51. this._options = options || Object.create(null);
  52. this._onDidChange.fire(this);
  53. };
  54. LanguageServiceDefaultsImpl.prototype.setDiagnosticsOptions = function (options) {
  55. this.setOptions(options);
  56. };
  57. LanguageServiceDefaultsImpl.prototype.setModeConfiguration = function (modeConfiguration) {
  58. this._modeConfiguration = modeConfiguration || Object.create(null);
  59. this._onDidChange.fire(this);
  60. };
  61. return LanguageServiceDefaultsImpl;
  62. }());
  63. var optionsDefault = {
  64. validate: true,
  65. lint: {
  66. compatibleVendorPrefixes: 'ignore',
  67. vendorPrefix: 'warning',
  68. duplicateProperties: 'warning',
  69. emptyRules: 'warning',
  70. importStatement: 'ignore',
  71. boxModel: 'ignore',
  72. universalSelector: 'ignore',
  73. zeroUnits: 'ignore',
  74. fontFaceProperties: 'warning',
  75. hexColorLength: 'error',
  76. argumentsInColorFunction: 'error',
  77. unknownProperties: 'warning',
  78. ieHack: 'ignore',
  79. unknownVendorSpecificProperties: 'ignore',
  80. propertyIgnoredDueToDisplay: 'warning',
  81. important: 'ignore',
  82. float: 'ignore',
  83. idSelector: 'ignore'
  84. },
  85. data: { useDefaultDataProvider: true }
  86. };
  87. var modeConfigurationDefault = {
  88. completionItems: true,
  89. hovers: true,
  90. documentSymbols: true,
  91. definitions: true,
  92. references: true,
  93. documentHighlights: true,
  94. rename: true,
  95. colors: true,
  96. foldingRanges: true,
  97. diagnostics: true,
  98. selectionRanges: true
  99. };
  100. export var cssDefaults = new LanguageServiceDefaultsImpl('css', optionsDefault, modeConfigurationDefault);
  101. export var scssDefaults = new LanguageServiceDefaultsImpl('scss', optionsDefault, modeConfigurationDefault);
  102. export var lessDefaults = new LanguageServiceDefaultsImpl('less', optionsDefault, modeConfigurationDefault);
  103. // export to the global based API
  104. languages.css = { cssDefaults: cssDefaults, lessDefaults: lessDefaults, scssDefaults: scssDefaults };
  105. // --- Registration to monaco editor ---
  106. function getMode() {
  107. return import('./cssMode.js');
  108. }
  109. languages.onLanguage('less', function () {
  110. getMode().then(function (mode) { return mode.setupMode(lessDefaults); });
  111. });
  112. languages.onLanguage('scss', function () {
  113. getMode().then(function (mode) { return mode.setupMode(scssDefaults); });
  114. });
  115. languages.onLanguage('css', function () {
  116. getMode().then(function (mode) { return mode.setupMode(cssDefaults); });
  117. });