jsonMode.js 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.38.0(0e330ae453813de4e6cf272460fb79c7117073d0)
  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 __copyProps = (to, from, except, desc) => {
  12. if (from && typeof from === "object" || typeof from === "function") {
  13. for (let key of __getOwnPropNames(from))
  14. if (!__hasOwnProp.call(to, key) && key !== except)
  15. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  16. }
  17. return to;
  18. };
  19. var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
  20. // src/fillers/monaco-editor-core.ts
  21. var monaco_editor_core_exports = {};
  22. __reExport(monaco_editor_core_exports, monaco_editor_core_star);
  23. import * as monaco_editor_core_star from "../../editor/editor.api.js";
  24. // src/language/json/workerManager.ts
  25. var STOP_WHEN_IDLE_FOR = 2 * 60 * 1e3;
  26. var WorkerManager = class {
  27. _defaults;
  28. _idleCheckInterval;
  29. _lastUsedTime;
  30. _configChangeListener;
  31. _worker;
  32. _client;
  33. constructor(defaults) {
  34. this._defaults = defaults;
  35. this._worker = null;
  36. this._client = null;
  37. this._idleCheckInterval = window.setInterval(() => this._checkIfIdle(), 30 * 1e3);
  38. this._lastUsedTime = 0;
  39. this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());
  40. }
  41. _stopWorker() {
  42. if (this._worker) {
  43. this._worker.dispose();
  44. this._worker = null;
  45. }
  46. this._client = null;
  47. }
  48. dispose() {
  49. clearInterval(this._idleCheckInterval);
  50. this._configChangeListener.dispose();
  51. this._stopWorker();
  52. }
  53. _checkIfIdle() {
  54. if (!this._worker) {
  55. return;
  56. }
  57. let timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
  58. if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
  59. this._stopWorker();
  60. }
  61. }
  62. _getClient() {
  63. this._lastUsedTime = Date.now();
  64. if (!this._client) {
  65. this._worker = monaco_editor_core_exports.editor.createWebWorker({
  66. moduleId: "vs/language/json/jsonWorker",
  67. label: this._defaults.languageId,
  68. createData: {
  69. languageSettings: this._defaults.diagnosticsOptions,
  70. languageId: this._defaults.languageId,
  71. enableSchemaRequest: this._defaults.diagnosticsOptions.enableSchemaRequest
  72. }
  73. });
  74. this._client = this._worker.getProxy();
  75. }
  76. return this._client;
  77. }
  78. getLanguageServiceWorker(...resources) {
  79. let _client;
  80. return this._getClient().then((client) => {
  81. _client = client;
  82. }).then((_) => {
  83. if (this._worker) {
  84. return this._worker.withSyncedResources(resources);
  85. }
  86. }).then((_) => _client);
  87. }
  88. };
  89. // node_modules/vscode-languageserver-types/lib/esm/main.js
  90. var integer;
  91. (function(integer2) {
  92. integer2.MIN_VALUE = -2147483648;
  93. integer2.MAX_VALUE = 2147483647;
  94. })(integer || (integer = {}));
  95. var uinteger;
  96. (function(uinteger2) {
  97. uinteger2.MIN_VALUE = 0;
  98. uinteger2.MAX_VALUE = 2147483647;
  99. })(uinteger || (uinteger = {}));
  100. var Position;
  101. (function(Position3) {
  102. function create(line, character) {
  103. if (line === Number.MAX_VALUE) {
  104. line = uinteger.MAX_VALUE;
  105. }
  106. if (character === Number.MAX_VALUE) {
  107. character = uinteger.MAX_VALUE;
  108. }
  109. return { line, character };
  110. }
  111. Position3.create = create;
  112. function is(value) {
  113. var candidate = value;
  114. return Is.objectLiteral(candidate) && Is.uinteger(candidate.line) && Is.uinteger(candidate.character);
  115. }
  116. Position3.is = is;
  117. })(Position || (Position = {}));
  118. var Range;
  119. (function(Range3) {
  120. function create(one, two, three, four) {
  121. if (Is.uinteger(one) && Is.uinteger(two) && Is.uinteger(three) && Is.uinteger(four)) {
  122. return { start: Position.create(one, two), end: Position.create(three, four) };
  123. } else if (Position.is(one) && Position.is(two)) {
  124. return { start: one, end: two };
  125. } else {
  126. throw new Error("Range#create called with invalid arguments[" + one + ", " + two + ", " + three + ", " + four + "]");
  127. }
  128. }
  129. Range3.create = create;
  130. function is(value) {
  131. var candidate = value;
  132. return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
  133. }
  134. Range3.is = is;
  135. })(Range || (Range = {}));
  136. var Location;
  137. (function(Location2) {
  138. function create(uri, range) {
  139. return { uri, range };
  140. }
  141. Location2.create = create;
  142. function is(value) {
  143. var candidate = value;
  144. return Is.defined(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
  145. }
  146. Location2.is = is;
  147. })(Location || (Location = {}));
  148. var LocationLink;
  149. (function(LocationLink2) {
  150. function create(targetUri, targetRange, targetSelectionRange, originSelectionRange) {
  151. return { targetUri, targetRange, targetSelectionRange, originSelectionRange };
  152. }
  153. LocationLink2.create = create;
  154. function is(value) {
  155. var candidate = value;
  156. 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));
  157. }
  158. LocationLink2.is = is;
  159. })(LocationLink || (LocationLink = {}));
  160. var Color;
  161. (function(Color2) {
  162. function create(red, green, blue, alpha) {
  163. return {
  164. red,
  165. green,
  166. blue,
  167. alpha
  168. };
  169. }
  170. Color2.create = create;
  171. function is(value) {
  172. var candidate = value;
  173. 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);
  174. }
  175. Color2.is = is;
  176. })(Color || (Color = {}));
  177. var ColorInformation;
  178. (function(ColorInformation2) {
  179. function create(range, color) {
  180. return {
  181. range,
  182. color
  183. };
  184. }
  185. ColorInformation2.create = create;
  186. function is(value) {
  187. var candidate = value;
  188. return Range.is(candidate.range) && Color.is(candidate.color);
  189. }
  190. ColorInformation2.is = is;
  191. })(ColorInformation || (ColorInformation = {}));
  192. var ColorPresentation;
  193. (function(ColorPresentation2) {
  194. function create(label, textEdit, additionalTextEdits) {
  195. return {
  196. label,
  197. textEdit,
  198. additionalTextEdits
  199. };
  200. }
  201. ColorPresentation2.create = create;
  202. function is(value) {
  203. var candidate = value;
  204. return Is.string(candidate.label) && (Is.undefined(candidate.textEdit) || TextEdit.is(candidate)) && (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is));
  205. }
  206. ColorPresentation2.is = is;
  207. })(ColorPresentation || (ColorPresentation = {}));
  208. var FoldingRangeKind;
  209. (function(FoldingRangeKind2) {
  210. FoldingRangeKind2["Comment"] = "comment";
  211. FoldingRangeKind2["Imports"] = "imports";
  212. FoldingRangeKind2["Region"] = "region";
  213. })(FoldingRangeKind || (FoldingRangeKind = {}));
  214. var FoldingRange;
  215. (function(FoldingRange2) {
  216. function create(startLine, endLine, startCharacter, endCharacter, kind) {
  217. var result = {
  218. startLine,
  219. endLine
  220. };
  221. if (Is.defined(startCharacter)) {
  222. result.startCharacter = startCharacter;
  223. }
  224. if (Is.defined(endCharacter)) {
  225. result.endCharacter = endCharacter;
  226. }
  227. if (Is.defined(kind)) {
  228. result.kind = kind;
  229. }
  230. return result;
  231. }
  232. FoldingRange2.create = create;
  233. function is(value) {
  234. var candidate = value;
  235. 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));
  236. }
  237. FoldingRange2.is = is;
  238. })(FoldingRange || (FoldingRange = {}));
  239. var DiagnosticRelatedInformation;
  240. (function(DiagnosticRelatedInformation2) {
  241. function create(location, message) {
  242. return {
  243. location,
  244. message
  245. };
  246. }
  247. DiagnosticRelatedInformation2.create = create;
  248. function is(value) {
  249. var candidate = value;
  250. return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message);
  251. }
  252. DiagnosticRelatedInformation2.is = is;
  253. })(DiagnosticRelatedInformation || (DiagnosticRelatedInformation = {}));
  254. var DiagnosticSeverity;
  255. (function(DiagnosticSeverity2) {
  256. DiagnosticSeverity2.Error = 1;
  257. DiagnosticSeverity2.Warning = 2;
  258. DiagnosticSeverity2.Information = 3;
  259. DiagnosticSeverity2.Hint = 4;
  260. })(DiagnosticSeverity || (DiagnosticSeverity = {}));
  261. var DiagnosticTag;
  262. (function(DiagnosticTag2) {
  263. DiagnosticTag2.Unnecessary = 1;
  264. DiagnosticTag2.Deprecated = 2;
  265. })(DiagnosticTag || (DiagnosticTag = {}));
  266. var CodeDescription;
  267. (function(CodeDescription2) {
  268. function is(value) {
  269. var candidate = value;
  270. return candidate !== void 0 && candidate !== null && Is.string(candidate.href);
  271. }
  272. CodeDescription2.is = is;
  273. })(CodeDescription || (CodeDescription = {}));
  274. var Diagnostic;
  275. (function(Diagnostic2) {
  276. function create(range, message, severity, code, source, relatedInformation) {
  277. var result = { range, message };
  278. if (Is.defined(severity)) {
  279. result.severity = severity;
  280. }
  281. if (Is.defined(code)) {
  282. result.code = code;
  283. }
  284. if (Is.defined(source)) {
  285. result.source = source;
  286. }
  287. if (Is.defined(relatedInformation)) {
  288. result.relatedInformation = relatedInformation;
  289. }
  290. return result;
  291. }
  292. Diagnostic2.create = create;
  293. function is(value) {
  294. var _a;
  295. var candidate = value;
  296. 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));
  297. }
  298. Diagnostic2.is = is;
  299. })(Diagnostic || (Diagnostic = {}));
  300. var Command;
  301. (function(Command2) {
  302. function create(title, command) {
  303. var args = [];
  304. for (var _i = 2; _i < arguments.length; _i++) {
  305. args[_i - 2] = arguments[_i];
  306. }
  307. var result = { title, command };
  308. if (Is.defined(args) && args.length > 0) {
  309. result.arguments = args;
  310. }
  311. return result;
  312. }
  313. Command2.create = create;
  314. function is(value) {
  315. var candidate = value;
  316. return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command);
  317. }
  318. Command2.is = is;
  319. })(Command || (Command = {}));
  320. var TextEdit;
  321. (function(TextEdit2) {
  322. function replace(range, newText) {
  323. return { range, newText };
  324. }
  325. TextEdit2.replace = replace;
  326. function insert(position, newText) {
  327. return { range: { start: position, end: position }, newText };
  328. }
  329. TextEdit2.insert = insert;
  330. function del(range) {
  331. return { range, newText: "" };
  332. }
  333. TextEdit2.del = del;
  334. function is(value) {
  335. var candidate = value;
  336. return Is.objectLiteral(candidate) && Is.string(candidate.newText) && Range.is(candidate.range);
  337. }
  338. TextEdit2.is = is;
  339. })(TextEdit || (TextEdit = {}));
  340. var ChangeAnnotation;
  341. (function(ChangeAnnotation2) {
  342. function create(label, needsConfirmation, description) {
  343. var result = { label };
  344. if (needsConfirmation !== void 0) {
  345. result.needsConfirmation = needsConfirmation;
  346. }
  347. if (description !== void 0) {
  348. result.description = description;
  349. }
  350. return result;
  351. }
  352. ChangeAnnotation2.create = create;
  353. function is(value) {
  354. var candidate = value;
  355. 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);
  356. }
  357. ChangeAnnotation2.is = is;
  358. })(ChangeAnnotation || (ChangeAnnotation = {}));
  359. var ChangeAnnotationIdentifier;
  360. (function(ChangeAnnotationIdentifier2) {
  361. function is(value) {
  362. var candidate = value;
  363. return typeof candidate === "string";
  364. }
  365. ChangeAnnotationIdentifier2.is = is;
  366. })(ChangeAnnotationIdentifier || (ChangeAnnotationIdentifier = {}));
  367. var AnnotatedTextEdit;
  368. (function(AnnotatedTextEdit2) {
  369. function replace(range, newText, annotation) {
  370. return { range, newText, annotationId: annotation };
  371. }
  372. AnnotatedTextEdit2.replace = replace;
  373. function insert(position, newText, annotation) {
  374. return { range: { start: position, end: position }, newText, annotationId: annotation };
  375. }
  376. AnnotatedTextEdit2.insert = insert;
  377. function del(range, annotation) {
  378. return { range, newText: "", annotationId: annotation };
  379. }
  380. AnnotatedTextEdit2.del = del;
  381. function is(value) {
  382. var candidate = value;
  383. return TextEdit.is(candidate) && (ChangeAnnotation.is(candidate.annotationId) || ChangeAnnotationIdentifier.is(candidate.annotationId));
  384. }
  385. AnnotatedTextEdit2.is = is;
  386. })(AnnotatedTextEdit || (AnnotatedTextEdit = {}));
  387. var TextDocumentEdit;
  388. (function(TextDocumentEdit2) {
  389. function create(textDocument, edits) {
  390. return { textDocument, edits };
  391. }
  392. TextDocumentEdit2.create = create;
  393. function is(value) {
  394. var candidate = value;
  395. return Is.defined(candidate) && OptionalVersionedTextDocumentIdentifier.is(candidate.textDocument) && Array.isArray(candidate.edits);
  396. }
  397. TextDocumentEdit2.is = is;
  398. })(TextDocumentEdit || (TextDocumentEdit = {}));
  399. var CreateFile;
  400. (function(CreateFile2) {
  401. function create(uri, options, annotation) {
  402. var result = {
  403. kind: "create",
  404. uri
  405. };
  406. if (options !== void 0 && (options.overwrite !== void 0 || options.ignoreIfExists !== void 0)) {
  407. result.options = options;
  408. }
  409. if (annotation !== void 0) {
  410. result.annotationId = annotation;
  411. }
  412. return result;
  413. }
  414. CreateFile2.create = create;
  415. function is(value) {
  416. var candidate = value;
  417. 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));
  418. }
  419. CreateFile2.is = is;
  420. })(CreateFile || (CreateFile = {}));
  421. var RenameFile;
  422. (function(RenameFile2) {
  423. function create(oldUri, newUri, options, annotation) {
  424. var result = {
  425. kind: "rename",
  426. oldUri,
  427. newUri
  428. };
  429. if (options !== void 0 && (options.overwrite !== void 0 || options.ignoreIfExists !== void 0)) {
  430. result.options = options;
  431. }
  432. if (annotation !== void 0) {
  433. result.annotationId = annotation;
  434. }
  435. return result;
  436. }
  437. RenameFile2.create = create;
  438. function is(value) {
  439. var candidate = value;
  440. 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));
  441. }
  442. RenameFile2.is = is;
  443. })(RenameFile || (RenameFile = {}));
  444. var DeleteFile;
  445. (function(DeleteFile2) {
  446. function create(uri, options, annotation) {
  447. var result = {
  448. kind: "delete",
  449. uri
  450. };
  451. if (options !== void 0 && (options.recursive !== void 0 || options.ignoreIfNotExists !== void 0)) {
  452. result.options = options;
  453. }
  454. if (annotation !== void 0) {
  455. result.annotationId = annotation;
  456. }
  457. return result;
  458. }
  459. DeleteFile2.create = create;
  460. function is(value) {
  461. var candidate = value;
  462. 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));
  463. }
  464. DeleteFile2.is = is;
  465. })(DeleteFile || (DeleteFile = {}));
  466. var WorkspaceEdit;
  467. (function(WorkspaceEdit2) {
  468. function is(value) {
  469. var candidate = value;
  470. return candidate && (candidate.changes !== void 0 || candidate.documentChanges !== void 0) && (candidate.documentChanges === void 0 || candidate.documentChanges.every(function(change) {
  471. if (Is.string(change.kind)) {
  472. return CreateFile.is(change) || RenameFile.is(change) || DeleteFile.is(change);
  473. } else {
  474. return TextDocumentEdit.is(change);
  475. }
  476. }));
  477. }
  478. WorkspaceEdit2.is = is;
  479. })(WorkspaceEdit || (WorkspaceEdit = {}));
  480. var TextEditChangeImpl = function() {
  481. function TextEditChangeImpl2(edits, changeAnnotations) {
  482. this.edits = edits;
  483. this.changeAnnotations = changeAnnotations;
  484. }
  485. TextEditChangeImpl2.prototype.insert = function(position, newText, annotation) {
  486. var edit;
  487. var id;
  488. if (annotation === void 0) {
  489. edit = TextEdit.insert(position, newText);
  490. } else if (ChangeAnnotationIdentifier.is(annotation)) {
  491. id = annotation;
  492. edit = AnnotatedTextEdit.insert(position, newText, annotation);
  493. } else {
  494. this.assertChangeAnnotations(this.changeAnnotations);
  495. id = this.changeAnnotations.manage(annotation);
  496. edit = AnnotatedTextEdit.insert(position, newText, id);
  497. }
  498. this.edits.push(edit);
  499. if (id !== void 0) {
  500. return id;
  501. }
  502. };
  503. TextEditChangeImpl2.prototype.replace = function(range, newText, annotation) {
  504. var edit;
  505. var id;
  506. if (annotation === void 0) {
  507. edit = TextEdit.replace(range, newText);
  508. } else if (ChangeAnnotationIdentifier.is(annotation)) {
  509. id = annotation;
  510. edit = AnnotatedTextEdit.replace(range, newText, annotation);
  511. } else {
  512. this.assertChangeAnnotations(this.changeAnnotations);
  513. id = this.changeAnnotations.manage(annotation);
  514. edit = AnnotatedTextEdit.replace(range, newText, id);
  515. }
  516. this.edits.push(edit);
  517. if (id !== void 0) {
  518. return id;
  519. }
  520. };
  521. TextEditChangeImpl2.prototype.delete = function(range, annotation) {
  522. var edit;
  523. var id;
  524. if (annotation === void 0) {
  525. edit = TextEdit.del(range);
  526. } else if (ChangeAnnotationIdentifier.is(annotation)) {
  527. id = annotation;
  528. edit = AnnotatedTextEdit.del(range, annotation);
  529. } else {
  530. this.assertChangeAnnotations(this.changeAnnotations);
  531. id = this.changeAnnotations.manage(annotation);
  532. edit = AnnotatedTextEdit.del(range, id);
  533. }
  534. this.edits.push(edit);
  535. if (id !== void 0) {
  536. return id;
  537. }
  538. };
  539. TextEditChangeImpl2.prototype.add = function(edit) {
  540. this.edits.push(edit);
  541. };
  542. TextEditChangeImpl2.prototype.all = function() {
  543. return this.edits;
  544. };
  545. TextEditChangeImpl2.prototype.clear = function() {
  546. this.edits.splice(0, this.edits.length);
  547. };
  548. TextEditChangeImpl2.prototype.assertChangeAnnotations = function(value) {
  549. if (value === void 0) {
  550. throw new Error("Text edit change is not configured to manage change annotations.");
  551. }
  552. };
  553. return TextEditChangeImpl2;
  554. }();
  555. var ChangeAnnotations = function() {
  556. function ChangeAnnotations2(annotations) {
  557. this._annotations = annotations === void 0 ? /* @__PURE__ */ Object.create(null) : annotations;
  558. this._counter = 0;
  559. this._size = 0;
  560. }
  561. ChangeAnnotations2.prototype.all = function() {
  562. return this._annotations;
  563. };
  564. Object.defineProperty(ChangeAnnotations2.prototype, "size", {
  565. get: function() {
  566. return this._size;
  567. },
  568. enumerable: false,
  569. configurable: true
  570. });
  571. ChangeAnnotations2.prototype.manage = function(idOrAnnotation, annotation) {
  572. var id;
  573. if (ChangeAnnotationIdentifier.is(idOrAnnotation)) {
  574. id = idOrAnnotation;
  575. } else {
  576. id = this.nextId();
  577. annotation = idOrAnnotation;
  578. }
  579. if (this._annotations[id] !== void 0) {
  580. throw new Error("Id " + id + " is already in use.");
  581. }
  582. if (annotation === void 0) {
  583. throw new Error("No annotation provided for id " + id);
  584. }
  585. this._annotations[id] = annotation;
  586. this._size++;
  587. return id;
  588. };
  589. ChangeAnnotations2.prototype.nextId = function() {
  590. this._counter++;
  591. return this._counter.toString();
  592. };
  593. return ChangeAnnotations2;
  594. }();
  595. var WorkspaceChange = function() {
  596. function WorkspaceChange2(workspaceEdit) {
  597. var _this = this;
  598. this._textEditChanges = /* @__PURE__ */ Object.create(null);
  599. if (workspaceEdit !== void 0) {
  600. this._workspaceEdit = workspaceEdit;
  601. if (workspaceEdit.documentChanges) {
  602. this._changeAnnotations = new ChangeAnnotations(workspaceEdit.changeAnnotations);
  603. workspaceEdit.changeAnnotations = this._changeAnnotations.all();
  604. workspaceEdit.documentChanges.forEach(function(change) {
  605. if (TextDocumentEdit.is(change)) {
  606. var textEditChange = new TextEditChangeImpl(change.edits, _this._changeAnnotations);
  607. _this._textEditChanges[change.textDocument.uri] = textEditChange;
  608. }
  609. });
  610. } else if (workspaceEdit.changes) {
  611. Object.keys(workspaceEdit.changes).forEach(function(key) {
  612. var textEditChange = new TextEditChangeImpl(workspaceEdit.changes[key]);
  613. _this._textEditChanges[key] = textEditChange;
  614. });
  615. }
  616. } else {
  617. this._workspaceEdit = {};
  618. }
  619. }
  620. Object.defineProperty(WorkspaceChange2.prototype, "edit", {
  621. get: function() {
  622. this.initDocumentChanges();
  623. if (this._changeAnnotations !== void 0) {
  624. if (this._changeAnnotations.size === 0) {
  625. this._workspaceEdit.changeAnnotations = void 0;
  626. } else {
  627. this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
  628. }
  629. }
  630. return this._workspaceEdit;
  631. },
  632. enumerable: false,
  633. configurable: true
  634. });
  635. WorkspaceChange2.prototype.getTextEditChange = function(key) {
  636. if (OptionalVersionedTextDocumentIdentifier.is(key)) {
  637. this.initDocumentChanges();
  638. if (this._workspaceEdit.documentChanges === void 0) {
  639. throw new Error("Workspace edit is not configured for document changes.");
  640. }
  641. var textDocument = { uri: key.uri, version: key.version };
  642. var result = this._textEditChanges[textDocument.uri];
  643. if (!result) {
  644. var edits = [];
  645. var textDocumentEdit = {
  646. textDocument,
  647. edits
  648. };
  649. this._workspaceEdit.documentChanges.push(textDocumentEdit);
  650. result = new TextEditChangeImpl(edits, this._changeAnnotations);
  651. this._textEditChanges[textDocument.uri] = result;
  652. }
  653. return result;
  654. } else {
  655. this.initChanges();
  656. if (this._workspaceEdit.changes === void 0) {
  657. throw new Error("Workspace edit is not configured for normal text edit changes.");
  658. }
  659. var result = this._textEditChanges[key];
  660. if (!result) {
  661. var edits = [];
  662. this._workspaceEdit.changes[key] = edits;
  663. result = new TextEditChangeImpl(edits);
  664. this._textEditChanges[key] = result;
  665. }
  666. return result;
  667. }
  668. };
  669. WorkspaceChange2.prototype.initDocumentChanges = function() {
  670. if (this._workspaceEdit.documentChanges === void 0 && this._workspaceEdit.changes === void 0) {
  671. this._changeAnnotations = new ChangeAnnotations();
  672. this._workspaceEdit.documentChanges = [];
  673. this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
  674. }
  675. };
  676. WorkspaceChange2.prototype.initChanges = function() {
  677. if (this._workspaceEdit.documentChanges === void 0 && this._workspaceEdit.changes === void 0) {
  678. this._workspaceEdit.changes = /* @__PURE__ */ Object.create(null);
  679. }
  680. };
  681. WorkspaceChange2.prototype.createFile = function(uri, optionsOrAnnotation, options) {
  682. this.initDocumentChanges();
  683. if (this._workspaceEdit.documentChanges === void 0) {
  684. throw new Error("Workspace edit is not configured for document changes.");
  685. }
  686. var annotation;
  687. if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
  688. annotation = optionsOrAnnotation;
  689. } else {
  690. options = optionsOrAnnotation;
  691. }
  692. var operation;
  693. var id;
  694. if (annotation === void 0) {
  695. operation = CreateFile.create(uri, options);
  696. } else {
  697. id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
  698. operation = CreateFile.create(uri, options, id);
  699. }
  700. this._workspaceEdit.documentChanges.push(operation);
  701. if (id !== void 0) {
  702. return id;
  703. }
  704. };
  705. WorkspaceChange2.prototype.renameFile = function(oldUri, newUri, optionsOrAnnotation, options) {
  706. this.initDocumentChanges();
  707. if (this._workspaceEdit.documentChanges === void 0) {
  708. throw new Error("Workspace edit is not configured for document changes.");
  709. }
  710. var annotation;
  711. if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
  712. annotation = optionsOrAnnotation;
  713. } else {
  714. options = optionsOrAnnotation;
  715. }
  716. var operation;
  717. var id;
  718. if (annotation === void 0) {
  719. operation = RenameFile.create(oldUri, newUri, options);
  720. } else {
  721. id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
  722. operation = RenameFile.create(oldUri, newUri, options, id);
  723. }
  724. this._workspaceEdit.documentChanges.push(operation);
  725. if (id !== void 0) {
  726. return id;
  727. }
  728. };
  729. WorkspaceChange2.prototype.deleteFile = function(uri, optionsOrAnnotation, options) {
  730. this.initDocumentChanges();
  731. if (this._workspaceEdit.documentChanges === void 0) {
  732. throw new Error("Workspace edit is not configured for document changes.");
  733. }
  734. var annotation;
  735. if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
  736. annotation = optionsOrAnnotation;
  737. } else {
  738. options = optionsOrAnnotation;
  739. }
  740. var operation;
  741. var id;
  742. if (annotation === void 0) {
  743. operation = DeleteFile.create(uri, options);
  744. } else {
  745. id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
  746. operation = DeleteFile.create(uri, options, id);
  747. }
  748. this._workspaceEdit.documentChanges.push(operation);
  749. if (id !== void 0) {
  750. return id;
  751. }
  752. };
  753. return WorkspaceChange2;
  754. }();
  755. var TextDocumentIdentifier;
  756. (function(TextDocumentIdentifier2) {
  757. function create(uri) {
  758. return { uri };
  759. }
  760. TextDocumentIdentifier2.create = create;
  761. function is(value) {
  762. var candidate = value;
  763. return Is.defined(candidate) && Is.string(candidate.uri);
  764. }
  765. TextDocumentIdentifier2.is = is;
  766. })(TextDocumentIdentifier || (TextDocumentIdentifier = {}));
  767. var VersionedTextDocumentIdentifier;
  768. (function(VersionedTextDocumentIdentifier2) {
  769. function create(uri, version) {
  770. return { uri, version };
  771. }
  772. VersionedTextDocumentIdentifier2.create = create;
  773. function is(value) {
  774. var candidate = value;
  775. return Is.defined(candidate) && Is.string(candidate.uri) && Is.integer(candidate.version);
  776. }
  777. VersionedTextDocumentIdentifier2.is = is;
  778. })(VersionedTextDocumentIdentifier || (VersionedTextDocumentIdentifier = {}));
  779. var OptionalVersionedTextDocumentIdentifier;
  780. (function(OptionalVersionedTextDocumentIdentifier2) {
  781. function create(uri, version) {
  782. return { uri, version };
  783. }
  784. OptionalVersionedTextDocumentIdentifier2.create = create;
  785. function is(value) {
  786. var candidate = value;
  787. return Is.defined(candidate) && Is.string(candidate.uri) && (candidate.version === null || Is.integer(candidate.version));
  788. }
  789. OptionalVersionedTextDocumentIdentifier2.is = is;
  790. })(OptionalVersionedTextDocumentIdentifier || (OptionalVersionedTextDocumentIdentifier = {}));
  791. var TextDocumentItem;
  792. (function(TextDocumentItem2) {
  793. function create(uri, languageId, version, text) {
  794. return { uri, languageId, version, text };
  795. }
  796. TextDocumentItem2.create = create;
  797. function is(value) {
  798. var candidate = value;
  799. return Is.defined(candidate) && Is.string(candidate.uri) && Is.string(candidate.languageId) && Is.integer(candidate.version) && Is.string(candidate.text);
  800. }
  801. TextDocumentItem2.is = is;
  802. })(TextDocumentItem || (TextDocumentItem = {}));
  803. var MarkupKind;
  804. (function(MarkupKind2) {
  805. MarkupKind2.PlainText = "plaintext";
  806. MarkupKind2.Markdown = "markdown";
  807. })(MarkupKind || (MarkupKind = {}));
  808. (function(MarkupKind2) {
  809. function is(value) {
  810. var candidate = value;
  811. return candidate === MarkupKind2.PlainText || candidate === MarkupKind2.Markdown;
  812. }
  813. MarkupKind2.is = is;
  814. })(MarkupKind || (MarkupKind = {}));
  815. var MarkupContent;
  816. (function(MarkupContent2) {
  817. function is(value) {
  818. var candidate = value;
  819. return Is.objectLiteral(value) && MarkupKind.is(candidate.kind) && Is.string(candidate.value);
  820. }
  821. MarkupContent2.is = is;
  822. })(MarkupContent || (MarkupContent = {}));
  823. var CompletionItemKind;
  824. (function(CompletionItemKind2) {
  825. CompletionItemKind2.Text = 1;
  826. CompletionItemKind2.Method = 2;
  827. CompletionItemKind2.Function = 3;
  828. CompletionItemKind2.Constructor = 4;
  829. CompletionItemKind2.Field = 5;
  830. CompletionItemKind2.Variable = 6;
  831. CompletionItemKind2.Class = 7;
  832. CompletionItemKind2.Interface = 8;
  833. CompletionItemKind2.Module = 9;
  834. CompletionItemKind2.Property = 10;
  835. CompletionItemKind2.Unit = 11;
  836. CompletionItemKind2.Value = 12;
  837. CompletionItemKind2.Enum = 13;
  838. CompletionItemKind2.Keyword = 14;
  839. CompletionItemKind2.Snippet = 15;
  840. CompletionItemKind2.Color = 16;
  841. CompletionItemKind2.File = 17;
  842. CompletionItemKind2.Reference = 18;
  843. CompletionItemKind2.Folder = 19;
  844. CompletionItemKind2.EnumMember = 20;
  845. CompletionItemKind2.Constant = 21;
  846. CompletionItemKind2.Struct = 22;
  847. CompletionItemKind2.Event = 23;
  848. CompletionItemKind2.Operator = 24;
  849. CompletionItemKind2.TypeParameter = 25;
  850. })(CompletionItemKind || (CompletionItemKind = {}));
  851. var InsertTextFormat;
  852. (function(InsertTextFormat2) {
  853. InsertTextFormat2.PlainText = 1;
  854. InsertTextFormat2.Snippet = 2;
  855. })(InsertTextFormat || (InsertTextFormat = {}));
  856. var CompletionItemTag;
  857. (function(CompletionItemTag2) {
  858. CompletionItemTag2.Deprecated = 1;
  859. })(CompletionItemTag || (CompletionItemTag = {}));
  860. var InsertReplaceEdit;
  861. (function(InsertReplaceEdit2) {
  862. function create(newText, insert, replace) {
  863. return { newText, insert, replace };
  864. }
  865. InsertReplaceEdit2.create = create;
  866. function is(value) {
  867. var candidate = value;
  868. return candidate && Is.string(candidate.newText) && Range.is(candidate.insert) && Range.is(candidate.replace);
  869. }
  870. InsertReplaceEdit2.is = is;
  871. })(InsertReplaceEdit || (InsertReplaceEdit = {}));
  872. var InsertTextMode;
  873. (function(InsertTextMode2) {
  874. InsertTextMode2.asIs = 1;
  875. InsertTextMode2.adjustIndentation = 2;
  876. })(InsertTextMode || (InsertTextMode = {}));
  877. var CompletionItem;
  878. (function(CompletionItem2) {
  879. function create(label) {
  880. return { label };
  881. }
  882. CompletionItem2.create = create;
  883. })(CompletionItem || (CompletionItem = {}));
  884. var CompletionList;
  885. (function(CompletionList2) {
  886. function create(items, isIncomplete) {
  887. return { items: items ? items : [], isIncomplete: !!isIncomplete };
  888. }
  889. CompletionList2.create = create;
  890. })(CompletionList || (CompletionList = {}));
  891. var MarkedString;
  892. (function(MarkedString2) {
  893. function fromPlainText(plainText) {
  894. return plainText.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&");
  895. }
  896. MarkedString2.fromPlainText = fromPlainText;
  897. function is(value) {
  898. var candidate = value;
  899. return Is.string(candidate) || Is.objectLiteral(candidate) && Is.string(candidate.language) && Is.string(candidate.value);
  900. }
  901. MarkedString2.is = is;
  902. })(MarkedString || (MarkedString = {}));
  903. var Hover;
  904. (function(Hover2) {
  905. function is(value) {
  906. var candidate = value;
  907. 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));
  908. }
  909. Hover2.is = is;
  910. })(Hover || (Hover = {}));
  911. var ParameterInformation;
  912. (function(ParameterInformation2) {
  913. function create(label, documentation) {
  914. return documentation ? { label, documentation } : { label };
  915. }
  916. ParameterInformation2.create = create;
  917. })(ParameterInformation || (ParameterInformation = {}));
  918. var SignatureInformation;
  919. (function(SignatureInformation2) {
  920. function create(label, documentation) {
  921. var parameters = [];
  922. for (var _i = 2; _i < arguments.length; _i++) {
  923. parameters[_i - 2] = arguments[_i];
  924. }
  925. var result = { label };
  926. if (Is.defined(documentation)) {
  927. result.documentation = documentation;
  928. }
  929. if (Is.defined(parameters)) {
  930. result.parameters = parameters;
  931. } else {
  932. result.parameters = [];
  933. }
  934. return result;
  935. }
  936. SignatureInformation2.create = create;
  937. })(SignatureInformation || (SignatureInformation = {}));
  938. var DocumentHighlightKind;
  939. (function(DocumentHighlightKind2) {
  940. DocumentHighlightKind2.Text = 1;
  941. DocumentHighlightKind2.Read = 2;
  942. DocumentHighlightKind2.Write = 3;
  943. })(DocumentHighlightKind || (DocumentHighlightKind = {}));
  944. var DocumentHighlight;
  945. (function(DocumentHighlight2) {
  946. function create(range, kind) {
  947. var result = { range };
  948. if (Is.number(kind)) {
  949. result.kind = kind;
  950. }
  951. return result;
  952. }
  953. DocumentHighlight2.create = create;
  954. })(DocumentHighlight || (DocumentHighlight = {}));
  955. var SymbolKind;
  956. (function(SymbolKind2) {
  957. SymbolKind2.File = 1;
  958. SymbolKind2.Module = 2;
  959. SymbolKind2.Namespace = 3;
  960. SymbolKind2.Package = 4;
  961. SymbolKind2.Class = 5;
  962. SymbolKind2.Method = 6;
  963. SymbolKind2.Property = 7;
  964. SymbolKind2.Field = 8;
  965. SymbolKind2.Constructor = 9;
  966. SymbolKind2.Enum = 10;
  967. SymbolKind2.Interface = 11;
  968. SymbolKind2.Function = 12;
  969. SymbolKind2.Variable = 13;
  970. SymbolKind2.Constant = 14;
  971. SymbolKind2.String = 15;
  972. SymbolKind2.Number = 16;
  973. SymbolKind2.Boolean = 17;
  974. SymbolKind2.Array = 18;
  975. SymbolKind2.Object = 19;
  976. SymbolKind2.Key = 20;
  977. SymbolKind2.Null = 21;
  978. SymbolKind2.EnumMember = 22;
  979. SymbolKind2.Struct = 23;
  980. SymbolKind2.Event = 24;
  981. SymbolKind2.Operator = 25;
  982. SymbolKind2.TypeParameter = 26;
  983. })(SymbolKind || (SymbolKind = {}));
  984. var SymbolTag;
  985. (function(SymbolTag2) {
  986. SymbolTag2.Deprecated = 1;
  987. })(SymbolTag || (SymbolTag = {}));
  988. var SymbolInformation;
  989. (function(SymbolInformation2) {
  990. function create(name, kind, range, uri, containerName) {
  991. var result = {
  992. name,
  993. kind,
  994. location: { uri, range }
  995. };
  996. if (containerName) {
  997. result.containerName = containerName;
  998. }
  999. return result;
  1000. }
  1001. SymbolInformation2.create = create;
  1002. })(SymbolInformation || (SymbolInformation = {}));
  1003. var DocumentSymbol;
  1004. (function(DocumentSymbol2) {
  1005. function create(name, detail, kind, range, selectionRange, children) {
  1006. var result = {
  1007. name,
  1008. detail,
  1009. kind,
  1010. range,
  1011. selectionRange
  1012. };
  1013. if (children !== void 0) {
  1014. result.children = children;
  1015. }
  1016. return result;
  1017. }
  1018. DocumentSymbol2.create = create;
  1019. function is(value) {
  1020. var candidate = value;
  1021. 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));
  1022. }
  1023. DocumentSymbol2.is = is;
  1024. })(DocumentSymbol || (DocumentSymbol = {}));
  1025. var CodeActionKind;
  1026. (function(CodeActionKind2) {
  1027. CodeActionKind2.Empty = "";
  1028. CodeActionKind2.QuickFix = "quickfix";
  1029. CodeActionKind2.Refactor = "refactor";
  1030. CodeActionKind2.RefactorExtract = "refactor.extract";
  1031. CodeActionKind2.RefactorInline = "refactor.inline";
  1032. CodeActionKind2.RefactorRewrite = "refactor.rewrite";
  1033. CodeActionKind2.Source = "source";
  1034. CodeActionKind2.SourceOrganizeImports = "source.organizeImports";
  1035. CodeActionKind2.SourceFixAll = "source.fixAll";
  1036. })(CodeActionKind || (CodeActionKind = {}));
  1037. var CodeActionContext;
  1038. (function(CodeActionContext2) {
  1039. function create(diagnostics, only) {
  1040. var result = { diagnostics };
  1041. if (only !== void 0 && only !== null) {
  1042. result.only = only;
  1043. }
  1044. return result;
  1045. }
  1046. CodeActionContext2.create = create;
  1047. function is(value) {
  1048. var candidate = value;
  1049. return Is.defined(candidate) && Is.typedArray(candidate.diagnostics, Diagnostic.is) && (candidate.only === void 0 || Is.typedArray(candidate.only, Is.string));
  1050. }
  1051. CodeActionContext2.is = is;
  1052. })(CodeActionContext || (CodeActionContext = {}));
  1053. var CodeAction;
  1054. (function(CodeAction2) {
  1055. function create(title, kindOrCommandOrEdit, kind) {
  1056. var result = { title };
  1057. var checkKind = true;
  1058. if (typeof kindOrCommandOrEdit === "string") {
  1059. checkKind = false;
  1060. result.kind = kindOrCommandOrEdit;
  1061. } else if (Command.is(kindOrCommandOrEdit)) {
  1062. result.command = kindOrCommandOrEdit;
  1063. } else {
  1064. result.edit = kindOrCommandOrEdit;
  1065. }
  1066. if (checkKind && kind !== void 0) {
  1067. result.kind = kind;
  1068. }
  1069. return result;
  1070. }
  1071. CodeAction2.create = create;
  1072. function is(value) {
  1073. var candidate = value;
  1074. 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));
  1075. }
  1076. CodeAction2.is = is;
  1077. })(CodeAction || (CodeAction = {}));
  1078. var CodeLens;
  1079. (function(CodeLens2) {
  1080. function create(range, data) {
  1081. var result = { range };
  1082. if (Is.defined(data)) {
  1083. result.data = data;
  1084. }
  1085. return result;
  1086. }
  1087. CodeLens2.create = create;
  1088. function is(value) {
  1089. var candidate = value;
  1090. return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command));
  1091. }
  1092. CodeLens2.is = is;
  1093. })(CodeLens || (CodeLens = {}));
  1094. var FormattingOptions;
  1095. (function(FormattingOptions2) {
  1096. function create(tabSize, insertSpaces) {
  1097. return { tabSize, insertSpaces };
  1098. }
  1099. FormattingOptions2.create = create;
  1100. function is(value) {
  1101. var candidate = value;
  1102. return Is.defined(candidate) && Is.uinteger(candidate.tabSize) && Is.boolean(candidate.insertSpaces);
  1103. }
  1104. FormattingOptions2.is = is;
  1105. })(FormattingOptions || (FormattingOptions = {}));
  1106. var DocumentLink;
  1107. (function(DocumentLink2) {
  1108. function create(range, target, data) {
  1109. return { range, target, data };
  1110. }
  1111. DocumentLink2.create = create;
  1112. function is(value) {
  1113. var candidate = value;
  1114. return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.target) || Is.string(candidate.target));
  1115. }
  1116. DocumentLink2.is = is;
  1117. })(DocumentLink || (DocumentLink = {}));
  1118. var SelectionRange;
  1119. (function(SelectionRange2) {
  1120. function create(range, parent) {
  1121. return { range, parent };
  1122. }
  1123. SelectionRange2.create = create;
  1124. function is(value) {
  1125. var candidate = value;
  1126. return candidate !== void 0 && Range.is(candidate.range) && (candidate.parent === void 0 || SelectionRange2.is(candidate.parent));
  1127. }
  1128. SelectionRange2.is = is;
  1129. })(SelectionRange || (SelectionRange = {}));
  1130. var TextDocument;
  1131. (function(TextDocument2) {
  1132. function create(uri, languageId, version, content) {
  1133. return new FullTextDocument(uri, languageId, version, content);
  1134. }
  1135. TextDocument2.create = create;
  1136. function is(value) {
  1137. var candidate = value;
  1138. 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;
  1139. }
  1140. TextDocument2.is = is;
  1141. function applyEdits(document, edits) {
  1142. var text = document.getText();
  1143. var sortedEdits = mergeSort(edits, function(a, b) {
  1144. var diff = a.range.start.line - b.range.start.line;
  1145. if (diff === 0) {
  1146. return a.range.start.character - b.range.start.character;
  1147. }
  1148. return diff;
  1149. });
  1150. var lastModifiedOffset = text.length;
  1151. for (var i = sortedEdits.length - 1; i >= 0; i--) {
  1152. var e = sortedEdits[i];
  1153. var startOffset = document.offsetAt(e.range.start);
  1154. var endOffset = document.offsetAt(e.range.end);
  1155. if (endOffset <= lastModifiedOffset) {
  1156. text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
  1157. } else {
  1158. throw new Error("Overlapping edit");
  1159. }
  1160. lastModifiedOffset = startOffset;
  1161. }
  1162. return text;
  1163. }
  1164. TextDocument2.applyEdits = applyEdits;
  1165. function mergeSort(data, compare) {
  1166. if (data.length <= 1) {
  1167. return data;
  1168. }
  1169. var p = data.length / 2 | 0;
  1170. var left = data.slice(0, p);
  1171. var right = data.slice(p);
  1172. mergeSort(left, compare);
  1173. mergeSort(right, compare);
  1174. var leftIdx = 0;
  1175. var rightIdx = 0;
  1176. var i = 0;
  1177. while (leftIdx < left.length && rightIdx < right.length) {
  1178. var ret = compare(left[leftIdx], right[rightIdx]);
  1179. if (ret <= 0) {
  1180. data[i++] = left[leftIdx++];
  1181. } else {
  1182. data[i++] = right[rightIdx++];
  1183. }
  1184. }
  1185. while (leftIdx < left.length) {
  1186. data[i++] = left[leftIdx++];
  1187. }
  1188. while (rightIdx < right.length) {
  1189. data[i++] = right[rightIdx++];
  1190. }
  1191. return data;
  1192. }
  1193. })(TextDocument || (TextDocument = {}));
  1194. var FullTextDocument = function() {
  1195. function FullTextDocument2(uri, languageId, version, content) {
  1196. this._uri = uri;
  1197. this._languageId = languageId;
  1198. this._version = version;
  1199. this._content = content;
  1200. this._lineOffsets = void 0;
  1201. }
  1202. Object.defineProperty(FullTextDocument2.prototype, "uri", {
  1203. get: function() {
  1204. return this._uri;
  1205. },
  1206. enumerable: false,
  1207. configurable: true
  1208. });
  1209. Object.defineProperty(FullTextDocument2.prototype, "languageId", {
  1210. get: function() {
  1211. return this._languageId;
  1212. },
  1213. enumerable: false,
  1214. configurable: true
  1215. });
  1216. Object.defineProperty(FullTextDocument2.prototype, "version", {
  1217. get: function() {
  1218. return this._version;
  1219. },
  1220. enumerable: false,
  1221. configurable: true
  1222. });
  1223. FullTextDocument2.prototype.getText = function(range) {
  1224. if (range) {
  1225. var start = this.offsetAt(range.start);
  1226. var end = this.offsetAt(range.end);
  1227. return this._content.substring(start, end);
  1228. }
  1229. return this._content;
  1230. };
  1231. FullTextDocument2.prototype.update = function(event, version) {
  1232. this._content = event.text;
  1233. this._version = version;
  1234. this._lineOffsets = void 0;
  1235. };
  1236. FullTextDocument2.prototype.getLineOffsets = function() {
  1237. if (this._lineOffsets === void 0) {
  1238. var lineOffsets = [];
  1239. var text = this._content;
  1240. var isLineStart = true;
  1241. for (var i = 0; i < text.length; i++) {
  1242. if (isLineStart) {
  1243. lineOffsets.push(i);
  1244. isLineStart = false;
  1245. }
  1246. var ch = text.charAt(i);
  1247. isLineStart = ch === "\r" || ch === "\n";
  1248. if (ch === "\r" && i + 1 < text.length && text.charAt(i + 1) === "\n") {
  1249. i++;
  1250. }
  1251. }
  1252. if (isLineStart && text.length > 0) {
  1253. lineOffsets.push(text.length);
  1254. }
  1255. this._lineOffsets = lineOffsets;
  1256. }
  1257. return this._lineOffsets;
  1258. };
  1259. FullTextDocument2.prototype.positionAt = function(offset) {
  1260. offset = Math.max(Math.min(offset, this._content.length), 0);
  1261. var lineOffsets = this.getLineOffsets();
  1262. var low = 0, high = lineOffsets.length;
  1263. if (high === 0) {
  1264. return Position.create(0, offset);
  1265. }
  1266. while (low < high) {
  1267. var mid = Math.floor((low + high) / 2);
  1268. if (lineOffsets[mid] > offset) {
  1269. high = mid;
  1270. } else {
  1271. low = mid + 1;
  1272. }
  1273. }
  1274. var line = low - 1;
  1275. return Position.create(line, offset - lineOffsets[line]);
  1276. };
  1277. FullTextDocument2.prototype.offsetAt = function(position) {
  1278. var lineOffsets = this.getLineOffsets();
  1279. if (position.line >= lineOffsets.length) {
  1280. return this._content.length;
  1281. } else if (position.line < 0) {
  1282. return 0;
  1283. }
  1284. var lineOffset = lineOffsets[position.line];
  1285. var nextLineOffset = position.line + 1 < lineOffsets.length ? lineOffsets[position.line + 1] : this._content.length;
  1286. return Math.max(Math.min(lineOffset + position.character, nextLineOffset), lineOffset);
  1287. };
  1288. Object.defineProperty(FullTextDocument2.prototype, "lineCount", {
  1289. get: function() {
  1290. return this.getLineOffsets().length;
  1291. },
  1292. enumerable: false,
  1293. configurable: true
  1294. });
  1295. return FullTextDocument2;
  1296. }();
  1297. var Is;
  1298. (function(Is2) {
  1299. var toString = Object.prototype.toString;
  1300. function defined(value) {
  1301. return typeof value !== "undefined";
  1302. }
  1303. Is2.defined = defined;
  1304. function undefined2(value) {
  1305. return typeof value === "undefined";
  1306. }
  1307. Is2.undefined = undefined2;
  1308. function boolean(value) {
  1309. return value === true || value === false;
  1310. }
  1311. Is2.boolean = boolean;
  1312. function string(value) {
  1313. return toString.call(value) === "[object String]";
  1314. }
  1315. Is2.string = string;
  1316. function number(value) {
  1317. return toString.call(value) === "[object Number]";
  1318. }
  1319. Is2.number = number;
  1320. function numberRange(value, min, max) {
  1321. return toString.call(value) === "[object Number]" && min <= value && value <= max;
  1322. }
  1323. Is2.numberRange = numberRange;
  1324. function integer2(value) {
  1325. return toString.call(value) === "[object Number]" && -2147483648 <= value && value <= 2147483647;
  1326. }
  1327. Is2.integer = integer2;
  1328. function uinteger2(value) {
  1329. return toString.call(value) === "[object Number]" && 0 <= value && value <= 2147483647;
  1330. }
  1331. Is2.uinteger = uinteger2;
  1332. function func(value) {
  1333. return toString.call(value) === "[object Function]";
  1334. }
  1335. Is2.func = func;
  1336. function objectLiteral(value) {
  1337. return value !== null && typeof value === "object";
  1338. }
  1339. Is2.objectLiteral = objectLiteral;
  1340. function typedArray(value, check) {
  1341. return Array.isArray(value) && value.every(check);
  1342. }
  1343. Is2.typedArray = typedArray;
  1344. })(Is || (Is = {}));
  1345. // src/language/common/lspLanguageFeatures.ts
  1346. var DiagnosticsAdapter = class {
  1347. constructor(_languageId, _worker, configChangeEvent) {
  1348. this._languageId = _languageId;
  1349. this._worker = _worker;
  1350. const onModelAdd = (model) => {
  1351. let modeId = model.getLanguageId();
  1352. if (modeId !== this._languageId) {
  1353. return;
  1354. }
  1355. let handle;
  1356. this._listener[model.uri.toString()] = model.onDidChangeContent(() => {
  1357. window.clearTimeout(handle);
  1358. handle = window.setTimeout(() => this._doValidate(model.uri, modeId), 500);
  1359. });
  1360. this._doValidate(model.uri, modeId);
  1361. };
  1362. const onModelRemoved = (model) => {
  1363. monaco_editor_core_exports.editor.setModelMarkers(model, this._languageId, []);
  1364. let uriStr = model.uri.toString();
  1365. let listener = this._listener[uriStr];
  1366. if (listener) {
  1367. listener.dispose();
  1368. delete this._listener[uriStr];
  1369. }
  1370. };
  1371. this._disposables.push(monaco_editor_core_exports.editor.onDidCreateModel(onModelAdd));
  1372. this._disposables.push(monaco_editor_core_exports.editor.onWillDisposeModel(onModelRemoved));
  1373. this._disposables.push(monaco_editor_core_exports.editor.onDidChangeModelLanguage((event) => {
  1374. onModelRemoved(event.model);
  1375. onModelAdd(event.model);
  1376. }));
  1377. this._disposables.push(configChangeEvent((_) => {
  1378. monaco_editor_core_exports.editor.getModels().forEach((model) => {
  1379. if (model.getLanguageId() === this._languageId) {
  1380. onModelRemoved(model);
  1381. onModelAdd(model);
  1382. }
  1383. });
  1384. }));
  1385. this._disposables.push({
  1386. dispose: () => {
  1387. monaco_editor_core_exports.editor.getModels().forEach(onModelRemoved);
  1388. for (let key in this._listener) {
  1389. this._listener[key].dispose();
  1390. }
  1391. }
  1392. });
  1393. monaco_editor_core_exports.editor.getModels().forEach(onModelAdd);
  1394. }
  1395. _disposables = [];
  1396. _listener = /* @__PURE__ */ Object.create(null);
  1397. dispose() {
  1398. this._disposables.forEach((d) => d && d.dispose());
  1399. this._disposables.length = 0;
  1400. }
  1401. _doValidate(resource, languageId) {
  1402. this._worker(resource).then((worker) => {
  1403. return worker.doValidation(resource.toString());
  1404. }).then((diagnostics) => {
  1405. const markers = diagnostics.map((d) => toDiagnostics(resource, d));
  1406. let model = monaco_editor_core_exports.editor.getModel(resource);
  1407. if (model && model.getLanguageId() === languageId) {
  1408. monaco_editor_core_exports.editor.setModelMarkers(model, languageId, markers);
  1409. }
  1410. }).then(void 0, (err) => {
  1411. console.error(err);
  1412. });
  1413. }
  1414. };
  1415. function toSeverity(lsSeverity) {
  1416. switch (lsSeverity) {
  1417. case DiagnosticSeverity.Error:
  1418. return monaco_editor_core_exports.MarkerSeverity.Error;
  1419. case DiagnosticSeverity.Warning:
  1420. return monaco_editor_core_exports.MarkerSeverity.Warning;
  1421. case DiagnosticSeverity.Information:
  1422. return monaco_editor_core_exports.MarkerSeverity.Info;
  1423. case DiagnosticSeverity.Hint:
  1424. return monaco_editor_core_exports.MarkerSeverity.Hint;
  1425. default:
  1426. return monaco_editor_core_exports.MarkerSeverity.Info;
  1427. }
  1428. }
  1429. function toDiagnostics(resource, diag) {
  1430. let code = typeof diag.code === "number" ? String(diag.code) : diag.code;
  1431. return {
  1432. severity: toSeverity(diag.severity),
  1433. startLineNumber: diag.range.start.line + 1,
  1434. startColumn: diag.range.start.character + 1,
  1435. endLineNumber: diag.range.end.line + 1,
  1436. endColumn: diag.range.end.character + 1,
  1437. message: diag.message,
  1438. code,
  1439. source: diag.source
  1440. };
  1441. }
  1442. var CompletionAdapter = class {
  1443. constructor(_worker, _triggerCharacters) {
  1444. this._worker = _worker;
  1445. this._triggerCharacters = _triggerCharacters;
  1446. }
  1447. get triggerCharacters() {
  1448. return this._triggerCharacters;
  1449. }
  1450. provideCompletionItems(model, position, context, token) {
  1451. const resource = model.uri;
  1452. return this._worker(resource).then((worker) => {
  1453. return worker.doComplete(resource.toString(), fromPosition(position));
  1454. }).then((info) => {
  1455. if (!info) {
  1456. return;
  1457. }
  1458. const wordInfo = model.getWordUntilPosition(position);
  1459. const wordRange = new monaco_editor_core_exports.Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn);
  1460. const items = info.items.map((entry) => {
  1461. const item = {
  1462. label: entry.label,
  1463. insertText: entry.insertText || entry.label,
  1464. sortText: entry.sortText,
  1465. filterText: entry.filterText,
  1466. documentation: entry.documentation,
  1467. detail: entry.detail,
  1468. command: toCommand(entry.command),
  1469. range: wordRange,
  1470. kind: toCompletionItemKind(entry.kind)
  1471. };
  1472. if (entry.textEdit) {
  1473. if (isInsertReplaceEdit(entry.textEdit)) {
  1474. item.range = {
  1475. insert: toRange(entry.textEdit.insert),
  1476. replace: toRange(entry.textEdit.replace)
  1477. };
  1478. } else {
  1479. item.range = toRange(entry.textEdit.range);
  1480. }
  1481. item.insertText = entry.textEdit.newText;
  1482. }
  1483. if (entry.additionalTextEdits) {
  1484. item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
  1485. }
  1486. if (entry.insertTextFormat === InsertTextFormat.Snippet) {
  1487. item.insertTextRules = monaco_editor_core_exports.languages.CompletionItemInsertTextRule.InsertAsSnippet;
  1488. }
  1489. return item;
  1490. });
  1491. return {
  1492. isIncomplete: info.isIncomplete,
  1493. suggestions: items
  1494. };
  1495. });
  1496. }
  1497. };
  1498. function fromPosition(position) {
  1499. if (!position) {
  1500. return void 0;
  1501. }
  1502. return { character: position.column - 1, line: position.lineNumber - 1 };
  1503. }
  1504. function fromRange(range) {
  1505. if (!range) {
  1506. return void 0;
  1507. }
  1508. return {
  1509. start: {
  1510. line: range.startLineNumber - 1,
  1511. character: range.startColumn - 1
  1512. },
  1513. end: { line: range.endLineNumber - 1, character: range.endColumn - 1 }
  1514. };
  1515. }
  1516. function toRange(range) {
  1517. if (!range) {
  1518. return void 0;
  1519. }
  1520. return new monaco_editor_core_exports.Range(range.start.line + 1, range.start.character + 1, range.end.line + 1, range.end.character + 1);
  1521. }
  1522. function isInsertReplaceEdit(edit) {
  1523. return typeof edit.insert !== "undefined" && typeof edit.replace !== "undefined";
  1524. }
  1525. function toCompletionItemKind(kind) {
  1526. const mItemKind = monaco_editor_core_exports.languages.CompletionItemKind;
  1527. switch (kind) {
  1528. case CompletionItemKind.Text:
  1529. return mItemKind.Text;
  1530. case CompletionItemKind.Method:
  1531. return mItemKind.Method;
  1532. case CompletionItemKind.Function:
  1533. return mItemKind.Function;
  1534. case CompletionItemKind.Constructor:
  1535. return mItemKind.Constructor;
  1536. case CompletionItemKind.Field:
  1537. return mItemKind.Field;
  1538. case CompletionItemKind.Variable:
  1539. return mItemKind.Variable;
  1540. case CompletionItemKind.Class:
  1541. return mItemKind.Class;
  1542. case CompletionItemKind.Interface:
  1543. return mItemKind.Interface;
  1544. case CompletionItemKind.Module:
  1545. return mItemKind.Module;
  1546. case CompletionItemKind.Property:
  1547. return mItemKind.Property;
  1548. case CompletionItemKind.Unit:
  1549. return mItemKind.Unit;
  1550. case CompletionItemKind.Value:
  1551. return mItemKind.Value;
  1552. case CompletionItemKind.Enum:
  1553. return mItemKind.Enum;
  1554. case CompletionItemKind.Keyword:
  1555. return mItemKind.Keyword;
  1556. case CompletionItemKind.Snippet:
  1557. return mItemKind.Snippet;
  1558. case CompletionItemKind.Color:
  1559. return mItemKind.Color;
  1560. case CompletionItemKind.File:
  1561. return mItemKind.File;
  1562. case CompletionItemKind.Reference:
  1563. return mItemKind.Reference;
  1564. }
  1565. return mItemKind.Property;
  1566. }
  1567. function toTextEdit(textEdit) {
  1568. if (!textEdit) {
  1569. return void 0;
  1570. }
  1571. return {
  1572. range: toRange(textEdit.range),
  1573. text: textEdit.newText
  1574. };
  1575. }
  1576. function toCommand(c) {
  1577. return c && c.command === "editor.action.triggerSuggest" ? { id: c.command, title: c.title, arguments: c.arguments } : void 0;
  1578. }
  1579. var HoverAdapter = class {
  1580. constructor(_worker) {
  1581. this._worker = _worker;
  1582. }
  1583. provideHover(model, position, token) {
  1584. let resource = model.uri;
  1585. return this._worker(resource).then((worker) => {
  1586. return worker.doHover(resource.toString(), fromPosition(position));
  1587. }).then((info) => {
  1588. if (!info) {
  1589. return;
  1590. }
  1591. return {
  1592. range: toRange(info.range),
  1593. contents: toMarkedStringArray(info.contents)
  1594. };
  1595. });
  1596. }
  1597. };
  1598. function isMarkupContent(thing) {
  1599. return thing && typeof thing === "object" && typeof thing.kind === "string";
  1600. }
  1601. function toMarkdownString(entry) {
  1602. if (typeof entry === "string") {
  1603. return {
  1604. value: entry
  1605. };
  1606. }
  1607. if (isMarkupContent(entry)) {
  1608. if (entry.kind === "plaintext") {
  1609. return {
  1610. value: entry.value.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&")
  1611. };
  1612. }
  1613. return {
  1614. value: entry.value
  1615. };
  1616. }
  1617. return { value: "```" + entry.language + "\n" + entry.value + "\n```\n" };
  1618. }
  1619. function toMarkedStringArray(contents) {
  1620. if (!contents) {
  1621. return void 0;
  1622. }
  1623. if (Array.isArray(contents)) {
  1624. return contents.map(toMarkdownString);
  1625. }
  1626. return [toMarkdownString(contents)];
  1627. }
  1628. var DocumentHighlightAdapter = class {
  1629. constructor(_worker) {
  1630. this._worker = _worker;
  1631. }
  1632. provideDocumentHighlights(model, position, token) {
  1633. const resource = model.uri;
  1634. return this._worker(resource).then((worker) => worker.findDocumentHighlights(resource.toString(), fromPosition(position))).then((entries) => {
  1635. if (!entries) {
  1636. return;
  1637. }
  1638. return entries.map((entry) => {
  1639. return {
  1640. range: toRange(entry.range),
  1641. kind: toDocumentHighlightKind(entry.kind)
  1642. };
  1643. });
  1644. });
  1645. }
  1646. };
  1647. function toDocumentHighlightKind(kind) {
  1648. switch (kind) {
  1649. case DocumentHighlightKind.Read:
  1650. return monaco_editor_core_exports.languages.DocumentHighlightKind.Read;
  1651. case DocumentHighlightKind.Write:
  1652. return monaco_editor_core_exports.languages.DocumentHighlightKind.Write;
  1653. case DocumentHighlightKind.Text:
  1654. return monaco_editor_core_exports.languages.DocumentHighlightKind.Text;
  1655. }
  1656. return monaco_editor_core_exports.languages.DocumentHighlightKind.Text;
  1657. }
  1658. var DefinitionAdapter = class {
  1659. constructor(_worker) {
  1660. this._worker = _worker;
  1661. }
  1662. provideDefinition(model, position, token) {
  1663. const resource = model.uri;
  1664. return this._worker(resource).then((worker) => {
  1665. return worker.findDefinition(resource.toString(), fromPosition(position));
  1666. }).then((definition) => {
  1667. if (!definition) {
  1668. return;
  1669. }
  1670. return [toLocation(definition)];
  1671. });
  1672. }
  1673. };
  1674. function toLocation(location) {
  1675. return {
  1676. uri: monaco_editor_core_exports.Uri.parse(location.uri),
  1677. range: toRange(location.range)
  1678. };
  1679. }
  1680. var ReferenceAdapter = class {
  1681. constructor(_worker) {
  1682. this._worker = _worker;
  1683. }
  1684. provideReferences(model, position, context, token) {
  1685. const resource = model.uri;
  1686. return this._worker(resource).then((worker) => {
  1687. return worker.findReferences(resource.toString(), fromPosition(position));
  1688. }).then((entries) => {
  1689. if (!entries) {
  1690. return;
  1691. }
  1692. return entries.map(toLocation);
  1693. });
  1694. }
  1695. };
  1696. var RenameAdapter = class {
  1697. constructor(_worker) {
  1698. this._worker = _worker;
  1699. }
  1700. provideRenameEdits(model, position, newName, token) {
  1701. const resource = model.uri;
  1702. return this._worker(resource).then((worker) => {
  1703. return worker.doRename(resource.toString(), fromPosition(position), newName);
  1704. }).then((edit) => {
  1705. return toWorkspaceEdit(edit);
  1706. });
  1707. }
  1708. };
  1709. function toWorkspaceEdit(edit) {
  1710. if (!edit || !edit.changes) {
  1711. return void 0;
  1712. }
  1713. let resourceEdits = [];
  1714. for (let uri in edit.changes) {
  1715. const _uri = monaco_editor_core_exports.Uri.parse(uri);
  1716. for (let e of edit.changes[uri]) {
  1717. resourceEdits.push({
  1718. resource: _uri,
  1719. versionId: void 0,
  1720. textEdit: {
  1721. range: toRange(e.range),
  1722. text: e.newText
  1723. }
  1724. });
  1725. }
  1726. }
  1727. return {
  1728. edits: resourceEdits
  1729. };
  1730. }
  1731. var DocumentSymbolAdapter = class {
  1732. constructor(_worker) {
  1733. this._worker = _worker;
  1734. }
  1735. provideDocumentSymbols(model, token) {
  1736. const resource = model.uri;
  1737. return this._worker(resource).then((worker) => worker.findDocumentSymbols(resource.toString())).then((items) => {
  1738. if (!items) {
  1739. return;
  1740. }
  1741. return items.map((item) => ({
  1742. name: item.name,
  1743. detail: "",
  1744. containerName: item.containerName,
  1745. kind: toSymbolKind(item.kind),
  1746. range: toRange(item.location.range),
  1747. selectionRange: toRange(item.location.range),
  1748. tags: []
  1749. }));
  1750. });
  1751. }
  1752. };
  1753. function toSymbolKind(kind) {
  1754. let mKind = monaco_editor_core_exports.languages.SymbolKind;
  1755. switch (kind) {
  1756. case SymbolKind.File:
  1757. return mKind.Array;
  1758. case SymbolKind.Module:
  1759. return mKind.Module;
  1760. case SymbolKind.Namespace:
  1761. return mKind.Namespace;
  1762. case SymbolKind.Package:
  1763. return mKind.Package;
  1764. case SymbolKind.Class:
  1765. return mKind.Class;
  1766. case SymbolKind.Method:
  1767. return mKind.Method;
  1768. case SymbolKind.Property:
  1769. return mKind.Property;
  1770. case SymbolKind.Field:
  1771. return mKind.Field;
  1772. case SymbolKind.Constructor:
  1773. return mKind.Constructor;
  1774. case SymbolKind.Enum:
  1775. return mKind.Enum;
  1776. case SymbolKind.Interface:
  1777. return mKind.Interface;
  1778. case SymbolKind.Function:
  1779. return mKind.Function;
  1780. case SymbolKind.Variable:
  1781. return mKind.Variable;
  1782. case SymbolKind.Constant:
  1783. return mKind.Constant;
  1784. case SymbolKind.String:
  1785. return mKind.String;
  1786. case SymbolKind.Number:
  1787. return mKind.Number;
  1788. case SymbolKind.Boolean:
  1789. return mKind.Boolean;
  1790. case SymbolKind.Array:
  1791. return mKind.Array;
  1792. }
  1793. return mKind.Function;
  1794. }
  1795. var DocumentLinkAdapter = class {
  1796. constructor(_worker) {
  1797. this._worker = _worker;
  1798. }
  1799. provideLinks(model, token) {
  1800. const resource = model.uri;
  1801. return this._worker(resource).then((worker) => worker.findDocumentLinks(resource.toString())).then((items) => {
  1802. if (!items) {
  1803. return;
  1804. }
  1805. return {
  1806. links: items.map((item) => ({
  1807. range: toRange(item.range),
  1808. url: item.target
  1809. }))
  1810. };
  1811. });
  1812. }
  1813. };
  1814. var DocumentFormattingEditProvider = class {
  1815. constructor(_worker) {
  1816. this._worker = _worker;
  1817. }
  1818. provideDocumentFormattingEdits(model, options, token) {
  1819. const resource = model.uri;
  1820. return this._worker(resource).then((worker) => {
  1821. return worker.format(resource.toString(), null, fromFormattingOptions(options)).then((edits) => {
  1822. if (!edits || edits.length === 0) {
  1823. return;
  1824. }
  1825. return edits.map(toTextEdit);
  1826. });
  1827. });
  1828. }
  1829. };
  1830. var DocumentRangeFormattingEditProvider = class {
  1831. constructor(_worker) {
  1832. this._worker = _worker;
  1833. }
  1834. canFormatMultipleRanges = false;
  1835. provideDocumentRangeFormattingEdits(model, range, options, token) {
  1836. const resource = model.uri;
  1837. return this._worker(resource).then((worker) => {
  1838. return worker.format(resource.toString(), fromRange(range), fromFormattingOptions(options)).then((edits) => {
  1839. if (!edits || edits.length === 0) {
  1840. return;
  1841. }
  1842. return edits.map(toTextEdit);
  1843. });
  1844. });
  1845. }
  1846. };
  1847. function fromFormattingOptions(options) {
  1848. return {
  1849. tabSize: options.tabSize,
  1850. insertSpaces: options.insertSpaces
  1851. };
  1852. }
  1853. var DocumentColorAdapter = class {
  1854. constructor(_worker) {
  1855. this._worker = _worker;
  1856. }
  1857. provideDocumentColors(model, token) {
  1858. const resource = model.uri;
  1859. return this._worker(resource).then((worker) => worker.findDocumentColors(resource.toString())).then((infos) => {
  1860. if (!infos) {
  1861. return;
  1862. }
  1863. return infos.map((item) => ({
  1864. color: item.color,
  1865. range: toRange(item.range)
  1866. }));
  1867. });
  1868. }
  1869. provideColorPresentations(model, info, token) {
  1870. const resource = model.uri;
  1871. return this._worker(resource).then((worker) => worker.getColorPresentations(resource.toString(), info.color, fromRange(info.range))).then((presentations) => {
  1872. if (!presentations) {
  1873. return;
  1874. }
  1875. return presentations.map((presentation) => {
  1876. let item = {
  1877. label: presentation.label
  1878. };
  1879. if (presentation.textEdit) {
  1880. item.textEdit = toTextEdit(presentation.textEdit);
  1881. }
  1882. if (presentation.additionalTextEdits) {
  1883. item.additionalTextEdits = presentation.additionalTextEdits.map(toTextEdit);
  1884. }
  1885. return item;
  1886. });
  1887. });
  1888. }
  1889. };
  1890. var FoldingRangeAdapter = class {
  1891. constructor(_worker) {
  1892. this._worker = _worker;
  1893. }
  1894. provideFoldingRanges(model, context, token) {
  1895. const resource = model.uri;
  1896. return this._worker(resource).then((worker) => worker.getFoldingRanges(resource.toString(), context)).then((ranges) => {
  1897. if (!ranges) {
  1898. return;
  1899. }
  1900. return ranges.map((range) => {
  1901. const result = {
  1902. start: range.startLine + 1,
  1903. end: range.endLine + 1
  1904. };
  1905. if (typeof range.kind !== "undefined") {
  1906. result.kind = toFoldingRangeKind(range.kind);
  1907. }
  1908. return result;
  1909. });
  1910. });
  1911. }
  1912. };
  1913. function toFoldingRangeKind(kind) {
  1914. switch (kind) {
  1915. case FoldingRangeKind.Comment:
  1916. return monaco_editor_core_exports.languages.FoldingRangeKind.Comment;
  1917. case FoldingRangeKind.Imports:
  1918. return monaco_editor_core_exports.languages.FoldingRangeKind.Imports;
  1919. case FoldingRangeKind.Region:
  1920. return monaco_editor_core_exports.languages.FoldingRangeKind.Region;
  1921. }
  1922. return void 0;
  1923. }
  1924. var SelectionRangeAdapter = class {
  1925. constructor(_worker) {
  1926. this._worker = _worker;
  1927. }
  1928. provideSelectionRanges(model, positions, token) {
  1929. const resource = model.uri;
  1930. return this._worker(resource).then((worker) => worker.getSelectionRanges(resource.toString(), positions.map(fromPosition))).then((selectionRanges) => {
  1931. if (!selectionRanges) {
  1932. return;
  1933. }
  1934. return selectionRanges.map((selectionRange) => {
  1935. const result = [];
  1936. while (selectionRange) {
  1937. result.push({ range: toRange(selectionRange.range) });
  1938. selectionRange = selectionRange.parent;
  1939. }
  1940. return result;
  1941. });
  1942. });
  1943. }
  1944. };
  1945. // node_modules/jsonc-parser/lib/esm/impl/scanner.js
  1946. function createScanner(text, ignoreTrivia) {
  1947. if (ignoreTrivia === void 0) {
  1948. ignoreTrivia = false;
  1949. }
  1950. var len = text.length;
  1951. var pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
  1952. function scanHexDigits(count, exact) {
  1953. var digits = 0;
  1954. var value2 = 0;
  1955. while (digits < count || !exact) {
  1956. var ch = text.charCodeAt(pos);
  1957. if (ch >= 48 && ch <= 57) {
  1958. value2 = value2 * 16 + ch - 48;
  1959. } else if (ch >= 65 && ch <= 70) {
  1960. value2 = value2 * 16 + ch - 65 + 10;
  1961. } else if (ch >= 97 && ch <= 102) {
  1962. value2 = value2 * 16 + ch - 97 + 10;
  1963. } else {
  1964. break;
  1965. }
  1966. pos++;
  1967. digits++;
  1968. }
  1969. if (digits < count) {
  1970. value2 = -1;
  1971. }
  1972. return value2;
  1973. }
  1974. function setPosition(newPosition) {
  1975. pos = newPosition;
  1976. value = "";
  1977. tokenOffset = 0;
  1978. token = 16;
  1979. scanError = 0;
  1980. }
  1981. function scanNumber() {
  1982. var start = pos;
  1983. if (text.charCodeAt(pos) === 48) {
  1984. pos++;
  1985. } else {
  1986. pos++;
  1987. while (pos < text.length && isDigit(text.charCodeAt(pos))) {
  1988. pos++;
  1989. }
  1990. }
  1991. if (pos < text.length && text.charCodeAt(pos) === 46) {
  1992. pos++;
  1993. if (pos < text.length && isDigit(text.charCodeAt(pos))) {
  1994. pos++;
  1995. while (pos < text.length && isDigit(text.charCodeAt(pos))) {
  1996. pos++;
  1997. }
  1998. } else {
  1999. scanError = 3;
  2000. return text.substring(start, pos);
  2001. }
  2002. }
  2003. var end = pos;
  2004. if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
  2005. pos++;
  2006. if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
  2007. pos++;
  2008. }
  2009. if (pos < text.length && isDigit(text.charCodeAt(pos))) {
  2010. pos++;
  2011. while (pos < text.length && isDigit(text.charCodeAt(pos))) {
  2012. pos++;
  2013. }
  2014. end = pos;
  2015. } else {
  2016. scanError = 3;
  2017. }
  2018. }
  2019. return text.substring(start, end);
  2020. }
  2021. function scanString() {
  2022. var result = "", start = pos;
  2023. while (true) {
  2024. if (pos >= len) {
  2025. result += text.substring(start, pos);
  2026. scanError = 2;
  2027. break;
  2028. }
  2029. var ch = text.charCodeAt(pos);
  2030. if (ch === 34) {
  2031. result += text.substring(start, pos);
  2032. pos++;
  2033. break;
  2034. }
  2035. if (ch === 92) {
  2036. result += text.substring(start, pos);
  2037. pos++;
  2038. if (pos >= len) {
  2039. scanError = 2;
  2040. break;
  2041. }
  2042. var ch2 = text.charCodeAt(pos++);
  2043. switch (ch2) {
  2044. case 34:
  2045. result += '"';
  2046. break;
  2047. case 92:
  2048. result += "\\";
  2049. break;
  2050. case 47:
  2051. result += "/";
  2052. break;
  2053. case 98:
  2054. result += "\b";
  2055. break;
  2056. case 102:
  2057. result += "\f";
  2058. break;
  2059. case 110:
  2060. result += "\n";
  2061. break;
  2062. case 114:
  2063. result += "\r";
  2064. break;
  2065. case 116:
  2066. result += " ";
  2067. break;
  2068. case 117:
  2069. var ch3 = scanHexDigits(4, true);
  2070. if (ch3 >= 0) {
  2071. result += String.fromCharCode(ch3);
  2072. } else {
  2073. scanError = 4;
  2074. }
  2075. break;
  2076. default:
  2077. scanError = 5;
  2078. }
  2079. start = pos;
  2080. continue;
  2081. }
  2082. if (ch >= 0 && ch <= 31) {
  2083. if (isLineBreak(ch)) {
  2084. result += text.substring(start, pos);
  2085. scanError = 2;
  2086. break;
  2087. } else {
  2088. scanError = 6;
  2089. }
  2090. }
  2091. pos++;
  2092. }
  2093. return result;
  2094. }
  2095. function scanNext() {
  2096. value = "";
  2097. scanError = 0;
  2098. tokenOffset = pos;
  2099. lineStartOffset = lineNumber;
  2100. prevTokenLineStartOffset = tokenLineStartOffset;
  2101. if (pos >= len) {
  2102. tokenOffset = len;
  2103. return token = 17;
  2104. }
  2105. var code = text.charCodeAt(pos);
  2106. if (isWhiteSpace(code)) {
  2107. do {
  2108. pos++;
  2109. value += String.fromCharCode(code);
  2110. code = text.charCodeAt(pos);
  2111. } while (isWhiteSpace(code));
  2112. return token = 15;
  2113. }
  2114. if (isLineBreak(code)) {
  2115. pos++;
  2116. value += String.fromCharCode(code);
  2117. if (code === 13 && text.charCodeAt(pos) === 10) {
  2118. pos++;
  2119. value += "\n";
  2120. }
  2121. lineNumber++;
  2122. tokenLineStartOffset = pos;
  2123. return token = 14;
  2124. }
  2125. switch (code) {
  2126. case 123:
  2127. pos++;
  2128. return token = 1;
  2129. case 125:
  2130. pos++;
  2131. return token = 2;
  2132. case 91:
  2133. pos++;
  2134. return token = 3;
  2135. case 93:
  2136. pos++;
  2137. return token = 4;
  2138. case 58:
  2139. pos++;
  2140. return token = 6;
  2141. case 44:
  2142. pos++;
  2143. return token = 5;
  2144. case 34:
  2145. pos++;
  2146. value = scanString();
  2147. return token = 10;
  2148. case 47:
  2149. var start = pos - 1;
  2150. if (text.charCodeAt(pos + 1) === 47) {
  2151. pos += 2;
  2152. while (pos < len) {
  2153. if (isLineBreak(text.charCodeAt(pos))) {
  2154. break;
  2155. }
  2156. pos++;
  2157. }
  2158. value = text.substring(start, pos);
  2159. return token = 12;
  2160. }
  2161. if (text.charCodeAt(pos + 1) === 42) {
  2162. pos += 2;
  2163. var safeLength = len - 1;
  2164. var commentClosed = false;
  2165. while (pos < safeLength) {
  2166. var ch = text.charCodeAt(pos);
  2167. if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
  2168. pos += 2;
  2169. commentClosed = true;
  2170. break;
  2171. }
  2172. pos++;
  2173. if (isLineBreak(ch)) {
  2174. if (ch === 13 && text.charCodeAt(pos) === 10) {
  2175. pos++;
  2176. }
  2177. lineNumber++;
  2178. tokenLineStartOffset = pos;
  2179. }
  2180. }
  2181. if (!commentClosed) {
  2182. pos++;
  2183. scanError = 1;
  2184. }
  2185. value = text.substring(start, pos);
  2186. return token = 13;
  2187. }
  2188. value += String.fromCharCode(code);
  2189. pos++;
  2190. return token = 16;
  2191. case 45:
  2192. value += String.fromCharCode(code);
  2193. pos++;
  2194. if (pos === len || !isDigit(text.charCodeAt(pos))) {
  2195. return token = 16;
  2196. }
  2197. case 48:
  2198. case 49:
  2199. case 50:
  2200. case 51:
  2201. case 52:
  2202. case 53:
  2203. case 54:
  2204. case 55:
  2205. case 56:
  2206. case 57:
  2207. value += scanNumber();
  2208. return token = 11;
  2209. default:
  2210. while (pos < len && isUnknownContentCharacter(code)) {
  2211. pos++;
  2212. code = text.charCodeAt(pos);
  2213. }
  2214. if (tokenOffset !== pos) {
  2215. value = text.substring(tokenOffset, pos);
  2216. switch (value) {
  2217. case "true":
  2218. return token = 8;
  2219. case "false":
  2220. return token = 9;
  2221. case "null":
  2222. return token = 7;
  2223. }
  2224. return token = 16;
  2225. }
  2226. value += String.fromCharCode(code);
  2227. pos++;
  2228. return token = 16;
  2229. }
  2230. }
  2231. function isUnknownContentCharacter(code) {
  2232. if (isWhiteSpace(code) || isLineBreak(code)) {
  2233. return false;
  2234. }
  2235. switch (code) {
  2236. case 125:
  2237. case 93:
  2238. case 123:
  2239. case 91:
  2240. case 34:
  2241. case 58:
  2242. case 44:
  2243. case 47:
  2244. return false;
  2245. }
  2246. return true;
  2247. }
  2248. function scanNextNonTrivia() {
  2249. var result;
  2250. do {
  2251. result = scanNext();
  2252. } while (result >= 12 && result <= 15);
  2253. return result;
  2254. }
  2255. return {
  2256. setPosition,
  2257. getPosition: function() {
  2258. return pos;
  2259. },
  2260. scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
  2261. getToken: function() {
  2262. return token;
  2263. },
  2264. getTokenValue: function() {
  2265. return value;
  2266. },
  2267. getTokenOffset: function() {
  2268. return tokenOffset;
  2269. },
  2270. getTokenLength: function() {
  2271. return pos - tokenOffset;
  2272. },
  2273. getTokenStartLine: function() {
  2274. return lineStartOffset;
  2275. },
  2276. getTokenStartCharacter: function() {
  2277. return tokenOffset - prevTokenLineStartOffset;
  2278. },
  2279. getTokenError: function() {
  2280. return scanError;
  2281. }
  2282. };
  2283. }
  2284. function isWhiteSpace(ch) {
  2285. return ch === 32 || ch === 9 || ch === 11 || ch === 12 || ch === 160 || ch === 5760 || ch >= 8192 && ch <= 8203 || ch === 8239 || ch === 8287 || ch === 12288 || ch === 65279;
  2286. }
  2287. function isLineBreak(ch) {
  2288. return ch === 10 || ch === 13 || ch === 8232 || ch === 8233;
  2289. }
  2290. function isDigit(ch) {
  2291. return ch >= 48 && ch <= 57;
  2292. }
  2293. // node_modules/jsonc-parser/lib/esm/impl/parser.js
  2294. var ParseOptions;
  2295. (function(ParseOptions2) {
  2296. ParseOptions2.DEFAULT = {
  2297. allowTrailingComma: false
  2298. };
  2299. })(ParseOptions || (ParseOptions = {}));
  2300. // node_modules/jsonc-parser/lib/esm/main.js
  2301. var createScanner2 = createScanner;
  2302. // src/language/json/tokenization.ts
  2303. function createTokenizationSupport(supportComments) {
  2304. return {
  2305. getInitialState: () => new JSONState(null, null, false, null),
  2306. tokenize: (line, state) => tokenize(supportComments, line, state)
  2307. };
  2308. }
  2309. var TOKEN_DELIM_OBJECT = "delimiter.bracket.json";
  2310. var TOKEN_DELIM_ARRAY = "delimiter.array.json";
  2311. var TOKEN_DELIM_COLON = "delimiter.colon.json";
  2312. var TOKEN_DELIM_COMMA = "delimiter.comma.json";
  2313. var TOKEN_VALUE_BOOLEAN = "keyword.json";
  2314. var TOKEN_VALUE_NULL = "keyword.json";
  2315. var TOKEN_VALUE_STRING = "string.value.json";
  2316. var TOKEN_VALUE_NUMBER = "number.json";
  2317. var TOKEN_PROPERTY_NAME = "string.key.json";
  2318. var TOKEN_COMMENT_BLOCK = "comment.block.json";
  2319. var TOKEN_COMMENT_LINE = "comment.line.json";
  2320. var ParentsStack = class {
  2321. constructor(parent, type) {
  2322. this.parent = parent;
  2323. this.type = type;
  2324. }
  2325. static pop(parents) {
  2326. if (parents) {
  2327. return parents.parent;
  2328. }
  2329. return null;
  2330. }
  2331. static push(parents, type) {
  2332. return new ParentsStack(parents, type);
  2333. }
  2334. static equals(a, b) {
  2335. if (!a && !b) {
  2336. return true;
  2337. }
  2338. if (!a || !b) {
  2339. return false;
  2340. }
  2341. while (a && b) {
  2342. if (a === b) {
  2343. return true;
  2344. }
  2345. if (a.type !== b.type) {
  2346. return false;
  2347. }
  2348. a = a.parent;
  2349. b = b.parent;
  2350. }
  2351. return true;
  2352. }
  2353. };
  2354. var JSONState = class {
  2355. _state;
  2356. scanError;
  2357. lastWasColon;
  2358. parents;
  2359. constructor(state, scanError, lastWasColon, parents) {
  2360. this._state = state;
  2361. this.scanError = scanError;
  2362. this.lastWasColon = lastWasColon;
  2363. this.parents = parents;
  2364. }
  2365. clone() {
  2366. return new JSONState(this._state, this.scanError, this.lastWasColon, this.parents);
  2367. }
  2368. equals(other) {
  2369. if (other === this) {
  2370. return true;
  2371. }
  2372. if (!other || !(other instanceof JSONState)) {
  2373. return false;
  2374. }
  2375. return this.scanError === other.scanError && this.lastWasColon === other.lastWasColon && ParentsStack.equals(this.parents, other.parents);
  2376. }
  2377. getStateData() {
  2378. return this._state;
  2379. }
  2380. setStateData(state) {
  2381. this._state = state;
  2382. }
  2383. };
  2384. function tokenize(comments, line, state, offsetDelta = 0) {
  2385. let numberOfInsertedCharacters = 0;
  2386. let adjustOffset = false;
  2387. switch (state.scanError) {
  2388. case 2 /* UnexpectedEndOfString */:
  2389. line = '"' + line;
  2390. numberOfInsertedCharacters = 1;
  2391. break;
  2392. case 1 /* UnexpectedEndOfComment */:
  2393. line = "/*" + line;
  2394. numberOfInsertedCharacters = 2;
  2395. break;
  2396. }
  2397. const scanner = createScanner2(line);
  2398. let lastWasColon = state.lastWasColon;
  2399. let parents = state.parents;
  2400. const ret = {
  2401. tokens: [],
  2402. endState: state.clone()
  2403. };
  2404. while (true) {
  2405. let offset = offsetDelta + scanner.getPosition();
  2406. let type = "";
  2407. const kind = scanner.scan();
  2408. if (kind === 17 /* EOF */) {
  2409. break;
  2410. }
  2411. if (offset === offsetDelta + scanner.getPosition()) {
  2412. throw new Error("Scanner did not advance, next 3 characters are: " + line.substr(scanner.getPosition(), 3));
  2413. }
  2414. if (adjustOffset) {
  2415. offset -= numberOfInsertedCharacters;
  2416. }
  2417. adjustOffset = numberOfInsertedCharacters > 0;
  2418. switch (kind) {
  2419. case 1 /* OpenBraceToken */:
  2420. parents = ParentsStack.push(parents, 0 /* Object */);
  2421. type = TOKEN_DELIM_OBJECT;
  2422. lastWasColon = false;
  2423. break;
  2424. case 2 /* CloseBraceToken */:
  2425. parents = ParentsStack.pop(parents);
  2426. type = TOKEN_DELIM_OBJECT;
  2427. lastWasColon = false;
  2428. break;
  2429. case 3 /* OpenBracketToken */:
  2430. parents = ParentsStack.push(parents, 1 /* Array */);
  2431. type = TOKEN_DELIM_ARRAY;
  2432. lastWasColon = false;
  2433. break;
  2434. case 4 /* CloseBracketToken */:
  2435. parents = ParentsStack.pop(parents);
  2436. type = TOKEN_DELIM_ARRAY;
  2437. lastWasColon = false;
  2438. break;
  2439. case 6 /* ColonToken */:
  2440. type = TOKEN_DELIM_COLON;
  2441. lastWasColon = true;
  2442. break;
  2443. case 5 /* CommaToken */:
  2444. type = TOKEN_DELIM_COMMA;
  2445. lastWasColon = false;
  2446. break;
  2447. case 8 /* TrueKeyword */:
  2448. case 9 /* FalseKeyword */:
  2449. type = TOKEN_VALUE_BOOLEAN;
  2450. lastWasColon = false;
  2451. break;
  2452. case 7 /* NullKeyword */:
  2453. type = TOKEN_VALUE_NULL;
  2454. lastWasColon = false;
  2455. break;
  2456. case 10 /* StringLiteral */:
  2457. const currentParent = parents ? parents.type : 0 /* Object */;
  2458. const inArray = currentParent === 1 /* Array */;
  2459. type = lastWasColon || inArray ? TOKEN_VALUE_STRING : TOKEN_PROPERTY_NAME;
  2460. lastWasColon = false;
  2461. break;
  2462. case 11 /* NumericLiteral */:
  2463. type = TOKEN_VALUE_NUMBER;
  2464. lastWasColon = false;
  2465. break;
  2466. }
  2467. if (comments) {
  2468. switch (kind) {
  2469. case 12 /* LineCommentTrivia */:
  2470. type = TOKEN_COMMENT_LINE;
  2471. break;
  2472. case 13 /* BlockCommentTrivia */:
  2473. type = TOKEN_COMMENT_BLOCK;
  2474. break;
  2475. }
  2476. }
  2477. ret.endState = new JSONState(state.getStateData(), scanner.getTokenError(), lastWasColon, parents);
  2478. ret.tokens.push({
  2479. startIndex: offset,
  2480. scopes: type
  2481. });
  2482. }
  2483. return ret;
  2484. }
  2485. // src/language/json/jsonMode.ts
  2486. var JSONDiagnosticsAdapter = class extends DiagnosticsAdapter {
  2487. constructor(languageId, worker, defaults) {
  2488. super(languageId, worker, defaults.onDidChange);
  2489. this._disposables.push(monaco_editor_core_exports.editor.onWillDisposeModel((model) => {
  2490. this._resetSchema(model.uri);
  2491. }));
  2492. this._disposables.push(monaco_editor_core_exports.editor.onDidChangeModelLanguage((event) => {
  2493. this._resetSchema(event.model.uri);
  2494. }));
  2495. }
  2496. _resetSchema(resource) {
  2497. this._worker().then((worker) => {
  2498. worker.resetSchema(resource.toString());
  2499. });
  2500. }
  2501. };
  2502. function setupMode(defaults) {
  2503. const disposables = [];
  2504. const providers = [];
  2505. const client = new WorkerManager(defaults);
  2506. disposables.push(client);
  2507. const worker = (...uris) => {
  2508. return client.getLanguageServiceWorker(...uris);
  2509. };
  2510. function registerProviders() {
  2511. const { languageId, modeConfiguration: modeConfiguration2 } = defaults;
  2512. disposeAll(providers);
  2513. if (modeConfiguration2.documentFormattingEdits) {
  2514. providers.push(monaco_editor_core_exports.languages.registerDocumentFormattingEditProvider(languageId, new DocumentFormattingEditProvider(worker)));
  2515. }
  2516. if (modeConfiguration2.documentRangeFormattingEdits) {
  2517. providers.push(monaco_editor_core_exports.languages.registerDocumentRangeFormattingEditProvider(languageId, new DocumentRangeFormattingEditProvider(worker)));
  2518. }
  2519. if (modeConfiguration2.completionItems) {
  2520. providers.push(monaco_editor_core_exports.languages.registerCompletionItemProvider(languageId, new CompletionAdapter(worker, [" ", ":", '"'])));
  2521. }
  2522. if (modeConfiguration2.hovers) {
  2523. providers.push(monaco_editor_core_exports.languages.registerHoverProvider(languageId, new HoverAdapter(worker)));
  2524. }
  2525. if (modeConfiguration2.documentSymbols) {
  2526. providers.push(monaco_editor_core_exports.languages.registerDocumentSymbolProvider(languageId, new DocumentSymbolAdapter(worker)));
  2527. }
  2528. if (modeConfiguration2.tokens) {
  2529. providers.push(monaco_editor_core_exports.languages.setTokensProvider(languageId, createTokenizationSupport(true)));
  2530. }
  2531. if (modeConfiguration2.colors) {
  2532. providers.push(monaco_editor_core_exports.languages.registerColorProvider(languageId, new DocumentColorAdapter(worker)));
  2533. }
  2534. if (modeConfiguration2.foldingRanges) {
  2535. providers.push(monaco_editor_core_exports.languages.registerFoldingRangeProvider(languageId, new FoldingRangeAdapter(worker)));
  2536. }
  2537. if (modeConfiguration2.diagnostics) {
  2538. providers.push(new JSONDiagnosticsAdapter(languageId, worker, defaults));
  2539. }
  2540. if (modeConfiguration2.selectionRanges) {
  2541. providers.push(monaco_editor_core_exports.languages.registerSelectionRangeProvider(languageId, new SelectionRangeAdapter(worker)));
  2542. }
  2543. }
  2544. registerProviders();
  2545. disposables.push(monaco_editor_core_exports.languages.setLanguageConfiguration(defaults.languageId, richEditConfiguration));
  2546. let modeConfiguration = defaults.modeConfiguration;
  2547. defaults.onDidChange((newDefaults) => {
  2548. if (newDefaults.modeConfiguration !== modeConfiguration) {
  2549. modeConfiguration = newDefaults.modeConfiguration;
  2550. registerProviders();
  2551. }
  2552. });
  2553. disposables.push(asDisposable(providers));
  2554. return asDisposable(disposables);
  2555. }
  2556. function asDisposable(disposables) {
  2557. return { dispose: () => disposeAll(disposables) };
  2558. }
  2559. function disposeAll(disposables) {
  2560. while (disposables.length) {
  2561. disposables.pop().dispose();
  2562. }
  2563. }
  2564. var richEditConfiguration = {
  2565. wordPattern: /(-?\d*\.\d\w*)|([^\[\{\]\}\:\"\,\s]+)/g,
  2566. comments: {
  2567. lineComment: "//",
  2568. blockComment: ["/*", "*/"]
  2569. },
  2570. brackets: [
  2571. ["{", "}"],
  2572. ["[", "]"]
  2573. ],
  2574. autoClosingPairs: [
  2575. { open: "{", close: "}", notIn: ["string"] },
  2576. { open: "[", close: "]", notIn: ["string"] },
  2577. { open: '"', close: '"', notIn: ["string"] }
  2578. ]
  2579. };
  2580. export {
  2581. CompletionAdapter,
  2582. DefinitionAdapter,
  2583. DiagnosticsAdapter,
  2584. DocumentColorAdapter,
  2585. DocumentFormattingEditProvider,
  2586. DocumentHighlightAdapter,
  2587. DocumentLinkAdapter,
  2588. DocumentRangeFormattingEditProvider,
  2589. DocumentSymbolAdapter,
  2590. FoldingRangeAdapter,
  2591. HoverAdapter,
  2592. ReferenceAdapter,
  2593. RenameAdapter,
  2594. SelectionRangeAdapter,
  2595. WorkerManager,
  2596. fromPosition,
  2597. fromRange,
  2598. setupMode,
  2599. toRange,
  2600. toTextEdit
  2601. };