jsonMode.js 80 KB

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