htmlMode.js 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085
  1. "use strict";
  2. /*!-----------------------------------------------------------------------------
  3. * Copyright (c) Microsoft Corporation. All rights reserved.
  4. * Version: 0.38.0(0e330ae453813de4e6cf272460fb79c7117073d0)
  5. * Released under the MIT license
  6. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  7. *-----------------------------------------------------------------------------*/
  8. define("vs/language/html/htmlMode", ["require"],(require)=>{
  9. var moduleExports = (() => {
  10. var __create = Object.create;
  11. var __defProp = Object.defineProperty;
  12. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  13. var __getOwnPropNames = Object.getOwnPropertyNames;
  14. var __getProtoOf = Object.getPrototypeOf;
  15. var __hasOwnProp = Object.prototype.hasOwnProperty;
  16. var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
  17. get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
  18. }) : x)(function(x) {
  19. if (typeof require !== "undefined")
  20. return require.apply(this, arguments);
  21. throw new Error('Dynamic require of "' + x + '" is not supported');
  22. });
  23. var __commonJS = (cb, mod) => function __require2() {
  24. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  25. };
  26. var __export = (target, all) => {
  27. for (var name in all)
  28. __defProp(target, name, { get: all[name], enumerable: true });
  29. };
  30. var __copyProps = (to, from, except, desc) => {
  31. if (from && typeof from === "object" || typeof from === "function") {
  32. for (let key of __getOwnPropNames(from))
  33. if (!__hasOwnProp.call(to, key) && key !== except)
  34. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  35. }
  36. return to;
  37. };
  38. var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
  39. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
  40. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  41. // src/fillers/monaco-editor-core-amd.ts
  42. var require_monaco_editor_core_amd = __commonJS({
  43. "src/fillers/monaco-editor-core-amd.ts"(exports, module) {
  44. var api = __toESM(__require("vs/editor/editor.api"));
  45. module.exports = api;
  46. }
  47. });
  48. // src/language/html/htmlMode.ts
  49. var htmlMode_exports = {};
  50. __export(htmlMode_exports, {
  51. CompletionAdapter: () => CompletionAdapter,
  52. DefinitionAdapter: () => DefinitionAdapter,
  53. DiagnosticsAdapter: () => DiagnosticsAdapter,
  54. DocumentColorAdapter: () => DocumentColorAdapter,
  55. DocumentFormattingEditProvider: () => DocumentFormattingEditProvider,
  56. DocumentHighlightAdapter: () => DocumentHighlightAdapter,
  57. DocumentLinkAdapter: () => DocumentLinkAdapter,
  58. DocumentRangeFormattingEditProvider: () => DocumentRangeFormattingEditProvider,
  59. DocumentSymbolAdapter: () => DocumentSymbolAdapter,
  60. FoldingRangeAdapter: () => FoldingRangeAdapter,
  61. HoverAdapter: () => HoverAdapter,
  62. ReferenceAdapter: () => ReferenceAdapter,
  63. RenameAdapter: () => RenameAdapter,
  64. SelectionRangeAdapter: () => SelectionRangeAdapter,
  65. WorkerManager: () => WorkerManager,
  66. fromPosition: () => fromPosition,
  67. fromRange: () => fromRange,
  68. setupMode: () => setupMode,
  69. setupMode1: () => setupMode1,
  70. toRange: () => toRange,
  71. toTextEdit: () => toTextEdit
  72. });
  73. // src/fillers/monaco-editor-core.ts
  74. var monaco_editor_core_exports = {};
  75. __reExport(monaco_editor_core_exports, __toESM(require_monaco_editor_core_amd()));
  76. // src/language/html/workerManager.ts
  77. var STOP_WHEN_IDLE_FOR = 2 * 60 * 1e3;
  78. var WorkerManager = class {
  79. _defaults;
  80. _idleCheckInterval;
  81. _lastUsedTime;
  82. _configChangeListener;
  83. _worker;
  84. _client;
  85. constructor(defaults) {
  86. this._defaults = defaults;
  87. this._worker = null;
  88. this._client = null;
  89. this._idleCheckInterval = window.setInterval(() => this._checkIfIdle(), 30 * 1e3);
  90. this._lastUsedTime = 0;
  91. this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());
  92. }
  93. _stopWorker() {
  94. if (this._worker) {
  95. this._worker.dispose();
  96. this._worker = null;
  97. }
  98. this._client = null;
  99. }
  100. dispose() {
  101. clearInterval(this._idleCheckInterval);
  102. this._configChangeListener.dispose();
  103. this._stopWorker();
  104. }
  105. _checkIfIdle() {
  106. if (!this._worker) {
  107. return;
  108. }
  109. let timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
  110. if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
  111. this._stopWorker();
  112. }
  113. }
  114. _getClient() {
  115. this._lastUsedTime = Date.now();
  116. if (!this._client) {
  117. this._worker = monaco_editor_core_exports.editor.createWebWorker({
  118. moduleId: "vs/language/html/htmlWorker",
  119. createData: {
  120. languageSettings: this._defaults.options,
  121. languageId: this._defaults.languageId
  122. },
  123. label: this._defaults.languageId
  124. });
  125. this._client = this._worker.getProxy();
  126. }
  127. return this._client;
  128. }
  129. getLanguageServiceWorker(...resources) {
  130. let _client;
  131. return this._getClient().then((client) => {
  132. _client = client;
  133. }).then((_) => {
  134. if (this._worker) {
  135. return this._worker.withSyncedResources(resources);
  136. }
  137. }).then((_) => _client);
  138. }
  139. };
  140. // node_modules/vscode-languageserver-types/lib/esm/main.js
  141. var integer;
  142. (function(integer2) {
  143. integer2.MIN_VALUE = -2147483648;
  144. integer2.MAX_VALUE = 2147483647;
  145. })(integer || (integer = {}));
  146. var uinteger;
  147. (function(uinteger2) {
  148. uinteger2.MIN_VALUE = 0;
  149. uinteger2.MAX_VALUE = 2147483647;
  150. })(uinteger || (uinteger = {}));
  151. var Position;
  152. (function(Position3) {
  153. function create(line, character) {
  154. if (line === Number.MAX_VALUE) {
  155. line = uinteger.MAX_VALUE;
  156. }
  157. if (character === Number.MAX_VALUE) {
  158. character = uinteger.MAX_VALUE;
  159. }
  160. return { line, character };
  161. }
  162. Position3.create = create;
  163. function is(value) {
  164. var candidate = value;
  165. return Is.objectLiteral(candidate) && Is.uinteger(candidate.line) && Is.uinteger(candidate.character);
  166. }
  167. Position3.is = is;
  168. })(Position || (Position = {}));
  169. var Range;
  170. (function(Range3) {
  171. function create(one, two, three, four) {
  172. if (Is.uinteger(one) && Is.uinteger(two) && Is.uinteger(three) && Is.uinteger(four)) {
  173. return { start: Position.create(one, two), end: Position.create(three, four) };
  174. } else if (Position.is(one) && Position.is(two)) {
  175. return { start: one, end: two };
  176. } else {
  177. throw new Error("Range#create called with invalid arguments[" + one + ", " + two + ", " + three + ", " + four + "]");
  178. }
  179. }
  180. Range3.create = create;
  181. function is(value) {
  182. var candidate = value;
  183. return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
  184. }
  185. Range3.is = is;
  186. })(Range || (Range = {}));
  187. var Location;
  188. (function(Location2) {
  189. function create(uri, range) {
  190. return { uri, range };
  191. }
  192. Location2.create = create;
  193. function is(value) {
  194. var candidate = value;
  195. return Is.defined(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
  196. }
  197. Location2.is = is;
  198. })(Location || (Location = {}));
  199. var LocationLink;
  200. (function(LocationLink2) {
  201. function create(targetUri, targetRange, targetSelectionRange, originSelectionRange) {
  202. return { targetUri, targetRange, targetSelectionRange, originSelectionRange };
  203. }
  204. LocationLink2.create = create;
  205. function is(value) {
  206. var candidate = value;
  207. return Is.defined(candidate) && Range.is(candidate.targetRange) && Is.string(candidate.targetUri) && (Range.is(candidate.targetSelectionRange) || Is.undefined(candidate.targetSelectionRange)) && (Range.is(candidate.originSelectionRange) || Is.undefined(candidate.originSelectionRange));
  208. }
  209. LocationLink2.is = is;
  210. })(LocationLink || (LocationLink = {}));
  211. var Color;
  212. (function(Color2) {
  213. function create(red, green, blue, alpha) {
  214. return {
  215. red,
  216. green,
  217. blue,
  218. alpha
  219. };
  220. }
  221. Color2.create = create;
  222. function is(value) {
  223. var candidate = value;
  224. return Is.numberRange(candidate.red, 0, 1) && Is.numberRange(candidate.green, 0, 1) && Is.numberRange(candidate.blue, 0, 1) && Is.numberRange(candidate.alpha, 0, 1);
  225. }
  226. Color2.is = is;
  227. })(Color || (Color = {}));
  228. var ColorInformation;
  229. (function(ColorInformation2) {
  230. function create(range, color) {
  231. return {
  232. range,
  233. color
  234. };
  235. }
  236. ColorInformation2.create = create;
  237. function is(value) {
  238. var candidate = value;
  239. return Range.is(candidate.range) && Color.is(candidate.color);
  240. }
  241. ColorInformation2.is = is;
  242. })(ColorInformation || (ColorInformation = {}));
  243. var ColorPresentation;
  244. (function(ColorPresentation2) {
  245. function create(label, textEdit, additionalTextEdits) {
  246. return {
  247. label,
  248. textEdit,
  249. additionalTextEdits
  250. };
  251. }
  252. ColorPresentation2.create = create;
  253. function is(value) {
  254. var candidate = value;
  255. return Is.string(candidate.label) && (Is.undefined(candidate.textEdit) || TextEdit.is(candidate)) && (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is));
  256. }
  257. ColorPresentation2.is = is;
  258. })(ColorPresentation || (ColorPresentation = {}));
  259. var FoldingRangeKind;
  260. (function(FoldingRangeKind2) {
  261. FoldingRangeKind2["Comment"] = "comment";
  262. FoldingRangeKind2["Imports"] = "imports";
  263. FoldingRangeKind2["Region"] = "region";
  264. })(FoldingRangeKind || (FoldingRangeKind = {}));
  265. var FoldingRange;
  266. (function(FoldingRange2) {
  267. function create(startLine, endLine, startCharacter, endCharacter, kind) {
  268. var result = {
  269. startLine,
  270. endLine
  271. };
  272. if (Is.defined(startCharacter)) {
  273. result.startCharacter = startCharacter;
  274. }
  275. if (Is.defined(endCharacter)) {
  276. result.endCharacter = endCharacter;
  277. }
  278. if (Is.defined(kind)) {
  279. result.kind = kind;
  280. }
  281. return result;
  282. }
  283. FoldingRange2.create = create;
  284. function is(value) {
  285. var candidate = value;
  286. return Is.uinteger(candidate.startLine) && Is.uinteger(candidate.startLine) && (Is.undefined(candidate.startCharacter) || Is.uinteger(candidate.startCharacter)) && (Is.undefined(candidate.endCharacter) || Is.uinteger(candidate.endCharacter)) && (Is.undefined(candidate.kind) || Is.string(candidate.kind));
  287. }
  288. FoldingRange2.is = is;
  289. })(FoldingRange || (FoldingRange = {}));
  290. var DiagnosticRelatedInformation;
  291. (function(DiagnosticRelatedInformation2) {
  292. function create(location, message) {
  293. return {
  294. location,
  295. message
  296. };
  297. }
  298. DiagnosticRelatedInformation2.create = create;
  299. function is(value) {
  300. var candidate = value;
  301. return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message);
  302. }
  303. DiagnosticRelatedInformation2.is = is;
  304. })(DiagnosticRelatedInformation || (DiagnosticRelatedInformation = {}));
  305. var DiagnosticSeverity;
  306. (function(DiagnosticSeverity2) {
  307. DiagnosticSeverity2.Error = 1;
  308. DiagnosticSeverity2.Warning = 2;
  309. DiagnosticSeverity2.Information = 3;
  310. DiagnosticSeverity2.Hint = 4;
  311. })(DiagnosticSeverity || (DiagnosticSeverity = {}));
  312. var DiagnosticTag;
  313. (function(DiagnosticTag2) {
  314. DiagnosticTag2.Unnecessary = 1;
  315. DiagnosticTag2.Deprecated = 2;
  316. })(DiagnosticTag || (DiagnosticTag = {}));
  317. var CodeDescription;
  318. (function(CodeDescription2) {
  319. function is(value) {
  320. var candidate = value;
  321. return candidate !== void 0 && candidate !== null && Is.string(candidate.href);
  322. }
  323. CodeDescription2.is = is;
  324. })(CodeDescription || (CodeDescription = {}));
  325. var Diagnostic;
  326. (function(Diagnostic2) {
  327. function create(range, message, severity, code, source, relatedInformation) {
  328. var result = { range, message };
  329. if (Is.defined(severity)) {
  330. result.severity = severity;
  331. }
  332. if (Is.defined(code)) {
  333. result.code = code;
  334. }
  335. if (Is.defined(source)) {
  336. result.source = source;
  337. }
  338. if (Is.defined(relatedInformation)) {
  339. result.relatedInformation = relatedInformation;
  340. }
  341. return result;
  342. }
  343. Diagnostic2.create = create;
  344. function is(value) {
  345. var _a;
  346. var candidate = value;
  347. return Is.defined(candidate) && Range.is(candidate.range) && Is.string(candidate.message) && (Is.number(candidate.severity) || Is.undefined(candidate.severity)) && (Is.integer(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code)) && (Is.undefined(candidate.codeDescription) || Is.string((_a = candidate.codeDescription) === null || _a === void 0 ? void 0 : _a.href)) && (Is.string(candidate.source) || Is.undefined(candidate.source)) && (Is.undefined(candidate.relatedInformation) || Is.typedArray(candidate.relatedInformation, DiagnosticRelatedInformation.is));
  348. }
  349. Diagnostic2.is = is;
  350. })(Diagnostic || (Diagnostic = {}));
  351. var Command;
  352. (function(Command2) {
  353. function create(title, command) {
  354. var args = [];
  355. for (var _i = 2; _i < arguments.length; _i++) {
  356. args[_i - 2] = arguments[_i];
  357. }
  358. var result = { title, command };
  359. if (Is.defined(args) && args.length > 0) {
  360. result.arguments = args;
  361. }
  362. return result;
  363. }
  364. Command2.create = create;
  365. function is(value) {
  366. var candidate = value;
  367. return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command);
  368. }
  369. Command2.is = is;
  370. })(Command || (Command = {}));
  371. var TextEdit;
  372. (function(TextEdit2) {
  373. function replace(range, newText) {
  374. return { range, newText };
  375. }
  376. TextEdit2.replace = replace;
  377. function insert(position, newText) {
  378. return { range: { start: position, end: position }, newText };
  379. }
  380. TextEdit2.insert = insert;
  381. function del(range) {
  382. return { range, newText: "" };
  383. }
  384. TextEdit2.del = del;
  385. function is(value) {
  386. var candidate = value;
  387. return Is.objectLiteral(candidate) && Is.string(candidate.newText) && Range.is(candidate.range);
  388. }
  389. TextEdit2.is = is;
  390. })(TextEdit || (TextEdit = {}));
  391. var ChangeAnnotation;
  392. (function(ChangeAnnotation2) {
  393. function create(label, needsConfirmation, description) {
  394. var result = { label };
  395. if (needsConfirmation !== void 0) {
  396. result.needsConfirmation = needsConfirmation;
  397. }
  398. if (description !== void 0) {
  399. result.description = description;
  400. }
  401. return result;
  402. }
  403. ChangeAnnotation2.create = create;
  404. function is(value) {
  405. var candidate = value;
  406. return candidate !== void 0 && Is.objectLiteral(candidate) && Is.string(candidate.label) && (Is.boolean(candidate.needsConfirmation) || candidate.needsConfirmation === void 0) && (Is.string(candidate.description) || candidate.description === void 0);
  407. }
  408. ChangeAnnotation2.is = is;
  409. })(ChangeAnnotation || (ChangeAnnotation = {}));
  410. var ChangeAnnotationIdentifier;
  411. (function(ChangeAnnotationIdentifier2) {
  412. function is(value) {
  413. var candidate = value;
  414. return typeof candidate === "string";
  415. }
  416. ChangeAnnotationIdentifier2.is = is;
  417. })(ChangeAnnotationIdentifier || (ChangeAnnotationIdentifier = {}));
  418. var AnnotatedTextEdit;
  419. (function(AnnotatedTextEdit2) {
  420. function replace(range, newText, annotation) {
  421. return { range, newText, annotationId: annotation };
  422. }
  423. AnnotatedTextEdit2.replace = replace;
  424. function insert(position, newText, annotation) {
  425. return { range: { start: position, end: position }, newText, annotationId: annotation };
  426. }
  427. AnnotatedTextEdit2.insert = insert;
  428. function del(range, annotation) {
  429. return { range, newText: "", annotationId: annotation };
  430. }
  431. AnnotatedTextEdit2.del = del;
  432. function is(value) {
  433. var candidate = value;
  434. return TextEdit.is(candidate) && (ChangeAnnotation.is(candidate.annotationId) || ChangeAnnotationIdentifier.is(candidate.annotationId));
  435. }
  436. AnnotatedTextEdit2.is = is;
  437. })(AnnotatedTextEdit || (AnnotatedTextEdit = {}));
  438. var TextDocumentEdit;
  439. (function(TextDocumentEdit2) {
  440. function create(textDocument, edits) {
  441. return { textDocument, edits };
  442. }
  443. TextDocumentEdit2.create = create;
  444. function is(value) {
  445. var candidate = value;
  446. return Is.defined(candidate) && OptionalVersionedTextDocumentIdentifier.is(candidate.textDocument) && Array.isArray(candidate.edits);
  447. }
  448. TextDocumentEdit2.is = is;
  449. })(TextDocumentEdit || (TextDocumentEdit = {}));
  450. var CreateFile;
  451. (function(CreateFile2) {
  452. function create(uri, options, annotation) {
  453. var result = {
  454. kind: "create",
  455. uri
  456. };
  457. if (options !== void 0 && (options.overwrite !== void 0 || options.ignoreIfExists !== void 0)) {
  458. result.options = options;
  459. }
  460. if (annotation !== void 0) {
  461. result.annotationId = annotation;
  462. }
  463. return result;
  464. }
  465. CreateFile2.create = create;
  466. function is(value) {
  467. var candidate = value;
  468. return candidate && candidate.kind === "create" && Is.string(candidate.uri) && (candidate.options === void 0 || (candidate.options.overwrite === void 0 || Is.boolean(candidate.options.overwrite)) && (candidate.options.ignoreIfExists === void 0 || Is.boolean(candidate.options.ignoreIfExists))) && (candidate.annotationId === void 0 || ChangeAnnotationIdentifier.is(candidate.annotationId));
  469. }
  470. CreateFile2.is = is;
  471. })(CreateFile || (CreateFile = {}));
  472. var RenameFile;
  473. (function(RenameFile2) {
  474. function create(oldUri, newUri, options, annotation) {
  475. var result = {
  476. kind: "rename",
  477. oldUri,
  478. newUri
  479. };
  480. if (options !== void 0 && (options.overwrite !== void 0 || options.ignoreIfExists !== void 0)) {
  481. result.options = options;
  482. }
  483. if (annotation !== void 0) {
  484. result.annotationId = annotation;
  485. }
  486. return result;
  487. }
  488. RenameFile2.create = create;
  489. function is(value) {
  490. var candidate = value;
  491. return candidate && candidate.kind === "rename" && Is.string(candidate.oldUri) && Is.string(candidate.newUri) && (candidate.options === void 0 || (candidate.options.overwrite === void 0 || Is.boolean(candidate.options.overwrite)) && (candidate.options.ignoreIfExists === void 0 || Is.boolean(candidate.options.ignoreIfExists))) && (candidate.annotationId === void 0 || ChangeAnnotationIdentifier.is(candidate.annotationId));
  492. }
  493. RenameFile2.is = is;
  494. })(RenameFile || (RenameFile = {}));
  495. var DeleteFile;
  496. (function(DeleteFile2) {
  497. function create(uri, options, annotation) {
  498. var result = {
  499. kind: "delete",
  500. uri
  501. };
  502. if (options !== void 0 && (options.recursive !== void 0 || options.ignoreIfNotExists !== void 0)) {
  503. result.options = options;
  504. }
  505. if (annotation !== void 0) {
  506. result.annotationId = annotation;
  507. }
  508. return result;
  509. }
  510. DeleteFile2.create = create;
  511. function is(value) {
  512. var candidate = value;
  513. return candidate && candidate.kind === "delete" && Is.string(candidate.uri) && (candidate.options === void 0 || (candidate.options.recursive === void 0 || Is.boolean(candidate.options.recursive)) && (candidate.options.ignoreIfNotExists === void 0 || Is.boolean(candidate.options.ignoreIfNotExists))) && (candidate.annotationId === void 0 || ChangeAnnotationIdentifier.is(candidate.annotationId));
  514. }
  515. DeleteFile2.is = is;
  516. })(DeleteFile || (DeleteFile = {}));
  517. var WorkspaceEdit;
  518. (function(WorkspaceEdit2) {
  519. function is(value) {
  520. var candidate = value;
  521. return candidate && (candidate.changes !== void 0 || candidate.documentChanges !== void 0) && (candidate.documentChanges === void 0 || candidate.documentChanges.every(function(change) {
  522. if (Is.string(change.kind)) {
  523. return CreateFile.is(change) || RenameFile.is(change) || DeleteFile.is(change);
  524. } else {
  525. return TextDocumentEdit.is(change);
  526. }
  527. }));
  528. }
  529. WorkspaceEdit2.is = is;
  530. })(WorkspaceEdit || (WorkspaceEdit = {}));
  531. var TextEditChangeImpl = function() {
  532. function TextEditChangeImpl2(edits, changeAnnotations) {
  533. this.edits = edits;
  534. this.changeAnnotations = changeAnnotations;
  535. }
  536. TextEditChangeImpl2.prototype.insert = function(position, newText, annotation) {
  537. var edit;
  538. var id;
  539. if (annotation === void 0) {
  540. edit = TextEdit.insert(position, newText);
  541. } else if (ChangeAnnotationIdentifier.is(annotation)) {
  542. id = annotation;
  543. edit = AnnotatedTextEdit.insert(position, newText, annotation);
  544. } else {
  545. this.assertChangeAnnotations(this.changeAnnotations);
  546. id = this.changeAnnotations.manage(annotation);
  547. edit = AnnotatedTextEdit.insert(position, newText, id);
  548. }
  549. this.edits.push(edit);
  550. if (id !== void 0) {
  551. return id;
  552. }
  553. };
  554. TextEditChangeImpl2.prototype.replace = function(range, newText, annotation) {
  555. var edit;
  556. var id;
  557. if (annotation === void 0) {
  558. edit = TextEdit.replace(range, newText);
  559. } else if (ChangeAnnotationIdentifier.is(annotation)) {
  560. id = annotation;
  561. edit = AnnotatedTextEdit.replace(range, newText, annotation);
  562. } else {
  563. this.assertChangeAnnotations(this.changeAnnotations);
  564. id = this.changeAnnotations.manage(annotation);
  565. edit = AnnotatedTextEdit.replace(range, newText, id);
  566. }
  567. this.edits.push(edit);
  568. if (id !== void 0) {
  569. return id;
  570. }
  571. };
  572. TextEditChangeImpl2.prototype.delete = function(range, annotation) {
  573. var edit;
  574. var id;
  575. if (annotation === void 0) {
  576. edit = TextEdit.del(range);
  577. } else if (ChangeAnnotationIdentifier.is(annotation)) {
  578. id = annotation;
  579. edit = AnnotatedTextEdit.del(range, annotation);
  580. } else {
  581. this.assertChangeAnnotations(this.changeAnnotations);
  582. id = this.changeAnnotations.manage(annotation);
  583. edit = AnnotatedTextEdit.del(range, id);
  584. }
  585. this.edits.push(edit);
  586. if (id !== void 0) {
  587. return id;
  588. }
  589. };
  590. TextEditChangeImpl2.prototype.add = function(edit) {
  591. this.edits.push(edit);
  592. };
  593. TextEditChangeImpl2.prototype.all = function() {
  594. return this.edits;
  595. };
  596. TextEditChangeImpl2.prototype.clear = function() {
  597. this.edits.splice(0, this.edits.length);
  598. };
  599. TextEditChangeImpl2.prototype.assertChangeAnnotations = function(value) {
  600. if (value === void 0) {
  601. throw new Error("Text edit change is not configured to manage change annotations.");
  602. }
  603. };
  604. return TextEditChangeImpl2;
  605. }();
  606. var ChangeAnnotations = function() {
  607. function ChangeAnnotations2(annotations) {
  608. this._annotations = annotations === void 0 ? /* @__PURE__ */ Object.create(null) : annotations;
  609. this._counter = 0;
  610. this._size = 0;
  611. }
  612. ChangeAnnotations2.prototype.all = function() {
  613. return this._annotations;
  614. };
  615. Object.defineProperty(ChangeAnnotations2.prototype, "size", {
  616. get: function() {
  617. return this._size;
  618. },
  619. enumerable: false,
  620. configurable: true
  621. });
  622. ChangeAnnotations2.prototype.manage = function(idOrAnnotation, annotation) {
  623. var id;
  624. if (ChangeAnnotationIdentifier.is(idOrAnnotation)) {
  625. id = idOrAnnotation;
  626. } else {
  627. id = this.nextId();
  628. annotation = idOrAnnotation;
  629. }
  630. if (this._annotations[id] !== void 0) {
  631. throw new Error("Id " + id + " is already in use.");
  632. }
  633. if (annotation === void 0) {
  634. throw new Error("No annotation provided for id " + id);
  635. }
  636. this._annotations[id] = annotation;
  637. this._size++;
  638. return id;
  639. };
  640. ChangeAnnotations2.prototype.nextId = function() {
  641. this._counter++;
  642. return this._counter.toString();
  643. };
  644. return ChangeAnnotations2;
  645. }();
  646. var WorkspaceChange = function() {
  647. function WorkspaceChange2(workspaceEdit) {
  648. var _this = this;
  649. this._textEditChanges = /* @__PURE__ */ Object.create(null);
  650. if (workspaceEdit !== void 0) {
  651. this._workspaceEdit = workspaceEdit;
  652. if (workspaceEdit.documentChanges) {
  653. this._changeAnnotations = new ChangeAnnotations(workspaceEdit.changeAnnotations);
  654. workspaceEdit.changeAnnotations = this._changeAnnotations.all();
  655. workspaceEdit.documentChanges.forEach(function(change) {
  656. if (TextDocumentEdit.is(change)) {
  657. var textEditChange = new TextEditChangeImpl(change.edits, _this._changeAnnotations);
  658. _this._textEditChanges[change.textDocument.uri] = textEditChange;
  659. }
  660. });
  661. } else if (workspaceEdit.changes) {
  662. Object.keys(workspaceEdit.changes).forEach(function(key) {
  663. var textEditChange = new TextEditChangeImpl(workspaceEdit.changes[key]);
  664. _this._textEditChanges[key] = textEditChange;
  665. });
  666. }
  667. } else {
  668. this._workspaceEdit = {};
  669. }
  670. }
  671. Object.defineProperty(WorkspaceChange2.prototype, "edit", {
  672. get: function() {
  673. this.initDocumentChanges();
  674. if (this._changeAnnotations !== void 0) {
  675. if (this._changeAnnotations.size === 0) {
  676. this._workspaceEdit.changeAnnotations = void 0;
  677. } else {
  678. this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
  679. }
  680. }
  681. return this._workspaceEdit;
  682. },
  683. enumerable: false,
  684. configurable: true
  685. });
  686. WorkspaceChange2.prototype.getTextEditChange = function(key) {
  687. if (OptionalVersionedTextDocumentIdentifier.is(key)) {
  688. this.initDocumentChanges();
  689. if (this._workspaceEdit.documentChanges === void 0) {
  690. throw new Error("Workspace edit is not configured for document changes.");
  691. }
  692. var textDocument = { uri: key.uri, version: key.version };
  693. var result = this._textEditChanges[textDocument.uri];
  694. if (!result) {
  695. var edits = [];
  696. var textDocumentEdit = {
  697. textDocument,
  698. edits
  699. };
  700. this._workspaceEdit.documentChanges.push(textDocumentEdit);
  701. result = new TextEditChangeImpl(edits, this._changeAnnotations);
  702. this._textEditChanges[textDocument.uri] = result;
  703. }
  704. return result;
  705. } else {
  706. this.initChanges();
  707. if (this._workspaceEdit.changes === void 0) {
  708. throw new Error("Workspace edit is not configured for normal text edit changes.");
  709. }
  710. var result = this._textEditChanges[key];
  711. if (!result) {
  712. var edits = [];
  713. this._workspaceEdit.changes[key] = edits;
  714. result = new TextEditChangeImpl(edits);
  715. this._textEditChanges[key] = result;
  716. }
  717. return result;
  718. }
  719. };
  720. WorkspaceChange2.prototype.initDocumentChanges = function() {
  721. if (this._workspaceEdit.documentChanges === void 0 && this._workspaceEdit.changes === void 0) {
  722. this._changeAnnotations = new ChangeAnnotations();
  723. this._workspaceEdit.documentChanges = [];
  724. this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
  725. }
  726. };
  727. WorkspaceChange2.prototype.initChanges = function() {
  728. if (this._workspaceEdit.documentChanges === void 0 && this._workspaceEdit.changes === void 0) {
  729. this._workspaceEdit.changes = /* @__PURE__ */ Object.create(null);
  730. }
  731. };
  732. WorkspaceChange2.prototype.createFile = function(uri, optionsOrAnnotation, options) {
  733. this.initDocumentChanges();
  734. if (this._workspaceEdit.documentChanges === void 0) {
  735. throw new Error("Workspace edit is not configured for document changes.");
  736. }
  737. var annotation;
  738. if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
  739. annotation = optionsOrAnnotation;
  740. } else {
  741. options = optionsOrAnnotation;
  742. }
  743. var operation;
  744. var id;
  745. if (annotation === void 0) {
  746. operation = CreateFile.create(uri, options);
  747. } else {
  748. id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
  749. operation = CreateFile.create(uri, options, id);
  750. }
  751. this._workspaceEdit.documentChanges.push(operation);
  752. if (id !== void 0) {
  753. return id;
  754. }
  755. };
  756. WorkspaceChange2.prototype.renameFile = function(oldUri, newUri, optionsOrAnnotation, options) {
  757. this.initDocumentChanges();
  758. if (this._workspaceEdit.documentChanges === void 0) {
  759. throw new Error("Workspace edit is not configured for document changes.");
  760. }
  761. var annotation;
  762. if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
  763. annotation = optionsOrAnnotation;
  764. } else {
  765. options = optionsOrAnnotation;
  766. }
  767. var operation;
  768. var id;
  769. if (annotation === void 0) {
  770. operation = RenameFile.create(oldUri, newUri, options);
  771. } else {
  772. id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
  773. operation = RenameFile.create(oldUri, newUri, options, id);
  774. }
  775. this._workspaceEdit.documentChanges.push(operation);
  776. if (id !== void 0) {
  777. return id;
  778. }
  779. };
  780. WorkspaceChange2.prototype.deleteFile = function(uri, optionsOrAnnotation, options) {
  781. this.initDocumentChanges();
  782. if (this._workspaceEdit.documentChanges === void 0) {
  783. throw new Error("Workspace edit is not configured for document changes.");
  784. }
  785. var annotation;
  786. if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
  787. annotation = optionsOrAnnotation;
  788. } else {
  789. options = optionsOrAnnotation;
  790. }
  791. var operation;
  792. var id;
  793. if (annotation === void 0) {
  794. operation = DeleteFile.create(uri, options);
  795. } else {
  796. id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
  797. operation = DeleteFile.create(uri, options, id);
  798. }
  799. this._workspaceEdit.documentChanges.push(operation);
  800. if (id !== void 0) {
  801. return id;
  802. }
  803. };
  804. return WorkspaceChange2;
  805. }();
  806. var TextDocumentIdentifier;
  807. (function(TextDocumentIdentifier2) {
  808. function create(uri) {
  809. return { uri };
  810. }
  811. TextDocumentIdentifier2.create = create;
  812. function is(value) {
  813. var candidate = value;
  814. return Is.defined(candidate) && Is.string(candidate.uri);
  815. }
  816. TextDocumentIdentifier2.is = is;
  817. })(TextDocumentIdentifier || (TextDocumentIdentifier = {}));
  818. var VersionedTextDocumentIdentifier;
  819. (function(VersionedTextDocumentIdentifier2) {
  820. function create(uri, version) {
  821. return { uri, version };
  822. }
  823. VersionedTextDocumentIdentifier2.create = create;
  824. function is(value) {
  825. var candidate = value;
  826. return Is.defined(candidate) && Is.string(candidate.uri) && Is.integer(candidate.version);
  827. }
  828. VersionedTextDocumentIdentifier2.is = is;
  829. })(VersionedTextDocumentIdentifier || (VersionedTextDocumentIdentifier = {}));
  830. var OptionalVersionedTextDocumentIdentifier;
  831. (function(OptionalVersionedTextDocumentIdentifier2) {
  832. function create(uri, version) {
  833. return { uri, version };
  834. }
  835. OptionalVersionedTextDocumentIdentifier2.create = create;
  836. function is(value) {
  837. var candidate = value;
  838. return Is.defined(candidate) && Is.string(candidate.uri) && (candidate.version === null || Is.integer(candidate.version));
  839. }
  840. OptionalVersionedTextDocumentIdentifier2.is = is;
  841. })(OptionalVersionedTextDocumentIdentifier || (OptionalVersionedTextDocumentIdentifier = {}));
  842. var TextDocumentItem;
  843. (function(TextDocumentItem2) {
  844. function create(uri, languageId, version, text) {
  845. return { uri, languageId, version, text };
  846. }
  847. TextDocumentItem2.create = create;
  848. function is(value) {
  849. var candidate = value;
  850. return Is.defined(candidate) && Is.string(candidate.uri) && Is.string(candidate.languageId) && Is.integer(candidate.version) && Is.string(candidate.text);
  851. }
  852. TextDocumentItem2.is = is;
  853. })(TextDocumentItem || (TextDocumentItem = {}));
  854. var MarkupKind;
  855. (function(MarkupKind2) {
  856. MarkupKind2.PlainText = "plaintext";
  857. MarkupKind2.Markdown = "markdown";
  858. })(MarkupKind || (MarkupKind = {}));
  859. (function(MarkupKind2) {
  860. function is(value) {
  861. var candidate = value;
  862. return candidate === MarkupKind2.PlainText || candidate === MarkupKind2.Markdown;
  863. }
  864. MarkupKind2.is = is;
  865. })(MarkupKind || (MarkupKind = {}));
  866. var MarkupContent;
  867. (function(MarkupContent2) {
  868. function is(value) {
  869. var candidate = value;
  870. return Is.objectLiteral(value) && MarkupKind.is(candidate.kind) && Is.string(candidate.value);
  871. }
  872. MarkupContent2.is = is;
  873. })(MarkupContent || (MarkupContent = {}));
  874. var CompletionItemKind;
  875. (function(CompletionItemKind2) {
  876. CompletionItemKind2.Text = 1;
  877. CompletionItemKind2.Method = 2;
  878. CompletionItemKind2.Function = 3;
  879. CompletionItemKind2.Constructor = 4;
  880. CompletionItemKind2.Field = 5;
  881. CompletionItemKind2.Variable = 6;
  882. CompletionItemKind2.Class = 7;
  883. CompletionItemKind2.Interface = 8;
  884. CompletionItemKind2.Module = 9;
  885. CompletionItemKind2.Property = 10;
  886. CompletionItemKind2.Unit = 11;
  887. CompletionItemKind2.Value = 12;
  888. CompletionItemKind2.Enum = 13;
  889. CompletionItemKind2.Keyword = 14;
  890. CompletionItemKind2.Snippet = 15;
  891. CompletionItemKind2.Color = 16;
  892. CompletionItemKind2.File = 17;
  893. CompletionItemKind2.Reference = 18;
  894. CompletionItemKind2.Folder = 19;
  895. CompletionItemKind2.EnumMember = 20;
  896. CompletionItemKind2.Constant = 21;
  897. CompletionItemKind2.Struct = 22;
  898. CompletionItemKind2.Event = 23;
  899. CompletionItemKind2.Operator = 24;
  900. CompletionItemKind2.TypeParameter = 25;
  901. })(CompletionItemKind || (CompletionItemKind = {}));
  902. var InsertTextFormat;
  903. (function(InsertTextFormat2) {
  904. InsertTextFormat2.PlainText = 1;
  905. InsertTextFormat2.Snippet = 2;
  906. })(InsertTextFormat || (InsertTextFormat = {}));
  907. var CompletionItemTag;
  908. (function(CompletionItemTag2) {
  909. CompletionItemTag2.Deprecated = 1;
  910. })(CompletionItemTag || (CompletionItemTag = {}));
  911. var InsertReplaceEdit;
  912. (function(InsertReplaceEdit2) {
  913. function create(newText, insert, replace) {
  914. return { newText, insert, replace };
  915. }
  916. InsertReplaceEdit2.create = create;
  917. function is(value) {
  918. var candidate = value;
  919. return candidate && Is.string(candidate.newText) && Range.is(candidate.insert) && Range.is(candidate.replace);
  920. }
  921. InsertReplaceEdit2.is = is;
  922. })(InsertReplaceEdit || (InsertReplaceEdit = {}));
  923. var InsertTextMode;
  924. (function(InsertTextMode2) {
  925. InsertTextMode2.asIs = 1;
  926. InsertTextMode2.adjustIndentation = 2;
  927. })(InsertTextMode || (InsertTextMode = {}));
  928. var CompletionItem;
  929. (function(CompletionItem2) {
  930. function create(label) {
  931. return { label };
  932. }
  933. CompletionItem2.create = create;
  934. })(CompletionItem || (CompletionItem = {}));
  935. var CompletionList;
  936. (function(CompletionList2) {
  937. function create(items, isIncomplete) {
  938. return { items: items ? items : [], isIncomplete: !!isIncomplete };
  939. }
  940. CompletionList2.create = create;
  941. })(CompletionList || (CompletionList = {}));
  942. var MarkedString;
  943. (function(MarkedString2) {
  944. function fromPlainText(plainText) {
  945. return plainText.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&");
  946. }
  947. MarkedString2.fromPlainText = fromPlainText;
  948. function is(value) {
  949. var candidate = value;
  950. return Is.string(candidate) || Is.objectLiteral(candidate) && Is.string(candidate.language) && Is.string(candidate.value);
  951. }
  952. MarkedString2.is = is;
  953. })(MarkedString || (MarkedString = {}));
  954. var Hover;
  955. (function(Hover2) {
  956. function is(value) {
  957. var candidate = value;
  958. return !!candidate && Is.objectLiteral(candidate) && (MarkupContent.is(candidate.contents) || MarkedString.is(candidate.contents) || Is.typedArray(candidate.contents, MarkedString.is)) && (value.range === void 0 || Range.is(value.range));
  959. }
  960. Hover2.is = is;
  961. })(Hover || (Hover = {}));
  962. var ParameterInformation;
  963. (function(ParameterInformation2) {
  964. function create(label, documentation) {
  965. return documentation ? { label, documentation } : { label };
  966. }
  967. ParameterInformation2.create = create;
  968. })(ParameterInformation || (ParameterInformation = {}));
  969. var SignatureInformation;
  970. (function(SignatureInformation2) {
  971. function create(label, documentation) {
  972. var parameters = [];
  973. for (var _i = 2; _i < arguments.length; _i++) {
  974. parameters[_i - 2] = arguments[_i];
  975. }
  976. var result = { label };
  977. if (Is.defined(documentation)) {
  978. result.documentation = documentation;
  979. }
  980. if (Is.defined(parameters)) {
  981. result.parameters = parameters;
  982. } else {
  983. result.parameters = [];
  984. }
  985. return result;
  986. }
  987. SignatureInformation2.create = create;
  988. })(SignatureInformation || (SignatureInformation = {}));
  989. var DocumentHighlightKind;
  990. (function(DocumentHighlightKind2) {
  991. DocumentHighlightKind2.Text = 1;
  992. DocumentHighlightKind2.Read = 2;
  993. DocumentHighlightKind2.Write = 3;
  994. })(DocumentHighlightKind || (DocumentHighlightKind = {}));
  995. var DocumentHighlight;
  996. (function(DocumentHighlight2) {
  997. function create(range, kind) {
  998. var result = { range };
  999. if (Is.number(kind)) {
  1000. result.kind = kind;
  1001. }
  1002. return result;
  1003. }
  1004. DocumentHighlight2.create = create;
  1005. })(DocumentHighlight || (DocumentHighlight = {}));
  1006. var SymbolKind;
  1007. (function(SymbolKind2) {
  1008. SymbolKind2.File = 1;
  1009. SymbolKind2.Module = 2;
  1010. SymbolKind2.Namespace = 3;
  1011. SymbolKind2.Package = 4;
  1012. SymbolKind2.Class = 5;
  1013. SymbolKind2.Method = 6;
  1014. SymbolKind2.Property = 7;
  1015. SymbolKind2.Field = 8;
  1016. SymbolKind2.Constructor = 9;
  1017. SymbolKind2.Enum = 10;
  1018. SymbolKind2.Interface = 11;
  1019. SymbolKind2.Function = 12;
  1020. SymbolKind2.Variable = 13;
  1021. SymbolKind2.Constant = 14;
  1022. SymbolKind2.String = 15;
  1023. SymbolKind2.Number = 16;
  1024. SymbolKind2.Boolean = 17;
  1025. SymbolKind2.Array = 18;
  1026. SymbolKind2.Object = 19;
  1027. SymbolKind2.Key = 20;
  1028. SymbolKind2.Null = 21;
  1029. SymbolKind2.EnumMember = 22;
  1030. SymbolKind2.Struct = 23;
  1031. SymbolKind2.Event = 24;
  1032. SymbolKind2.Operator = 25;
  1033. SymbolKind2.TypeParameter = 26;
  1034. })(SymbolKind || (SymbolKind = {}));
  1035. var SymbolTag;
  1036. (function(SymbolTag2) {
  1037. SymbolTag2.Deprecated = 1;
  1038. })(SymbolTag || (SymbolTag = {}));
  1039. var SymbolInformation;
  1040. (function(SymbolInformation2) {
  1041. function create(name, kind, range, uri, containerName) {
  1042. var result = {
  1043. name,
  1044. kind,
  1045. location: { uri, range }
  1046. };
  1047. if (containerName) {
  1048. result.containerName = containerName;
  1049. }
  1050. return result;
  1051. }
  1052. SymbolInformation2.create = create;
  1053. })(SymbolInformation || (SymbolInformation = {}));
  1054. var DocumentSymbol;
  1055. (function(DocumentSymbol2) {
  1056. function create(name, detail, kind, range, selectionRange, children) {
  1057. var result = {
  1058. name,
  1059. detail,
  1060. kind,
  1061. range,
  1062. selectionRange
  1063. };
  1064. if (children !== void 0) {
  1065. result.children = children;
  1066. }
  1067. return result;
  1068. }
  1069. DocumentSymbol2.create = create;
  1070. function is(value) {
  1071. var candidate = value;
  1072. return candidate && Is.string(candidate.name) && Is.number(candidate.kind) && Range.is(candidate.range) && Range.is(candidate.selectionRange) && (candidate.detail === void 0 || Is.string(candidate.detail)) && (candidate.deprecated === void 0 || Is.boolean(candidate.deprecated)) && (candidate.children === void 0 || Array.isArray(candidate.children)) && (candidate.tags === void 0 || Array.isArray(candidate.tags));
  1073. }
  1074. DocumentSymbol2.is = is;
  1075. })(DocumentSymbol || (DocumentSymbol = {}));
  1076. var CodeActionKind;
  1077. (function(CodeActionKind2) {
  1078. CodeActionKind2.Empty = "";
  1079. CodeActionKind2.QuickFix = "quickfix";
  1080. CodeActionKind2.Refactor = "refactor";
  1081. CodeActionKind2.RefactorExtract = "refactor.extract";
  1082. CodeActionKind2.RefactorInline = "refactor.inline";
  1083. CodeActionKind2.RefactorRewrite = "refactor.rewrite";
  1084. CodeActionKind2.Source = "source";
  1085. CodeActionKind2.SourceOrganizeImports = "source.organizeImports";
  1086. CodeActionKind2.SourceFixAll = "source.fixAll";
  1087. })(CodeActionKind || (CodeActionKind = {}));
  1088. var CodeActionContext;
  1089. (function(CodeActionContext2) {
  1090. function create(diagnostics, only) {
  1091. var result = { diagnostics };
  1092. if (only !== void 0 && only !== null) {
  1093. result.only = only;
  1094. }
  1095. return result;
  1096. }
  1097. CodeActionContext2.create = create;
  1098. function is(value) {
  1099. var candidate = value;
  1100. return Is.defined(candidate) && Is.typedArray(candidate.diagnostics, Diagnostic.is) && (candidate.only === void 0 || Is.typedArray(candidate.only, Is.string));
  1101. }
  1102. CodeActionContext2.is = is;
  1103. })(CodeActionContext || (CodeActionContext = {}));
  1104. var CodeAction;
  1105. (function(CodeAction2) {
  1106. function create(title, kindOrCommandOrEdit, kind) {
  1107. var result = { title };
  1108. var checkKind = true;
  1109. if (typeof kindOrCommandOrEdit === "string") {
  1110. checkKind = false;
  1111. result.kind = kindOrCommandOrEdit;
  1112. } else if (Command.is(kindOrCommandOrEdit)) {
  1113. result.command = kindOrCommandOrEdit;
  1114. } else {
  1115. result.edit = kindOrCommandOrEdit;
  1116. }
  1117. if (checkKind && kind !== void 0) {
  1118. result.kind = kind;
  1119. }
  1120. return result;
  1121. }
  1122. CodeAction2.create = create;
  1123. function is(value) {
  1124. var candidate = value;
  1125. return candidate && Is.string(candidate.title) && (candidate.diagnostics === void 0 || Is.typedArray(candidate.diagnostics, Diagnostic.is)) && (candidate.kind === void 0 || Is.string(candidate.kind)) && (candidate.edit !== void 0 || candidate.command !== void 0) && (candidate.command === void 0 || Command.is(candidate.command)) && (candidate.isPreferred === void 0 || Is.boolean(candidate.isPreferred)) && (candidate.edit === void 0 || WorkspaceEdit.is(candidate.edit));
  1126. }
  1127. CodeAction2.is = is;
  1128. })(CodeAction || (CodeAction = {}));
  1129. var CodeLens;
  1130. (function(CodeLens2) {
  1131. function create(range, data) {
  1132. var result = { range };
  1133. if (Is.defined(data)) {
  1134. result.data = data;
  1135. }
  1136. return result;
  1137. }
  1138. CodeLens2.create = create;
  1139. function is(value) {
  1140. var candidate = value;
  1141. return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command));
  1142. }
  1143. CodeLens2.is = is;
  1144. })(CodeLens || (CodeLens = {}));
  1145. var FormattingOptions;
  1146. (function(FormattingOptions2) {
  1147. function create(tabSize, insertSpaces) {
  1148. return { tabSize, insertSpaces };
  1149. }
  1150. FormattingOptions2.create = create;
  1151. function is(value) {
  1152. var candidate = value;
  1153. return Is.defined(candidate) && Is.uinteger(candidate.tabSize) && Is.boolean(candidate.insertSpaces);
  1154. }
  1155. FormattingOptions2.is = is;
  1156. })(FormattingOptions || (FormattingOptions = {}));
  1157. var DocumentLink;
  1158. (function(DocumentLink2) {
  1159. function create(range, target, data) {
  1160. return { range, target, data };
  1161. }
  1162. DocumentLink2.create = create;
  1163. function is(value) {
  1164. var candidate = value;
  1165. return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.target) || Is.string(candidate.target));
  1166. }
  1167. DocumentLink2.is = is;
  1168. })(DocumentLink || (DocumentLink = {}));
  1169. var SelectionRange;
  1170. (function(SelectionRange2) {
  1171. function create(range, parent) {
  1172. return { range, parent };
  1173. }
  1174. SelectionRange2.create = create;
  1175. function is(value) {
  1176. var candidate = value;
  1177. return candidate !== void 0 && Range.is(candidate.range) && (candidate.parent === void 0 || SelectionRange2.is(candidate.parent));
  1178. }
  1179. SelectionRange2.is = is;
  1180. })(SelectionRange || (SelectionRange = {}));
  1181. var TextDocument;
  1182. (function(TextDocument2) {
  1183. function create(uri, languageId, version, content) {
  1184. return new FullTextDocument(uri, languageId, version, content);
  1185. }
  1186. TextDocument2.create = create;
  1187. function is(value) {
  1188. var candidate = value;
  1189. return Is.defined(candidate) && Is.string(candidate.uri) && (Is.undefined(candidate.languageId) || Is.string(candidate.languageId)) && Is.uinteger(candidate.lineCount) && Is.func(candidate.getText) && Is.func(candidate.positionAt) && Is.func(candidate.offsetAt) ? true : false;
  1190. }
  1191. TextDocument2.is = is;
  1192. function applyEdits(document, edits) {
  1193. var text = document.getText();
  1194. var sortedEdits = mergeSort(edits, function(a, b) {
  1195. var diff = a.range.start.line - b.range.start.line;
  1196. if (diff === 0) {
  1197. return a.range.start.character - b.range.start.character;
  1198. }
  1199. return diff;
  1200. });
  1201. var lastModifiedOffset = text.length;
  1202. for (var i = sortedEdits.length - 1; i >= 0; i--) {
  1203. var e = sortedEdits[i];
  1204. var startOffset = document.offsetAt(e.range.start);
  1205. var endOffset = document.offsetAt(e.range.end);
  1206. if (endOffset <= lastModifiedOffset) {
  1207. text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
  1208. } else {
  1209. throw new Error("Overlapping edit");
  1210. }
  1211. lastModifiedOffset = startOffset;
  1212. }
  1213. return text;
  1214. }
  1215. TextDocument2.applyEdits = applyEdits;
  1216. function mergeSort(data, compare) {
  1217. if (data.length <= 1) {
  1218. return data;
  1219. }
  1220. var p = data.length / 2 | 0;
  1221. var left = data.slice(0, p);
  1222. var right = data.slice(p);
  1223. mergeSort(left, compare);
  1224. mergeSort(right, compare);
  1225. var leftIdx = 0;
  1226. var rightIdx = 0;
  1227. var i = 0;
  1228. while (leftIdx < left.length && rightIdx < right.length) {
  1229. var ret = compare(left[leftIdx], right[rightIdx]);
  1230. if (ret <= 0) {
  1231. data[i++] = left[leftIdx++];
  1232. } else {
  1233. data[i++] = right[rightIdx++];
  1234. }
  1235. }
  1236. while (leftIdx < left.length) {
  1237. data[i++] = left[leftIdx++];
  1238. }
  1239. while (rightIdx < right.length) {
  1240. data[i++] = right[rightIdx++];
  1241. }
  1242. return data;
  1243. }
  1244. })(TextDocument || (TextDocument = {}));
  1245. var FullTextDocument = function() {
  1246. function FullTextDocument2(uri, languageId, version, content) {
  1247. this._uri = uri;
  1248. this._languageId = languageId;
  1249. this._version = version;
  1250. this._content = content;
  1251. this._lineOffsets = void 0;
  1252. }
  1253. Object.defineProperty(FullTextDocument2.prototype, "uri", {
  1254. get: function() {
  1255. return this._uri;
  1256. },
  1257. enumerable: false,
  1258. configurable: true
  1259. });
  1260. Object.defineProperty(FullTextDocument2.prototype, "languageId", {
  1261. get: function() {
  1262. return this._languageId;
  1263. },
  1264. enumerable: false,
  1265. configurable: true
  1266. });
  1267. Object.defineProperty(FullTextDocument2.prototype, "version", {
  1268. get: function() {
  1269. return this._version;
  1270. },
  1271. enumerable: false,
  1272. configurable: true
  1273. });
  1274. FullTextDocument2.prototype.getText = function(range) {
  1275. if (range) {
  1276. var start = this.offsetAt(range.start);
  1277. var end = this.offsetAt(range.end);
  1278. return this._content.substring(start, end);
  1279. }
  1280. return this._content;
  1281. };
  1282. FullTextDocument2.prototype.update = function(event, version) {
  1283. this._content = event.text;
  1284. this._version = version;
  1285. this._lineOffsets = void 0;
  1286. };
  1287. FullTextDocument2.prototype.getLineOffsets = function() {
  1288. if (this._lineOffsets === void 0) {
  1289. var lineOffsets = [];
  1290. var text = this._content;
  1291. var isLineStart = true;
  1292. for (var i = 0; i < text.length; i++) {
  1293. if (isLineStart) {
  1294. lineOffsets.push(i);
  1295. isLineStart = false;
  1296. }
  1297. var ch = text.charAt(i);
  1298. isLineStart = ch === "\r" || ch === "\n";
  1299. if (ch === "\r" && i + 1 < text.length && text.charAt(i + 1) === "\n") {
  1300. i++;
  1301. }
  1302. }
  1303. if (isLineStart && text.length > 0) {
  1304. lineOffsets.push(text.length);
  1305. }
  1306. this._lineOffsets = lineOffsets;
  1307. }
  1308. return this._lineOffsets;
  1309. };
  1310. FullTextDocument2.prototype.positionAt = function(offset) {
  1311. offset = Math.max(Math.min(offset, this._content.length), 0);
  1312. var lineOffsets = this.getLineOffsets();
  1313. var low = 0, high = lineOffsets.length;
  1314. if (high === 0) {
  1315. return Position.create(0, offset);
  1316. }
  1317. while (low < high) {
  1318. var mid = Math.floor((low + high) / 2);
  1319. if (lineOffsets[mid] > offset) {
  1320. high = mid;
  1321. } else {
  1322. low = mid + 1;
  1323. }
  1324. }
  1325. var line = low - 1;
  1326. return Position.create(line, offset - lineOffsets[line]);
  1327. };
  1328. FullTextDocument2.prototype.offsetAt = function(position) {
  1329. var lineOffsets = this.getLineOffsets();
  1330. if (position.line >= lineOffsets.length) {
  1331. return this._content.length;
  1332. } else if (position.line < 0) {
  1333. return 0;
  1334. }
  1335. var lineOffset = lineOffsets[position.line];
  1336. var nextLineOffset = position.line + 1 < lineOffsets.length ? lineOffsets[position.line + 1] : this._content.length;
  1337. return Math.max(Math.min(lineOffset + position.character, nextLineOffset), lineOffset);
  1338. };
  1339. Object.defineProperty(FullTextDocument2.prototype, "lineCount", {
  1340. get: function() {
  1341. return this.getLineOffsets().length;
  1342. },
  1343. enumerable: false,
  1344. configurable: true
  1345. });
  1346. return FullTextDocument2;
  1347. }();
  1348. var Is;
  1349. (function(Is2) {
  1350. var toString = Object.prototype.toString;
  1351. function defined(value) {
  1352. return typeof value !== "undefined";
  1353. }
  1354. Is2.defined = defined;
  1355. function undefined2(value) {
  1356. return typeof value === "undefined";
  1357. }
  1358. Is2.undefined = undefined2;
  1359. function boolean(value) {
  1360. return value === true || value === false;
  1361. }
  1362. Is2.boolean = boolean;
  1363. function string(value) {
  1364. return toString.call(value) === "[object String]";
  1365. }
  1366. Is2.string = string;
  1367. function number(value) {
  1368. return toString.call(value) === "[object Number]";
  1369. }
  1370. Is2.number = number;
  1371. function numberRange(value, min, max) {
  1372. return toString.call(value) === "[object Number]" && min <= value && value <= max;
  1373. }
  1374. Is2.numberRange = numberRange;
  1375. function integer2(value) {
  1376. return toString.call(value) === "[object Number]" && -2147483648 <= value && value <= 2147483647;
  1377. }
  1378. Is2.integer = integer2;
  1379. function uinteger2(value) {
  1380. return toString.call(value) === "[object Number]" && 0 <= value && value <= 2147483647;
  1381. }
  1382. Is2.uinteger = uinteger2;
  1383. function func(value) {
  1384. return toString.call(value) === "[object Function]";
  1385. }
  1386. Is2.func = func;
  1387. function objectLiteral(value) {
  1388. return value !== null && typeof value === "object";
  1389. }
  1390. Is2.objectLiteral = objectLiteral;
  1391. function typedArray(value, check) {
  1392. return Array.isArray(value) && value.every(check);
  1393. }
  1394. Is2.typedArray = typedArray;
  1395. })(Is || (Is = {}));
  1396. // src/language/common/lspLanguageFeatures.ts
  1397. var DiagnosticsAdapter = class {
  1398. constructor(_languageId, _worker, configChangeEvent) {
  1399. this._languageId = _languageId;
  1400. this._worker = _worker;
  1401. const onModelAdd = (model) => {
  1402. let modeId = model.getLanguageId();
  1403. if (modeId !== this._languageId) {
  1404. return;
  1405. }
  1406. let handle;
  1407. this._listener[model.uri.toString()] = model.onDidChangeContent(() => {
  1408. window.clearTimeout(handle);
  1409. handle = window.setTimeout(() => this._doValidate(model.uri, modeId), 500);
  1410. });
  1411. this._doValidate(model.uri, modeId);
  1412. };
  1413. const onModelRemoved = (model) => {
  1414. monaco_editor_core_exports.editor.setModelMarkers(model, this._languageId, []);
  1415. let uriStr = model.uri.toString();
  1416. let listener = this._listener[uriStr];
  1417. if (listener) {
  1418. listener.dispose();
  1419. delete this._listener[uriStr];
  1420. }
  1421. };
  1422. this._disposables.push(monaco_editor_core_exports.editor.onDidCreateModel(onModelAdd));
  1423. this._disposables.push(monaco_editor_core_exports.editor.onWillDisposeModel(onModelRemoved));
  1424. this._disposables.push(monaco_editor_core_exports.editor.onDidChangeModelLanguage((event) => {
  1425. onModelRemoved(event.model);
  1426. onModelAdd(event.model);
  1427. }));
  1428. this._disposables.push(configChangeEvent((_) => {
  1429. monaco_editor_core_exports.editor.getModels().forEach((model) => {
  1430. if (model.getLanguageId() === this._languageId) {
  1431. onModelRemoved(model);
  1432. onModelAdd(model);
  1433. }
  1434. });
  1435. }));
  1436. this._disposables.push({
  1437. dispose: () => {
  1438. monaco_editor_core_exports.editor.getModels().forEach(onModelRemoved);
  1439. for (let key in this._listener) {
  1440. this._listener[key].dispose();
  1441. }
  1442. }
  1443. });
  1444. monaco_editor_core_exports.editor.getModels().forEach(onModelAdd);
  1445. }
  1446. _disposables = [];
  1447. _listener = /* @__PURE__ */ Object.create(null);
  1448. dispose() {
  1449. this._disposables.forEach((d) => d && d.dispose());
  1450. this._disposables.length = 0;
  1451. }
  1452. _doValidate(resource, languageId) {
  1453. this._worker(resource).then((worker) => {
  1454. return worker.doValidation(resource.toString());
  1455. }).then((diagnostics) => {
  1456. const markers = diagnostics.map((d) => toDiagnostics(resource, d));
  1457. let model = monaco_editor_core_exports.editor.getModel(resource);
  1458. if (model && model.getLanguageId() === languageId) {
  1459. monaco_editor_core_exports.editor.setModelMarkers(model, languageId, markers);
  1460. }
  1461. }).then(void 0, (err) => {
  1462. console.error(err);
  1463. });
  1464. }
  1465. };
  1466. function toSeverity(lsSeverity) {
  1467. switch (lsSeverity) {
  1468. case DiagnosticSeverity.Error:
  1469. return monaco_editor_core_exports.MarkerSeverity.Error;
  1470. case DiagnosticSeverity.Warning:
  1471. return monaco_editor_core_exports.MarkerSeverity.Warning;
  1472. case DiagnosticSeverity.Information:
  1473. return monaco_editor_core_exports.MarkerSeverity.Info;
  1474. case DiagnosticSeverity.Hint:
  1475. return monaco_editor_core_exports.MarkerSeverity.Hint;
  1476. default:
  1477. return monaco_editor_core_exports.MarkerSeverity.Info;
  1478. }
  1479. }
  1480. function toDiagnostics(resource, diag) {
  1481. let code = typeof diag.code === "number" ? String(diag.code) : diag.code;
  1482. return {
  1483. severity: toSeverity(diag.severity),
  1484. startLineNumber: diag.range.start.line + 1,
  1485. startColumn: diag.range.start.character + 1,
  1486. endLineNumber: diag.range.end.line + 1,
  1487. endColumn: diag.range.end.character + 1,
  1488. message: diag.message,
  1489. code,
  1490. source: diag.source
  1491. };
  1492. }
  1493. var CompletionAdapter = class {
  1494. constructor(_worker, _triggerCharacters) {
  1495. this._worker = _worker;
  1496. this._triggerCharacters = _triggerCharacters;
  1497. }
  1498. get triggerCharacters() {
  1499. return this._triggerCharacters;
  1500. }
  1501. provideCompletionItems(model, position, context, token) {
  1502. const resource = model.uri;
  1503. return this._worker(resource).then((worker) => {
  1504. return worker.doComplete(resource.toString(), fromPosition(position));
  1505. }).then((info) => {
  1506. if (!info) {
  1507. return;
  1508. }
  1509. const wordInfo = model.getWordUntilPosition(position);
  1510. const wordRange = new monaco_editor_core_exports.Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn);
  1511. const items = info.items.map((entry) => {
  1512. const item = {
  1513. label: entry.label,
  1514. insertText: entry.insertText || entry.label,
  1515. sortText: entry.sortText,
  1516. filterText: entry.filterText,
  1517. documentation: entry.documentation,
  1518. detail: entry.detail,
  1519. command: toCommand(entry.command),
  1520. range: wordRange,
  1521. kind: toCompletionItemKind(entry.kind)
  1522. };
  1523. if (entry.textEdit) {
  1524. if (isInsertReplaceEdit(entry.textEdit)) {
  1525. item.range = {
  1526. insert: toRange(entry.textEdit.insert),
  1527. replace: toRange(entry.textEdit.replace)
  1528. };
  1529. } else {
  1530. item.range = toRange(entry.textEdit.range);
  1531. }
  1532. item.insertText = entry.textEdit.newText;
  1533. }
  1534. if (entry.additionalTextEdits) {
  1535. item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
  1536. }
  1537. if (entry.insertTextFormat === InsertTextFormat.Snippet) {
  1538. item.insertTextRules = monaco_editor_core_exports.languages.CompletionItemInsertTextRule.InsertAsSnippet;
  1539. }
  1540. return item;
  1541. });
  1542. return {
  1543. isIncomplete: info.isIncomplete,
  1544. suggestions: items
  1545. };
  1546. });
  1547. }
  1548. };
  1549. function fromPosition(position) {
  1550. if (!position) {
  1551. return void 0;
  1552. }
  1553. return { character: position.column - 1, line: position.lineNumber - 1 };
  1554. }
  1555. function fromRange(range) {
  1556. if (!range) {
  1557. return void 0;
  1558. }
  1559. return {
  1560. start: {
  1561. line: range.startLineNumber - 1,
  1562. character: range.startColumn - 1
  1563. },
  1564. end: { line: range.endLineNumber - 1, character: range.endColumn - 1 }
  1565. };
  1566. }
  1567. function toRange(range) {
  1568. if (!range) {
  1569. return void 0;
  1570. }
  1571. return new monaco_editor_core_exports.Range(range.start.line + 1, range.start.character + 1, range.end.line + 1, range.end.character + 1);
  1572. }
  1573. function isInsertReplaceEdit(edit) {
  1574. return typeof edit.insert !== "undefined" && typeof edit.replace !== "undefined";
  1575. }
  1576. function toCompletionItemKind(kind) {
  1577. const mItemKind = monaco_editor_core_exports.languages.CompletionItemKind;
  1578. switch (kind) {
  1579. case CompletionItemKind.Text:
  1580. return mItemKind.Text;
  1581. case CompletionItemKind.Method:
  1582. return mItemKind.Method;
  1583. case CompletionItemKind.Function:
  1584. return mItemKind.Function;
  1585. case CompletionItemKind.Constructor:
  1586. return mItemKind.Constructor;
  1587. case CompletionItemKind.Field:
  1588. return mItemKind.Field;
  1589. case CompletionItemKind.Variable:
  1590. return mItemKind.Variable;
  1591. case CompletionItemKind.Class:
  1592. return mItemKind.Class;
  1593. case CompletionItemKind.Interface:
  1594. return mItemKind.Interface;
  1595. case CompletionItemKind.Module:
  1596. return mItemKind.Module;
  1597. case CompletionItemKind.Property:
  1598. return mItemKind.Property;
  1599. case CompletionItemKind.Unit:
  1600. return mItemKind.Unit;
  1601. case CompletionItemKind.Value:
  1602. return mItemKind.Value;
  1603. case CompletionItemKind.Enum:
  1604. return mItemKind.Enum;
  1605. case CompletionItemKind.Keyword:
  1606. return mItemKind.Keyword;
  1607. case CompletionItemKind.Snippet:
  1608. return mItemKind.Snippet;
  1609. case CompletionItemKind.Color:
  1610. return mItemKind.Color;
  1611. case CompletionItemKind.File:
  1612. return mItemKind.File;
  1613. case CompletionItemKind.Reference:
  1614. return mItemKind.Reference;
  1615. }
  1616. return mItemKind.Property;
  1617. }
  1618. function toTextEdit(textEdit) {
  1619. if (!textEdit) {
  1620. return void 0;
  1621. }
  1622. return {
  1623. range: toRange(textEdit.range),
  1624. text: textEdit.newText
  1625. };
  1626. }
  1627. function toCommand(c) {
  1628. return c && c.command === "editor.action.triggerSuggest" ? { id: c.command, title: c.title, arguments: c.arguments } : void 0;
  1629. }
  1630. var HoverAdapter = class {
  1631. constructor(_worker) {
  1632. this._worker = _worker;
  1633. }
  1634. provideHover(model, position, token) {
  1635. let resource = model.uri;
  1636. return this._worker(resource).then((worker) => {
  1637. return worker.doHover(resource.toString(), fromPosition(position));
  1638. }).then((info) => {
  1639. if (!info) {
  1640. return;
  1641. }
  1642. return {
  1643. range: toRange(info.range),
  1644. contents: toMarkedStringArray(info.contents)
  1645. };
  1646. });
  1647. }
  1648. };
  1649. function isMarkupContent(thing) {
  1650. return thing && typeof thing === "object" && typeof thing.kind === "string";
  1651. }
  1652. function toMarkdownString(entry) {
  1653. if (typeof entry === "string") {
  1654. return {
  1655. value: entry
  1656. };
  1657. }
  1658. if (isMarkupContent(entry)) {
  1659. if (entry.kind === "plaintext") {
  1660. return {
  1661. value: entry.value.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&")
  1662. };
  1663. }
  1664. return {
  1665. value: entry.value
  1666. };
  1667. }
  1668. return { value: "```" + entry.language + "\n" + entry.value + "\n```\n" };
  1669. }
  1670. function toMarkedStringArray(contents) {
  1671. if (!contents) {
  1672. return void 0;
  1673. }
  1674. if (Array.isArray(contents)) {
  1675. return contents.map(toMarkdownString);
  1676. }
  1677. return [toMarkdownString(contents)];
  1678. }
  1679. var DocumentHighlightAdapter = class {
  1680. constructor(_worker) {
  1681. this._worker = _worker;
  1682. }
  1683. provideDocumentHighlights(model, position, token) {
  1684. const resource = model.uri;
  1685. return this._worker(resource).then((worker) => worker.findDocumentHighlights(resource.toString(), fromPosition(position))).then((entries) => {
  1686. if (!entries) {
  1687. return;
  1688. }
  1689. return entries.map((entry) => {
  1690. return {
  1691. range: toRange(entry.range),
  1692. kind: toDocumentHighlightKind(entry.kind)
  1693. };
  1694. });
  1695. });
  1696. }
  1697. };
  1698. function toDocumentHighlightKind(kind) {
  1699. switch (kind) {
  1700. case DocumentHighlightKind.Read:
  1701. return monaco_editor_core_exports.languages.DocumentHighlightKind.Read;
  1702. case DocumentHighlightKind.Write:
  1703. return monaco_editor_core_exports.languages.DocumentHighlightKind.Write;
  1704. case DocumentHighlightKind.Text:
  1705. return monaco_editor_core_exports.languages.DocumentHighlightKind.Text;
  1706. }
  1707. return monaco_editor_core_exports.languages.DocumentHighlightKind.Text;
  1708. }
  1709. var DefinitionAdapter = class {
  1710. constructor(_worker) {
  1711. this._worker = _worker;
  1712. }
  1713. provideDefinition(model, position, token) {
  1714. const resource = model.uri;
  1715. return this._worker(resource).then((worker) => {
  1716. return worker.findDefinition(resource.toString(), fromPosition(position));
  1717. }).then((definition) => {
  1718. if (!definition) {
  1719. return;
  1720. }
  1721. return [toLocation(definition)];
  1722. });
  1723. }
  1724. };
  1725. function toLocation(location) {
  1726. return {
  1727. uri: monaco_editor_core_exports.Uri.parse(location.uri),
  1728. range: toRange(location.range)
  1729. };
  1730. }
  1731. var ReferenceAdapter = class {
  1732. constructor(_worker) {
  1733. this._worker = _worker;
  1734. }
  1735. provideReferences(model, position, context, token) {
  1736. const resource = model.uri;
  1737. return this._worker(resource).then((worker) => {
  1738. return worker.findReferences(resource.toString(), fromPosition(position));
  1739. }).then((entries) => {
  1740. if (!entries) {
  1741. return;
  1742. }
  1743. return entries.map(toLocation);
  1744. });
  1745. }
  1746. };
  1747. var RenameAdapter = class {
  1748. constructor(_worker) {
  1749. this._worker = _worker;
  1750. }
  1751. provideRenameEdits(model, position, newName, token) {
  1752. const resource = model.uri;
  1753. return this._worker(resource).then((worker) => {
  1754. return worker.doRename(resource.toString(), fromPosition(position), newName);
  1755. }).then((edit) => {
  1756. return toWorkspaceEdit(edit);
  1757. });
  1758. }
  1759. };
  1760. function toWorkspaceEdit(edit) {
  1761. if (!edit || !edit.changes) {
  1762. return void 0;
  1763. }
  1764. let resourceEdits = [];
  1765. for (let uri in edit.changes) {
  1766. const _uri = monaco_editor_core_exports.Uri.parse(uri);
  1767. for (let e of edit.changes[uri]) {
  1768. resourceEdits.push({
  1769. resource: _uri,
  1770. versionId: void 0,
  1771. textEdit: {
  1772. range: toRange(e.range),
  1773. text: e.newText
  1774. }
  1775. });
  1776. }
  1777. }
  1778. return {
  1779. edits: resourceEdits
  1780. };
  1781. }
  1782. var DocumentSymbolAdapter = class {
  1783. constructor(_worker) {
  1784. this._worker = _worker;
  1785. }
  1786. provideDocumentSymbols(model, token) {
  1787. const resource = model.uri;
  1788. return this._worker(resource).then((worker) => worker.findDocumentSymbols(resource.toString())).then((items) => {
  1789. if (!items) {
  1790. return;
  1791. }
  1792. return items.map((item) => ({
  1793. name: item.name,
  1794. detail: "",
  1795. containerName: item.containerName,
  1796. kind: toSymbolKind(item.kind),
  1797. range: toRange(item.location.range),
  1798. selectionRange: toRange(item.location.range),
  1799. tags: []
  1800. }));
  1801. });
  1802. }
  1803. };
  1804. function toSymbolKind(kind) {
  1805. let mKind = monaco_editor_core_exports.languages.SymbolKind;
  1806. switch (kind) {
  1807. case SymbolKind.File:
  1808. return mKind.Array;
  1809. case SymbolKind.Module:
  1810. return mKind.Module;
  1811. case SymbolKind.Namespace:
  1812. return mKind.Namespace;
  1813. case SymbolKind.Package:
  1814. return mKind.Package;
  1815. case SymbolKind.Class:
  1816. return mKind.Class;
  1817. case SymbolKind.Method:
  1818. return mKind.Method;
  1819. case SymbolKind.Property:
  1820. return mKind.Property;
  1821. case SymbolKind.Field:
  1822. return mKind.Field;
  1823. case SymbolKind.Constructor:
  1824. return mKind.Constructor;
  1825. case SymbolKind.Enum:
  1826. return mKind.Enum;
  1827. case SymbolKind.Interface:
  1828. return mKind.Interface;
  1829. case SymbolKind.Function:
  1830. return mKind.Function;
  1831. case SymbolKind.Variable:
  1832. return mKind.Variable;
  1833. case SymbolKind.Constant:
  1834. return mKind.Constant;
  1835. case SymbolKind.String:
  1836. return mKind.String;
  1837. case SymbolKind.Number:
  1838. return mKind.Number;
  1839. case SymbolKind.Boolean:
  1840. return mKind.Boolean;
  1841. case SymbolKind.Array:
  1842. return mKind.Array;
  1843. }
  1844. return mKind.Function;
  1845. }
  1846. var DocumentLinkAdapter = class {
  1847. constructor(_worker) {
  1848. this._worker = _worker;
  1849. }
  1850. provideLinks(model, token) {
  1851. const resource = model.uri;
  1852. return this._worker(resource).then((worker) => worker.findDocumentLinks(resource.toString())).then((items) => {
  1853. if (!items) {
  1854. return;
  1855. }
  1856. return {
  1857. links: items.map((item) => ({
  1858. range: toRange(item.range),
  1859. url: item.target
  1860. }))
  1861. };
  1862. });
  1863. }
  1864. };
  1865. var DocumentFormattingEditProvider = class {
  1866. constructor(_worker) {
  1867. this._worker = _worker;
  1868. }
  1869. provideDocumentFormattingEdits(model, options, token) {
  1870. const resource = model.uri;
  1871. return this._worker(resource).then((worker) => {
  1872. return worker.format(resource.toString(), null, fromFormattingOptions(options)).then((edits) => {
  1873. if (!edits || edits.length === 0) {
  1874. return;
  1875. }
  1876. return edits.map(toTextEdit);
  1877. });
  1878. });
  1879. }
  1880. };
  1881. var DocumentRangeFormattingEditProvider = class {
  1882. constructor(_worker) {
  1883. this._worker = _worker;
  1884. }
  1885. canFormatMultipleRanges = false;
  1886. provideDocumentRangeFormattingEdits(model, range, options, token) {
  1887. const resource = model.uri;
  1888. return this._worker(resource).then((worker) => {
  1889. return worker.format(resource.toString(), fromRange(range), fromFormattingOptions(options)).then((edits) => {
  1890. if (!edits || edits.length === 0) {
  1891. return;
  1892. }
  1893. return edits.map(toTextEdit);
  1894. });
  1895. });
  1896. }
  1897. };
  1898. function fromFormattingOptions(options) {
  1899. return {
  1900. tabSize: options.tabSize,
  1901. insertSpaces: options.insertSpaces
  1902. };
  1903. }
  1904. var DocumentColorAdapter = class {
  1905. constructor(_worker) {
  1906. this._worker = _worker;
  1907. }
  1908. provideDocumentColors(model, token) {
  1909. const resource = model.uri;
  1910. return this._worker(resource).then((worker) => worker.findDocumentColors(resource.toString())).then((infos) => {
  1911. if (!infos) {
  1912. return;
  1913. }
  1914. return infos.map((item) => ({
  1915. color: item.color,
  1916. range: toRange(item.range)
  1917. }));
  1918. });
  1919. }
  1920. provideColorPresentations(model, info, token) {
  1921. const resource = model.uri;
  1922. return this._worker(resource).then((worker) => worker.getColorPresentations(resource.toString(), info.color, fromRange(info.range))).then((presentations) => {
  1923. if (!presentations) {
  1924. return;
  1925. }
  1926. return presentations.map((presentation) => {
  1927. let item = {
  1928. label: presentation.label
  1929. };
  1930. if (presentation.textEdit) {
  1931. item.textEdit = toTextEdit(presentation.textEdit);
  1932. }
  1933. if (presentation.additionalTextEdits) {
  1934. item.additionalTextEdits = presentation.additionalTextEdits.map(toTextEdit);
  1935. }
  1936. return item;
  1937. });
  1938. });
  1939. }
  1940. };
  1941. var FoldingRangeAdapter = class {
  1942. constructor(_worker) {
  1943. this._worker = _worker;
  1944. }
  1945. provideFoldingRanges(model, context, token) {
  1946. const resource = model.uri;
  1947. return this._worker(resource).then((worker) => worker.getFoldingRanges(resource.toString(), context)).then((ranges) => {
  1948. if (!ranges) {
  1949. return;
  1950. }
  1951. return ranges.map((range) => {
  1952. const result = {
  1953. start: range.startLine + 1,
  1954. end: range.endLine + 1
  1955. };
  1956. if (typeof range.kind !== "undefined") {
  1957. result.kind = toFoldingRangeKind(range.kind);
  1958. }
  1959. return result;
  1960. });
  1961. });
  1962. }
  1963. };
  1964. function toFoldingRangeKind(kind) {
  1965. switch (kind) {
  1966. case FoldingRangeKind.Comment:
  1967. return monaco_editor_core_exports.languages.FoldingRangeKind.Comment;
  1968. case FoldingRangeKind.Imports:
  1969. return monaco_editor_core_exports.languages.FoldingRangeKind.Imports;
  1970. case FoldingRangeKind.Region:
  1971. return monaco_editor_core_exports.languages.FoldingRangeKind.Region;
  1972. }
  1973. return void 0;
  1974. }
  1975. var SelectionRangeAdapter = class {
  1976. constructor(_worker) {
  1977. this._worker = _worker;
  1978. }
  1979. provideSelectionRanges(model, positions, token) {
  1980. const resource = model.uri;
  1981. return this._worker(resource).then((worker) => worker.getSelectionRanges(resource.toString(), positions.map(fromPosition))).then((selectionRanges) => {
  1982. if (!selectionRanges) {
  1983. return;
  1984. }
  1985. return selectionRanges.map((selectionRange) => {
  1986. const result = [];
  1987. while (selectionRange) {
  1988. result.push({ range: toRange(selectionRange.range) });
  1989. selectionRange = selectionRange.parent;
  1990. }
  1991. return result;
  1992. });
  1993. });
  1994. }
  1995. };
  1996. // src/language/html/htmlMode.ts
  1997. var HTMLCompletionAdapter = class extends CompletionAdapter {
  1998. constructor(worker) {
  1999. super(worker, [".", ":", "<", '"', "=", "/"]);
  2000. }
  2001. };
  2002. function setupMode1(defaults) {
  2003. const client = new WorkerManager(defaults);
  2004. const worker = (...uris) => {
  2005. return client.getLanguageServiceWorker(...uris);
  2006. };
  2007. let languageId = defaults.languageId;
  2008. monaco_editor_core_exports.languages.registerCompletionItemProvider(languageId, new HTMLCompletionAdapter(worker));
  2009. monaco_editor_core_exports.languages.registerHoverProvider(languageId, new HoverAdapter(worker));
  2010. monaco_editor_core_exports.languages.registerDocumentHighlightProvider(languageId, new DocumentHighlightAdapter(worker));
  2011. monaco_editor_core_exports.languages.registerLinkProvider(languageId, new DocumentLinkAdapter(worker));
  2012. monaco_editor_core_exports.languages.registerFoldingRangeProvider(languageId, new FoldingRangeAdapter(worker));
  2013. monaco_editor_core_exports.languages.registerDocumentSymbolProvider(languageId, new DocumentSymbolAdapter(worker));
  2014. monaco_editor_core_exports.languages.registerSelectionRangeProvider(languageId, new SelectionRangeAdapter(worker));
  2015. monaco_editor_core_exports.languages.registerRenameProvider(languageId, new RenameAdapter(worker));
  2016. if (languageId === "html") {
  2017. monaco_editor_core_exports.languages.registerDocumentFormattingEditProvider(languageId, new DocumentFormattingEditProvider(worker));
  2018. monaco_editor_core_exports.languages.registerDocumentRangeFormattingEditProvider(languageId, new DocumentRangeFormattingEditProvider(worker));
  2019. }
  2020. }
  2021. function setupMode(defaults) {
  2022. const disposables = [];
  2023. const providers = [];
  2024. const client = new WorkerManager(defaults);
  2025. disposables.push(client);
  2026. const worker = (...uris) => {
  2027. return client.getLanguageServiceWorker(...uris);
  2028. };
  2029. function registerProviders() {
  2030. const { languageId, modeConfiguration } = defaults;
  2031. disposeAll(providers);
  2032. if (modeConfiguration.completionItems) {
  2033. providers.push(monaco_editor_core_exports.languages.registerCompletionItemProvider(languageId, new HTMLCompletionAdapter(worker)));
  2034. }
  2035. if (modeConfiguration.hovers) {
  2036. providers.push(monaco_editor_core_exports.languages.registerHoverProvider(languageId, new HoverAdapter(worker)));
  2037. }
  2038. if (modeConfiguration.documentHighlights) {
  2039. providers.push(monaco_editor_core_exports.languages.registerDocumentHighlightProvider(languageId, new DocumentHighlightAdapter(worker)));
  2040. }
  2041. if (modeConfiguration.links) {
  2042. providers.push(monaco_editor_core_exports.languages.registerLinkProvider(languageId, new DocumentLinkAdapter(worker)));
  2043. }
  2044. if (modeConfiguration.documentSymbols) {
  2045. providers.push(monaco_editor_core_exports.languages.registerDocumentSymbolProvider(languageId, new DocumentSymbolAdapter(worker)));
  2046. }
  2047. if (modeConfiguration.rename) {
  2048. providers.push(monaco_editor_core_exports.languages.registerRenameProvider(languageId, new RenameAdapter(worker)));
  2049. }
  2050. if (modeConfiguration.foldingRanges) {
  2051. providers.push(monaco_editor_core_exports.languages.registerFoldingRangeProvider(languageId, new FoldingRangeAdapter(worker)));
  2052. }
  2053. if (modeConfiguration.selectionRanges) {
  2054. providers.push(monaco_editor_core_exports.languages.registerSelectionRangeProvider(languageId, new SelectionRangeAdapter(worker)));
  2055. }
  2056. if (modeConfiguration.documentFormattingEdits) {
  2057. providers.push(monaco_editor_core_exports.languages.registerDocumentFormattingEditProvider(languageId, new DocumentFormattingEditProvider(worker)));
  2058. }
  2059. if (modeConfiguration.documentRangeFormattingEdits) {
  2060. providers.push(monaco_editor_core_exports.languages.registerDocumentRangeFormattingEditProvider(languageId, new DocumentRangeFormattingEditProvider(worker)));
  2061. }
  2062. }
  2063. registerProviders();
  2064. disposables.push(asDisposable(providers));
  2065. return asDisposable(disposables);
  2066. }
  2067. function asDisposable(disposables) {
  2068. return { dispose: () => disposeAll(disposables) };
  2069. }
  2070. function disposeAll(disposables) {
  2071. while (disposables.length) {
  2072. disposables.pop().dispose();
  2073. }
  2074. }
  2075. return __toCommonJS(htmlMode_exports);
  2076. })();
  2077. return moduleExports;
  2078. });