jsonMode.js 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.34.1(547870b6881302c5b4ff32173c16d06009e3588f)
  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. provideDocumentRangeFormattingEdits(model, range, options, token) {
  1835. const resource = model.uri;
  1836. return this._worker(resource).then((worker) => {
  1837. return worker.format(resource.toString(), fromRange(range), fromFormattingOptions(options)).then((edits) => {
  1838. if (!edits || edits.length === 0) {
  1839. return;
  1840. }
  1841. return edits.map(toTextEdit);
  1842. });
  1843. });
  1844. }
  1845. };
  1846. function fromFormattingOptions(options) {
  1847. return {
  1848. tabSize: options.tabSize,
  1849. insertSpaces: options.insertSpaces
  1850. };
  1851. }
  1852. var DocumentColorAdapter = class {
  1853. constructor(_worker) {
  1854. this._worker = _worker;
  1855. }
  1856. provideDocumentColors(model, token) {
  1857. const resource = model.uri;
  1858. return this._worker(resource).then((worker) => worker.findDocumentColors(resource.toString())).then((infos) => {
  1859. if (!infos) {
  1860. return;
  1861. }
  1862. return infos.map((item) => ({
  1863. color: item.color,
  1864. range: toRange(item.range)
  1865. }));
  1866. });
  1867. }
  1868. provideColorPresentations(model, info, token) {
  1869. const resource = model.uri;
  1870. return this._worker(resource).then((worker) => worker.getColorPresentations(resource.toString(), info.color, fromRange(info.range))).then((presentations) => {
  1871. if (!presentations) {
  1872. return;
  1873. }
  1874. return presentations.map((presentation) => {
  1875. let item = {
  1876. label: presentation.label
  1877. };
  1878. if (presentation.textEdit) {
  1879. item.textEdit = toTextEdit(presentation.textEdit);
  1880. }
  1881. if (presentation.additionalTextEdits) {
  1882. item.additionalTextEdits = presentation.additionalTextEdits.map(toTextEdit);
  1883. }
  1884. return item;
  1885. });
  1886. });
  1887. }
  1888. };
  1889. var FoldingRangeAdapter = class {
  1890. constructor(_worker) {
  1891. this._worker = _worker;
  1892. }
  1893. provideFoldingRanges(model, context, token) {
  1894. const resource = model.uri;
  1895. return this._worker(resource).then((worker) => worker.getFoldingRanges(resource.toString(), context)).then((ranges) => {
  1896. if (!ranges) {
  1897. return;
  1898. }
  1899. return ranges.map((range) => {
  1900. const result = {
  1901. start: range.startLine + 1,
  1902. end: range.endLine + 1
  1903. };
  1904. if (typeof range.kind !== "undefined") {
  1905. result.kind = toFoldingRangeKind(range.kind);
  1906. }
  1907. return result;
  1908. });
  1909. });
  1910. }
  1911. };
  1912. function toFoldingRangeKind(kind) {
  1913. switch (kind) {
  1914. case FoldingRangeKind.Comment:
  1915. return monaco_editor_core_exports.languages.FoldingRangeKind.Comment;
  1916. case FoldingRangeKind.Imports:
  1917. return monaco_editor_core_exports.languages.FoldingRangeKind.Imports;
  1918. case FoldingRangeKind.Region:
  1919. return monaco_editor_core_exports.languages.FoldingRangeKind.Region;
  1920. }
  1921. return void 0;
  1922. }
  1923. var SelectionRangeAdapter = class {
  1924. constructor(_worker) {
  1925. this._worker = _worker;
  1926. }
  1927. provideSelectionRanges(model, positions, token) {
  1928. const resource = model.uri;
  1929. return this._worker(resource).then((worker) => worker.getSelectionRanges(resource.toString(), positions.map(fromPosition))).then((selectionRanges) => {
  1930. if (!selectionRanges) {
  1931. return;
  1932. }
  1933. return selectionRanges.map((selectionRange) => {
  1934. const result = [];
  1935. while (selectionRange) {
  1936. result.push({ range: toRange(selectionRange.range) });
  1937. selectionRange = selectionRange.parent;
  1938. }
  1939. return result;
  1940. });
  1941. });
  1942. }
  1943. };
  1944. // node_modules/jsonc-parser/lib/esm/impl/scanner.js
  1945. function createScanner(text, ignoreTrivia) {
  1946. if (ignoreTrivia === void 0) {
  1947. ignoreTrivia = false;
  1948. }
  1949. var len = text.length;
  1950. var pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
  1951. function scanHexDigits(count, exact) {
  1952. var digits = 0;
  1953. var value2 = 0;
  1954. while (digits < count || !exact) {
  1955. var ch = text.charCodeAt(pos);
  1956. if (ch >= 48 && ch <= 57) {
  1957. value2 = value2 * 16 + ch - 48;
  1958. } else if (ch >= 65 && ch <= 70) {
  1959. value2 = value2 * 16 + ch - 65 + 10;
  1960. } else if (ch >= 97 && ch <= 102) {
  1961. value2 = value2 * 16 + ch - 97 + 10;
  1962. } else {
  1963. break;
  1964. }
  1965. pos++;
  1966. digits++;
  1967. }
  1968. if (digits < count) {
  1969. value2 = -1;
  1970. }
  1971. return value2;
  1972. }
  1973. function setPosition(newPosition) {
  1974. pos = newPosition;
  1975. value = "";
  1976. tokenOffset = 0;
  1977. token = 16;
  1978. scanError = 0;
  1979. }
  1980. function scanNumber() {
  1981. var start = pos;
  1982. if (text.charCodeAt(pos) === 48) {
  1983. pos++;
  1984. } else {
  1985. pos++;
  1986. while (pos < text.length && isDigit(text.charCodeAt(pos))) {
  1987. pos++;
  1988. }
  1989. }
  1990. if (pos < text.length && text.charCodeAt(pos) === 46) {
  1991. pos++;
  1992. if (pos < text.length && isDigit(text.charCodeAt(pos))) {
  1993. pos++;
  1994. while (pos < text.length && isDigit(text.charCodeAt(pos))) {
  1995. pos++;
  1996. }
  1997. } else {
  1998. scanError = 3;
  1999. return text.substring(start, pos);
  2000. }
  2001. }
  2002. var end = pos;
  2003. if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
  2004. pos++;
  2005. if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
  2006. pos++;
  2007. }
  2008. if (pos < text.length && isDigit(text.charCodeAt(pos))) {
  2009. pos++;
  2010. while (pos < text.length && isDigit(text.charCodeAt(pos))) {
  2011. pos++;
  2012. }
  2013. end = pos;
  2014. } else {
  2015. scanError = 3;
  2016. }
  2017. }
  2018. return text.substring(start, end);
  2019. }
  2020. function scanString() {
  2021. var result = "", start = pos;
  2022. while (true) {
  2023. if (pos >= len) {
  2024. result += text.substring(start, pos);
  2025. scanError = 2;
  2026. break;
  2027. }
  2028. var ch = text.charCodeAt(pos);
  2029. if (ch === 34) {
  2030. result += text.substring(start, pos);
  2031. pos++;
  2032. break;
  2033. }
  2034. if (ch === 92) {
  2035. result += text.substring(start, pos);
  2036. pos++;
  2037. if (pos >= len) {
  2038. scanError = 2;
  2039. break;
  2040. }
  2041. var ch2 = text.charCodeAt(pos++);
  2042. switch (ch2) {
  2043. case 34:
  2044. result += '"';
  2045. break;
  2046. case 92:
  2047. result += "\\";
  2048. break;
  2049. case 47:
  2050. result += "/";
  2051. break;
  2052. case 98:
  2053. result += "\b";
  2054. break;
  2055. case 102:
  2056. result += "\f";
  2057. break;
  2058. case 110:
  2059. result += "\n";
  2060. break;
  2061. case 114:
  2062. result += "\r";
  2063. break;
  2064. case 116:
  2065. result += " ";
  2066. break;
  2067. case 117:
  2068. var ch3 = scanHexDigits(4, true);
  2069. if (ch3 >= 0) {
  2070. result += String.fromCharCode(ch3);
  2071. } else {
  2072. scanError = 4;
  2073. }
  2074. break;
  2075. default:
  2076. scanError = 5;
  2077. }
  2078. start = pos;
  2079. continue;
  2080. }
  2081. if (ch >= 0 && ch <= 31) {
  2082. if (isLineBreak(ch)) {
  2083. result += text.substring(start, pos);
  2084. scanError = 2;
  2085. break;
  2086. } else {
  2087. scanError = 6;
  2088. }
  2089. }
  2090. pos++;
  2091. }
  2092. return result;
  2093. }
  2094. function scanNext() {
  2095. value = "";
  2096. scanError = 0;
  2097. tokenOffset = pos;
  2098. lineStartOffset = lineNumber;
  2099. prevTokenLineStartOffset = tokenLineStartOffset;
  2100. if (pos >= len) {
  2101. tokenOffset = len;
  2102. return token = 17;
  2103. }
  2104. var code = text.charCodeAt(pos);
  2105. if (isWhiteSpace(code)) {
  2106. do {
  2107. pos++;
  2108. value += String.fromCharCode(code);
  2109. code = text.charCodeAt(pos);
  2110. } while (isWhiteSpace(code));
  2111. return token = 15;
  2112. }
  2113. if (isLineBreak(code)) {
  2114. pos++;
  2115. value += String.fromCharCode(code);
  2116. if (code === 13 && text.charCodeAt(pos) === 10) {
  2117. pos++;
  2118. value += "\n";
  2119. }
  2120. lineNumber++;
  2121. tokenLineStartOffset = pos;
  2122. return token = 14;
  2123. }
  2124. switch (code) {
  2125. case 123:
  2126. pos++;
  2127. return token = 1;
  2128. case 125:
  2129. pos++;
  2130. return token = 2;
  2131. case 91:
  2132. pos++;
  2133. return token = 3;
  2134. case 93:
  2135. pos++;
  2136. return token = 4;
  2137. case 58:
  2138. pos++;
  2139. return token = 6;
  2140. case 44:
  2141. pos++;
  2142. return token = 5;
  2143. case 34:
  2144. pos++;
  2145. value = scanString();
  2146. return token = 10;
  2147. case 47:
  2148. var start = pos - 1;
  2149. if (text.charCodeAt(pos + 1) === 47) {
  2150. pos += 2;
  2151. while (pos < len) {
  2152. if (isLineBreak(text.charCodeAt(pos))) {
  2153. break;
  2154. }
  2155. pos++;
  2156. }
  2157. value = text.substring(start, pos);
  2158. return token = 12;
  2159. }
  2160. if (text.charCodeAt(pos + 1) === 42) {
  2161. pos += 2;
  2162. var safeLength = len - 1;
  2163. var commentClosed = false;
  2164. while (pos < safeLength) {
  2165. var ch = text.charCodeAt(pos);
  2166. if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
  2167. pos += 2;
  2168. commentClosed = true;
  2169. break;
  2170. }
  2171. pos++;
  2172. if (isLineBreak(ch)) {
  2173. if (ch === 13 && text.charCodeAt(pos) === 10) {
  2174. pos++;
  2175. }
  2176. lineNumber++;
  2177. tokenLineStartOffset = pos;
  2178. }
  2179. }
  2180. if (!commentClosed) {
  2181. pos++;
  2182. scanError = 1;
  2183. }
  2184. value = text.substring(start, pos);
  2185. return token = 13;
  2186. }
  2187. value += String.fromCharCode(code);
  2188. pos++;
  2189. return token = 16;
  2190. case 45:
  2191. value += String.fromCharCode(code);
  2192. pos++;
  2193. if (pos === len || !isDigit(text.charCodeAt(pos))) {
  2194. return token = 16;
  2195. }
  2196. case 48:
  2197. case 49:
  2198. case 50:
  2199. case 51:
  2200. case 52:
  2201. case 53:
  2202. case 54:
  2203. case 55:
  2204. case 56:
  2205. case 57:
  2206. value += scanNumber();
  2207. return token = 11;
  2208. default:
  2209. while (pos < len && isUnknownContentCharacter(code)) {
  2210. pos++;
  2211. code = text.charCodeAt(pos);
  2212. }
  2213. if (tokenOffset !== pos) {
  2214. value = text.substring(tokenOffset, pos);
  2215. switch (value) {
  2216. case "true":
  2217. return token = 8;
  2218. case "false":
  2219. return token = 9;
  2220. case "null":
  2221. return token = 7;
  2222. }
  2223. return token = 16;
  2224. }
  2225. value += String.fromCharCode(code);
  2226. pos++;
  2227. return token = 16;
  2228. }
  2229. }
  2230. function isUnknownContentCharacter(code) {
  2231. if (isWhiteSpace(code) || isLineBreak(code)) {
  2232. return false;
  2233. }
  2234. switch (code) {
  2235. case 125:
  2236. case 93:
  2237. case 123:
  2238. case 91:
  2239. case 34:
  2240. case 58:
  2241. case 44:
  2242. case 47:
  2243. return false;
  2244. }
  2245. return true;
  2246. }
  2247. function scanNextNonTrivia() {
  2248. var result;
  2249. do {
  2250. result = scanNext();
  2251. } while (result >= 12 && result <= 15);
  2252. return result;
  2253. }
  2254. return {
  2255. setPosition,
  2256. getPosition: function() {
  2257. return pos;
  2258. },
  2259. scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
  2260. getToken: function() {
  2261. return token;
  2262. },
  2263. getTokenValue: function() {
  2264. return value;
  2265. },
  2266. getTokenOffset: function() {
  2267. return tokenOffset;
  2268. },
  2269. getTokenLength: function() {
  2270. return pos - tokenOffset;
  2271. },
  2272. getTokenStartLine: function() {
  2273. return lineStartOffset;
  2274. },
  2275. getTokenStartCharacter: function() {
  2276. return tokenOffset - prevTokenLineStartOffset;
  2277. },
  2278. getTokenError: function() {
  2279. return scanError;
  2280. }
  2281. };
  2282. }
  2283. function isWhiteSpace(ch) {
  2284. 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;
  2285. }
  2286. function isLineBreak(ch) {
  2287. return ch === 10 || ch === 13 || ch === 8232 || ch === 8233;
  2288. }
  2289. function isDigit(ch) {
  2290. return ch >= 48 && ch <= 57;
  2291. }
  2292. // node_modules/jsonc-parser/lib/esm/impl/parser.js
  2293. var ParseOptions;
  2294. (function(ParseOptions2) {
  2295. ParseOptions2.DEFAULT = {
  2296. allowTrailingComma: false
  2297. };
  2298. })(ParseOptions || (ParseOptions = {}));
  2299. // node_modules/jsonc-parser/lib/esm/main.js
  2300. var createScanner2 = createScanner;
  2301. // src/language/json/tokenization.ts
  2302. function createTokenizationSupport(supportComments) {
  2303. return {
  2304. getInitialState: () => new JSONState(null, null, false, null),
  2305. tokenize: (line, state) => tokenize(supportComments, line, state)
  2306. };
  2307. }
  2308. var TOKEN_DELIM_OBJECT = "delimiter.bracket.json";
  2309. var TOKEN_DELIM_ARRAY = "delimiter.array.json";
  2310. var TOKEN_DELIM_COLON = "delimiter.colon.json";
  2311. var TOKEN_DELIM_COMMA = "delimiter.comma.json";
  2312. var TOKEN_VALUE_BOOLEAN = "keyword.json";
  2313. var TOKEN_VALUE_NULL = "keyword.json";
  2314. var TOKEN_VALUE_STRING = "string.value.json";
  2315. var TOKEN_VALUE_NUMBER = "number.json";
  2316. var TOKEN_PROPERTY_NAME = "string.key.json";
  2317. var TOKEN_COMMENT_BLOCK = "comment.block.json";
  2318. var TOKEN_COMMENT_LINE = "comment.line.json";
  2319. var ParentsStack = class {
  2320. constructor(parent, type) {
  2321. this.parent = parent;
  2322. this.type = type;
  2323. }
  2324. static pop(parents) {
  2325. if (parents) {
  2326. return parents.parent;
  2327. }
  2328. return null;
  2329. }
  2330. static push(parents, type) {
  2331. return new ParentsStack(parents, type);
  2332. }
  2333. static equals(a, b) {
  2334. if (!a && !b) {
  2335. return true;
  2336. }
  2337. if (!a || !b) {
  2338. return false;
  2339. }
  2340. while (a && b) {
  2341. if (a === b) {
  2342. return true;
  2343. }
  2344. if (a.type !== b.type) {
  2345. return false;
  2346. }
  2347. a = a.parent;
  2348. b = b.parent;
  2349. }
  2350. return true;
  2351. }
  2352. };
  2353. var JSONState = class {
  2354. _state;
  2355. scanError;
  2356. lastWasColon;
  2357. parents;
  2358. constructor(state, scanError, lastWasColon, parents) {
  2359. this._state = state;
  2360. this.scanError = scanError;
  2361. this.lastWasColon = lastWasColon;
  2362. this.parents = parents;
  2363. }
  2364. clone() {
  2365. return new JSONState(this._state, this.scanError, this.lastWasColon, this.parents);
  2366. }
  2367. equals(other) {
  2368. if (other === this) {
  2369. return true;
  2370. }
  2371. if (!other || !(other instanceof JSONState)) {
  2372. return false;
  2373. }
  2374. return this.scanError === other.scanError && this.lastWasColon === other.lastWasColon && ParentsStack.equals(this.parents, other.parents);
  2375. }
  2376. getStateData() {
  2377. return this._state;
  2378. }
  2379. setStateData(state) {
  2380. this._state = state;
  2381. }
  2382. };
  2383. function tokenize(comments, line, state, offsetDelta = 0) {
  2384. let numberOfInsertedCharacters = 0;
  2385. let adjustOffset = false;
  2386. switch (state.scanError) {
  2387. case 2 /* UnexpectedEndOfString */:
  2388. line = '"' + line;
  2389. numberOfInsertedCharacters = 1;
  2390. break;
  2391. case 1 /* UnexpectedEndOfComment */:
  2392. line = "/*" + line;
  2393. numberOfInsertedCharacters = 2;
  2394. break;
  2395. }
  2396. const scanner = createScanner2(line);
  2397. let lastWasColon = state.lastWasColon;
  2398. let parents = state.parents;
  2399. const ret = {
  2400. tokens: [],
  2401. endState: state.clone()
  2402. };
  2403. while (true) {
  2404. let offset = offsetDelta + scanner.getPosition();
  2405. let type = "";
  2406. const kind = scanner.scan();
  2407. if (kind === 17 /* EOF */) {
  2408. break;
  2409. }
  2410. if (offset === offsetDelta + scanner.getPosition()) {
  2411. throw new Error("Scanner did not advance, next 3 characters are: " + line.substr(scanner.getPosition(), 3));
  2412. }
  2413. if (adjustOffset) {
  2414. offset -= numberOfInsertedCharacters;
  2415. }
  2416. adjustOffset = numberOfInsertedCharacters > 0;
  2417. switch (kind) {
  2418. case 1 /* OpenBraceToken */:
  2419. parents = ParentsStack.push(parents, 0 /* Object */);
  2420. type = TOKEN_DELIM_OBJECT;
  2421. lastWasColon = false;
  2422. break;
  2423. case 2 /* CloseBraceToken */:
  2424. parents = ParentsStack.pop(parents);
  2425. type = TOKEN_DELIM_OBJECT;
  2426. lastWasColon = false;
  2427. break;
  2428. case 3 /* OpenBracketToken */:
  2429. parents = ParentsStack.push(parents, 1 /* Array */);
  2430. type = TOKEN_DELIM_ARRAY;
  2431. lastWasColon = false;
  2432. break;
  2433. case 4 /* CloseBracketToken */:
  2434. parents = ParentsStack.pop(parents);
  2435. type = TOKEN_DELIM_ARRAY;
  2436. lastWasColon = false;
  2437. break;
  2438. case 6 /* ColonToken */:
  2439. type = TOKEN_DELIM_COLON;
  2440. lastWasColon = true;
  2441. break;
  2442. case 5 /* CommaToken */:
  2443. type = TOKEN_DELIM_COMMA;
  2444. lastWasColon = false;
  2445. break;
  2446. case 8 /* TrueKeyword */:
  2447. case 9 /* FalseKeyword */:
  2448. type = TOKEN_VALUE_BOOLEAN;
  2449. lastWasColon = false;
  2450. break;
  2451. case 7 /* NullKeyword */:
  2452. type = TOKEN_VALUE_NULL;
  2453. lastWasColon = false;
  2454. break;
  2455. case 10 /* StringLiteral */:
  2456. const currentParent = parents ? parents.type : 0 /* Object */;
  2457. const inArray = currentParent === 1 /* Array */;
  2458. type = lastWasColon || inArray ? TOKEN_VALUE_STRING : TOKEN_PROPERTY_NAME;
  2459. lastWasColon = false;
  2460. break;
  2461. case 11 /* NumericLiteral */:
  2462. type = TOKEN_VALUE_NUMBER;
  2463. lastWasColon = false;
  2464. break;
  2465. }
  2466. if (comments) {
  2467. switch (kind) {
  2468. case 12 /* LineCommentTrivia */:
  2469. type = TOKEN_COMMENT_LINE;
  2470. break;
  2471. case 13 /* BlockCommentTrivia */:
  2472. type = TOKEN_COMMENT_BLOCK;
  2473. break;
  2474. }
  2475. }
  2476. ret.endState = new JSONState(state.getStateData(), scanner.getTokenError(), lastWasColon, parents);
  2477. ret.tokens.push({
  2478. startIndex: offset,
  2479. scopes: type
  2480. });
  2481. }
  2482. return ret;
  2483. }
  2484. // src/language/json/jsonMode.ts
  2485. var JSONDiagnosticsAdapter = class extends DiagnosticsAdapter {
  2486. constructor(languageId, worker, defaults) {
  2487. super(languageId, worker, defaults.onDidChange);
  2488. this._disposables.push(monaco_editor_core_exports.editor.onWillDisposeModel((model) => {
  2489. this._resetSchema(model.uri);
  2490. }));
  2491. this._disposables.push(monaco_editor_core_exports.editor.onDidChangeModelLanguage((event) => {
  2492. this._resetSchema(event.model.uri);
  2493. }));
  2494. }
  2495. _resetSchema(resource) {
  2496. this._worker().then((worker) => {
  2497. worker.resetSchema(resource.toString());
  2498. });
  2499. }
  2500. };
  2501. function setupMode(defaults) {
  2502. const disposables = [];
  2503. const providers = [];
  2504. const client = new WorkerManager(defaults);
  2505. disposables.push(client);
  2506. const worker = (...uris) => {
  2507. return client.getLanguageServiceWorker(...uris);
  2508. };
  2509. function registerProviders() {
  2510. const { languageId, modeConfiguration: modeConfiguration2 } = defaults;
  2511. disposeAll(providers);
  2512. if (modeConfiguration2.documentFormattingEdits) {
  2513. providers.push(monaco_editor_core_exports.languages.registerDocumentFormattingEditProvider(languageId, new DocumentFormattingEditProvider(worker)));
  2514. }
  2515. if (modeConfiguration2.documentRangeFormattingEdits) {
  2516. providers.push(monaco_editor_core_exports.languages.registerDocumentRangeFormattingEditProvider(languageId, new DocumentRangeFormattingEditProvider(worker)));
  2517. }
  2518. if (modeConfiguration2.completionItems) {
  2519. providers.push(monaco_editor_core_exports.languages.registerCompletionItemProvider(languageId, new CompletionAdapter(worker, [" ", ":", '"'])));
  2520. }
  2521. if (modeConfiguration2.hovers) {
  2522. providers.push(monaco_editor_core_exports.languages.registerHoverProvider(languageId, new HoverAdapter(worker)));
  2523. }
  2524. if (modeConfiguration2.documentSymbols) {
  2525. providers.push(monaco_editor_core_exports.languages.registerDocumentSymbolProvider(languageId, new DocumentSymbolAdapter(worker)));
  2526. }
  2527. if (modeConfiguration2.tokens) {
  2528. providers.push(monaco_editor_core_exports.languages.setTokensProvider(languageId, createTokenizationSupport(true)));
  2529. }
  2530. if (modeConfiguration2.colors) {
  2531. providers.push(monaco_editor_core_exports.languages.registerColorProvider(languageId, new DocumentColorAdapter(worker)));
  2532. }
  2533. if (modeConfiguration2.foldingRanges) {
  2534. providers.push(monaco_editor_core_exports.languages.registerFoldingRangeProvider(languageId, new FoldingRangeAdapter(worker)));
  2535. }
  2536. if (modeConfiguration2.diagnostics) {
  2537. providers.push(new JSONDiagnosticsAdapter(languageId, worker, defaults));
  2538. }
  2539. if (modeConfiguration2.selectionRanges) {
  2540. providers.push(monaco_editor_core_exports.languages.registerSelectionRangeProvider(languageId, new SelectionRangeAdapter(worker)));
  2541. }
  2542. }
  2543. registerProviders();
  2544. disposables.push(monaco_editor_core_exports.languages.setLanguageConfiguration(defaults.languageId, richEditConfiguration));
  2545. let modeConfiguration = defaults.modeConfiguration;
  2546. defaults.onDidChange((newDefaults) => {
  2547. if (newDefaults.modeConfiguration !== modeConfiguration) {
  2548. modeConfiguration = newDefaults.modeConfiguration;
  2549. registerProviders();
  2550. }
  2551. });
  2552. disposables.push(asDisposable(providers));
  2553. return asDisposable(disposables);
  2554. }
  2555. function asDisposable(disposables) {
  2556. return { dispose: () => disposeAll(disposables) };
  2557. }
  2558. function disposeAll(disposables) {
  2559. while (disposables.length) {
  2560. disposables.pop().dispose();
  2561. }
  2562. }
  2563. var richEditConfiguration = {
  2564. wordPattern: /(-?\d*\.\d\w*)|([^\[\{\]\}\:\"\,\s]+)/g,
  2565. comments: {
  2566. lineComment: "//",
  2567. blockComment: ["/*", "*/"]
  2568. },
  2569. brackets: [
  2570. ["{", "}"],
  2571. ["[", "]"]
  2572. ],
  2573. autoClosingPairs: [
  2574. { open: "{", close: "}", notIn: ["string"] },
  2575. { open: "[", close: "]", notIn: ["string"] },
  2576. { open: '"', close: '"', notIn: ["string"] }
  2577. ]
  2578. };
  2579. export {
  2580. CompletionAdapter,
  2581. DefinitionAdapter,
  2582. DiagnosticsAdapter,
  2583. DocumentColorAdapter,
  2584. DocumentFormattingEditProvider,
  2585. DocumentHighlightAdapter,
  2586. DocumentLinkAdapter,
  2587. DocumentRangeFormattingEditProvider,
  2588. DocumentSymbolAdapter,
  2589. FoldingRangeAdapter,
  2590. HoverAdapter,
  2591. ReferenceAdapter,
  2592. RenameAdapter,
  2593. SelectionRangeAdapter,
  2594. WorkerManager,
  2595. fromPosition,
  2596. fromRange,
  2597. setupMode,
  2598. toRange,
  2599. toTextEdit
  2600. };