htmlMode.js 62 KB

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