jsonMode.js 152 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610
  1. define('vs/language/json/workerManager',["require", "exports"], function (require, exports) {
  2. /*---------------------------------------------------------------------------------------------
  3. * Copyright (c) Microsoft Corporation. All rights reserved.
  4. * Licensed under the MIT License. See License.txt in the project root for license information.
  5. *--------------------------------------------------------------------------------------------*/
  6. 'use strict';
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. var STOP_WHEN_IDLE_FOR = 2 * 60 * 1000; // 2min
  9. var WorkerManager = /** @class */ (function () {
  10. function WorkerManager(defaults) {
  11. var _this = this;
  12. this._defaults = defaults;
  13. this._worker = null;
  14. this._idleCheckInterval = setInterval(function () { return _this._checkIfIdle(); }, 30 * 1000);
  15. this._lastUsedTime = 0;
  16. this._configChangeListener = this._defaults.onDidChange(function () { return _this._stopWorker(); });
  17. }
  18. WorkerManager.prototype._stopWorker = function () {
  19. if (this._worker) {
  20. this._worker.dispose();
  21. this._worker = null;
  22. }
  23. this._client = null;
  24. };
  25. WorkerManager.prototype.dispose = function () {
  26. clearInterval(this._idleCheckInterval);
  27. this._configChangeListener.dispose();
  28. this._stopWorker();
  29. };
  30. WorkerManager.prototype._checkIfIdle = function () {
  31. if (!this._worker) {
  32. return;
  33. }
  34. var timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
  35. if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
  36. this._stopWorker();
  37. }
  38. };
  39. WorkerManager.prototype._getClient = function () {
  40. this._lastUsedTime = Date.now();
  41. if (!this._client) {
  42. this._worker = monaco.editor.createWebWorker({
  43. // module that exports the create() method and returns a `JSONWorker` instance
  44. moduleId: 'vs/language/json/jsonWorker',
  45. label: this._defaults.languageId,
  46. // passed in to the create() method
  47. createData: {
  48. languageSettings: this._defaults.diagnosticsOptions,
  49. languageId: this._defaults.languageId,
  50. enableSchemaRequest: this._defaults.diagnosticsOptions.enableSchemaRequest
  51. }
  52. });
  53. this._client = this._worker.getProxy();
  54. }
  55. return this._client;
  56. };
  57. WorkerManager.prototype.getLanguageServiceWorker = function () {
  58. var _this = this;
  59. var resources = [];
  60. for (var _i = 0; _i < arguments.length; _i++) {
  61. resources[_i] = arguments[_i];
  62. }
  63. var _client;
  64. return this._getClient().then(function (client) {
  65. _client = client;
  66. }).then(function (_) {
  67. return _this._worker.withSyncedResources(resources);
  68. }).then(function (_) { return _client; });
  69. };
  70. return WorkerManager;
  71. }());
  72. exports.WorkerManager = WorkerManager;
  73. });
  74. (function (factory) {
  75. if (typeof module === "object" && typeof module.exports === "object") {
  76. var v = factory(require, exports);
  77. if (v !== undefined) module.exports = v;
  78. }
  79. else if (typeof define === "function" && define.amd) {
  80. define('vscode-languageserver-types/main',["require", "exports"], factory);
  81. }
  82. })(function (require, exports) {
  83. /* --------------------------------------------------------------------------------------------
  84. * Copyright (c) Microsoft Corporation. All rights reserved.
  85. * Licensed under the MIT License. See License.txt in the project root for license information.
  86. * ------------------------------------------------------------------------------------------ */
  87. 'use strict';
  88. Object.defineProperty(exports, "__esModule", { value: true });
  89. /**
  90. * The Position namespace provides helper functions to work with
  91. * [Position](#Position) literals.
  92. */
  93. var Position;
  94. (function (Position) {
  95. /**
  96. * Creates a new Position literal from the given line and character.
  97. * @param line The position's line.
  98. * @param character The position's character.
  99. */
  100. function create(line, character) {
  101. return { line: line, character: character };
  102. }
  103. Position.create = create;
  104. /**
  105. * Checks whether the given liternal conforms to the [Position](#Position) interface.
  106. */
  107. function is(value) {
  108. var candidate = value;
  109. return Is.objectLiteral(candidate) && Is.number(candidate.line) && Is.number(candidate.character);
  110. }
  111. Position.is = is;
  112. })(Position = exports.Position || (exports.Position = {}));
  113. /**
  114. * The Range namespace provides helper functions to work with
  115. * [Range](#Range) literals.
  116. */
  117. var Range;
  118. (function (Range) {
  119. function create(one, two, three, four) {
  120. if (Is.number(one) && Is.number(two) && Is.number(three) && Is.number(four)) {
  121. return { start: Position.create(one, two), end: Position.create(three, four) };
  122. }
  123. else if (Position.is(one) && Position.is(two)) {
  124. return { start: one, end: two };
  125. }
  126. else {
  127. throw new Error("Range#create called with invalid arguments[" + one + ", " + two + ", " + three + ", " + four + "]");
  128. }
  129. }
  130. Range.create = create;
  131. /**
  132. * Checks whether the given literal conforms to the [Range](#Range) interface.
  133. */
  134. function is(value) {
  135. var candidate = value;
  136. return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
  137. }
  138. Range.is = is;
  139. })(Range = exports.Range || (exports.Range = {}));
  140. /**
  141. * The Location namespace provides helper functions to work with
  142. * [Location](#Location) literals.
  143. */
  144. var Location;
  145. (function (Location) {
  146. /**
  147. * Creates a Location literal.
  148. * @param uri The location's uri.
  149. * @param range The location's range.
  150. */
  151. function create(uri, range) {
  152. return { uri: uri, range: range };
  153. }
  154. Location.create = create;
  155. /**
  156. * Checks whether the given literal conforms to the [Location](#Location) interface.
  157. */
  158. function is(value) {
  159. var candidate = value;
  160. return Is.defined(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
  161. }
  162. Location.is = is;
  163. })(Location = exports.Location || (exports.Location = {}));
  164. /**
  165. * The Color namespace provides helper functions to work with
  166. * [Color](#Color) literals.
  167. */
  168. var Color;
  169. (function (Color) {
  170. /**
  171. * Creates a new Color literal.
  172. */
  173. function create(red, green, blue, alpha) {
  174. return {
  175. red: red,
  176. green: green,
  177. blue: blue,
  178. alpha: alpha,
  179. };
  180. }
  181. Color.create = create;
  182. /**
  183. * Checks whether the given literal conforms to the [Color](#Color) interface.
  184. */
  185. function is(value) {
  186. var candidate = value;
  187. return Is.number(candidate.red)
  188. && Is.number(candidate.green)
  189. && Is.number(candidate.blue)
  190. && Is.number(candidate.alpha);
  191. }
  192. Color.is = is;
  193. })(Color = exports.Color || (exports.Color = {}));
  194. /**
  195. * The ColorInformation namespace provides helper functions to work with
  196. * [ColorInformation](#ColorInformation) literals.
  197. */
  198. var ColorInformation;
  199. (function (ColorInformation) {
  200. /**
  201. * Creates a new ColorInformation literal.
  202. */
  203. function create(range, color) {
  204. return {
  205. range: range,
  206. color: color,
  207. };
  208. }
  209. ColorInformation.create = create;
  210. /**
  211. * Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
  212. */
  213. function is(value) {
  214. var candidate = value;
  215. return Range.is(candidate.range) && Color.is(candidate.color);
  216. }
  217. ColorInformation.is = is;
  218. })(ColorInformation = exports.ColorInformation || (exports.ColorInformation = {}));
  219. /**
  220. * The Color namespace provides helper functions to work with
  221. * [ColorPresentation](#ColorPresentation) literals.
  222. */
  223. var ColorPresentation;
  224. (function (ColorPresentation) {
  225. /**
  226. * Creates a new ColorInformation literal.
  227. */
  228. function create(label, textEdit, additionalTextEdits) {
  229. return {
  230. label: label,
  231. textEdit: textEdit,
  232. additionalTextEdits: additionalTextEdits,
  233. };
  234. }
  235. ColorPresentation.create = create;
  236. /**
  237. * Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
  238. */
  239. function is(value) {
  240. var candidate = value;
  241. return Is.string(candidate.label)
  242. && (Is.undefined(candidate.textEdit) || TextEdit.is(candidate))
  243. && (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is));
  244. }
  245. ColorPresentation.is = is;
  246. })(ColorPresentation = exports.ColorPresentation || (exports.ColorPresentation = {}));
  247. /**
  248. * Enum of known range kinds
  249. */
  250. var FoldingRangeKind;
  251. (function (FoldingRangeKind) {
  252. /**
  253. * Folding range for a comment
  254. */
  255. FoldingRangeKind["Comment"] = "comment";
  256. /**
  257. * Folding range for a imports or includes
  258. */
  259. FoldingRangeKind["Imports"] = "imports";
  260. /**
  261. * Folding range for a region (e.g. `#region`)
  262. */
  263. FoldingRangeKind["Region"] = "region";
  264. })(FoldingRangeKind = exports.FoldingRangeKind || (exports.FoldingRangeKind = {}));
  265. /**
  266. * The folding range namespace provides helper functions to work with
  267. * [FoldingRange](#FoldingRange) literals.
  268. */
  269. var FoldingRange;
  270. (function (FoldingRange) {
  271. /**
  272. * Creates a new FoldingRange literal.
  273. */
  274. function create(startLine, endLine, startCharacter, endCharacter, kind) {
  275. var result = {
  276. startLine: startLine,
  277. endLine: endLine
  278. };
  279. if (Is.defined(startCharacter)) {
  280. result.startCharacter = startCharacter;
  281. }
  282. if (Is.defined(endCharacter)) {
  283. result.endCharacter = endCharacter;
  284. }
  285. if (Is.defined(kind)) {
  286. result.kind = kind;
  287. }
  288. return result;
  289. }
  290. FoldingRange.create = create;
  291. /**
  292. * Checks whether the given literal conforms to the [FoldingRange](#FoldingRange) interface.
  293. */
  294. function is(value) {
  295. var candidate = value;
  296. return Is.number(candidate.startLine) && Is.number(candidate.startLine)
  297. && (Is.undefined(candidate.startCharacter) || Is.number(candidate.startCharacter))
  298. && (Is.undefined(candidate.endCharacter) || Is.number(candidate.endCharacter))
  299. && (Is.undefined(candidate.kind) || Is.string(candidate.kind));
  300. }
  301. FoldingRange.is = is;
  302. })(FoldingRange = exports.FoldingRange || (exports.FoldingRange = {}));
  303. /**
  304. * The DiagnosticRelatedInformation namespace provides helper functions to work with
  305. * [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) literals.
  306. */
  307. var DiagnosticRelatedInformation;
  308. (function (DiagnosticRelatedInformation) {
  309. /**
  310. * Creates a new DiagnosticRelatedInformation literal.
  311. */
  312. function create(location, message) {
  313. return {
  314. location: location,
  315. message: message
  316. };
  317. }
  318. DiagnosticRelatedInformation.create = create;
  319. /**
  320. * Checks whether the given literal conforms to the [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) interface.
  321. */
  322. function is(value) {
  323. var candidate = value;
  324. return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message);
  325. }
  326. DiagnosticRelatedInformation.is = is;
  327. })(DiagnosticRelatedInformation = exports.DiagnosticRelatedInformation || (exports.DiagnosticRelatedInformation = {}));
  328. /**
  329. * The diagnostic's severity.
  330. */
  331. var DiagnosticSeverity;
  332. (function (DiagnosticSeverity) {
  333. /**
  334. * Reports an error.
  335. */
  336. DiagnosticSeverity.Error = 1;
  337. /**
  338. * Reports a warning.
  339. */
  340. DiagnosticSeverity.Warning = 2;
  341. /**
  342. * Reports an information.
  343. */
  344. DiagnosticSeverity.Information = 3;
  345. /**
  346. * Reports a hint.
  347. */
  348. DiagnosticSeverity.Hint = 4;
  349. })(DiagnosticSeverity = exports.DiagnosticSeverity || (exports.DiagnosticSeverity = {}));
  350. /**
  351. * The Diagnostic namespace provides helper functions to work with
  352. * [Diagnostic](#Diagnostic) literals.
  353. */
  354. var Diagnostic;
  355. (function (Diagnostic) {
  356. /**
  357. * Creates a new Diagnostic literal.
  358. */
  359. function create(range, message, severity, code, source, relatedInformation) {
  360. var result = { range: range, message: message };
  361. if (Is.defined(severity)) {
  362. result.severity = severity;
  363. }
  364. if (Is.defined(code)) {
  365. result.code = code;
  366. }
  367. if (Is.defined(source)) {
  368. result.source = source;
  369. }
  370. if (Is.defined(relatedInformation)) {
  371. result.relatedInformation = relatedInformation;
  372. }
  373. return result;
  374. }
  375. Diagnostic.create = create;
  376. /**
  377. * Checks whether the given literal conforms to the [Diagnostic](#Diagnostic) interface.
  378. */
  379. function is(value) {
  380. var candidate = value;
  381. return Is.defined(candidate)
  382. && Range.is(candidate.range)
  383. && Is.string(candidate.message)
  384. && (Is.number(candidate.severity) || Is.undefined(candidate.severity))
  385. && (Is.number(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code))
  386. && (Is.string(candidate.source) || Is.undefined(candidate.source))
  387. && (Is.undefined(candidate.relatedInformation) || Is.typedArray(candidate.relatedInformation, DiagnosticRelatedInformation.is));
  388. }
  389. Diagnostic.is = is;
  390. })(Diagnostic = exports.Diagnostic || (exports.Diagnostic = {}));
  391. /**
  392. * The Command namespace provides helper functions to work with
  393. * [Command](#Command) literals.
  394. */
  395. var Command;
  396. (function (Command) {
  397. /**
  398. * Creates a new Command literal.
  399. */
  400. function create(title, command) {
  401. var args = [];
  402. for (var _i = 2; _i < arguments.length; _i++) {
  403. args[_i - 2] = arguments[_i];
  404. }
  405. var result = { title: title, command: command };
  406. if (Is.defined(args) && args.length > 0) {
  407. result.arguments = args;
  408. }
  409. return result;
  410. }
  411. Command.create = create;
  412. /**
  413. * Checks whether the given literal conforms to the [Command](#Command) interface.
  414. */
  415. function is(value) {
  416. var candidate = value;
  417. return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command);
  418. }
  419. Command.is = is;
  420. })(Command = exports.Command || (exports.Command = {}));
  421. /**
  422. * The TextEdit namespace provides helper function to create replace,
  423. * insert and delete edits more easily.
  424. */
  425. var TextEdit;
  426. (function (TextEdit) {
  427. /**
  428. * Creates a replace text edit.
  429. * @param range The range of text to be replaced.
  430. * @param newText The new text.
  431. */
  432. function replace(range, newText) {
  433. return { range: range, newText: newText };
  434. }
  435. TextEdit.replace = replace;
  436. /**
  437. * Creates a insert text edit.
  438. * @param position The position to insert the text at.
  439. * @param newText The text to be inserted.
  440. */
  441. function insert(position, newText) {
  442. return { range: { start: position, end: position }, newText: newText };
  443. }
  444. TextEdit.insert = insert;
  445. /**
  446. * Creates a delete text edit.
  447. * @param range The range of text to be deleted.
  448. */
  449. function del(range) {
  450. return { range: range, newText: '' };
  451. }
  452. TextEdit.del = del;
  453. function is(value) {
  454. var candidate = value;
  455. return Is.objectLiteral(candidate)
  456. && Is.string(candidate.newText)
  457. && Range.is(candidate.range);
  458. }
  459. TextEdit.is = is;
  460. })(TextEdit = exports.TextEdit || (exports.TextEdit = {}));
  461. /**
  462. * The TextDocumentEdit namespace provides helper function to create
  463. * an edit that manipulates a text document.
  464. */
  465. var TextDocumentEdit;
  466. (function (TextDocumentEdit) {
  467. /**
  468. * Creates a new `TextDocumentEdit`
  469. */
  470. function create(textDocument, edits) {
  471. return { textDocument: textDocument, edits: edits };
  472. }
  473. TextDocumentEdit.create = create;
  474. function is(value) {
  475. var candidate = value;
  476. return Is.defined(candidate)
  477. && VersionedTextDocumentIdentifier.is(candidate.textDocument)
  478. && Array.isArray(candidate.edits);
  479. }
  480. TextDocumentEdit.is = is;
  481. })(TextDocumentEdit = exports.TextDocumentEdit || (exports.TextDocumentEdit = {}));
  482. var WorkspaceEdit;
  483. (function (WorkspaceEdit) {
  484. function is(value) {
  485. var candidate = value;
  486. return candidate &&
  487. (candidate.changes !== void 0 || candidate.documentChanges !== void 0) &&
  488. (candidate.documentChanges === void 0 || Is.typedArray(candidate.documentChanges, TextDocumentEdit.is));
  489. }
  490. WorkspaceEdit.is = is;
  491. })(WorkspaceEdit = exports.WorkspaceEdit || (exports.WorkspaceEdit = {}));
  492. var TextEditChangeImpl = /** @class */ (function () {
  493. function TextEditChangeImpl(edits) {
  494. this.edits = edits;
  495. }
  496. TextEditChangeImpl.prototype.insert = function (position, newText) {
  497. this.edits.push(TextEdit.insert(position, newText));
  498. };
  499. TextEditChangeImpl.prototype.replace = function (range, newText) {
  500. this.edits.push(TextEdit.replace(range, newText));
  501. };
  502. TextEditChangeImpl.prototype.delete = function (range) {
  503. this.edits.push(TextEdit.del(range));
  504. };
  505. TextEditChangeImpl.prototype.add = function (edit) {
  506. this.edits.push(edit);
  507. };
  508. TextEditChangeImpl.prototype.all = function () {
  509. return this.edits;
  510. };
  511. TextEditChangeImpl.prototype.clear = function () {
  512. this.edits.splice(0, this.edits.length);
  513. };
  514. return TextEditChangeImpl;
  515. }());
  516. /**
  517. * A workspace change helps constructing changes to a workspace.
  518. */
  519. var WorkspaceChange = /** @class */ (function () {
  520. function WorkspaceChange(workspaceEdit) {
  521. var _this = this;
  522. this._textEditChanges = Object.create(null);
  523. if (workspaceEdit) {
  524. this._workspaceEdit = workspaceEdit;
  525. if (workspaceEdit.documentChanges) {
  526. workspaceEdit.documentChanges.forEach(function (textDocumentEdit) {
  527. var textEditChange = new TextEditChangeImpl(textDocumentEdit.edits);
  528. _this._textEditChanges[textDocumentEdit.textDocument.uri] = textEditChange;
  529. });
  530. }
  531. else if (workspaceEdit.changes) {
  532. Object.keys(workspaceEdit.changes).forEach(function (key) {
  533. var textEditChange = new TextEditChangeImpl(workspaceEdit.changes[key]);
  534. _this._textEditChanges[key] = textEditChange;
  535. });
  536. }
  537. }
  538. }
  539. Object.defineProperty(WorkspaceChange.prototype, "edit", {
  540. /**
  541. * Returns the underlying [WorkspaceEdit](#WorkspaceEdit) literal
  542. * use to be returned from a workspace edit operation like rename.
  543. */
  544. get: function () {
  545. return this._workspaceEdit;
  546. },
  547. enumerable: true,
  548. configurable: true
  549. });
  550. WorkspaceChange.prototype.getTextEditChange = function (key) {
  551. if (VersionedTextDocumentIdentifier.is(key)) {
  552. if (!this._workspaceEdit) {
  553. this._workspaceEdit = {
  554. documentChanges: []
  555. };
  556. }
  557. if (!this._workspaceEdit.documentChanges) {
  558. throw new Error('Workspace edit is not configured for versioned document changes.');
  559. }
  560. var textDocument = key;
  561. var result = this._textEditChanges[textDocument.uri];
  562. if (!result) {
  563. var edits = [];
  564. var textDocumentEdit = {
  565. textDocument: textDocument,
  566. edits: edits
  567. };
  568. this._workspaceEdit.documentChanges.push(textDocumentEdit);
  569. result = new TextEditChangeImpl(edits);
  570. this._textEditChanges[textDocument.uri] = result;
  571. }
  572. return result;
  573. }
  574. else {
  575. if (!this._workspaceEdit) {
  576. this._workspaceEdit = {
  577. changes: Object.create(null)
  578. };
  579. }
  580. if (!this._workspaceEdit.changes) {
  581. throw new Error('Workspace edit is not configured for normal text edit changes.');
  582. }
  583. var result = this._textEditChanges[key];
  584. if (!result) {
  585. var edits = [];
  586. this._workspaceEdit.changes[key] = edits;
  587. result = new TextEditChangeImpl(edits);
  588. this._textEditChanges[key] = result;
  589. }
  590. return result;
  591. }
  592. };
  593. return WorkspaceChange;
  594. }());
  595. exports.WorkspaceChange = WorkspaceChange;
  596. /**
  597. * The TextDocumentIdentifier namespace provides helper functions to work with
  598. * [TextDocumentIdentifier](#TextDocumentIdentifier) literals.
  599. */
  600. var TextDocumentIdentifier;
  601. (function (TextDocumentIdentifier) {
  602. /**
  603. * Creates a new TextDocumentIdentifier literal.
  604. * @param uri The document's uri.
  605. */
  606. function create(uri) {
  607. return { uri: uri };
  608. }
  609. TextDocumentIdentifier.create = create;
  610. /**
  611. * Checks whether the given literal conforms to the [TextDocumentIdentifier](#TextDocumentIdentifier) interface.
  612. */
  613. function is(value) {
  614. var candidate = value;
  615. return Is.defined(candidate) && Is.string(candidate.uri);
  616. }
  617. TextDocumentIdentifier.is = is;
  618. })(TextDocumentIdentifier = exports.TextDocumentIdentifier || (exports.TextDocumentIdentifier = {}));
  619. /**
  620. * The VersionedTextDocumentIdentifier namespace provides helper functions to work with
  621. * [VersionedTextDocumentIdentifier](#VersionedTextDocumentIdentifier) literals.
  622. */
  623. var VersionedTextDocumentIdentifier;
  624. (function (VersionedTextDocumentIdentifier) {
  625. /**
  626. * Creates a new VersionedTextDocumentIdentifier literal.
  627. * @param uri The document's uri.
  628. * @param uri The document's text.
  629. */
  630. function create(uri, version) {
  631. return { uri: uri, version: version };
  632. }
  633. VersionedTextDocumentIdentifier.create = create;
  634. /**
  635. * Checks whether the given literal conforms to the [VersionedTextDocumentIdentifier](#VersionedTextDocumentIdentifier) interface.
  636. */
  637. function is(value) {
  638. var candidate = value;
  639. return Is.defined(candidate) && Is.string(candidate.uri) && Is.number(candidate.version);
  640. }
  641. VersionedTextDocumentIdentifier.is = is;
  642. })(VersionedTextDocumentIdentifier = exports.VersionedTextDocumentIdentifier || (exports.VersionedTextDocumentIdentifier = {}));
  643. /**
  644. * The TextDocumentItem namespace provides helper functions to work with
  645. * [TextDocumentItem](#TextDocumentItem) literals.
  646. */
  647. var TextDocumentItem;
  648. (function (TextDocumentItem) {
  649. /**
  650. * Creates a new TextDocumentItem literal.
  651. * @param uri The document's uri.
  652. * @param languageId The document's language identifier.
  653. * @param version The document's version number.
  654. * @param text The document's text.
  655. */
  656. function create(uri, languageId, version, text) {
  657. return { uri: uri, languageId: languageId, version: version, text: text };
  658. }
  659. TextDocumentItem.create = create;
  660. /**
  661. * Checks whether the given literal conforms to the [TextDocumentItem](#TextDocumentItem) interface.
  662. */
  663. function is(value) {
  664. var candidate = value;
  665. return Is.defined(candidate) && Is.string(candidate.uri) && Is.string(candidate.languageId) && Is.number(candidate.version) && Is.string(candidate.text);
  666. }
  667. TextDocumentItem.is = is;
  668. })(TextDocumentItem = exports.TextDocumentItem || (exports.TextDocumentItem = {}));
  669. /**
  670. * Describes the content type that a client supports in various
  671. * result literals like `Hover`, `ParameterInfo` or `CompletionItem`.
  672. *
  673. * Please note that `MarkupKinds` must not start with a `$`. This kinds
  674. * are reserved for internal usage.
  675. */
  676. var MarkupKind;
  677. (function (MarkupKind) {
  678. /**
  679. * Plain text is supported as a content format
  680. */
  681. MarkupKind.PlainText = 'plaintext';
  682. /**
  683. * Markdown is supported as a content format
  684. */
  685. MarkupKind.Markdown = 'markdown';
  686. })(MarkupKind = exports.MarkupKind || (exports.MarkupKind = {}));
  687. (function (MarkupKind) {
  688. /**
  689. * Checks whether the given value is a value of the [MarkupKind](#MarkupKind) type.
  690. */
  691. function is(value) {
  692. var candidate = value;
  693. return candidate === MarkupKind.PlainText || candidate === MarkupKind.Markdown;
  694. }
  695. MarkupKind.is = is;
  696. })(MarkupKind = exports.MarkupKind || (exports.MarkupKind = {}));
  697. var MarkupContent;
  698. (function (MarkupContent) {
  699. /**
  700. * Checks whether the given value conforms to the [MarkupContent](#MarkupContent) interface.
  701. */
  702. function is(value) {
  703. var candidate = value;
  704. return Is.objectLiteral(value) && MarkupKind.is(candidate.kind) && Is.string(candidate.value);
  705. }
  706. MarkupContent.is = is;
  707. })(MarkupContent = exports.MarkupContent || (exports.MarkupContent = {}));
  708. /**
  709. * The kind of a completion entry.
  710. */
  711. var CompletionItemKind;
  712. (function (CompletionItemKind) {
  713. CompletionItemKind.Text = 1;
  714. CompletionItemKind.Method = 2;
  715. CompletionItemKind.Function = 3;
  716. CompletionItemKind.Constructor = 4;
  717. CompletionItemKind.Field = 5;
  718. CompletionItemKind.Variable = 6;
  719. CompletionItemKind.Class = 7;
  720. CompletionItemKind.Interface = 8;
  721. CompletionItemKind.Module = 9;
  722. CompletionItemKind.Property = 10;
  723. CompletionItemKind.Unit = 11;
  724. CompletionItemKind.Value = 12;
  725. CompletionItemKind.Enum = 13;
  726. CompletionItemKind.Keyword = 14;
  727. CompletionItemKind.Snippet = 15;
  728. CompletionItemKind.Color = 16;
  729. CompletionItemKind.File = 17;
  730. CompletionItemKind.Reference = 18;
  731. CompletionItemKind.Folder = 19;
  732. CompletionItemKind.EnumMember = 20;
  733. CompletionItemKind.Constant = 21;
  734. CompletionItemKind.Struct = 22;
  735. CompletionItemKind.Event = 23;
  736. CompletionItemKind.Operator = 24;
  737. CompletionItemKind.TypeParameter = 25;
  738. })(CompletionItemKind = exports.CompletionItemKind || (exports.CompletionItemKind = {}));
  739. /**
  740. * Defines whether the insert text in a completion item should be interpreted as
  741. * plain text or a snippet.
  742. */
  743. var InsertTextFormat;
  744. (function (InsertTextFormat) {
  745. /**
  746. * The primary text to be inserted is treated as a plain string.
  747. */
  748. InsertTextFormat.PlainText = 1;
  749. /**
  750. * The primary text to be inserted is treated as a snippet.
  751. *
  752. * A snippet can define tab stops and placeholders with `$1`, `$2`
  753. * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
  754. * the end of the snippet. Placeholders with equal identifiers are linked,
  755. * that is typing in one will update others too.
  756. *
  757. * See also: https://github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md
  758. */
  759. InsertTextFormat.Snippet = 2;
  760. })(InsertTextFormat = exports.InsertTextFormat || (exports.InsertTextFormat = {}));
  761. /**
  762. * The CompletionItem namespace provides functions to deal with
  763. * completion items.
  764. */
  765. var CompletionItem;
  766. (function (CompletionItem) {
  767. /**
  768. * Create a completion item and seed it with a label.
  769. * @param label The completion item's label
  770. */
  771. function create(label) {
  772. return { label: label };
  773. }
  774. CompletionItem.create = create;
  775. })(CompletionItem = exports.CompletionItem || (exports.CompletionItem = {}));
  776. /**
  777. * The CompletionList namespace provides functions to deal with
  778. * completion lists.
  779. */
  780. var CompletionList;
  781. (function (CompletionList) {
  782. /**
  783. * Creates a new completion list.
  784. *
  785. * @param items The completion items.
  786. * @param isIncomplete The list is not complete.
  787. */
  788. function create(items, isIncomplete) {
  789. return { items: items ? items : [], isIncomplete: !!isIncomplete };
  790. }
  791. CompletionList.create = create;
  792. })(CompletionList = exports.CompletionList || (exports.CompletionList = {}));
  793. var MarkedString;
  794. (function (MarkedString) {
  795. /**
  796. * Creates a marked string from plain text.
  797. *
  798. * @param plainText The plain text.
  799. */
  800. function fromPlainText(plainText) {
  801. return plainText.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&"); // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
  802. }
  803. MarkedString.fromPlainText = fromPlainText;
  804. /**
  805. * Checks whether the given value conforms to the [MarkedString](#MarkedString) type.
  806. */
  807. function is(value) {
  808. var candidate = value;
  809. return Is.string(candidate) || (Is.objectLiteral(candidate) && Is.string(candidate.language) && Is.string(candidate.value));
  810. }
  811. MarkedString.is = is;
  812. })(MarkedString = exports.MarkedString || (exports.MarkedString = {}));
  813. var Hover;
  814. (function (Hover) {
  815. /**
  816. * Checks whether the given value conforms to the [Hover](#Hover) interface.
  817. */
  818. function is(value) {
  819. var candidate = value;
  820. return Is.objectLiteral(candidate) && (MarkupContent.is(candidate.contents) ||
  821. MarkedString.is(candidate.contents) ||
  822. Is.typedArray(candidate.contents, MarkedString.is)) && (value.range === void 0 || Range.is(value.range));
  823. }
  824. Hover.is = is;
  825. })(Hover = exports.Hover || (exports.Hover = {}));
  826. /**
  827. * The ParameterInformation namespace provides helper functions to work with
  828. * [ParameterInformation](#ParameterInformation) literals.
  829. */
  830. var ParameterInformation;
  831. (function (ParameterInformation) {
  832. /**
  833. * Creates a new parameter information literal.
  834. *
  835. * @param label A label string.
  836. * @param documentation A doc string.
  837. */
  838. function create(label, documentation) {
  839. return documentation ? { label: label, documentation: documentation } : { label: label };
  840. }
  841. ParameterInformation.create = create;
  842. ;
  843. })(ParameterInformation = exports.ParameterInformation || (exports.ParameterInformation = {}));
  844. /**
  845. * The SignatureInformation namespace provides helper functions to work with
  846. * [SignatureInformation](#SignatureInformation) literals.
  847. */
  848. var SignatureInformation;
  849. (function (SignatureInformation) {
  850. function create(label, documentation) {
  851. var parameters = [];
  852. for (var _i = 2; _i < arguments.length; _i++) {
  853. parameters[_i - 2] = arguments[_i];
  854. }
  855. var result = { label: label };
  856. if (Is.defined(documentation)) {
  857. result.documentation = documentation;
  858. }
  859. if (Is.defined(parameters)) {
  860. result.parameters = parameters;
  861. }
  862. else {
  863. result.parameters = [];
  864. }
  865. return result;
  866. }
  867. SignatureInformation.create = create;
  868. })(SignatureInformation = exports.SignatureInformation || (exports.SignatureInformation = {}));
  869. /**
  870. * A document highlight kind.
  871. */
  872. var DocumentHighlightKind;
  873. (function (DocumentHighlightKind) {
  874. /**
  875. * A textual occurrence.
  876. */
  877. DocumentHighlightKind.Text = 1;
  878. /**
  879. * Read-access of a symbol, like reading a variable.
  880. */
  881. DocumentHighlightKind.Read = 2;
  882. /**
  883. * Write-access of a symbol, like writing to a variable.
  884. */
  885. DocumentHighlightKind.Write = 3;
  886. })(DocumentHighlightKind = exports.DocumentHighlightKind || (exports.DocumentHighlightKind = {}));
  887. /**
  888. * DocumentHighlight namespace to provide helper functions to work with
  889. * [DocumentHighlight](#DocumentHighlight) literals.
  890. */
  891. var DocumentHighlight;
  892. (function (DocumentHighlight) {
  893. /**
  894. * Create a DocumentHighlight object.
  895. * @param range The range the highlight applies to.
  896. */
  897. function create(range, kind) {
  898. var result = { range: range };
  899. if (Is.number(kind)) {
  900. result.kind = kind;
  901. }
  902. return result;
  903. }
  904. DocumentHighlight.create = create;
  905. })(DocumentHighlight = exports.DocumentHighlight || (exports.DocumentHighlight = {}));
  906. /**
  907. * A symbol kind.
  908. */
  909. var SymbolKind;
  910. (function (SymbolKind) {
  911. SymbolKind.File = 1;
  912. SymbolKind.Module = 2;
  913. SymbolKind.Namespace = 3;
  914. SymbolKind.Package = 4;
  915. SymbolKind.Class = 5;
  916. SymbolKind.Method = 6;
  917. SymbolKind.Property = 7;
  918. SymbolKind.Field = 8;
  919. SymbolKind.Constructor = 9;
  920. SymbolKind.Enum = 10;
  921. SymbolKind.Interface = 11;
  922. SymbolKind.Function = 12;
  923. SymbolKind.Variable = 13;
  924. SymbolKind.Constant = 14;
  925. SymbolKind.String = 15;
  926. SymbolKind.Number = 16;
  927. SymbolKind.Boolean = 17;
  928. SymbolKind.Array = 18;
  929. SymbolKind.Object = 19;
  930. SymbolKind.Key = 20;
  931. SymbolKind.Null = 21;
  932. SymbolKind.EnumMember = 22;
  933. SymbolKind.Struct = 23;
  934. SymbolKind.Event = 24;
  935. SymbolKind.Operator = 25;
  936. SymbolKind.TypeParameter = 26;
  937. })(SymbolKind = exports.SymbolKind || (exports.SymbolKind = {}));
  938. var SymbolInformation;
  939. (function (SymbolInformation) {
  940. /**
  941. * Creates a new symbol information literal.
  942. *
  943. * @param name The name of the symbol.
  944. * @param kind The kind of the symbol.
  945. * @param range The range of the location of the symbol.
  946. * @param uri The resource of the location of symbol, defaults to the current document.
  947. * @param containerName The name of the symbol containing the symbol.
  948. */
  949. function create(name, kind, range, uri, containerName) {
  950. var result = {
  951. name: name,
  952. kind: kind,
  953. location: { uri: uri, range: range }
  954. };
  955. if (containerName) {
  956. result.containerName = containerName;
  957. }
  958. return result;
  959. }
  960. SymbolInformation.create = create;
  961. })(SymbolInformation = exports.SymbolInformation || (exports.SymbolInformation = {}));
  962. /**
  963. * Represents programming constructs like variables, classes, interfaces etc.
  964. * that appear in a document. Document symbols can be hierarchical and they
  965. * have two ranges: one that encloses its definition and one that points to
  966. * its most interesting range, e.g. the range of an identifier.
  967. */
  968. var DocumentSymbol = /** @class */ (function () {
  969. function DocumentSymbol() {
  970. }
  971. return DocumentSymbol;
  972. }());
  973. exports.DocumentSymbol = DocumentSymbol;
  974. (function (DocumentSymbol) {
  975. /**
  976. * Creates a new symbol information literal.
  977. *
  978. * @param name The name of the symbol.
  979. * @param detail The detail of the symbol.
  980. * @param kind The kind of the symbol.
  981. * @param range The range of the symbol.
  982. * @param selectionRange The selectionRange of the symbol.
  983. * @param children Children of the symbol.
  984. */
  985. function create(name, detail, kind, range, selectionRange, children) {
  986. var result = {
  987. name: name,
  988. detail: detail,
  989. kind: kind,
  990. range: range,
  991. selectionRange: selectionRange
  992. };
  993. if (children !== void 0) {
  994. result.children = children;
  995. }
  996. return result;
  997. }
  998. DocumentSymbol.create = create;
  999. /**
  1000. * Checks whether the given literal conforms to the [DocumentSymbol](#DocumentSymbol) interface.
  1001. */
  1002. function is(value) {
  1003. var candidate = value;
  1004. return candidate &&
  1005. Is.string(candidate.name) && Is.number(candidate.kind) &&
  1006. Range.is(candidate.range) && Range.is(candidate.selectionRange) &&
  1007. (candidate.detail === void 0 || Is.string(candidate.detail)) &&
  1008. (candidate.deprecated === void 0 || Is.boolean(candidate.deprecated)) &&
  1009. (candidate.children === void 0 || Array.isArray(candidate.children));
  1010. }
  1011. DocumentSymbol.is = is;
  1012. })(DocumentSymbol = exports.DocumentSymbol || (exports.DocumentSymbol = {}));
  1013. exports.DocumentSymbol = DocumentSymbol;
  1014. /**
  1015. * A set of predefined code action kinds
  1016. */
  1017. var CodeActionKind;
  1018. (function (CodeActionKind) {
  1019. /**
  1020. * Base kind for quickfix actions: 'quickfix'
  1021. */
  1022. CodeActionKind.QuickFix = 'quickfix';
  1023. /**
  1024. * Base kind for refactoring actions: 'refactor'
  1025. */
  1026. CodeActionKind.Refactor = 'refactor';
  1027. /**
  1028. * Base kind for refactoring extraction actions: 'refactor.extract'
  1029. *
  1030. * Example extract actions:
  1031. *
  1032. * - Extract method
  1033. * - Extract function
  1034. * - Extract variable
  1035. * - Extract interface from class
  1036. * - ...
  1037. */
  1038. CodeActionKind.RefactorExtract = 'refactor.extract';
  1039. /**
  1040. * Base kind for refactoring inline actions: 'refactor.inline'
  1041. *
  1042. * Example inline actions:
  1043. *
  1044. * - Inline function
  1045. * - Inline variable
  1046. * - Inline constant
  1047. * - ...
  1048. */
  1049. CodeActionKind.RefactorInline = 'refactor.inline';
  1050. /**
  1051. * Base kind for refactoring rewrite actions: 'refactor.rewrite'
  1052. *
  1053. * Example rewrite actions:
  1054. *
  1055. * - Convert JavaScript function to class
  1056. * - Add or remove parameter
  1057. * - Encapsulate field
  1058. * - Make method static
  1059. * - Move method to base class
  1060. * - ...
  1061. */
  1062. CodeActionKind.RefactorRewrite = 'refactor.rewrite';
  1063. /**
  1064. * Base kind for source actions: `source`
  1065. *
  1066. * Source code actions apply to the entire file.
  1067. */
  1068. CodeActionKind.Source = 'source';
  1069. /**
  1070. * Base kind for an organize imports source action: `source.organizeImports`
  1071. */
  1072. CodeActionKind.SourceOrganizeImports = 'source.organizeImports';
  1073. })(CodeActionKind = exports.CodeActionKind || (exports.CodeActionKind = {}));
  1074. /**
  1075. * The CodeActionContext namespace provides helper functions to work with
  1076. * [CodeActionContext](#CodeActionContext) literals.
  1077. */
  1078. var CodeActionContext;
  1079. (function (CodeActionContext) {
  1080. /**
  1081. * Creates a new CodeActionContext literal.
  1082. */
  1083. function create(diagnostics, only) {
  1084. var result = { diagnostics: diagnostics };
  1085. if (only !== void 0 && only !== null) {
  1086. result.only = only;
  1087. }
  1088. return result;
  1089. }
  1090. CodeActionContext.create = create;
  1091. /**
  1092. * Checks whether the given literal conforms to the [CodeActionContext](#CodeActionContext) interface.
  1093. */
  1094. function is(value) {
  1095. var candidate = value;
  1096. return Is.defined(candidate) && Is.typedArray(candidate.diagnostics, Diagnostic.is) && (candidate.only === void 0 || Is.typedArray(candidate.only, Is.string));
  1097. }
  1098. CodeActionContext.is = is;
  1099. })(CodeActionContext = exports.CodeActionContext || (exports.CodeActionContext = {}));
  1100. var CodeAction;
  1101. (function (CodeAction) {
  1102. function create(title, commandOrEdit, kind) {
  1103. var result = { title: title };
  1104. if (Command.is(commandOrEdit)) {
  1105. result.command = commandOrEdit;
  1106. }
  1107. else {
  1108. result.edit = commandOrEdit;
  1109. }
  1110. if (kind !== void null) {
  1111. result.kind = kind;
  1112. }
  1113. return result;
  1114. }
  1115. CodeAction.create = create;
  1116. function is(value) {
  1117. var candidate = value;
  1118. return candidate && Is.string(candidate.title) &&
  1119. (candidate.diagnostics === void 0 || Is.typedArray(candidate.diagnostics, Diagnostic.is)) &&
  1120. (candidate.kind === void 0 || Is.string(candidate.kind)) &&
  1121. (candidate.edit !== void 0 || candidate.command !== void 0) &&
  1122. (candidate.command === void 0 || Command.is(candidate.command)) &&
  1123. (candidate.edit === void 0 || WorkspaceEdit.is(candidate.edit));
  1124. }
  1125. CodeAction.is = is;
  1126. })(CodeAction = exports.CodeAction || (exports.CodeAction = {}));
  1127. /**
  1128. * The CodeLens namespace provides helper functions to work with
  1129. * [CodeLens](#CodeLens) literals.
  1130. */
  1131. var CodeLens;
  1132. (function (CodeLens) {
  1133. /**
  1134. * Creates a new CodeLens literal.
  1135. */
  1136. function create(range, data) {
  1137. var result = { range: range };
  1138. if (Is.defined(data))
  1139. result.data = data;
  1140. return result;
  1141. }
  1142. CodeLens.create = create;
  1143. /**
  1144. * Checks whether the given literal conforms to the [CodeLens](#CodeLens) interface.
  1145. */
  1146. function is(value) {
  1147. var candidate = value;
  1148. return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command));
  1149. }
  1150. CodeLens.is = is;
  1151. })(CodeLens = exports.CodeLens || (exports.CodeLens = {}));
  1152. /**
  1153. * The FormattingOptions namespace provides helper functions to work with
  1154. * [FormattingOptions](#FormattingOptions) literals.
  1155. */
  1156. var FormattingOptions;
  1157. (function (FormattingOptions) {
  1158. /**
  1159. * Creates a new FormattingOptions literal.
  1160. */
  1161. function create(tabSize, insertSpaces) {
  1162. return { tabSize: tabSize, insertSpaces: insertSpaces };
  1163. }
  1164. FormattingOptions.create = create;
  1165. /**
  1166. * Checks whether the given literal conforms to the [FormattingOptions](#FormattingOptions) interface.
  1167. */
  1168. function is(value) {
  1169. var candidate = value;
  1170. return Is.defined(candidate) && Is.number(candidate.tabSize) && Is.boolean(candidate.insertSpaces);
  1171. }
  1172. FormattingOptions.is = is;
  1173. })(FormattingOptions = exports.FormattingOptions || (exports.FormattingOptions = {}));
  1174. /**
  1175. * A document link is a range in a text document that links to an internal or external resource, like another
  1176. * text document or a web site.
  1177. */
  1178. var DocumentLink = /** @class */ (function () {
  1179. function DocumentLink() {
  1180. }
  1181. return DocumentLink;
  1182. }());
  1183. exports.DocumentLink = DocumentLink;
  1184. /**
  1185. * The DocumentLink namespace provides helper functions to work with
  1186. * [DocumentLink](#DocumentLink) literals.
  1187. */
  1188. (function (DocumentLink) {
  1189. /**
  1190. * Creates a new DocumentLink literal.
  1191. */
  1192. function create(range, target, data) {
  1193. return { range: range, target: target, data: data };
  1194. }
  1195. DocumentLink.create = create;
  1196. /**
  1197. * Checks whether the given literal conforms to the [DocumentLink](#DocumentLink) interface.
  1198. */
  1199. function is(value) {
  1200. var candidate = value;
  1201. return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.target) || Is.string(candidate.target));
  1202. }
  1203. DocumentLink.is = is;
  1204. })(DocumentLink = exports.DocumentLink || (exports.DocumentLink = {}));
  1205. exports.DocumentLink = DocumentLink;
  1206. exports.EOL = ['\n', '\r\n', '\r'];
  1207. var TextDocument;
  1208. (function (TextDocument) {
  1209. /**
  1210. * Creates a new ITextDocument literal from the given uri and content.
  1211. * @param uri The document's uri.
  1212. * @param languageId The document's language Id.
  1213. * @param content The document's content.
  1214. */
  1215. function create(uri, languageId, version, content) {
  1216. return new FullTextDocument(uri, languageId, version, content);
  1217. }
  1218. TextDocument.create = create;
  1219. /**
  1220. * Checks whether the given literal conforms to the [ITextDocument](#ITextDocument) interface.
  1221. */
  1222. function is(value) {
  1223. var candidate = value;
  1224. return Is.defined(candidate) && Is.string(candidate.uri) && (Is.undefined(candidate.languageId) || Is.string(candidate.languageId)) && Is.number(candidate.lineCount)
  1225. && Is.func(candidate.getText) && Is.func(candidate.positionAt) && Is.func(candidate.offsetAt) ? true : false;
  1226. }
  1227. TextDocument.is = is;
  1228. function applyEdits(document, edits) {
  1229. var text = document.getText();
  1230. var sortedEdits = mergeSort(edits, function (a, b) {
  1231. var diff = a.range.start.line - b.range.start.line;
  1232. if (diff === 0) {
  1233. return a.range.start.character - b.range.start.character;
  1234. }
  1235. return diff;
  1236. });
  1237. var lastModifiedOffset = text.length;
  1238. for (var i = sortedEdits.length - 1; i >= 0; i--) {
  1239. var e = sortedEdits[i];
  1240. var startOffset = document.offsetAt(e.range.start);
  1241. var endOffset = document.offsetAt(e.range.end);
  1242. if (endOffset <= lastModifiedOffset) {
  1243. text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
  1244. }
  1245. else {
  1246. throw new Error('Ovelapping edit');
  1247. }
  1248. lastModifiedOffset = startOffset;
  1249. }
  1250. return text;
  1251. }
  1252. TextDocument.applyEdits = applyEdits;
  1253. function mergeSort(data, compare) {
  1254. if (data.length <= 1) {
  1255. // sorted
  1256. return data;
  1257. }
  1258. var p = (data.length / 2) | 0;
  1259. var left = data.slice(0, p);
  1260. var right = data.slice(p);
  1261. mergeSort(left, compare);
  1262. mergeSort(right, compare);
  1263. var leftIdx = 0;
  1264. var rightIdx = 0;
  1265. var i = 0;
  1266. while (leftIdx < left.length && rightIdx < right.length) {
  1267. var ret = compare(left[leftIdx], right[rightIdx]);
  1268. if (ret <= 0) {
  1269. // smaller_equal -> take left to preserve order
  1270. data[i++] = left[leftIdx++];
  1271. }
  1272. else {
  1273. // greater -> take right
  1274. data[i++] = right[rightIdx++];
  1275. }
  1276. }
  1277. while (leftIdx < left.length) {
  1278. data[i++] = left[leftIdx++];
  1279. }
  1280. while (rightIdx < right.length) {
  1281. data[i++] = right[rightIdx++];
  1282. }
  1283. return data;
  1284. }
  1285. })(TextDocument = exports.TextDocument || (exports.TextDocument = {}));
  1286. /**
  1287. * Represents reasons why a text document is saved.
  1288. */
  1289. var TextDocumentSaveReason;
  1290. (function (TextDocumentSaveReason) {
  1291. /**
  1292. * Manually triggered, e.g. by the user pressing save, by starting debugging,
  1293. * or by an API call.
  1294. */
  1295. TextDocumentSaveReason.Manual = 1;
  1296. /**
  1297. * Automatic after a delay.
  1298. */
  1299. TextDocumentSaveReason.AfterDelay = 2;
  1300. /**
  1301. * When the editor lost focus.
  1302. */
  1303. TextDocumentSaveReason.FocusOut = 3;
  1304. })(TextDocumentSaveReason = exports.TextDocumentSaveReason || (exports.TextDocumentSaveReason = {}));
  1305. var FullTextDocument = /** @class */ (function () {
  1306. function FullTextDocument(uri, languageId, version, content) {
  1307. this._uri = uri;
  1308. this._languageId = languageId;
  1309. this._version = version;
  1310. this._content = content;
  1311. this._lineOffsets = null;
  1312. }
  1313. Object.defineProperty(FullTextDocument.prototype, "uri", {
  1314. get: function () {
  1315. return this._uri;
  1316. },
  1317. enumerable: true,
  1318. configurable: true
  1319. });
  1320. Object.defineProperty(FullTextDocument.prototype, "languageId", {
  1321. get: function () {
  1322. return this._languageId;
  1323. },
  1324. enumerable: true,
  1325. configurable: true
  1326. });
  1327. Object.defineProperty(FullTextDocument.prototype, "version", {
  1328. get: function () {
  1329. return this._version;
  1330. },
  1331. enumerable: true,
  1332. configurable: true
  1333. });
  1334. FullTextDocument.prototype.getText = function (range) {
  1335. if (range) {
  1336. var start = this.offsetAt(range.start);
  1337. var end = this.offsetAt(range.end);
  1338. return this._content.substring(start, end);
  1339. }
  1340. return this._content;
  1341. };
  1342. FullTextDocument.prototype.update = function (event, version) {
  1343. this._content = event.text;
  1344. this._version = version;
  1345. this._lineOffsets = null;
  1346. };
  1347. FullTextDocument.prototype.getLineOffsets = function () {
  1348. if (this._lineOffsets === null) {
  1349. var lineOffsets = [];
  1350. var text = this._content;
  1351. var isLineStart = true;
  1352. for (var i = 0; i < text.length; i++) {
  1353. if (isLineStart) {
  1354. lineOffsets.push(i);
  1355. isLineStart = false;
  1356. }
  1357. var ch = text.charAt(i);
  1358. isLineStart = (ch === '\r' || ch === '\n');
  1359. if (ch === '\r' && i + 1 < text.length && text.charAt(i + 1) === '\n') {
  1360. i++;
  1361. }
  1362. }
  1363. if (isLineStart && text.length > 0) {
  1364. lineOffsets.push(text.length);
  1365. }
  1366. this._lineOffsets = lineOffsets;
  1367. }
  1368. return this._lineOffsets;
  1369. };
  1370. FullTextDocument.prototype.positionAt = function (offset) {
  1371. offset = Math.max(Math.min(offset, this._content.length), 0);
  1372. var lineOffsets = this.getLineOffsets();
  1373. var low = 0, high = lineOffsets.length;
  1374. if (high === 0) {
  1375. return Position.create(0, offset);
  1376. }
  1377. while (low < high) {
  1378. var mid = Math.floor((low + high) / 2);
  1379. if (lineOffsets[mid] > offset) {
  1380. high = mid;
  1381. }
  1382. else {
  1383. low = mid + 1;
  1384. }
  1385. }
  1386. // low is the least x for which the line offset is larger than the current offset
  1387. // or array.length if no line offset is larger than the current offset
  1388. var line = low - 1;
  1389. return Position.create(line, offset - lineOffsets[line]);
  1390. };
  1391. FullTextDocument.prototype.offsetAt = function (position) {
  1392. var lineOffsets = this.getLineOffsets();
  1393. if (position.line >= lineOffsets.length) {
  1394. return this._content.length;
  1395. }
  1396. else if (position.line < 0) {
  1397. return 0;
  1398. }
  1399. var lineOffset = lineOffsets[position.line];
  1400. var nextLineOffset = (position.line + 1 < lineOffsets.length) ? lineOffsets[position.line + 1] : this._content.length;
  1401. return Math.max(Math.min(lineOffset + position.character, nextLineOffset), lineOffset);
  1402. };
  1403. Object.defineProperty(FullTextDocument.prototype, "lineCount", {
  1404. get: function () {
  1405. return this.getLineOffsets().length;
  1406. },
  1407. enumerable: true,
  1408. configurable: true
  1409. });
  1410. return FullTextDocument;
  1411. }());
  1412. var Is;
  1413. (function (Is) {
  1414. var toString = Object.prototype.toString;
  1415. function defined(value) {
  1416. return typeof value !== 'undefined';
  1417. }
  1418. Is.defined = defined;
  1419. function undefined(value) {
  1420. return typeof value === 'undefined';
  1421. }
  1422. Is.undefined = undefined;
  1423. function boolean(value) {
  1424. return value === true || value === false;
  1425. }
  1426. Is.boolean = boolean;
  1427. function string(value) {
  1428. return toString.call(value) === '[object String]';
  1429. }
  1430. Is.string = string;
  1431. function number(value) {
  1432. return toString.call(value) === '[object Number]';
  1433. }
  1434. Is.number = number;
  1435. function func(value) {
  1436. return toString.call(value) === '[object Function]';
  1437. }
  1438. Is.func = func;
  1439. function objectLiteral(value) {
  1440. // Strictly speaking class instances pass this check as well. Since the LSP
  1441. // doesn't use classes we ignore this for now. If we do we need to add something
  1442. // like this: `Object.getPrototypeOf(Object.getPrototypeOf(x)) === null`
  1443. return value !== null && typeof value === 'object';
  1444. }
  1445. Is.objectLiteral = objectLiteral;
  1446. function typedArray(value, check) {
  1447. return Array.isArray(value) && value.every(check);
  1448. }
  1449. Is.typedArray = typedArray;
  1450. })(Is || (Is = {}));
  1451. });
  1452. define('vscode-languageserver-types', ['vscode-languageserver-types/main'], function (main) { return main; });
  1453. define('vs/language/json/languageFeatures',["require", "exports", "vscode-languageserver-types"], function (require, exports, ls) {
  1454. /*---------------------------------------------------------------------------------------------
  1455. * Copyright (c) Microsoft Corporation. All rights reserved.
  1456. * Licensed under the MIT License. See License.txt in the project root for license information.
  1457. *--------------------------------------------------------------------------------------------*/
  1458. 'use strict';
  1459. Object.defineProperty(exports, "__esModule", { value: true });
  1460. var Uri = monaco.Uri;
  1461. var Range = monaco.Range;
  1462. // --- diagnostics --- ---
  1463. var DiagnosticsAdapter = /** @class */ (function () {
  1464. function DiagnosticsAdapter(_languageId, _worker, defaults) {
  1465. var _this = this;
  1466. this._languageId = _languageId;
  1467. this._worker = _worker;
  1468. this._disposables = [];
  1469. this._listener = Object.create(null);
  1470. var onModelAdd = function (model) {
  1471. var modeId = model.getModeId();
  1472. if (modeId !== _this._languageId) {
  1473. return;
  1474. }
  1475. var handle;
  1476. _this._listener[model.uri.toString()] = model.onDidChangeContent(function () {
  1477. clearTimeout(handle);
  1478. handle = setTimeout(function () { return _this._doValidate(model.uri, modeId); }, 500);
  1479. });
  1480. _this._doValidate(model.uri, modeId);
  1481. };
  1482. var onModelRemoved = function (model) {
  1483. monaco.editor.setModelMarkers(model, _this._languageId, []);
  1484. var uriStr = model.uri.toString();
  1485. var listener = _this._listener[uriStr];
  1486. if (listener) {
  1487. listener.dispose();
  1488. delete _this._listener[uriStr];
  1489. }
  1490. };
  1491. this._disposables.push(monaco.editor.onDidCreateModel(onModelAdd));
  1492. this._disposables.push(monaco.editor.onWillDisposeModel(function (model) {
  1493. onModelRemoved(model);
  1494. _this._resetSchema(model.uri);
  1495. }));
  1496. this._disposables.push(monaco.editor.onDidChangeModelLanguage(function (event) {
  1497. onModelRemoved(event.model);
  1498. onModelAdd(event.model);
  1499. _this._resetSchema(event.model.uri);
  1500. }));
  1501. this._disposables.push(defaults.onDidChange(function (_) {
  1502. monaco.editor.getModels().forEach(function (model) {
  1503. if (model.getModeId() === _this._languageId) {
  1504. onModelRemoved(model);
  1505. onModelAdd(model);
  1506. }
  1507. });
  1508. }));
  1509. this._disposables.push({
  1510. dispose: function () {
  1511. monaco.editor.getModels().forEach(onModelRemoved);
  1512. for (var key in _this._listener) {
  1513. _this._listener[key].dispose();
  1514. }
  1515. }
  1516. });
  1517. monaco.editor.getModels().forEach(onModelAdd);
  1518. }
  1519. DiagnosticsAdapter.prototype.dispose = function () {
  1520. this._disposables.forEach(function (d) { return d && d.dispose(); });
  1521. this._disposables = [];
  1522. };
  1523. DiagnosticsAdapter.prototype._resetSchema = function (resource) {
  1524. this._worker().then(function (worker) {
  1525. worker.resetSchema(resource.toString());
  1526. });
  1527. };
  1528. DiagnosticsAdapter.prototype._doValidate = function (resource, languageId) {
  1529. this._worker(resource).then(function (worker) {
  1530. return worker.doValidation(resource.toString()).then(function (diagnostics) {
  1531. var markers = diagnostics.map(function (d) { return toDiagnostics(resource, d); });
  1532. var model = monaco.editor.getModel(resource);
  1533. if (model.getModeId() === languageId) {
  1534. monaco.editor.setModelMarkers(model, languageId, markers);
  1535. }
  1536. });
  1537. }).then(undefined, function (err) {
  1538. console.error(err);
  1539. });
  1540. };
  1541. return DiagnosticsAdapter;
  1542. }());
  1543. exports.DiagnosticsAdapter = DiagnosticsAdapter;
  1544. function toSeverity(lsSeverity) {
  1545. switch (lsSeverity) {
  1546. case ls.DiagnosticSeverity.Error: return monaco.MarkerSeverity.Error;
  1547. case ls.DiagnosticSeverity.Warning: return monaco.MarkerSeverity.Warning;
  1548. case ls.DiagnosticSeverity.Information: return monaco.MarkerSeverity.Info;
  1549. case ls.DiagnosticSeverity.Hint: return monaco.MarkerSeverity.Hint;
  1550. default:
  1551. return monaco.MarkerSeverity.Info;
  1552. }
  1553. }
  1554. function toDiagnostics(resource, diag) {
  1555. var code = typeof diag.code === 'number' ? String(diag.code) : diag.code;
  1556. return {
  1557. severity: toSeverity(diag.severity),
  1558. startLineNumber: diag.range.start.line + 1,
  1559. startColumn: diag.range.start.character + 1,
  1560. endLineNumber: diag.range.end.line + 1,
  1561. endColumn: diag.range.end.character + 1,
  1562. message: diag.message,
  1563. code: code,
  1564. source: diag.source
  1565. };
  1566. }
  1567. // --- completion ------
  1568. function fromPosition(position) {
  1569. if (!position) {
  1570. return void 0;
  1571. }
  1572. return { character: position.column - 1, line: position.lineNumber - 1 };
  1573. }
  1574. function fromRange(range) {
  1575. if (!range) {
  1576. return void 0;
  1577. }
  1578. return { start: { line: range.startLineNumber - 1, character: range.startColumn - 1 }, end: { line: range.endLineNumber - 1, character: range.endColumn - 1 } };
  1579. }
  1580. function toRange(range) {
  1581. if (!range) {
  1582. return void 0;
  1583. }
  1584. return new Range(range.start.line + 1, range.start.character + 1, range.end.line + 1, range.end.character + 1);
  1585. }
  1586. function toCompletionItemKind(kind) {
  1587. var mItemKind = monaco.languages.CompletionItemKind;
  1588. switch (kind) {
  1589. case ls.CompletionItemKind.Text: return mItemKind.Text;
  1590. case ls.CompletionItemKind.Method: return mItemKind.Method;
  1591. case ls.CompletionItemKind.Function: return mItemKind.Function;
  1592. case ls.CompletionItemKind.Constructor: return mItemKind.Constructor;
  1593. case ls.CompletionItemKind.Field: return mItemKind.Field;
  1594. case ls.CompletionItemKind.Variable: return mItemKind.Variable;
  1595. case ls.CompletionItemKind.Class: return mItemKind.Class;
  1596. case ls.CompletionItemKind.Interface: return mItemKind.Interface;
  1597. case ls.CompletionItemKind.Module: return mItemKind.Module;
  1598. case ls.CompletionItemKind.Property: return mItemKind.Property;
  1599. case ls.CompletionItemKind.Unit: return mItemKind.Unit;
  1600. case ls.CompletionItemKind.Value: return mItemKind.Value;
  1601. case ls.CompletionItemKind.Enum: return mItemKind.Enum;
  1602. case ls.CompletionItemKind.Keyword: return mItemKind.Keyword;
  1603. case ls.CompletionItemKind.Snippet: return mItemKind.Snippet;
  1604. case ls.CompletionItemKind.Color: return mItemKind.Color;
  1605. case ls.CompletionItemKind.File: return mItemKind.File;
  1606. case ls.CompletionItemKind.Reference: return mItemKind.Reference;
  1607. }
  1608. return mItemKind.Property;
  1609. }
  1610. function fromCompletionItemKind(kind) {
  1611. var mItemKind = monaco.languages.CompletionItemKind;
  1612. switch (kind) {
  1613. case mItemKind.Text: return ls.CompletionItemKind.Text;
  1614. case mItemKind.Method: return ls.CompletionItemKind.Method;
  1615. case mItemKind.Function: return ls.CompletionItemKind.Function;
  1616. case mItemKind.Constructor: return ls.CompletionItemKind.Constructor;
  1617. case mItemKind.Field: return ls.CompletionItemKind.Field;
  1618. case mItemKind.Variable: return ls.CompletionItemKind.Variable;
  1619. case mItemKind.Class: return ls.CompletionItemKind.Class;
  1620. case mItemKind.Interface: return ls.CompletionItemKind.Interface;
  1621. case mItemKind.Module: return ls.CompletionItemKind.Module;
  1622. case mItemKind.Property: return ls.CompletionItemKind.Property;
  1623. case mItemKind.Unit: return ls.CompletionItemKind.Unit;
  1624. case mItemKind.Value: return ls.CompletionItemKind.Value;
  1625. case mItemKind.Enum: return ls.CompletionItemKind.Enum;
  1626. case mItemKind.Keyword: return ls.CompletionItemKind.Keyword;
  1627. case mItemKind.Snippet: return ls.CompletionItemKind.Snippet;
  1628. case mItemKind.Color: return ls.CompletionItemKind.Color;
  1629. case mItemKind.File: return ls.CompletionItemKind.File;
  1630. case mItemKind.Reference: return ls.CompletionItemKind.Reference;
  1631. }
  1632. return ls.CompletionItemKind.Property;
  1633. }
  1634. function toTextEdit(textEdit) {
  1635. if (!textEdit) {
  1636. return void 0;
  1637. }
  1638. return {
  1639. range: toRange(textEdit.range),
  1640. text: textEdit.newText
  1641. };
  1642. }
  1643. var CompletionAdapter = /** @class */ (function () {
  1644. function CompletionAdapter(_worker) {
  1645. this._worker = _worker;
  1646. }
  1647. Object.defineProperty(CompletionAdapter.prototype, "triggerCharacters", {
  1648. get: function () {
  1649. return [' ', ':'];
  1650. },
  1651. enumerable: true,
  1652. configurable: true
  1653. });
  1654. CompletionAdapter.prototype.provideCompletionItems = function (model, position, context, token) {
  1655. var wordInfo = model.getWordUntilPosition(position);
  1656. var resource = model.uri;
  1657. return this._worker(resource).then(function (worker) {
  1658. return worker.doComplete(resource.toString(), fromPosition(position));
  1659. }).then(function (info) {
  1660. if (!info) {
  1661. return;
  1662. }
  1663. var items = info.items.map(function (entry) {
  1664. var item = {
  1665. label: entry.label,
  1666. insertText: entry.insertText || entry.label,
  1667. sortText: entry.sortText,
  1668. filterText: entry.filterText,
  1669. documentation: entry.documentation,
  1670. detail: entry.detail,
  1671. kind: toCompletionItemKind(entry.kind),
  1672. };
  1673. if (entry.textEdit) {
  1674. item.range = toRange(entry.textEdit.range);
  1675. item.insertText = entry.textEdit.newText;
  1676. }
  1677. if (entry.additionalTextEdits) {
  1678. item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
  1679. }
  1680. if (entry.insertTextFormat === ls.InsertTextFormat.Snippet) {
  1681. item.insertTextRules = monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet;
  1682. }
  1683. return item;
  1684. });
  1685. return {
  1686. isIncomplete: info.isIncomplete,
  1687. suggestions: items
  1688. };
  1689. });
  1690. };
  1691. return CompletionAdapter;
  1692. }());
  1693. exports.CompletionAdapter = CompletionAdapter;
  1694. function isMarkupContent(thing) {
  1695. return thing && typeof thing === 'object' && typeof thing.kind === 'string';
  1696. }
  1697. function toMarkdownString(entry) {
  1698. if (typeof entry === 'string') {
  1699. return {
  1700. value: entry
  1701. };
  1702. }
  1703. if (isMarkupContent(entry)) {
  1704. if (entry.kind === 'plaintext') {
  1705. return {
  1706. value: entry.value.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&')
  1707. };
  1708. }
  1709. return {
  1710. value: entry.value
  1711. };
  1712. }
  1713. return { value: '```' + entry.language + '\n' + entry.value + '\n```\n' };
  1714. }
  1715. function toMarkedStringArray(contents) {
  1716. if (!contents) {
  1717. return void 0;
  1718. }
  1719. if (Array.isArray(contents)) {
  1720. return contents.map(toMarkdownString);
  1721. }
  1722. return [toMarkdownString(contents)];
  1723. }
  1724. // --- hover ------
  1725. var HoverAdapter = /** @class */ (function () {
  1726. function HoverAdapter(_worker) {
  1727. this._worker = _worker;
  1728. }
  1729. HoverAdapter.prototype.provideHover = function (model, position, token) {
  1730. var resource = model.uri;
  1731. return this._worker(resource).then(function (worker) {
  1732. return worker.doHover(resource.toString(), fromPosition(position));
  1733. }).then(function (info) {
  1734. if (!info) {
  1735. return;
  1736. }
  1737. return {
  1738. range: toRange(info.range),
  1739. contents: toMarkedStringArray(info.contents)
  1740. };
  1741. });
  1742. };
  1743. return HoverAdapter;
  1744. }());
  1745. exports.HoverAdapter = HoverAdapter;
  1746. // --- definition ------
  1747. function toLocation(location) {
  1748. return {
  1749. uri: Uri.parse(location.uri),
  1750. range: toRange(location.range)
  1751. };
  1752. }
  1753. // --- document symbols ------
  1754. function toSymbolKind(kind) {
  1755. var mKind = monaco.languages.SymbolKind;
  1756. switch (kind) {
  1757. case ls.SymbolKind.File: return mKind.Array;
  1758. case ls.SymbolKind.Module: return mKind.Module;
  1759. case ls.SymbolKind.Namespace: return mKind.Namespace;
  1760. case ls.SymbolKind.Package: return mKind.Package;
  1761. case ls.SymbolKind.Class: return mKind.Class;
  1762. case ls.SymbolKind.Method: return mKind.Method;
  1763. case ls.SymbolKind.Property: return mKind.Property;
  1764. case ls.SymbolKind.Field: return mKind.Field;
  1765. case ls.SymbolKind.Constructor: return mKind.Constructor;
  1766. case ls.SymbolKind.Enum: return mKind.Enum;
  1767. case ls.SymbolKind.Interface: return mKind.Interface;
  1768. case ls.SymbolKind.Function: return mKind.Function;
  1769. case ls.SymbolKind.Variable: return mKind.Variable;
  1770. case ls.SymbolKind.Constant: return mKind.Constant;
  1771. case ls.SymbolKind.String: return mKind.String;
  1772. case ls.SymbolKind.Number: return mKind.Number;
  1773. case ls.SymbolKind.Boolean: return mKind.Boolean;
  1774. case ls.SymbolKind.Array: return mKind.Array;
  1775. }
  1776. return mKind.Function;
  1777. }
  1778. var DocumentSymbolAdapter = /** @class */ (function () {
  1779. function DocumentSymbolAdapter(_worker) {
  1780. this._worker = _worker;
  1781. }
  1782. DocumentSymbolAdapter.prototype.provideDocumentSymbols = function (model, token) {
  1783. var resource = model.uri;
  1784. return this._worker(resource).then(function (worker) { return worker.findDocumentSymbols(resource.toString()); }).then(function (items) {
  1785. if (!items) {
  1786. return;
  1787. }
  1788. return items.map(function (item) { return ({
  1789. name: item.name,
  1790. detail: '',
  1791. containerName: item.containerName,
  1792. kind: toSymbolKind(item.kind),
  1793. range: toRange(item.location.range),
  1794. selectionRange: toRange(item.location.range)
  1795. }); });
  1796. });
  1797. };
  1798. return DocumentSymbolAdapter;
  1799. }());
  1800. exports.DocumentSymbolAdapter = DocumentSymbolAdapter;
  1801. function fromFormattingOptions(options) {
  1802. return {
  1803. tabSize: options.tabSize,
  1804. insertSpaces: options.insertSpaces
  1805. };
  1806. }
  1807. var DocumentFormattingEditProvider = /** @class */ (function () {
  1808. function DocumentFormattingEditProvider(_worker) {
  1809. this._worker = _worker;
  1810. }
  1811. DocumentFormattingEditProvider.prototype.provideDocumentFormattingEdits = function (model, options, token) {
  1812. var resource = model.uri;
  1813. return this._worker(resource).then(function (worker) {
  1814. return worker.format(resource.toString(), null, fromFormattingOptions(options)).then(function (edits) {
  1815. if (!edits || edits.length === 0) {
  1816. return;
  1817. }
  1818. return edits.map(toTextEdit);
  1819. });
  1820. });
  1821. };
  1822. return DocumentFormattingEditProvider;
  1823. }());
  1824. exports.DocumentFormattingEditProvider = DocumentFormattingEditProvider;
  1825. var DocumentRangeFormattingEditProvider = /** @class */ (function () {
  1826. function DocumentRangeFormattingEditProvider(_worker) {
  1827. this._worker = _worker;
  1828. }
  1829. DocumentRangeFormattingEditProvider.prototype.provideDocumentRangeFormattingEdits = function (model, range, options, token) {
  1830. var resource = model.uri;
  1831. return this._worker(resource).then(function (worker) {
  1832. return worker.format(resource.toString(), fromRange(range), fromFormattingOptions(options)).then(function (edits) {
  1833. if (!edits || edits.length === 0) {
  1834. return;
  1835. }
  1836. return edits.map(toTextEdit);
  1837. });
  1838. });
  1839. };
  1840. return DocumentRangeFormattingEditProvider;
  1841. }());
  1842. exports.DocumentRangeFormattingEditProvider = DocumentRangeFormattingEditProvider;
  1843. var DocumentColorAdapter = /** @class */ (function () {
  1844. function DocumentColorAdapter(_worker) {
  1845. this._worker = _worker;
  1846. }
  1847. DocumentColorAdapter.prototype.provideDocumentColors = function (model, token) {
  1848. var resource = model.uri;
  1849. return this._worker(resource).then(function (worker) { return worker.findDocumentColors(resource.toString()); }).then(function (infos) {
  1850. if (!infos) {
  1851. return;
  1852. }
  1853. return infos.map(function (item) { return ({
  1854. color: item.color,
  1855. range: toRange(item.range)
  1856. }); });
  1857. });
  1858. };
  1859. DocumentColorAdapter.prototype.provideColorPresentations = function (model, info, token) {
  1860. var resource = model.uri;
  1861. return this._worker(resource).then(function (worker) { return worker.getColorPresentations(resource.toString(), info.color, fromRange(info.range)); }).then(function (presentations) {
  1862. if (!presentations) {
  1863. return;
  1864. }
  1865. return presentations.map(function (presentation) {
  1866. var item = {
  1867. label: presentation.label,
  1868. };
  1869. if (presentation.textEdit) {
  1870. item.textEdit = toTextEdit(presentation.textEdit);
  1871. }
  1872. if (presentation.additionalTextEdits) {
  1873. item.additionalTextEdits = presentation.additionalTextEdits.map(toTextEdit);
  1874. }
  1875. return item;
  1876. });
  1877. });
  1878. };
  1879. return DocumentColorAdapter;
  1880. }());
  1881. exports.DocumentColorAdapter = DocumentColorAdapter;
  1882. var FoldingRangeAdapter = /** @class */ (function () {
  1883. function FoldingRangeAdapter(_worker) {
  1884. this._worker = _worker;
  1885. }
  1886. FoldingRangeAdapter.prototype.provideFoldingRanges = function (model, context, token) {
  1887. var resource = model.uri;
  1888. return this._worker(resource).then(function (worker) { return worker.provideFoldingRanges(resource.toString(), context); }).then(function (ranges) {
  1889. if (!ranges) {
  1890. return;
  1891. }
  1892. return ranges.map(function (range) {
  1893. var result = {
  1894. start: range.startLine + 1,
  1895. end: range.endLine + 1
  1896. };
  1897. if (typeof range.kind !== 'undefined') {
  1898. result.kind = toFoldingRangeKind(range.kind);
  1899. }
  1900. return result;
  1901. });
  1902. });
  1903. };
  1904. return FoldingRangeAdapter;
  1905. }());
  1906. exports.FoldingRangeAdapter = FoldingRangeAdapter;
  1907. function toFoldingRangeKind(kind) {
  1908. switch (kind) {
  1909. case ls.FoldingRangeKind.Comment: return monaco.languages.FoldingRangeKind.Comment;
  1910. case ls.FoldingRangeKind.Imports: return monaco.languages.FoldingRangeKind.Imports;
  1911. case ls.FoldingRangeKind.Region: return monaco.languages.FoldingRangeKind.Region;
  1912. }
  1913. return void 0;
  1914. }
  1915. });
  1916. (function (factory) {
  1917. if (typeof module === "object" && typeof module.exports === "object") {
  1918. var v = factory(require, exports);
  1919. if (v !== undefined) module.exports = v;
  1920. }
  1921. else if (typeof define === "function" && define.amd) {
  1922. define('jsonc-parser/impl/scanner',["require", "exports"], factory);
  1923. }
  1924. })(function (require, exports) {
  1925. /*---------------------------------------------------------------------------------------------
  1926. * Copyright (c) Microsoft Corporation. All rights reserved.
  1927. * Licensed under the MIT License. See License.txt in the project root for license information.
  1928. *--------------------------------------------------------------------------------------------*/
  1929. 'use strict';
  1930. Object.defineProperty(exports, "__esModule", { value: true });
  1931. /**
  1932. * Creates a JSON scanner on the given text.
  1933. * If ignoreTrivia is set, whitespaces or comments are ignored.
  1934. */
  1935. function createScanner(text, ignoreTrivia) {
  1936. if (ignoreTrivia === void 0) { ignoreTrivia = false; }
  1937. var pos = 0, len = text.length, value = '', tokenOffset = 0, token = 16 /* Unknown */, scanError = 0 /* None */;
  1938. function scanHexDigits(count, exact) {
  1939. var digits = 0;
  1940. var value = 0;
  1941. while (digits < count || !exact) {
  1942. var ch = text.charCodeAt(pos);
  1943. if (ch >= 48 /* _0 */ && ch <= 57 /* _9 */) {
  1944. value = value * 16 + ch - 48 /* _0 */;
  1945. }
  1946. else if (ch >= 65 /* A */ && ch <= 70 /* F */) {
  1947. value = value * 16 + ch - 65 /* A */ + 10;
  1948. }
  1949. else if (ch >= 97 /* a */ && ch <= 102 /* f */) {
  1950. value = value * 16 + ch - 97 /* a */ + 10;
  1951. }
  1952. else {
  1953. break;
  1954. }
  1955. pos++;
  1956. digits++;
  1957. }
  1958. if (digits < count) {
  1959. value = -1;
  1960. }
  1961. return value;
  1962. }
  1963. function setPosition(newPosition) {
  1964. pos = newPosition;
  1965. value = '';
  1966. tokenOffset = 0;
  1967. token = 16 /* Unknown */;
  1968. scanError = 0 /* None */;
  1969. }
  1970. function scanNumber() {
  1971. var start = pos;
  1972. if (text.charCodeAt(pos) === 48 /* _0 */) {
  1973. pos++;
  1974. }
  1975. else {
  1976. pos++;
  1977. while (pos < text.length && isDigit(text.charCodeAt(pos))) {
  1978. pos++;
  1979. }
  1980. }
  1981. if (pos < text.length && text.charCodeAt(pos) === 46 /* dot */) {
  1982. pos++;
  1983. if (pos < text.length && isDigit(text.charCodeAt(pos))) {
  1984. pos++;
  1985. while (pos < text.length && isDigit(text.charCodeAt(pos))) {
  1986. pos++;
  1987. }
  1988. }
  1989. else {
  1990. scanError = 3 /* UnexpectedEndOfNumber */;
  1991. return text.substring(start, pos);
  1992. }
  1993. }
  1994. var end = pos;
  1995. if (pos < text.length && (text.charCodeAt(pos) === 69 /* E */ || text.charCodeAt(pos) === 101 /* e */)) {
  1996. pos++;
  1997. if (pos < text.length && text.charCodeAt(pos) === 43 /* plus */ || text.charCodeAt(pos) === 45 /* minus */) {
  1998. pos++;
  1999. }
  2000. if (pos < text.length && isDigit(text.charCodeAt(pos))) {
  2001. pos++;
  2002. while (pos < text.length && isDigit(text.charCodeAt(pos))) {
  2003. pos++;
  2004. }
  2005. end = pos;
  2006. }
  2007. else {
  2008. scanError = 3 /* UnexpectedEndOfNumber */;
  2009. }
  2010. }
  2011. return text.substring(start, end);
  2012. }
  2013. function scanString() {
  2014. var result = '', start = pos;
  2015. while (true) {
  2016. if (pos >= len) {
  2017. result += text.substring(start, pos);
  2018. scanError = 2 /* UnexpectedEndOfString */;
  2019. break;
  2020. }
  2021. var ch = text.charCodeAt(pos);
  2022. if (ch === 34 /* doubleQuote */) {
  2023. result += text.substring(start, pos);
  2024. pos++;
  2025. break;
  2026. }
  2027. if (ch === 92 /* backslash */) {
  2028. result += text.substring(start, pos);
  2029. pos++;
  2030. if (pos >= len) {
  2031. scanError = 2 /* UnexpectedEndOfString */;
  2032. break;
  2033. }
  2034. ch = text.charCodeAt(pos++);
  2035. switch (ch) {
  2036. case 34 /* doubleQuote */:
  2037. result += '\"';
  2038. break;
  2039. case 92 /* backslash */:
  2040. result += '\\';
  2041. break;
  2042. case 47 /* slash */:
  2043. result += '/';
  2044. break;
  2045. case 98 /* b */:
  2046. result += '\b';
  2047. break;
  2048. case 102 /* f */:
  2049. result += '\f';
  2050. break;
  2051. case 110 /* n */:
  2052. result += '\n';
  2053. break;
  2054. case 114 /* r */:
  2055. result += '\r';
  2056. break;
  2057. case 116 /* t */:
  2058. result += '\t';
  2059. break;
  2060. case 117 /* u */:
  2061. var ch_1 = scanHexDigits(4, true);
  2062. if (ch_1 >= 0) {
  2063. result += String.fromCharCode(ch_1);
  2064. }
  2065. else {
  2066. scanError = 4 /* InvalidUnicode */;
  2067. }
  2068. break;
  2069. default:
  2070. scanError = 5 /* InvalidEscapeCharacter */;
  2071. }
  2072. start = pos;
  2073. continue;
  2074. }
  2075. if (ch >= 0 && ch <= 0x1f) {
  2076. if (isLineBreak(ch)) {
  2077. result += text.substring(start, pos);
  2078. scanError = 2 /* UnexpectedEndOfString */;
  2079. break;
  2080. }
  2081. else {
  2082. scanError = 6 /* InvalidCharacter */;
  2083. // mark as error but continue with string
  2084. }
  2085. }
  2086. pos++;
  2087. }
  2088. return result;
  2089. }
  2090. function scanNext() {
  2091. value = '';
  2092. scanError = 0 /* None */;
  2093. tokenOffset = pos;
  2094. if (pos >= len) {
  2095. // at the end
  2096. tokenOffset = len;
  2097. return token = 17 /* EOF */;
  2098. }
  2099. var code = text.charCodeAt(pos);
  2100. // trivia: whitespace
  2101. if (isWhiteSpace(code)) {
  2102. do {
  2103. pos++;
  2104. value += String.fromCharCode(code);
  2105. code = text.charCodeAt(pos);
  2106. } while (isWhiteSpace(code));
  2107. return token = 15 /* Trivia */;
  2108. }
  2109. // trivia: newlines
  2110. if (isLineBreak(code)) {
  2111. pos++;
  2112. value += String.fromCharCode(code);
  2113. if (code === 13 /* carriageReturn */ && text.charCodeAt(pos) === 10 /* lineFeed */) {
  2114. pos++;
  2115. value += '\n';
  2116. }
  2117. return token = 14 /* LineBreakTrivia */;
  2118. }
  2119. switch (code) {
  2120. // tokens: []{}:,
  2121. case 123 /* openBrace */:
  2122. pos++;
  2123. return token = 1 /* OpenBraceToken */;
  2124. case 125 /* closeBrace */:
  2125. pos++;
  2126. return token = 2 /* CloseBraceToken */;
  2127. case 91 /* openBracket */:
  2128. pos++;
  2129. return token = 3 /* OpenBracketToken */;
  2130. case 93 /* closeBracket */:
  2131. pos++;
  2132. return token = 4 /* CloseBracketToken */;
  2133. case 58 /* colon */:
  2134. pos++;
  2135. return token = 6 /* ColonToken */;
  2136. case 44 /* comma */:
  2137. pos++;
  2138. return token = 5 /* CommaToken */;
  2139. // strings
  2140. case 34 /* doubleQuote */:
  2141. pos++;
  2142. value = scanString();
  2143. return token = 10 /* StringLiteral */;
  2144. // comments
  2145. case 47 /* slash */:
  2146. var start = pos - 1;
  2147. // Single-line comment
  2148. if (text.charCodeAt(pos + 1) === 47 /* slash */) {
  2149. pos += 2;
  2150. while (pos < len) {
  2151. if (isLineBreak(text.charCodeAt(pos))) {
  2152. break;
  2153. }
  2154. pos++;
  2155. }
  2156. value = text.substring(start, pos);
  2157. return token = 12 /* LineCommentTrivia */;
  2158. }
  2159. // Multi-line comment
  2160. if (text.charCodeAt(pos + 1) === 42 /* asterisk */) {
  2161. pos += 2;
  2162. var commentClosed = false;
  2163. while (pos < len) {
  2164. var ch = text.charCodeAt(pos);
  2165. if (ch === 42 /* asterisk */ && (pos + 1 < len) && text.charCodeAt(pos + 1) === 47 /* slash */) {
  2166. pos += 2;
  2167. commentClosed = true;
  2168. break;
  2169. }
  2170. pos++;
  2171. }
  2172. if (!commentClosed) {
  2173. pos++;
  2174. scanError = 1 /* UnexpectedEndOfComment */;
  2175. }
  2176. value = text.substring(start, pos);
  2177. return token = 13 /* BlockCommentTrivia */;
  2178. }
  2179. // just a single slash
  2180. value += String.fromCharCode(code);
  2181. pos++;
  2182. return token = 16 /* Unknown */;
  2183. // numbers
  2184. case 45 /* minus */:
  2185. value += String.fromCharCode(code);
  2186. pos++;
  2187. if (pos === len || !isDigit(text.charCodeAt(pos))) {
  2188. return token = 16 /* Unknown */;
  2189. }
  2190. // found a minus, followed by a number so
  2191. // we fall through to proceed with scanning
  2192. // numbers
  2193. case 48 /* _0 */:
  2194. case 49 /* _1 */:
  2195. case 50 /* _2 */:
  2196. case 51 /* _3 */:
  2197. case 52 /* _4 */:
  2198. case 53 /* _5 */:
  2199. case 54 /* _6 */:
  2200. case 55 /* _7 */:
  2201. case 56 /* _8 */:
  2202. case 57 /* _9 */:
  2203. value += scanNumber();
  2204. return token = 11 /* NumericLiteral */;
  2205. // literals and unknown symbols
  2206. default:
  2207. // is a literal? Read the full word.
  2208. while (pos < len && isUnknownContentCharacter(code)) {
  2209. pos++;
  2210. code = text.charCodeAt(pos);
  2211. }
  2212. if (tokenOffset !== pos) {
  2213. value = text.substring(tokenOffset, pos);
  2214. // keywords: true, false, null
  2215. switch (value) {
  2216. case 'true': return token = 8 /* TrueKeyword */;
  2217. case 'false': return token = 9 /* FalseKeyword */;
  2218. case 'null': return token = 7 /* NullKeyword */;
  2219. }
  2220. return token = 16 /* Unknown */;
  2221. }
  2222. // some
  2223. value += String.fromCharCode(code);
  2224. pos++;
  2225. return token = 16 /* Unknown */;
  2226. }
  2227. }
  2228. function isUnknownContentCharacter(code) {
  2229. if (isWhiteSpace(code) || isLineBreak(code)) {
  2230. return false;
  2231. }
  2232. switch (code) {
  2233. case 125 /* closeBrace */:
  2234. case 93 /* closeBracket */:
  2235. case 123 /* openBrace */:
  2236. case 91 /* openBracket */:
  2237. case 34 /* doubleQuote */:
  2238. case 58 /* colon */:
  2239. case 44 /* comma */:
  2240. case 47 /* slash */:
  2241. return false;
  2242. }
  2243. return true;
  2244. }
  2245. function scanNextNonTrivia() {
  2246. var result;
  2247. do {
  2248. result = scanNext();
  2249. } while (result >= 12 /* LineCommentTrivia */ && result <= 15 /* Trivia */);
  2250. return result;
  2251. }
  2252. return {
  2253. setPosition: setPosition,
  2254. getPosition: function () { return pos; },
  2255. scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
  2256. getToken: function () { return token; },
  2257. getTokenValue: function () { return value; },
  2258. getTokenOffset: function () { return tokenOffset; },
  2259. getTokenLength: function () { return pos - tokenOffset; },
  2260. getTokenError: function () { return scanError; }
  2261. };
  2262. }
  2263. exports.createScanner = createScanner;
  2264. function isWhiteSpace(ch) {
  2265. return ch === 32 /* space */ || ch === 9 /* tab */ || ch === 11 /* verticalTab */ || ch === 12 /* formFeed */ ||
  2266. ch === 160 /* nonBreakingSpace */ || ch === 5760 /* ogham */ || ch >= 8192 /* enQuad */ && ch <= 8203 /* zeroWidthSpace */ ||
  2267. ch === 8239 /* narrowNoBreakSpace */ || ch === 8287 /* mathematicalSpace */ || ch === 12288 /* ideographicSpace */ || ch === 65279 /* byteOrderMark */;
  2268. }
  2269. function isLineBreak(ch) {
  2270. return ch === 10 /* lineFeed */ || ch === 13 /* carriageReturn */ || ch === 8232 /* lineSeparator */ || ch === 8233 /* paragraphSeparator */;
  2271. }
  2272. function isDigit(ch) {
  2273. return ch >= 48 /* _0 */ && ch <= 57 /* _9 */;
  2274. }
  2275. });
  2276. //# sourceMappingURL=scanner.js.map;
  2277. (function (factory) {
  2278. if (typeof module === "object" && typeof module.exports === "object") {
  2279. var v = factory(require, exports);
  2280. if (v !== undefined) module.exports = v;
  2281. }
  2282. else if (typeof define === "function" && define.amd) {
  2283. define('jsonc-parser/impl/format',["require", "exports", "./scanner"], factory);
  2284. }
  2285. })(function (require, exports) {
  2286. /*---------------------------------------------------------------------------------------------
  2287. * Copyright (c) Microsoft Corporation. All rights reserved.
  2288. * Licensed under the MIT License. See License.txt in the project root for license information.
  2289. *--------------------------------------------------------------------------------------------*/
  2290. 'use strict';
  2291. Object.defineProperty(exports, "__esModule", { value: true });
  2292. var scanner_1 = require("./scanner");
  2293. function format(documentText, range, options) {
  2294. var initialIndentLevel;
  2295. var formatText;
  2296. var formatTextStart;
  2297. var rangeStart;
  2298. var rangeEnd;
  2299. if (range) {
  2300. rangeStart = range.offset;
  2301. rangeEnd = rangeStart + range.length;
  2302. formatTextStart = rangeStart;
  2303. while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
  2304. formatTextStart--;
  2305. }
  2306. var endOffset = rangeEnd;
  2307. while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
  2308. endOffset++;
  2309. }
  2310. formatText = documentText.substring(formatTextStart, endOffset);
  2311. initialIndentLevel = computeIndentLevel(formatText, options);
  2312. }
  2313. else {
  2314. formatText = documentText;
  2315. initialIndentLevel = 0;
  2316. formatTextStart = 0;
  2317. rangeStart = 0;
  2318. rangeEnd = documentText.length;
  2319. }
  2320. var eol = getEOL(options, documentText);
  2321. var lineBreak = false;
  2322. var indentLevel = 0;
  2323. var indentValue;
  2324. if (options.insertSpaces) {
  2325. indentValue = repeat(' ', options.tabSize || 4);
  2326. }
  2327. else {
  2328. indentValue = '\t';
  2329. }
  2330. var scanner = scanner_1.createScanner(formatText, false);
  2331. var hasError = false;
  2332. function newLineAndIndent() {
  2333. return eol + repeat(indentValue, initialIndentLevel + indentLevel);
  2334. }
  2335. function scanNext() {
  2336. var token = scanner.scan();
  2337. lineBreak = false;
  2338. while (token === 15 /* Trivia */ || token === 14 /* LineBreakTrivia */) {
  2339. lineBreak = lineBreak || (token === 14 /* LineBreakTrivia */);
  2340. token = scanner.scan();
  2341. }
  2342. hasError = token === 16 /* Unknown */ || scanner.getTokenError() !== 0 /* None */;
  2343. return token;
  2344. }
  2345. var editOperations = [];
  2346. function addEdit(text, startOffset, endOffset) {
  2347. if (!hasError && startOffset < rangeEnd && endOffset > rangeStart && documentText.substring(startOffset, endOffset) !== text) {
  2348. editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
  2349. }
  2350. }
  2351. var firstToken = scanNext();
  2352. if (firstToken !== 17 /* EOF */) {
  2353. var firstTokenStart = scanner.getTokenOffset() + formatTextStart;
  2354. var initialIndent = repeat(indentValue, initialIndentLevel);
  2355. addEdit(initialIndent, formatTextStart, firstTokenStart);
  2356. }
  2357. while (firstToken !== 17 /* EOF */) {
  2358. var firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
  2359. var secondToken = scanNext();
  2360. var replaceContent = '';
  2361. while (!lineBreak && (secondToken === 12 /* LineCommentTrivia */ || secondToken === 13 /* BlockCommentTrivia */)) {
  2362. // comments on the same line: keep them on the same line, but ignore them otherwise
  2363. var commentTokenStart = scanner.getTokenOffset() + formatTextStart;
  2364. addEdit(' ', firstTokenEnd, commentTokenStart);
  2365. firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
  2366. replaceContent = secondToken === 12 /* LineCommentTrivia */ ? newLineAndIndent() : '';
  2367. secondToken = scanNext();
  2368. }
  2369. if (secondToken === 2 /* CloseBraceToken */) {
  2370. if (firstToken !== 1 /* OpenBraceToken */) {
  2371. indentLevel--;
  2372. replaceContent = newLineAndIndent();
  2373. }
  2374. }
  2375. else if (secondToken === 4 /* CloseBracketToken */) {
  2376. if (firstToken !== 3 /* OpenBracketToken */) {
  2377. indentLevel--;
  2378. replaceContent = newLineAndIndent();
  2379. }
  2380. }
  2381. else {
  2382. switch (firstToken) {
  2383. case 3 /* OpenBracketToken */:
  2384. case 1 /* OpenBraceToken */:
  2385. indentLevel++;
  2386. replaceContent = newLineAndIndent();
  2387. break;
  2388. case 5 /* CommaToken */:
  2389. case 12 /* LineCommentTrivia */:
  2390. replaceContent = newLineAndIndent();
  2391. break;
  2392. case 13 /* BlockCommentTrivia */:
  2393. if (lineBreak) {
  2394. replaceContent = newLineAndIndent();
  2395. }
  2396. else {
  2397. // symbol following comment on the same line: keep on same line, separate with ' '
  2398. replaceContent = ' ';
  2399. }
  2400. break;
  2401. case 6 /* ColonToken */:
  2402. replaceContent = ' ';
  2403. break;
  2404. case 10 /* StringLiteral */:
  2405. if (secondToken === 6 /* ColonToken */) {
  2406. replaceContent = '';
  2407. break;
  2408. }
  2409. // fall through
  2410. case 7 /* NullKeyword */:
  2411. case 8 /* TrueKeyword */:
  2412. case 9 /* FalseKeyword */:
  2413. case 11 /* NumericLiteral */:
  2414. case 2 /* CloseBraceToken */:
  2415. case 4 /* CloseBracketToken */:
  2416. if (secondToken === 12 /* LineCommentTrivia */ || secondToken === 13 /* BlockCommentTrivia */) {
  2417. replaceContent = ' ';
  2418. }
  2419. else if (secondToken !== 5 /* CommaToken */ && secondToken !== 17 /* EOF */) {
  2420. hasError = true;
  2421. }
  2422. break;
  2423. case 16 /* Unknown */:
  2424. hasError = true;
  2425. break;
  2426. }
  2427. if (lineBreak && (secondToken === 12 /* LineCommentTrivia */ || secondToken === 13 /* BlockCommentTrivia */)) {
  2428. replaceContent = newLineAndIndent();
  2429. }
  2430. }
  2431. var secondTokenStart = scanner.getTokenOffset() + formatTextStart;
  2432. addEdit(replaceContent, firstTokenEnd, secondTokenStart);
  2433. firstToken = secondToken;
  2434. }
  2435. return editOperations;
  2436. }
  2437. exports.format = format;
  2438. function repeat(s, count) {
  2439. var result = '';
  2440. for (var i = 0; i < count; i++) {
  2441. result += s;
  2442. }
  2443. return result;
  2444. }
  2445. function computeIndentLevel(content, options) {
  2446. var i = 0;
  2447. var nChars = 0;
  2448. var tabSize = options.tabSize || 4;
  2449. while (i < content.length) {
  2450. var ch = content.charAt(i);
  2451. if (ch === ' ') {
  2452. nChars++;
  2453. }
  2454. else if (ch === '\t') {
  2455. nChars += tabSize;
  2456. }
  2457. else {
  2458. break;
  2459. }
  2460. i++;
  2461. }
  2462. return Math.floor(nChars / tabSize);
  2463. }
  2464. function getEOL(options, text) {
  2465. for (var i = 0; i < text.length; i++) {
  2466. var ch = text.charAt(i);
  2467. if (ch === '\r') {
  2468. if (i + 1 < text.length && text.charAt(i + 1) === '\n') {
  2469. return '\r\n';
  2470. }
  2471. return '\r';
  2472. }
  2473. else if (ch === '\n') {
  2474. return '\n';
  2475. }
  2476. }
  2477. return (options && options.eol) || '\n';
  2478. }
  2479. function isEOL(text, offset) {
  2480. return '\r\n'.indexOf(text.charAt(offset)) !== -1;
  2481. }
  2482. exports.isEOL = isEOL;
  2483. });
  2484. //# sourceMappingURL=format.js.map;
  2485. (function (factory) {
  2486. if (typeof module === "object" && typeof module.exports === "object") {
  2487. var v = factory(require, exports);
  2488. if (v !== undefined) module.exports = v;
  2489. }
  2490. else if (typeof define === "function" && define.amd) {
  2491. define('jsonc-parser/impl/parser',["require", "exports", "./scanner"], factory);
  2492. }
  2493. })(function (require, exports) {
  2494. /*---------------------------------------------------------------------------------------------
  2495. * Copyright (c) Microsoft Corporation. All rights reserved.
  2496. * Licensed under the MIT License. See License.txt in the project root for license information.
  2497. *--------------------------------------------------------------------------------------------*/
  2498. 'use strict';
  2499. Object.defineProperty(exports, "__esModule", { value: true });
  2500. var scanner_1 = require("./scanner");
  2501. /**
  2502. * For a given offset, evaluate the location in the JSON document. Each segment in the location path is either a property name or an array index.
  2503. */
  2504. function getLocation(text, position) {
  2505. var segments = []; // strings or numbers
  2506. var earlyReturnException = new Object();
  2507. var previousNode = void 0;
  2508. var previousNodeInst = {
  2509. value: {},
  2510. offset: 0,
  2511. length: 0,
  2512. type: 'object',
  2513. parent: void 0
  2514. };
  2515. var isAtPropertyKey = false;
  2516. function setPreviousNode(value, offset, length, type) {
  2517. previousNodeInst.value = value;
  2518. previousNodeInst.offset = offset;
  2519. previousNodeInst.length = length;
  2520. previousNodeInst.type = type;
  2521. previousNodeInst.colonOffset = void 0;
  2522. previousNode = previousNodeInst;
  2523. }
  2524. try {
  2525. visit(text, {
  2526. onObjectBegin: function (offset, length) {
  2527. if (position <= offset) {
  2528. throw earlyReturnException;
  2529. }
  2530. previousNode = void 0;
  2531. isAtPropertyKey = position > offset;
  2532. segments.push(''); // push a placeholder (will be replaced)
  2533. },
  2534. onObjectProperty: function (name, offset, length) {
  2535. if (position < offset) {
  2536. throw earlyReturnException;
  2537. }
  2538. setPreviousNode(name, offset, length, 'property');
  2539. segments[segments.length - 1] = name;
  2540. if (position <= offset + length) {
  2541. throw earlyReturnException;
  2542. }
  2543. },
  2544. onObjectEnd: function (offset, length) {
  2545. if (position <= offset) {
  2546. throw earlyReturnException;
  2547. }
  2548. previousNode = void 0;
  2549. segments.pop();
  2550. },
  2551. onArrayBegin: function (offset, length) {
  2552. if (position <= offset) {
  2553. throw earlyReturnException;
  2554. }
  2555. previousNode = void 0;
  2556. segments.push(0);
  2557. },
  2558. onArrayEnd: function (offset, length) {
  2559. if (position <= offset) {
  2560. throw earlyReturnException;
  2561. }
  2562. previousNode = void 0;
  2563. segments.pop();
  2564. },
  2565. onLiteralValue: function (value, offset, length) {
  2566. if (position < offset) {
  2567. throw earlyReturnException;
  2568. }
  2569. setPreviousNode(value, offset, length, getLiteralNodeType(value));
  2570. if (position <= offset + length) {
  2571. throw earlyReturnException;
  2572. }
  2573. },
  2574. onSeparator: function (sep, offset, length) {
  2575. if (position <= offset) {
  2576. throw earlyReturnException;
  2577. }
  2578. if (sep === ':' && previousNode && previousNode.type === 'property') {
  2579. previousNode.colonOffset = offset;
  2580. isAtPropertyKey = false;
  2581. previousNode = void 0;
  2582. }
  2583. else if (sep === ',') {
  2584. var last = segments[segments.length - 1];
  2585. if (typeof last === 'number') {
  2586. segments[segments.length - 1] = last + 1;
  2587. }
  2588. else {
  2589. isAtPropertyKey = true;
  2590. segments[segments.length - 1] = '';
  2591. }
  2592. previousNode = void 0;
  2593. }
  2594. }
  2595. });
  2596. }
  2597. catch (e) {
  2598. if (e !== earlyReturnException) {
  2599. throw e;
  2600. }
  2601. }
  2602. return {
  2603. path: segments,
  2604. previousNode: previousNode,
  2605. isAtPropertyKey: isAtPropertyKey,
  2606. matches: function (pattern) {
  2607. var k = 0;
  2608. for (var i = 0; k < pattern.length && i < segments.length; i++) {
  2609. if (pattern[k] === segments[i] || pattern[k] === '*') {
  2610. k++;
  2611. }
  2612. else if (pattern[k] !== '**') {
  2613. return false;
  2614. }
  2615. }
  2616. return k === pattern.length;
  2617. }
  2618. };
  2619. }
  2620. exports.getLocation = getLocation;
  2621. /**
  2622. * Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
  2623. * Therefore always check the errors list to find out if the input was valid.
  2624. */
  2625. function parse(text, errors, options) {
  2626. if (errors === void 0) { errors = []; }
  2627. var currentProperty = null;
  2628. var currentParent = [];
  2629. var previousParents = [];
  2630. function onValue(value) {
  2631. if (Array.isArray(currentParent)) {
  2632. currentParent.push(value);
  2633. }
  2634. else if (currentProperty) {
  2635. currentParent[currentProperty] = value;
  2636. }
  2637. }
  2638. var visitor = {
  2639. onObjectBegin: function () {
  2640. var object = {};
  2641. onValue(object);
  2642. previousParents.push(currentParent);
  2643. currentParent = object;
  2644. currentProperty = null;
  2645. },
  2646. onObjectProperty: function (name) {
  2647. currentProperty = name;
  2648. },
  2649. onObjectEnd: function () {
  2650. currentParent = previousParents.pop();
  2651. },
  2652. onArrayBegin: function () {
  2653. var array = [];
  2654. onValue(array);
  2655. previousParents.push(currentParent);
  2656. currentParent = array;
  2657. currentProperty = null;
  2658. },
  2659. onArrayEnd: function () {
  2660. currentParent = previousParents.pop();
  2661. },
  2662. onLiteralValue: onValue,
  2663. onError: function (error, offset, length) {
  2664. errors.push({ error: error, offset: offset, length: length });
  2665. }
  2666. };
  2667. visit(text, visitor, options);
  2668. return currentParent[0];
  2669. }
  2670. exports.parse = parse;
  2671. /**
  2672. * Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
  2673. */
  2674. function parseTree(text, errors, options) {
  2675. if (errors === void 0) { errors = []; }
  2676. var currentParent = { type: 'array', offset: -1, length: -1, children: [], parent: void 0 }; // artificial root
  2677. function ensurePropertyComplete(endOffset) {
  2678. if (currentParent.type === 'property') {
  2679. currentParent.length = endOffset - currentParent.offset;
  2680. currentParent = currentParent.parent;
  2681. }
  2682. }
  2683. function onValue(valueNode) {
  2684. currentParent.children.push(valueNode);
  2685. return valueNode;
  2686. }
  2687. var visitor = {
  2688. onObjectBegin: function (offset) {
  2689. currentParent = onValue({ type: 'object', offset: offset, length: -1, parent: currentParent, children: [] });
  2690. },
  2691. onObjectProperty: function (name, offset, length) {
  2692. currentParent = onValue({ type: 'property', offset: offset, length: -1, parent: currentParent, children: [] });
  2693. currentParent.children.push({ type: 'string', value: name, offset: offset, length: length, parent: currentParent });
  2694. },
  2695. onObjectEnd: function (offset, length) {
  2696. currentParent.length = offset + length - currentParent.offset;
  2697. currentParent = currentParent.parent;
  2698. ensurePropertyComplete(offset + length);
  2699. },
  2700. onArrayBegin: function (offset, length) {
  2701. currentParent = onValue({ type: 'array', offset: offset, length: -1, parent: currentParent, children: [] });
  2702. },
  2703. onArrayEnd: function (offset, length) {
  2704. currentParent.length = offset + length - currentParent.offset;
  2705. currentParent = currentParent.parent;
  2706. ensurePropertyComplete(offset + length);
  2707. },
  2708. onLiteralValue: function (value, offset, length) {
  2709. onValue({ type: getLiteralNodeType(value), offset: offset, length: length, parent: currentParent, value: value });
  2710. ensurePropertyComplete(offset + length);
  2711. },
  2712. onSeparator: function (sep, offset, length) {
  2713. if (currentParent.type === 'property') {
  2714. if (sep === ':') {
  2715. currentParent.colonOffset = offset;
  2716. }
  2717. else if (sep === ',') {
  2718. ensurePropertyComplete(offset);
  2719. }
  2720. }
  2721. },
  2722. onError: function (error, offset, length) {
  2723. errors.push({ error: error, offset: offset, length: length });
  2724. }
  2725. };
  2726. visit(text, visitor, options);
  2727. var result = currentParent.children[0];
  2728. if (result) {
  2729. delete result.parent;
  2730. }
  2731. return result;
  2732. }
  2733. exports.parseTree = parseTree;
  2734. /**
  2735. * Finds the node at the given path in a JSON DOM.
  2736. */
  2737. function findNodeAtLocation(root, path) {
  2738. if (!root) {
  2739. return void 0;
  2740. }
  2741. var node = root;
  2742. for (var _i = 0, path_1 = path; _i < path_1.length; _i++) {
  2743. var segment = path_1[_i];
  2744. if (typeof segment === 'string') {
  2745. if (node.type !== 'object' || !Array.isArray(node.children)) {
  2746. return void 0;
  2747. }
  2748. var found = false;
  2749. for (var _a = 0, _b = node.children; _a < _b.length; _a++) {
  2750. var propertyNode = _b[_a];
  2751. if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment) {
  2752. node = propertyNode.children[1];
  2753. found = true;
  2754. break;
  2755. }
  2756. }
  2757. if (!found) {
  2758. return void 0;
  2759. }
  2760. }
  2761. else {
  2762. var index = segment;
  2763. if (node.type !== 'array' || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
  2764. return void 0;
  2765. }
  2766. node = node.children[index];
  2767. }
  2768. }
  2769. return node;
  2770. }
  2771. exports.findNodeAtLocation = findNodeAtLocation;
  2772. /**
  2773. * Gets the JSON path of the given JSON DOM node
  2774. */
  2775. function getNodePath(node) {
  2776. if (!node.parent || !node.parent.children) {
  2777. return [];
  2778. }
  2779. var path = getNodePath(node.parent);
  2780. if (node.parent.type === 'property') {
  2781. var key = node.parent.children[0].value;
  2782. path.push(key);
  2783. }
  2784. else if (node.parent.type === 'array') {
  2785. var index = node.parent.children.indexOf(node);
  2786. if (index !== -1) {
  2787. path.push(index);
  2788. }
  2789. }
  2790. return path;
  2791. }
  2792. exports.getNodePath = getNodePath;
  2793. /**
  2794. * Evaluates the JavaScript object of the given JSON DOM node
  2795. */
  2796. function getNodeValue(node) {
  2797. switch (node.type) {
  2798. case 'array':
  2799. return node.children.map(getNodeValue);
  2800. case 'object':
  2801. var obj = Object.create(null);
  2802. for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
  2803. var prop = _a[_i];
  2804. var valueNode = prop.children[1];
  2805. if (valueNode) {
  2806. obj[prop.children[0].value] = getNodeValue(valueNode);
  2807. }
  2808. }
  2809. return obj;
  2810. case 'null':
  2811. case 'string':
  2812. case 'number':
  2813. case 'boolean':
  2814. return node.value;
  2815. default:
  2816. return void 0;
  2817. }
  2818. }
  2819. exports.getNodeValue = getNodeValue;
  2820. function contains(node, offset, includeRightBound) {
  2821. if (includeRightBound === void 0) { includeRightBound = false; }
  2822. return (offset >= node.offset && offset < (node.offset + node.length)) || includeRightBound && (offset === (node.offset + node.length));
  2823. }
  2824. exports.contains = contains;
  2825. /**
  2826. * Finds the most inner node at the given offset. If includeRightBound is set, also finds nodes that end at the given offset.
  2827. */
  2828. function findNodeAtOffset(node, offset, includeRightBound) {
  2829. if (includeRightBound === void 0) { includeRightBound = false; }
  2830. if (contains(node, offset, includeRightBound)) {
  2831. var children = node.children;
  2832. if (Array.isArray(children)) {
  2833. for (var i = 0; i < children.length && children[i].offset <= offset; i++) {
  2834. var item = findNodeAtOffset(children[i], offset, includeRightBound);
  2835. if (item) {
  2836. return item;
  2837. }
  2838. }
  2839. }
  2840. return node;
  2841. }
  2842. return void 0;
  2843. }
  2844. exports.findNodeAtOffset = findNodeAtOffset;
  2845. /**
  2846. * Parses the given text and invokes the visitor functions for each object, array and literal reached.
  2847. */
  2848. function visit(text, visitor, options) {
  2849. var _scanner = scanner_1.createScanner(text, false);
  2850. function toNoArgVisit(visitFunction) {
  2851. return visitFunction ? function () { return visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength()); } : function () { return true; };
  2852. }
  2853. function toOneArgVisit(visitFunction) {
  2854. return visitFunction ? function (arg) { return visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength()); } : function () { return true; };
  2855. }
  2856. var onObjectBegin = toNoArgVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisit(visitor.onObjectProperty), onObjectEnd = toNoArgVisit(visitor.onObjectEnd), onArrayBegin = toNoArgVisit(visitor.onArrayBegin), onArrayEnd = toNoArgVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisit(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
  2857. var disallowComments = options && options.disallowComments;
  2858. var allowTrailingComma = options && options.allowTrailingComma;
  2859. function scanNext() {
  2860. while (true) {
  2861. var token = _scanner.scan();
  2862. switch (_scanner.getTokenError()) {
  2863. case 4 /* InvalidUnicode */:
  2864. handleError(14 /* InvalidUnicode */);
  2865. break;
  2866. case 5 /* InvalidEscapeCharacter */:
  2867. handleError(15 /* InvalidEscapeCharacter */);
  2868. break;
  2869. case 3 /* UnexpectedEndOfNumber */:
  2870. handleError(13 /* UnexpectedEndOfNumber */);
  2871. break;
  2872. case 1 /* UnexpectedEndOfComment */:
  2873. if (!disallowComments) {
  2874. handleError(11 /* UnexpectedEndOfComment */);
  2875. }
  2876. break;
  2877. case 2 /* UnexpectedEndOfString */:
  2878. handleError(12 /* UnexpectedEndOfString */);
  2879. break;
  2880. case 6 /* InvalidCharacter */:
  2881. handleError(16 /* InvalidCharacter */);
  2882. break;
  2883. }
  2884. switch (token) {
  2885. case 12 /* LineCommentTrivia */:
  2886. case 13 /* BlockCommentTrivia */:
  2887. if (disallowComments) {
  2888. handleError(10 /* InvalidCommentToken */);
  2889. }
  2890. else {
  2891. onComment();
  2892. }
  2893. break;
  2894. case 16 /* Unknown */:
  2895. handleError(1 /* InvalidSymbol */);
  2896. break;
  2897. case 15 /* Trivia */:
  2898. case 14 /* LineBreakTrivia */:
  2899. break;
  2900. default:
  2901. return token;
  2902. }
  2903. }
  2904. }
  2905. function handleError(error, skipUntilAfter, skipUntil) {
  2906. if (skipUntilAfter === void 0) { skipUntilAfter = []; }
  2907. if (skipUntil === void 0) { skipUntil = []; }
  2908. onError(error);
  2909. if (skipUntilAfter.length + skipUntil.length > 0) {
  2910. var token = _scanner.getToken();
  2911. while (token !== 17 /* EOF */) {
  2912. if (skipUntilAfter.indexOf(token) !== -1) {
  2913. scanNext();
  2914. break;
  2915. }
  2916. else if (skipUntil.indexOf(token) !== -1) {
  2917. break;
  2918. }
  2919. token = scanNext();
  2920. }
  2921. }
  2922. }
  2923. function parseString(isValue) {
  2924. var value = _scanner.getTokenValue();
  2925. if (isValue) {
  2926. onLiteralValue(value);
  2927. }
  2928. else {
  2929. onObjectProperty(value);
  2930. }
  2931. scanNext();
  2932. return true;
  2933. }
  2934. function parseLiteral() {
  2935. switch (_scanner.getToken()) {
  2936. case 11 /* NumericLiteral */:
  2937. var value = 0;
  2938. try {
  2939. value = JSON.parse(_scanner.getTokenValue());
  2940. if (typeof value !== 'number') {
  2941. handleError(2 /* InvalidNumberFormat */);
  2942. value = 0;
  2943. }
  2944. }
  2945. catch (e) {
  2946. handleError(2 /* InvalidNumberFormat */);
  2947. }
  2948. onLiteralValue(value);
  2949. break;
  2950. case 7 /* NullKeyword */:
  2951. onLiteralValue(null);
  2952. break;
  2953. case 8 /* TrueKeyword */:
  2954. onLiteralValue(true);
  2955. break;
  2956. case 9 /* FalseKeyword */:
  2957. onLiteralValue(false);
  2958. break;
  2959. default:
  2960. return false;
  2961. }
  2962. scanNext();
  2963. return true;
  2964. }
  2965. function parseProperty() {
  2966. if (_scanner.getToken() !== 10 /* StringLiteral */) {
  2967. handleError(3 /* PropertyNameExpected */, [], [2 /* CloseBraceToken */, 5 /* CommaToken */]);
  2968. return false;
  2969. }
  2970. parseString(false);
  2971. if (_scanner.getToken() === 6 /* ColonToken */) {
  2972. onSeparator(':');
  2973. scanNext(); // consume colon
  2974. if (!parseValue()) {
  2975. handleError(4 /* ValueExpected */, [], [2 /* CloseBraceToken */, 5 /* CommaToken */]);
  2976. }
  2977. }
  2978. else {
  2979. handleError(5 /* ColonExpected */, [], [2 /* CloseBraceToken */, 5 /* CommaToken */]);
  2980. }
  2981. return true;
  2982. }
  2983. function parseObject() {
  2984. onObjectBegin();
  2985. scanNext(); // consume open brace
  2986. var needsComma = false;
  2987. while (_scanner.getToken() !== 2 /* CloseBraceToken */ && _scanner.getToken() !== 17 /* EOF */) {
  2988. if (_scanner.getToken() === 5 /* CommaToken */) {
  2989. if (!needsComma) {
  2990. handleError(4 /* ValueExpected */, [], []);
  2991. }
  2992. onSeparator(',');
  2993. scanNext(); // consume comma
  2994. if (_scanner.getToken() === 2 /* CloseBraceToken */ && allowTrailingComma) {
  2995. break;
  2996. }
  2997. }
  2998. else if (needsComma) {
  2999. handleError(6 /* CommaExpected */, [], []);
  3000. }
  3001. if (!parseProperty()) {
  3002. handleError(4 /* ValueExpected */, [], [2 /* CloseBraceToken */, 5 /* CommaToken */]);
  3003. }
  3004. needsComma = true;
  3005. }
  3006. onObjectEnd();
  3007. if (_scanner.getToken() !== 2 /* CloseBraceToken */) {
  3008. handleError(7 /* CloseBraceExpected */, [2 /* CloseBraceToken */], []);
  3009. }
  3010. else {
  3011. scanNext(); // consume close brace
  3012. }
  3013. return true;
  3014. }
  3015. function parseArray() {
  3016. onArrayBegin();
  3017. scanNext(); // consume open bracket
  3018. var needsComma = false;
  3019. while (_scanner.getToken() !== 4 /* CloseBracketToken */ && _scanner.getToken() !== 17 /* EOF */) {
  3020. if (_scanner.getToken() === 5 /* CommaToken */) {
  3021. if (!needsComma) {
  3022. handleError(4 /* ValueExpected */, [], []);
  3023. }
  3024. onSeparator(',');
  3025. scanNext(); // consume comma
  3026. if (_scanner.getToken() === 4 /* CloseBracketToken */ && allowTrailingComma) {
  3027. break;
  3028. }
  3029. }
  3030. else if (needsComma) {
  3031. handleError(6 /* CommaExpected */, [], []);
  3032. }
  3033. if (!parseValue()) {
  3034. handleError(4 /* ValueExpected */, [], [4 /* CloseBracketToken */, 5 /* CommaToken */]);
  3035. }
  3036. needsComma = true;
  3037. }
  3038. onArrayEnd();
  3039. if (_scanner.getToken() !== 4 /* CloseBracketToken */) {
  3040. handleError(8 /* CloseBracketExpected */, [4 /* CloseBracketToken */], []);
  3041. }
  3042. else {
  3043. scanNext(); // consume close bracket
  3044. }
  3045. return true;
  3046. }
  3047. function parseValue() {
  3048. switch (_scanner.getToken()) {
  3049. case 3 /* OpenBracketToken */:
  3050. return parseArray();
  3051. case 1 /* OpenBraceToken */:
  3052. return parseObject();
  3053. case 10 /* StringLiteral */:
  3054. return parseString(true);
  3055. default:
  3056. return parseLiteral();
  3057. }
  3058. }
  3059. scanNext();
  3060. if (_scanner.getToken() === 17 /* EOF */) {
  3061. return true;
  3062. }
  3063. if (!parseValue()) {
  3064. handleError(4 /* ValueExpected */, [], []);
  3065. return false;
  3066. }
  3067. if (_scanner.getToken() !== 17 /* EOF */) {
  3068. handleError(9 /* EndOfFileExpected */, [], []);
  3069. }
  3070. return true;
  3071. }
  3072. exports.visit = visit;
  3073. /**
  3074. * Takes JSON with JavaScript-style comments and remove
  3075. * them. Optionally replaces every none-newline character
  3076. * of comments with a replaceCharacter
  3077. */
  3078. function stripComments(text, replaceCh) {
  3079. var _scanner = scanner_1.createScanner(text), parts = [], kind, offset = 0, pos;
  3080. do {
  3081. pos = _scanner.getPosition();
  3082. kind = _scanner.scan();
  3083. switch (kind) {
  3084. case 12 /* LineCommentTrivia */:
  3085. case 13 /* BlockCommentTrivia */:
  3086. case 17 /* EOF */:
  3087. if (offset !== pos) {
  3088. parts.push(text.substring(offset, pos));
  3089. }
  3090. if (replaceCh !== void 0) {
  3091. parts.push(_scanner.getTokenValue().replace(/[^\r\n]/g, replaceCh));
  3092. }
  3093. offset = _scanner.getPosition();
  3094. break;
  3095. }
  3096. } while (kind !== 17 /* EOF */);
  3097. return parts.join('');
  3098. }
  3099. exports.stripComments = stripComments;
  3100. function getLiteralNodeType(value) {
  3101. switch (typeof value) {
  3102. case 'boolean': return 'boolean';
  3103. case 'number': return 'number';
  3104. case 'string': return 'string';
  3105. default: return 'null';
  3106. }
  3107. }
  3108. });
  3109. //# sourceMappingURL=parser.js.map;
  3110. (function (factory) {
  3111. if (typeof module === "object" && typeof module.exports === "object") {
  3112. var v = factory(require, exports);
  3113. if (v !== undefined) module.exports = v;
  3114. }
  3115. else if (typeof define === "function" && define.amd) {
  3116. define('jsonc-parser/impl/edit',["require", "exports", "./format", "./parser"], factory);
  3117. }
  3118. })(function (require, exports) {
  3119. /*---------------------------------------------------------------------------------------------
  3120. * Copyright (c) Microsoft Corporation. All rights reserved.
  3121. * Licensed under the MIT License. See License.txt in the project root for license information.
  3122. *--------------------------------------------------------------------------------------------*/
  3123. 'use strict';
  3124. Object.defineProperty(exports, "__esModule", { value: true });
  3125. var format_1 = require("./format");
  3126. var parser_1 = require("./parser");
  3127. function removeProperty(text, path, formattingOptions) {
  3128. return setProperty(text, path, void 0, formattingOptions);
  3129. }
  3130. exports.removeProperty = removeProperty;
  3131. function setProperty(text, originalPath, value, formattingOptions, getInsertionIndex) {
  3132. var path = originalPath.slice();
  3133. var errors = [];
  3134. var root = parser_1.parseTree(text, errors);
  3135. var parent = void 0;
  3136. var lastSegment = void 0;
  3137. while (path.length > 0) {
  3138. lastSegment = path.pop();
  3139. parent = parser_1.findNodeAtLocation(root, path);
  3140. if (parent === void 0 && value !== void 0) {
  3141. if (typeof lastSegment === 'string') {
  3142. value = (_a = {}, _a[lastSegment] = value, _a);
  3143. }
  3144. else {
  3145. value = [value];
  3146. }
  3147. }
  3148. else {
  3149. break;
  3150. }
  3151. }
  3152. if (!parent) {
  3153. // empty document
  3154. if (value === void 0) { // delete
  3155. throw new Error('Can not delete in empty document');
  3156. }
  3157. return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, formattingOptions);
  3158. }
  3159. else if (parent.type === 'object' && typeof lastSegment === 'string' && Array.isArray(parent.children)) {
  3160. var existing = parser_1.findNodeAtLocation(parent, [lastSegment]);
  3161. if (existing !== void 0) {
  3162. if (value === void 0) { // delete
  3163. if (!existing.parent) {
  3164. throw new Error('Malformed AST');
  3165. }
  3166. var propertyIndex = parent.children.indexOf(existing.parent);
  3167. var removeBegin = void 0;
  3168. var removeEnd = existing.parent.offset + existing.parent.length;
  3169. if (propertyIndex > 0) {
  3170. // remove the comma of the previous node
  3171. var previous = parent.children[propertyIndex - 1];
  3172. removeBegin = previous.offset + previous.length;
  3173. }
  3174. else {
  3175. removeBegin = parent.offset + 1;
  3176. if (parent.children.length > 1) {
  3177. // remove the comma of the next node
  3178. var next = parent.children[1];
  3179. removeEnd = next.offset;
  3180. }
  3181. }
  3182. return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: '' }, formattingOptions);
  3183. }
  3184. else {
  3185. // set value of existing property
  3186. return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, formattingOptions);
  3187. }
  3188. }
  3189. else {
  3190. if (value === void 0) { // delete
  3191. return []; // property does not exist, nothing to do
  3192. }
  3193. var newProperty = JSON.stringify(lastSegment) + ": " + JSON.stringify(value);
  3194. var index = getInsertionIndex ? getInsertionIndex(parent.children.map(function (p) { return p.children[0].value; })) : parent.children.length;
  3195. var edit = void 0;
  3196. if (index > 0) {
  3197. var previous = parent.children[index - 1];
  3198. edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
  3199. }
  3200. else if (parent.children.length === 0) {
  3201. edit = { offset: parent.offset + 1, length: 0, content: newProperty };
  3202. }
  3203. else {
  3204. edit = { offset: parent.offset + 1, length: 0, content: newProperty + ',' };
  3205. }
  3206. return withFormatting(text, edit, formattingOptions);
  3207. }
  3208. }
  3209. else if (parent.type === 'array' && typeof lastSegment === 'number' && Array.isArray(parent.children)) {
  3210. var insertIndex = lastSegment;
  3211. if (insertIndex === -1) {
  3212. // Insert
  3213. var newProperty = "" + JSON.stringify(value);
  3214. var edit = void 0;
  3215. if (parent.children.length === 0) {
  3216. edit = { offset: parent.offset + 1, length: 0, content: newProperty };
  3217. }
  3218. else {
  3219. var previous = parent.children[parent.children.length - 1];
  3220. edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
  3221. }
  3222. return withFormatting(text, edit, formattingOptions);
  3223. }
  3224. else {
  3225. if (value === void 0 && parent.children.length >= 0) {
  3226. //Removal
  3227. var removalIndex = lastSegment;
  3228. var toRemove = parent.children[removalIndex];
  3229. var edit = void 0;
  3230. if (parent.children.length === 1) {
  3231. // only item
  3232. edit = { offset: parent.offset + 1, length: parent.length - 2, content: '' };
  3233. }
  3234. else if (parent.children.length - 1 === removalIndex) {
  3235. // last item
  3236. var previous = parent.children[removalIndex - 1];
  3237. var offset = previous.offset + previous.length;
  3238. var parentEndOffset = parent.offset + parent.length;
  3239. edit = { offset: offset, length: parentEndOffset - 2 - offset, content: '' };
  3240. }
  3241. else {
  3242. edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: '' };
  3243. }
  3244. return withFormatting(text, edit, formattingOptions);
  3245. }
  3246. else {
  3247. throw new Error('Array modification not supported yet');
  3248. }
  3249. }
  3250. }
  3251. else {
  3252. throw new Error("Can not add " + (typeof lastSegment !== 'number' ? 'index' : 'property') + " to parent of type " + parent.type);
  3253. }
  3254. var _a;
  3255. }
  3256. exports.setProperty = setProperty;
  3257. function withFormatting(text, edit, formattingOptions) {
  3258. // apply the edit
  3259. var newText = applyEdit(text, edit);
  3260. // format the new text
  3261. var begin = edit.offset;
  3262. var end = edit.offset + edit.content.length;
  3263. if (edit.length === 0 || edit.content.length === 0) { // insert or remove
  3264. while (begin > 0 && !format_1.isEOL(newText, begin - 1)) {
  3265. begin--;
  3266. }
  3267. while (end < newText.length && !format_1.isEOL(newText, end)) {
  3268. end++;
  3269. }
  3270. }
  3271. var edits = format_1.format(newText, { offset: begin, length: end - begin }, formattingOptions);
  3272. // apply the formatting edits and track the begin and end offsets of the changes
  3273. for (var i = edits.length - 1; i >= 0; i--) {
  3274. var edit_1 = edits[i];
  3275. newText = applyEdit(newText, edit_1);
  3276. begin = Math.min(begin, edit_1.offset);
  3277. end = Math.max(end, edit_1.offset + edit_1.length);
  3278. end += edit_1.content.length - edit_1.length;
  3279. }
  3280. // create a single edit with all changes
  3281. var editLength = text.length - (newText.length - end) - begin;
  3282. return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
  3283. }
  3284. function applyEdit(text, edit) {
  3285. return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
  3286. }
  3287. exports.applyEdit = applyEdit;
  3288. function isWS(text, offset) {
  3289. return '\r\n \t'.indexOf(text.charAt(offset)) !== -1;
  3290. }
  3291. exports.isWS = isWS;
  3292. });
  3293. //# sourceMappingURL=edit.js.map;
  3294. (function (factory) {
  3295. if (typeof module === "object" && typeof module.exports === "object") {
  3296. var v = factory(require, exports);
  3297. if (v !== undefined) module.exports = v;
  3298. }
  3299. else if (typeof define === "function" && define.amd) {
  3300. define('jsonc-parser/main',["require", "exports", "./impl/format", "./impl/edit", "./impl/scanner", "./impl/parser"], factory);
  3301. }
  3302. })(function (require, exports) {
  3303. /*---------------------------------------------------------------------------------------------
  3304. * Copyright (c) Microsoft Corporation. All rights reserved.
  3305. * Licensed under the MIT License. See License.txt in the project root for license information.
  3306. *--------------------------------------------------------------------------------------------*/
  3307. 'use strict';
  3308. Object.defineProperty(exports, "__esModule", { value: true });
  3309. var formatter = require("./impl/format");
  3310. var edit = require("./impl/edit");
  3311. var scanner = require("./impl/scanner");
  3312. var parser = require("./impl/parser");
  3313. /**
  3314. * Creates a JSON scanner on the given text.
  3315. * If ignoreTrivia is set, whitespaces or comments are ignored.
  3316. */
  3317. exports.createScanner = scanner.createScanner;
  3318. /**
  3319. * For a given offset, evaluate the location in the JSON document. Each segment in the location path is either a property name or an array index.
  3320. */
  3321. exports.getLocation = parser.getLocation;
  3322. /**
  3323. * Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
  3324. * Therefore always check the errors list to find out if the input was valid.
  3325. */
  3326. exports.parse = parser.parse;
  3327. /**
  3328. * Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
  3329. */
  3330. exports.parseTree = parser.parseTree;
  3331. /**
  3332. * Finds the node at the given path in a JSON DOM.
  3333. */
  3334. exports.findNodeAtLocation = parser.findNodeAtLocation;
  3335. /**
  3336. * Finds the most inner node at the given offset. If includeRightBound is set, also finds nodes that end at the given offset.
  3337. */
  3338. exports.findNodeAtOffset = parser.findNodeAtOffset;
  3339. /**
  3340. * Gets the JSON path of the given JSON DOM node
  3341. */
  3342. exports.getNodePath = parser.getNodePath;
  3343. /**
  3344. * Evaluates the JavaScript object of the given JSON DOM node
  3345. */
  3346. exports.getNodeValue = parser.getNodeValue;
  3347. /**
  3348. * Parses the given text and invokes the visitor functions for each object, array and literal reached.
  3349. */
  3350. exports.visit = parser.visit;
  3351. /**
  3352. * Takes JSON with JavaScript-style comments and remove
  3353. * them. Optionally replaces every none-newline character
  3354. * of comments with a replaceCharacter
  3355. */
  3356. exports.stripComments = parser.stripComments;
  3357. /**
  3358. * Computes the edits needed to format a JSON document.
  3359. *
  3360. * @param documentText The input text
  3361. * @param range The range to format or `undefined` to format the full content
  3362. * @param options The formatting options
  3363. * @returns A list of edit operations describing the formatting changes to the original document. Edits can be either inserts, replacements or
  3364. * removals of text segments. All offsets refer to the original state of the document. No two edits must change or remove the same range of
  3365. * text in the original document. However, multiple edits can have
  3366. * the same offset, for example multiple inserts, or an insert followed by a remove or replace. The order in the array defines which edit is applied first.
  3367. * To apply edits to an input, you can use `applyEdits`
  3368. */
  3369. function format(documentText, range, options) {
  3370. return formatter.format(documentText, range, options);
  3371. }
  3372. exports.format = format;
  3373. /**
  3374. * Computes the edits needed to modify a value in the JSON document.
  3375. *
  3376. * @param documentText The input text
  3377. * @param path The path of the value to change. The path represents either to the document root, a property or an array item.
  3378. * If the path points to an non-existing property or item, it will be created.
  3379. * @param value The new value for the specified property or item. If the value is undefined,
  3380. * the property or item will be removed.
  3381. * @param options Options
  3382. * @returns A list of edit operations describing the formatting changes to the original document. Edits can be either inserts, replacements or
  3383. * removals of text segments. All offsets refer to the original state of the document. No two edits must change or remove the same range of
  3384. * text in the original document. However, multiple edits can have
  3385. * the same offset, for example multiple inserts, or an insert followed by a remove or replace. The order in the array defines which edit is applied first.
  3386. * To apply edits to an input, you can use `applyEdits`
  3387. */
  3388. function modify(text, path, value, options) {
  3389. return edit.setProperty(text, path, value, options.formattingOptions, options.getInsertionIndex);
  3390. }
  3391. exports.modify = modify;
  3392. /**
  3393. * Applies edits to a input string.
  3394. */
  3395. function applyEdits(text, edits) {
  3396. for (var i = edits.length - 1; i >= 0; i--) {
  3397. text = edit.applyEdit(text, edits[i]);
  3398. }
  3399. return text;
  3400. }
  3401. exports.applyEdits = applyEdits;
  3402. });
  3403. //# sourceMappingURL=main.js.map;
  3404. define('jsonc-parser', ['jsonc-parser/main'], function (main) { return main; });
  3405. define('vs/language/json/tokenization',["require", "exports", "jsonc-parser"], function (require, exports, json) {
  3406. /*---------------------------------------------------------------------------------------------
  3407. * Copyright (c) Microsoft Corporation. All rights reserved.
  3408. * Licensed under the MIT License. See License.txt in the project root for license information.
  3409. *--------------------------------------------------------------------------------------------*/
  3410. 'use strict';
  3411. Object.defineProperty(exports, "__esModule", { value: true });
  3412. function createTokenizationSupport(supportComments) {
  3413. return {
  3414. getInitialState: function () { return new JSONState(null, null, false); },
  3415. tokenize: function (line, state, offsetDelta, stopAtOffset) { return tokenize(supportComments, line, state, offsetDelta, stopAtOffset); }
  3416. };
  3417. }
  3418. exports.createTokenizationSupport = createTokenizationSupport;
  3419. exports.TOKEN_DELIM_OBJECT = 'delimiter.bracket.json';
  3420. exports.TOKEN_DELIM_ARRAY = 'delimiter.array.json';
  3421. exports.TOKEN_DELIM_COLON = 'delimiter.colon.json';
  3422. exports.TOKEN_DELIM_COMMA = 'delimiter.comma.json';
  3423. exports.TOKEN_VALUE_BOOLEAN = 'keyword.json';
  3424. exports.TOKEN_VALUE_NULL = 'keyword.json';
  3425. exports.TOKEN_VALUE_STRING = 'string.value.json';
  3426. exports.TOKEN_VALUE_NUMBER = 'number.json';
  3427. exports.TOKEN_PROPERTY_NAME = 'string.key.json';
  3428. exports.TOKEN_COMMENT_BLOCK = 'comment.block.json';
  3429. exports.TOKEN_COMMENT_LINE = 'comment.line.json';
  3430. var JSONState = /** @class */ (function () {
  3431. function JSONState(state, scanError, lastWasColon) {
  3432. this._state = state;
  3433. this.scanError = scanError;
  3434. this.lastWasColon = lastWasColon;
  3435. }
  3436. JSONState.prototype.clone = function () {
  3437. return new JSONState(this._state, this.scanError, this.lastWasColon);
  3438. };
  3439. JSONState.prototype.equals = function (other) {
  3440. if (other === this) {
  3441. return true;
  3442. }
  3443. if (!other || !(other instanceof JSONState)) {
  3444. return false;
  3445. }
  3446. return this.scanError === other.scanError &&
  3447. this.lastWasColon === other.lastWasColon;
  3448. };
  3449. JSONState.prototype.getStateData = function () {
  3450. return this._state;
  3451. };
  3452. JSONState.prototype.setStateData = function (state) {
  3453. this._state = state;
  3454. };
  3455. return JSONState;
  3456. }());
  3457. function tokenize(comments, line, state, offsetDelta, stopAtOffset) {
  3458. if (offsetDelta === void 0) { offsetDelta = 0; }
  3459. // handle multiline strings and block comments
  3460. var numberOfInsertedCharacters = 0, adjustOffset = false;
  3461. switch (state.scanError) {
  3462. case 2 /* UnexpectedEndOfString */:
  3463. line = '"' + line;
  3464. numberOfInsertedCharacters = 1;
  3465. break;
  3466. case 1 /* UnexpectedEndOfComment */:
  3467. line = '/*' + line;
  3468. numberOfInsertedCharacters = 2;
  3469. break;
  3470. }
  3471. var scanner = json.createScanner(line), kind, ret, lastWasColon = state.lastWasColon;
  3472. ret = {
  3473. tokens: [],
  3474. endState: state.clone()
  3475. };
  3476. while (true) {
  3477. var offset = offsetDelta + scanner.getPosition(), type = '';
  3478. kind = scanner.scan();
  3479. if (kind === 17 /* EOF */) {
  3480. break;
  3481. }
  3482. // Check that the scanner has advanced
  3483. if (offset === offsetDelta + scanner.getPosition()) {
  3484. throw new Error('Scanner did not advance, next 3 characters are: ' + line.substr(scanner.getPosition(), 3));
  3485. }
  3486. // In case we inserted /* or " character, we need to
  3487. // adjust the offset of all tokens (except the first)
  3488. if (adjustOffset) {
  3489. offset -= numberOfInsertedCharacters;
  3490. }
  3491. adjustOffset = numberOfInsertedCharacters > 0;
  3492. // brackets and type
  3493. switch (kind) {
  3494. case 1 /* OpenBraceToken */:
  3495. type = exports.TOKEN_DELIM_OBJECT;
  3496. lastWasColon = false;
  3497. break;
  3498. case 2 /* CloseBraceToken */:
  3499. type = exports.TOKEN_DELIM_OBJECT;
  3500. lastWasColon = false;
  3501. break;
  3502. case 3 /* OpenBracketToken */:
  3503. type = exports.TOKEN_DELIM_ARRAY;
  3504. lastWasColon = false;
  3505. break;
  3506. case 4 /* CloseBracketToken */:
  3507. type = exports.TOKEN_DELIM_ARRAY;
  3508. lastWasColon = false;
  3509. break;
  3510. case 6 /* ColonToken */:
  3511. type = exports.TOKEN_DELIM_COLON;
  3512. lastWasColon = true;
  3513. break;
  3514. case 5 /* CommaToken */:
  3515. type = exports.TOKEN_DELIM_COMMA;
  3516. lastWasColon = false;
  3517. break;
  3518. case 8 /* TrueKeyword */:
  3519. case 9 /* FalseKeyword */:
  3520. type = exports.TOKEN_VALUE_BOOLEAN;
  3521. lastWasColon = false;
  3522. break;
  3523. case 7 /* NullKeyword */:
  3524. type = exports.TOKEN_VALUE_NULL;
  3525. lastWasColon = false;
  3526. break;
  3527. case 10 /* StringLiteral */:
  3528. type = lastWasColon ? exports.TOKEN_VALUE_STRING : exports.TOKEN_PROPERTY_NAME;
  3529. lastWasColon = false;
  3530. break;
  3531. case 11 /* NumericLiteral */:
  3532. type = exports.TOKEN_VALUE_NUMBER;
  3533. lastWasColon = false;
  3534. break;
  3535. }
  3536. // comments, iff enabled
  3537. if (comments) {
  3538. switch (kind) {
  3539. case 12 /* LineCommentTrivia */:
  3540. type = exports.TOKEN_COMMENT_LINE;
  3541. break;
  3542. case 13 /* BlockCommentTrivia */:
  3543. type = exports.TOKEN_COMMENT_BLOCK;
  3544. break;
  3545. }
  3546. }
  3547. ret.endState = new JSONState(state.getStateData(), scanner.getTokenError(), lastWasColon);
  3548. ret.tokens.push({
  3549. startIndex: offset,
  3550. scopes: type
  3551. });
  3552. }
  3553. return ret;
  3554. }
  3555. });
  3556. define('vs/language/json/jsonMode',["require", "exports", "./workerManager", "./languageFeatures", "./tokenization"], function (require, exports, workerManager_1, languageFeatures, tokenization_1) {
  3557. /*---------------------------------------------------------------------------------------------
  3558. * Copyright (c) Microsoft Corporation. All rights reserved.
  3559. * Licensed under the MIT License. See License.txt in the project root for license information.
  3560. *--------------------------------------------------------------------------------------------*/
  3561. 'use strict';
  3562. Object.defineProperty(exports, "__esModule", { value: true });
  3563. function setupMode(defaults) {
  3564. var disposables = [];
  3565. var client = new workerManager_1.WorkerManager(defaults);
  3566. disposables.push(client);
  3567. var worker = function () {
  3568. var uris = [];
  3569. for (var _i = 0; _i < arguments.length; _i++) {
  3570. uris[_i] = arguments[_i];
  3571. }
  3572. return client.getLanguageServiceWorker.apply(client, uris);
  3573. };
  3574. var languageId = defaults.languageId;
  3575. disposables.push(monaco.languages.registerCompletionItemProvider(languageId, new languageFeatures.CompletionAdapter(worker)));
  3576. disposables.push(monaco.languages.registerHoverProvider(languageId, new languageFeatures.HoverAdapter(worker)));
  3577. disposables.push(monaco.languages.registerDocumentSymbolProvider(languageId, new languageFeatures.DocumentSymbolAdapter(worker)));
  3578. disposables.push(monaco.languages.registerDocumentFormattingEditProvider(languageId, new languageFeatures.DocumentFormattingEditProvider(worker)));
  3579. disposables.push(monaco.languages.registerDocumentRangeFormattingEditProvider(languageId, new languageFeatures.DocumentRangeFormattingEditProvider(worker)));
  3580. disposables.push(new languageFeatures.DiagnosticsAdapter(languageId, worker, defaults));
  3581. disposables.push(monaco.languages.setTokensProvider(languageId, tokenization_1.createTokenizationSupport(true)));
  3582. disposables.push(monaco.languages.setLanguageConfiguration(languageId, richEditConfiguration));
  3583. disposables.push(monaco.languages.registerColorProvider(languageId, new languageFeatures.DocumentColorAdapter(worker)));
  3584. disposables.push(monaco.languages.registerFoldingRangeProvider(languageId, new languageFeatures.FoldingRangeAdapter(worker)));
  3585. }
  3586. exports.setupMode = setupMode;
  3587. var richEditConfiguration = {
  3588. wordPattern: /(-?\d*\.\d\w*)|([^\[\{\]\}\:\"\,\s]+)/g,
  3589. comments: {
  3590. lineComment: '//',
  3591. blockComment: ['/*', '*/']
  3592. },
  3593. brackets: [
  3594. ['{', '}'],
  3595. ['[', ']']
  3596. ],
  3597. autoClosingPairs: [
  3598. { open: '{', close: '}', notIn: ['string'] },
  3599. { open: '[', close: ']', notIn: ['string'] },
  3600. { open: '"', close: '"', notIn: ['string'] }
  3601. ]
  3602. };
  3603. });