1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610 |
- define('vs/language/json/workerManager',["require", "exports"], function (require, exports) {
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- var STOP_WHEN_IDLE_FOR = 2 * 60 * 1000; // 2min
- var WorkerManager = /** @class */ (function () {
- function WorkerManager(defaults) {
- var _this = this;
- this._defaults = defaults;
- this._worker = null;
- this._idleCheckInterval = setInterval(function () { return _this._checkIfIdle(); }, 30 * 1000);
- this._lastUsedTime = 0;
- this._configChangeListener = this._defaults.onDidChange(function () { return _this._stopWorker(); });
- }
- WorkerManager.prototype._stopWorker = function () {
- if (this._worker) {
- this._worker.dispose();
- this._worker = null;
- }
- this._client = null;
- };
- WorkerManager.prototype.dispose = function () {
- clearInterval(this._idleCheckInterval);
- this._configChangeListener.dispose();
- this._stopWorker();
- };
- WorkerManager.prototype._checkIfIdle = function () {
- if (!this._worker) {
- return;
- }
- var timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
- if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
- this._stopWorker();
- }
- };
- WorkerManager.prototype._getClient = function () {
- this._lastUsedTime = Date.now();
- if (!this._client) {
- this._worker = monaco.editor.createWebWorker({
- // module that exports the create() method and returns a `JSONWorker` instance
- moduleId: 'vs/language/json/jsonWorker',
- label: this._defaults.languageId,
- // passed in to the create() method
- createData: {
- languageSettings: this._defaults.diagnosticsOptions,
- languageId: this._defaults.languageId,
- enableSchemaRequest: this._defaults.diagnosticsOptions.enableSchemaRequest
- }
- });
- this._client = this._worker.getProxy();
- }
- return this._client;
- };
- WorkerManager.prototype.getLanguageServiceWorker = function () {
- var _this = this;
- var resources = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- resources[_i] = arguments[_i];
- }
- var _client;
- return this._getClient().then(function (client) {
- _client = client;
- }).then(function (_) {
- return _this._worker.withSyncedResources(resources);
- }).then(function (_) { return _client; });
- };
- return WorkerManager;
- }());
- exports.WorkerManager = WorkerManager;
- });
- (function (factory) {
- if (typeof module === "object" && typeof module.exports === "object") {
- var v = factory(require, exports);
- if (v !== undefined) module.exports = v;
- }
- else if (typeof define === "function" && define.amd) {
- define('vscode-languageserver-types/main',["require", "exports"], factory);
- }
- })(function (require, exports) {
- /* --------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- * ------------------------------------------------------------------------------------------ */
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- /**
- * The Position namespace provides helper functions to work with
- * [Position](#Position) literals.
- */
- var Position;
- (function (Position) {
- /**
- * Creates a new Position literal from the given line and character.
- * @param line The position's line.
- * @param character The position's character.
- */
- function create(line, character) {
- return { line: line, character: character };
- }
- Position.create = create;
- /**
- * Checks whether the given liternal conforms to the [Position](#Position) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.objectLiteral(candidate) && Is.number(candidate.line) && Is.number(candidate.character);
- }
- Position.is = is;
- })(Position = exports.Position || (exports.Position = {}));
- /**
- * The Range namespace provides helper functions to work with
- * [Range](#Range) literals.
- */
- var Range;
- (function (Range) {
- function create(one, two, three, four) {
- if (Is.number(one) && Is.number(two) && Is.number(three) && Is.number(four)) {
- return { start: Position.create(one, two), end: Position.create(three, four) };
- }
- else if (Position.is(one) && Position.is(two)) {
- return { start: one, end: two };
- }
- else {
- throw new Error("Range#create called with invalid arguments[" + one + ", " + two + ", " + three + ", " + four + "]");
- }
- }
- Range.create = create;
- /**
- * Checks whether the given literal conforms to the [Range](#Range) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
- }
- Range.is = is;
- })(Range = exports.Range || (exports.Range = {}));
- /**
- * The Location namespace provides helper functions to work with
- * [Location](#Location) literals.
- */
- var Location;
- (function (Location) {
- /**
- * Creates a Location literal.
- * @param uri The location's uri.
- * @param range The location's range.
- */
- function create(uri, range) {
- return { uri: uri, range: range };
- }
- Location.create = create;
- /**
- * Checks whether the given literal conforms to the [Location](#Location) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
- }
- Location.is = is;
- })(Location = exports.Location || (exports.Location = {}));
- /**
- * The Color namespace provides helper functions to work with
- * [Color](#Color) literals.
- */
- var Color;
- (function (Color) {
- /**
- * Creates a new Color literal.
- */
- function create(red, green, blue, alpha) {
- return {
- red: red,
- green: green,
- blue: blue,
- alpha: alpha,
- };
- }
- Color.create = create;
- /**
- * Checks whether the given literal conforms to the [Color](#Color) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.number(candidate.red)
- && Is.number(candidate.green)
- && Is.number(candidate.blue)
- && Is.number(candidate.alpha);
- }
- Color.is = is;
- })(Color = exports.Color || (exports.Color = {}));
- /**
- * The ColorInformation namespace provides helper functions to work with
- * [ColorInformation](#ColorInformation) literals.
- */
- var ColorInformation;
- (function (ColorInformation) {
- /**
- * Creates a new ColorInformation literal.
- */
- function create(range, color) {
- return {
- range: range,
- color: color,
- };
- }
- ColorInformation.create = create;
- /**
- * Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
- */
- function is(value) {
- var candidate = value;
- return Range.is(candidate.range) && Color.is(candidate.color);
- }
- ColorInformation.is = is;
- })(ColorInformation = exports.ColorInformation || (exports.ColorInformation = {}));
- /**
- * The Color namespace provides helper functions to work with
- * [ColorPresentation](#ColorPresentation) literals.
- */
- var ColorPresentation;
- (function (ColorPresentation) {
- /**
- * Creates a new ColorInformation literal.
- */
- function create(label, textEdit, additionalTextEdits) {
- return {
- label: label,
- textEdit: textEdit,
- additionalTextEdits: additionalTextEdits,
- };
- }
- ColorPresentation.create = create;
- /**
- * Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.string(candidate.label)
- && (Is.undefined(candidate.textEdit) || TextEdit.is(candidate))
- && (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is));
- }
- ColorPresentation.is = is;
- })(ColorPresentation = exports.ColorPresentation || (exports.ColorPresentation = {}));
- /**
- * Enum of known range kinds
- */
- var FoldingRangeKind;
- (function (FoldingRangeKind) {
- /**
- * Folding range for a comment
- */
- FoldingRangeKind["Comment"] = "comment";
- /**
- * Folding range for a imports or includes
- */
- FoldingRangeKind["Imports"] = "imports";
- /**
- * Folding range for a region (e.g. `#region`)
- */
- FoldingRangeKind["Region"] = "region";
- })(FoldingRangeKind = exports.FoldingRangeKind || (exports.FoldingRangeKind = {}));
- /**
- * The folding range namespace provides helper functions to work with
- * [FoldingRange](#FoldingRange) literals.
- */
- var FoldingRange;
- (function (FoldingRange) {
- /**
- * Creates a new FoldingRange literal.
- */
- function create(startLine, endLine, startCharacter, endCharacter, kind) {
- var result = {
- startLine: startLine,
- endLine: endLine
- };
- if (Is.defined(startCharacter)) {
- result.startCharacter = startCharacter;
- }
- if (Is.defined(endCharacter)) {
- result.endCharacter = endCharacter;
- }
- if (Is.defined(kind)) {
- result.kind = kind;
- }
- return result;
- }
- FoldingRange.create = create;
- /**
- * Checks whether the given literal conforms to the [FoldingRange](#FoldingRange) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.number(candidate.startLine) && Is.number(candidate.startLine)
- && (Is.undefined(candidate.startCharacter) || Is.number(candidate.startCharacter))
- && (Is.undefined(candidate.endCharacter) || Is.number(candidate.endCharacter))
- && (Is.undefined(candidate.kind) || Is.string(candidate.kind));
- }
- FoldingRange.is = is;
- })(FoldingRange = exports.FoldingRange || (exports.FoldingRange = {}));
- /**
- * The DiagnosticRelatedInformation namespace provides helper functions to work with
- * [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) literals.
- */
- var DiagnosticRelatedInformation;
- (function (DiagnosticRelatedInformation) {
- /**
- * Creates a new DiagnosticRelatedInformation literal.
- */
- function create(location, message) {
- return {
- location: location,
- message: message
- };
- }
- DiagnosticRelatedInformation.create = create;
- /**
- * Checks whether the given literal conforms to the [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message);
- }
- DiagnosticRelatedInformation.is = is;
- })(DiagnosticRelatedInformation = exports.DiagnosticRelatedInformation || (exports.DiagnosticRelatedInformation = {}));
- /**
- * The diagnostic's severity.
- */
- var DiagnosticSeverity;
- (function (DiagnosticSeverity) {
- /**
- * Reports an error.
- */
- DiagnosticSeverity.Error = 1;
- /**
- * Reports a warning.
- */
- DiagnosticSeverity.Warning = 2;
- /**
- * Reports an information.
- */
- DiagnosticSeverity.Information = 3;
- /**
- * Reports a hint.
- */
- DiagnosticSeverity.Hint = 4;
- })(DiagnosticSeverity = exports.DiagnosticSeverity || (exports.DiagnosticSeverity = {}));
- /**
- * The Diagnostic namespace provides helper functions to work with
- * [Diagnostic](#Diagnostic) literals.
- */
- var Diagnostic;
- (function (Diagnostic) {
- /**
- * Creates a new Diagnostic literal.
- */
- function create(range, message, severity, code, source, relatedInformation) {
- var result = { range: range, message: message };
- if (Is.defined(severity)) {
- result.severity = severity;
- }
- if (Is.defined(code)) {
- result.code = code;
- }
- if (Is.defined(source)) {
- result.source = source;
- }
- if (Is.defined(relatedInformation)) {
- result.relatedInformation = relatedInformation;
- }
- return result;
- }
- Diagnostic.create = create;
- /**
- * Checks whether the given literal conforms to the [Diagnostic](#Diagnostic) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate)
- && Range.is(candidate.range)
- && Is.string(candidate.message)
- && (Is.number(candidate.severity) || Is.undefined(candidate.severity))
- && (Is.number(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code))
- && (Is.string(candidate.source) || Is.undefined(candidate.source))
- && (Is.undefined(candidate.relatedInformation) || Is.typedArray(candidate.relatedInformation, DiagnosticRelatedInformation.is));
- }
- Diagnostic.is = is;
- })(Diagnostic = exports.Diagnostic || (exports.Diagnostic = {}));
- /**
- * The Command namespace provides helper functions to work with
- * [Command](#Command) literals.
- */
- var Command;
- (function (Command) {
- /**
- * Creates a new Command literal.
- */
- function create(title, command) {
- var args = [];
- for (var _i = 2; _i < arguments.length; _i++) {
- args[_i - 2] = arguments[_i];
- }
- var result = { title: title, command: command };
- if (Is.defined(args) && args.length > 0) {
- result.arguments = args;
- }
- return result;
- }
- Command.create = create;
- /**
- * Checks whether the given literal conforms to the [Command](#Command) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command);
- }
- Command.is = is;
- })(Command = exports.Command || (exports.Command = {}));
- /**
- * The TextEdit namespace provides helper function to create replace,
- * insert and delete edits more easily.
- */
- var TextEdit;
- (function (TextEdit) {
- /**
- * Creates a replace text edit.
- * @param range The range of text to be replaced.
- * @param newText The new text.
- */
- function replace(range, newText) {
- return { range: range, newText: newText };
- }
- TextEdit.replace = replace;
- /**
- * Creates a insert text edit.
- * @param position The position to insert the text at.
- * @param newText The text to be inserted.
- */
- function insert(position, newText) {
- return { range: { start: position, end: position }, newText: newText };
- }
- TextEdit.insert = insert;
- /**
- * Creates a delete text edit.
- * @param range The range of text to be deleted.
- */
- function del(range) {
- return { range: range, newText: '' };
- }
- TextEdit.del = del;
- function is(value) {
- var candidate = value;
- return Is.objectLiteral(candidate)
- && Is.string(candidate.newText)
- && Range.is(candidate.range);
- }
- TextEdit.is = is;
- })(TextEdit = exports.TextEdit || (exports.TextEdit = {}));
- /**
- * The TextDocumentEdit namespace provides helper function to create
- * an edit that manipulates a text document.
- */
- var TextDocumentEdit;
- (function (TextDocumentEdit) {
- /**
- * Creates a new `TextDocumentEdit`
- */
- function create(textDocument, edits) {
- return { textDocument: textDocument, edits: edits };
- }
- TextDocumentEdit.create = create;
- function is(value) {
- var candidate = value;
- return Is.defined(candidate)
- && VersionedTextDocumentIdentifier.is(candidate.textDocument)
- && Array.isArray(candidate.edits);
- }
- TextDocumentEdit.is = is;
- })(TextDocumentEdit = exports.TextDocumentEdit || (exports.TextDocumentEdit = {}));
- var WorkspaceEdit;
- (function (WorkspaceEdit) {
- function is(value) {
- var candidate = value;
- return candidate &&
- (candidate.changes !== void 0 || candidate.documentChanges !== void 0) &&
- (candidate.documentChanges === void 0 || Is.typedArray(candidate.documentChanges, TextDocumentEdit.is));
- }
- WorkspaceEdit.is = is;
- })(WorkspaceEdit = exports.WorkspaceEdit || (exports.WorkspaceEdit = {}));
- var TextEditChangeImpl = /** @class */ (function () {
- function TextEditChangeImpl(edits) {
- this.edits = edits;
- }
- TextEditChangeImpl.prototype.insert = function (position, newText) {
- this.edits.push(TextEdit.insert(position, newText));
- };
- TextEditChangeImpl.prototype.replace = function (range, newText) {
- this.edits.push(TextEdit.replace(range, newText));
- };
- TextEditChangeImpl.prototype.delete = function (range) {
- this.edits.push(TextEdit.del(range));
- };
- TextEditChangeImpl.prototype.add = function (edit) {
- this.edits.push(edit);
- };
- TextEditChangeImpl.prototype.all = function () {
- return this.edits;
- };
- TextEditChangeImpl.prototype.clear = function () {
- this.edits.splice(0, this.edits.length);
- };
- return TextEditChangeImpl;
- }());
- /**
- * A workspace change helps constructing changes to a workspace.
- */
- var WorkspaceChange = /** @class */ (function () {
- function WorkspaceChange(workspaceEdit) {
- var _this = this;
- this._textEditChanges = Object.create(null);
- if (workspaceEdit) {
- this._workspaceEdit = workspaceEdit;
- if (workspaceEdit.documentChanges) {
- workspaceEdit.documentChanges.forEach(function (textDocumentEdit) {
- var textEditChange = new TextEditChangeImpl(textDocumentEdit.edits);
- _this._textEditChanges[textDocumentEdit.textDocument.uri] = textEditChange;
- });
- }
- else if (workspaceEdit.changes) {
- Object.keys(workspaceEdit.changes).forEach(function (key) {
- var textEditChange = new TextEditChangeImpl(workspaceEdit.changes[key]);
- _this._textEditChanges[key] = textEditChange;
- });
- }
- }
- }
- Object.defineProperty(WorkspaceChange.prototype, "edit", {
- /**
- * Returns the underlying [WorkspaceEdit](#WorkspaceEdit) literal
- * use to be returned from a workspace edit operation like rename.
- */
- get: function () {
- return this._workspaceEdit;
- },
- enumerable: true,
- configurable: true
- });
- WorkspaceChange.prototype.getTextEditChange = function (key) {
- if (VersionedTextDocumentIdentifier.is(key)) {
- if (!this._workspaceEdit) {
- this._workspaceEdit = {
- documentChanges: []
- };
- }
- if (!this._workspaceEdit.documentChanges) {
- throw new Error('Workspace edit is not configured for versioned document changes.');
- }
- var textDocument = key;
- var result = this._textEditChanges[textDocument.uri];
- if (!result) {
- var edits = [];
- var textDocumentEdit = {
- textDocument: textDocument,
- edits: edits
- };
- this._workspaceEdit.documentChanges.push(textDocumentEdit);
- result = new TextEditChangeImpl(edits);
- this._textEditChanges[textDocument.uri] = result;
- }
- return result;
- }
- else {
- if (!this._workspaceEdit) {
- this._workspaceEdit = {
- changes: Object.create(null)
- };
- }
- if (!this._workspaceEdit.changes) {
- throw new Error('Workspace edit is not configured for normal text edit changes.');
- }
- var result = this._textEditChanges[key];
- if (!result) {
- var edits = [];
- this._workspaceEdit.changes[key] = edits;
- result = new TextEditChangeImpl(edits);
- this._textEditChanges[key] = result;
- }
- return result;
- }
- };
- return WorkspaceChange;
- }());
- exports.WorkspaceChange = WorkspaceChange;
- /**
- * The TextDocumentIdentifier namespace provides helper functions to work with
- * [TextDocumentIdentifier](#TextDocumentIdentifier) literals.
- */
- var TextDocumentIdentifier;
- (function (TextDocumentIdentifier) {
- /**
- * Creates a new TextDocumentIdentifier literal.
- * @param uri The document's uri.
- */
- function create(uri) {
- return { uri: uri };
- }
- TextDocumentIdentifier.create = create;
- /**
- * Checks whether the given literal conforms to the [TextDocumentIdentifier](#TextDocumentIdentifier) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Is.string(candidate.uri);
- }
- TextDocumentIdentifier.is = is;
- })(TextDocumentIdentifier = exports.TextDocumentIdentifier || (exports.TextDocumentIdentifier = {}));
- /**
- * The VersionedTextDocumentIdentifier namespace provides helper functions to work with
- * [VersionedTextDocumentIdentifier](#VersionedTextDocumentIdentifier) literals.
- */
- var VersionedTextDocumentIdentifier;
- (function (VersionedTextDocumentIdentifier) {
- /**
- * Creates a new VersionedTextDocumentIdentifier literal.
- * @param uri The document's uri.
- * @param uri The document's text.
- */
- function create(uri, version) {
- return { uri: uri, version: version };
- }
- VersionedTextDocumentIdentifier.create = create;
- /**
- * Checks whether the given literal conforms to the [VersionedTextDocumentIdentifier](#VersionedTextDocumentIdentifier) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Is.string(candidate.uri) && Is.number(candidate.version);
- }
- VersionedTextDocumentIdentifier.is = is;
- })(VersionedTextDocumentIdentifier = exports.VersionedTextDocumentIdentifier || (exports.VersionedTextDocumentIdentifier = {}));
- /**
- * The TextDocumentItem namespace provides helper functions to work with
- * [TextDocumentItem](#TextDocumentItem) literals.
- */
- var TextDocumentItem;
- (function (TextDocumentItem) {
- /**
- * Creates a new TextDocumentItem literal.
- * @param uri The document's uri.
- * @param languageId The document's language identifier.
- * @param version The document's version number.
- * @param text The document's text.
- */
- function create(uri, languageId, version, text) {
- return { uri: uri, languageId: languageId, version: version, text: text };
- }
- TextDocumentItem.create = create;
- /**
- * Checks whether the given literal conforms to the [TextDocumentItem](#TextDocumentItem) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Is.string(candidate.uri) && Is.string(candidate.languageId) && Is.number(candidate.version) && Is.string(candidate.text);
- }
- TextDocumentItem.is = is;
- })(TextDocumentItem = exports.TextDocumentItem || (exports.TextDocumentItem = {}));
- /**
- * Describes the content type that a client supports in various
- * result literals like `Hover`, `ParameterInfo` or `CompletionItem`.
- *
- * Please note that `MarkupKinds` must not start with a `$`. This kinds
- * are reserved for internal usage.
- */
- var MarkupKind;
- (function (MarkupKind) {
- /**
- * Plain text is supported as a content format
- */
- MarkupKind.PlainText = 'plaintext';
- /**
- * Markdown is supported as a content format
- */
- MarkupKind.Markdown = 'markdown';
- })(MarkupKind = exports.MarkupKind || (exports.MarkupKind = {}));
- (function (MarkupKind) {
- /**
- * Checks whether the given value is a value of the [MarkupKind](#MarkupKind) type.
- */
- function is(value) {
- var candidate = value;
- return candidate === MarkupKind.PlainText || candidate === MarkupKind.Markdown;
- }
- MarkupKind.is = is;
- })(MarkupKind = exports.MarkupKind || (exports.MarkupKind = {}));
- var MarkupContent;
- (function (MarkupContent) {
- /**
- * Checks whether the given value conforms to the [MarkupContent](#MarkupContent) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.objectLiteral(value) && MarkupKind.is(candidate.kind) && Is.string(candidate.value);
- }
- MarkupContent.is = is;
- })(MarkupContent = exports.MarkupContent || (exports.MarkupContent = {}));
- /**
- * The kind of a completion entry.
- */
- var CompletionItemKind;
- (function (CompletionItemKind) {
- CompletionItemKind.Text = 1;
- CompletionItemKind.Method = 2;
- CompletionItemKind.Function = 3;
- CompletionItemKind.Constructor = 4;
- CompletionItemKind.Field = 5;
- CompletionItemKind.Variable = 6;
- CompletionItemKind.Class = 7;
- CompletionItemKind.Interface = 8;
- CompletionItemKind.Module = 9;
- CompletionItemKind.Property = 10;
- CompletionItemKind.Unit = 11;
- CompletionItemKind.Value = 12;
- CompletionItemKind.Enum = 13;
- CompletionItemKind.Keyword = 14;
- CompletionItemKind.Snippet = 15;
- CompletionItemKind.Color = 16;
- CompletionItemKind.File = 17;
- CompletionItemKind.Reference = 18;
- CompletionItemKind.Folder = 19;
- CompletionItemKind.EnumMember = 20;
- CompletionItemKind.Constant = 21;
- CompletionItemKind.Struct = 22;
- CompletionItemKind.Event = 23;
- CompletionItemKind.Operator = 24;
- CompletionItemKind.TypeParameter = 25;
- })(CompletionItemKind = exports.CompletionItemKind || (exports.CompletionItemKind = {}));
- /**
- * Defines whether the insert text in a completion item should be interpreted as
- * plain text or a snippet.
- */
- var InsertTextFormat;
- (function (InsertTextFormat) {
- /**
- * The primary text to be inserted is treated as a plain string.
- */
- InsertTextFormat.PlainText = 1;
- /**
- * The primary text to be inserted is treated as a snippet.
- *
- * A snippet can define tab stops and placeholders with `$1`, `$2`
- * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
- * the end of the snippet. Placeholders with equal identifiers are linked,
- * that is typing in one will update others too.
- *
- * See also: https://github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md
- */
- InsertTextFormat.Snippet = 2;
- })(InsertTextFormat = exports.InsertTextFormat || (exports.InsertTextFormat = {}));
- /**
- * The CompletionItem namespace provides functions to deal with
- * completion items.
- */
- var CompletionItem;
- (function (CompletionItem) {
- /**
- * Create a completion item and seed it with a label.
- * @param label The completion item's label
- */
- function create(label) {
- return { label: label };
- }
- CompletionItem.create = create;
- })(CompletionItem = exports.CompletionItem || (exports.CompletionItem = {}));
- /**
- * The CompletionList namespace provides functions to deal with
- * completion lists.
- */
- var CompletionList;
- (function (CompletionList) {
- /**
- * Creates a new completion list.
- *
- * @param items The completion items.
- * @param isIncomplete The list is not complete.
- */
- function create(items, isIncomplete) {
- return { items: items ? items : [], isIncomplete: !!isIncomplete };
- }
- CompletionList.create = create;
- })(CompletionList = exports.CompletionList || (exports.CompletionList = {}));
- var MarkedString;
- (function (MarkedString) {
- /**
- * Creates a marked string from plain text.
- *
- * @param plainText The plain text.
- */
- function fromPlainText(plainText) {
- return plainText.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&"); // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
- }
- MarkedString.fromPlainText = fromPlainText;
- /**
- * Checks whether the given value conforms to the [MarkedString](#MarkedString) type.
- */
- function is(value) {
- var candidate = value;
- return Is.string(candidate) || (Is.objectLiteral(candidate) && Is.string(candidate.language) && Is.string(candidate.value));
- }
- MarkedString.is = is;
- })(MarkedString = exports.MarkedString || (exports.MarkedString = {}));
- var Hover;
- (function (Hover) {
- /**
- * Checks whether the given value conforms to the [Hover](#Hover) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.objectLiteral(candidate) && (MarkupContent.is(candidate.contents) ||
- MarkedString.is(candidate.contents) ||
- Is.typedArray(candidate.contents, MarkedString.is)) && (value.range === void 0 || Range.is(value.range));
- }
- Hover.is = is;
- })(Hover = exports.Hover || (exports.Hover = {}));
- /**
- * The ParameterInformation namespace provides helper functions to work with
- * [ParameterInformation](#ParameterInformation) literals.
- */
- var ParameterInformation;
- (function (ParameterInformation) {
- /**
- * Creates a new parameter information literal.
- *
- * @param label A label string.
- * @param documentation A doc string.
- */
- function create(label, documentation) {
- return documentation ? { label: label, documentation: documentation } : { label: label };
- }
- ParameterInformation.create = create;
- ;
- })(ParameterInformation = exports.ParameterInformation || (exports.ParameterInformation = {}));
- /**
- * The SignatureInformation namespace provides helper functions to work with
- * [SignatureInformation](#SignatureInformation) literals.
- */
- var SignatureInformation;
- (function (SignatureInformation) {
- function create(label, documentation) {
- var parameters = [];
- for (var _i = 2; _i < arguments.length; _i++) {
- parameters[_i - 2] = arguments[_i];
- }
- var result = { label: label };
- if (Is.defined(documentation)) {
- result.documentation = documentation;
- }
- if (Is.defined(parameters)) {
- result.parameters = parameters;
- }
- else {
- result.parameters = [];
- }
- return result;
- }
- SignatureInformation.create = create;
- })(SignatureInformation = exports.SignatureInformation || (exports.SignatureInformation = {}));
- /**
- * A document highlight kind.
- */
- var DocumentHighlightKind;
- (function (DocumentHighlightKind) {
- /**
- * A textual occurrence.
- */
- DocumentHighlightKind.Text = 1;
- /**
- * Read-access of a symbol, like reading a variable.
- */
- DocumentHighlightKind.Read = 2;
- /**
- * Write-access of a symbol, like writing to a variable.
- */
- DocumentHighlightKind.Write = 3;
- })(DocumentHighlightKind = exports.DocumentHighlightKind || (exports.DocumentHighlightKind = {}));
- /**
- * DocumentHighlight namespace to provide helper functions to work with
- * [DocumentHighlight](#DocumentHighlight) literals.
- */
- var DocumentHighlight;
- (function (DocumentHighlight) {
- /**
- * Create a DocumentHighlight object.
- * @param range The range the highlight applies to.
- */
- function create(range, kind) {
- var result = { range: range };
- if (Is.number(kind)) {
- result.kind = kind;
- }
- return result;
- }
- DocumentHighlight.create = create;
- })(DocumentHighlight = exports.DocumentHighlight || (exports.DocumentHighlight = {}));
- /**
- * A symbol kind.
- */
- var SymbolKind;
- (function (SymbolKind) {
- SymbolKind.File = 1;
- SymbolKind.Module = 2;
- SymbolKind.Namespace = 3;
- SymbolKind.Package = 4;
- SymbolKind.Class = 5;
- SymbolKind.Method = 6;
- SymbolKind.Property = 7;
- SymbolKind.Field = 8;
- SymbolKind.Constructor = 9;
- SymbolKind.Enum = 10;
- SymbolKind.Interface = 11;
- SymbolKind.Function = 12;
- SymbolKind.Variable = 13;
- SymbolKind.Constant = 14;
- SymbolKind.String = 15;
- SymbolKind.Number = 16;
- SymbolKind.Boolean = 17;
- SymbolKind.Array = 18;
- SymbolKind.Object = 19;
- SymbolKind.Key = 20;
- SymbolKind.Null = 21;
- SymbolKind.EnumMember = 22;
- SymbolKind.Struct = 23;
- SymbolKind.Event = 24;
- SymbolKind.Operator = 25;
- SymbolKind.TypeParameter = 26;
- })(SymbolKind = exports.SymbolKind || (exports.SymbolKind = {}));
- var SymbolInformation;
- (function (SymbolInformation) {
- /**
- * Creates a new symbol information literal.
- *
- * @param name The name of the symbol.
- * @param kind The kind of the symbol.
- * @param range The range of the location of the symbol.
- * @param uri The resource of the location of symbol, defaults to the current document.
- * @param containerName The name of the symbol containing the symbol.
- */
- function create(name, kind, range, uri, containerName) {
- var result = {
- name: name,
- kind: kind,
- location: { uri: uri, range: range }
- };
- if (containerName) {
- result.containerName = containerName;
- }
- return result;
- }
- SymbolInformation.create = create;
- })(SymbolInformation = exports.SymbolInformation || (exports.SymbolInformation = {}));
- /**
- * Represents programming constructs like variables, classes, interfaces etc.
- * that appear in a document. Document symbols can be hierarchical and they
- * have two ranges: one that encloses its definition and one that points to
- * its most interesting range, e.g. the range of an identifier.
- */
- var DocumentSymbol = /** @class */ (function () {
- function DocumentSymbol() {
- }
- return DocumentSymbol;
- }());
- exports.DocumentSymbol = DocumentSymbol;
- (function (DocumentSymbol) {
- /**
- * Creates a new symbol information literal.
- *
- * @param name The name of the symbol.
- * @param detail The detail of the symbol.
- * @param kind The kind of the symbol.
- * @param range The range of the symbol.
- * @param selectionRange The selectionRange of the symbol.
- * @param children Children of the symbol.
- */
- function create(name, detail, kind, range, selectionRange, children) {
- var result = {
- name: name,
- detail: detail,
- kind: kind,
- range: range,
- selectionRange: selectionRange
- };
- if (children !== void 0) {
- result.children = children;
- }
- return result;
- }
- DocumentSymbol.create = create;
- /**
- * Checks whether the given literal conforms to the [DocumentSymbol](#DocumentSymbol) interface.
- */
- function is(value) {
- var candidate = value;
- return candidate &&
- Is.string(candidate.name) && Is.number(candidate.kind) &&
- Range.is(candidate.range) && Range.is(candidate.selectionRange) &&
- (candidate.detail === void 0 || Is.string(candidate.detail)) &&
- (candidate.deprecated === void 0 || Is.boolean(candidate.deprecated)) &&
- (candidate.children === void 0 || Array.isArray(candidate.children));
- }
- DocumentSymbol.is = is;
- })(DocumentSymbol = exports.DocumentSymbol || (exports.DocumentSymbol = {}));
- exports.DocumentSymbol = DocumentSymbol;
- /**
- * A set of predefined code action kinds
- */
- var CodeActionKind;
- (function (CodeActionKind) {
- /**
- * Base kind for quickfix actions: 'quickfix'
- */
- CodeActionKind.QuickFix = 'quickfix';
- /**
- * Base kind for refactoring actions: 'refactor'
- */
- CodeActionKind.Refactor = 'refactor';
- /**
- * Base kind for refactoring extraction actions: 'refactor.extract'
- *
- * Example extract actions:
- *
- * - Extract method
- * - Extract function
- * - Extract variable
- * - Extract interface from class
- * - ...
- */
- CodeActionKind.RefactorExtract = 'refactor.extract';
- /**
- * Base kind for refactoring inline actions: 'refactor.inline'
- *
- * Example inline actions:
- *
- * - Inline function
- * - Inline variable
- * - Inline constant
- * - ...
- */
- CodeActionKind.RefactorInline = 'refactor.inline';
- /**
- * Base kind for refactoring rewrite actions: 'refactor.rewrite'
- *
- * Example rewrite actions:
- *
- * - Convert JavaScript function to class
- * - Add or remove parameter
- * - Encapsulate field
- * - Make method static
- * - Move method to base class
- * - ...
- */
- CodeActionKind.RefactorRewrite = 'refactor.rewrite';
- /**
- * Base kind for source actions: `source`
- *
- * Source code actions apply to the entire file.
- */
- CodeActionKind.Source = 'source';
- /**
- * Base kind for an organize imports source action: `source.organizeImports`
- */
- CodeActionKind.SourceOrganizeImports = 'source.organizeImports';
- })(CodeActionKind = exports.CodeActionKind || (exports.CodeActionKind = {}));
- /**
- * The CodeActionContext namespace provides helper functions to work with
- * [CodeActionContext](#CodeActionContext) literals.
- */
- var CodeActionContext;
- (function (CodeActionContext) {
- /**
- * Creates a new CodeActionContext literal.
- */
- function create(diagnostics, only) {
- var result = { diagnostics: diagnostics };
- if (only !== void 0 && only !== null) {
- result.only = only;
- }
- return result;
- }
- CodeActionContext.create = create;
- /**
- * Checks whether the given literal conforms to the [CodeActionContext](#CodeActionContext) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Is.typedArray(candidate.diagnostics, Diagnostic.is) && (candidate.only === void 0 || Is.typedArray(candidate.only, Is.string));
- }
- CodeActionContext.is = is;
- })(CodeActionContext = exports.CodeActionContext || (exports.CodeActionContext = {}));
- var CodeAction;
- (function (CodeAction) {
- function create(title, commandOrEdit, kind) {
- var result = { title: title };
- if (Command.is(commandOrEdit)) {
- result.command = commandOrEdit;
- }
- else {
- result.edit = commandOrEdit;
- }
- if (kind !== void null) {
- result.kind = kind;
- }
- return result;
- }
- CodeAction.create = create;
- function is(value) {
- var candidate = value;
- return candidate && Is.string(candidate.title) &&
- (candidate.diagnostics === void 0 || Is.typedArray(candidate.diagnostics, Diagnostic.is)) &&
- (candidate.kind === void 0 || Is.string(candidate.kind)) &&
- (candidate.edit !== void 0 || candidate.command !== void 0) &&
- (candidate.command === void 0 || Command.is(candidate.command)) &&
- (candidate.edit === void 0 || WorkspaceEdit.is(candidate.edit));
- }
- CodeAction.is = is;
- })(CodeAction = exports.CodeAction || (exports.CodeAction = {}));
- /**
- * The CodeLens namespace provides helper functions to work with
- * [CodeLens](#CodeLens) literals.
- */
- var CodeLens;
- (function (CodeLens) {
- /**
- * Creates a new CodeLens literal.
- */
- function create(range, data) {
- var result = { range: range };
- if (Is.defined(data))
- result.data = data;
- return result;
- }
- CodeLens.create = create;
- /**
- * Checks whether the given literal conforms to the [CodeLens](#CodeLens) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command));
- }
- CodeLens.is = is;
- })(CodeLens = exports.CodeLens || (exports.CodeLens = {}));
- /**
- * The FormattingOptions namespace provides helper functions to work with
- * [FormattingOptions](#FormattingOptions) literals.
- */
- var FormattingOptions;
- (function (FormattingOptions) {
- /**
- * Creates a new FormattingOptions literal.
- */
- function create(tabSize, insertSpaces) {
- return { tabSize: tabSize, insertSpaces: insertSpaces };
- }
- FormattingOptions.create = create;
- /**
- * Checks whether the given literal conforms to the [FormattingOptions](#FormattingOptions) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Is.number(candidate.tabSize) && Is.boolean(candidate.insertSpaces);
- }
- FormattingOptions.is = is;
- })(FormattingOptions = exports.FormattingOptions || (exports.FormattingOptions = {}));
- /**
- * A document link is a range in a text document that links to an internal or external resource, like another
- * text document or a web site.
- */
- var DocumentLink = /** @class */ (function () {
- function DocumentLink() {
- }
- return DocumentLink;
- }());
- exports.DocumentLink = DocumentLink;
- /**
- * The DocumentLink namespace provides helper functions to work with
- * [DocumentLink](#DocumentLink) literals.
- */
- (function (DocumentLink) {
- /**
- * Creates a new DocumentLink literal.
- */
- function create(range, target, data) {
- return { range: range, target: target, data: data };
- }
- DocumentLink.create = create;
- /**
- * Checks whether the given literal conforms to the [DocumentLink](#DocumentLink) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.target) || Is.string(candidate.target));
- }
- DocumentLink.is = is;
- })(DocumentLink = exports.DocumentLink || (exports.DocumentLink = {}));
- exports.DocumentLink = DocumentLink;
- exports.EOL = ['\n', '\r\n', '\r'];
- var TextDocument;
- (function (TextDocument) {
- /**
- * Creates a new ITextDocument literal from the given uri and content.
- * @param uri The document's uri.
- * @param languageId The document's language Id.
- * @param content The document's content.
- */
- function create(uri, languageId, version, content) {
- return new FullTextDocument(uri, languageId, version, content);
- }
- TextDocument.create = create;
- /**
- * Checks whether the given literal conforms to the [ITextDocument](#ITextDocument) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Is.string(candidate.uri) && (Is.undefined(candidate.languageId) || Is.string(candidate.languageId)) && Is.number(candidate.lineCount)
- && Is.func(candidate.getText) && Is.func(candidate.positionAt) && Is.func(candidate.offsetAt) ? true : false;
- }
- TextDocument.is = is;
- function applyEdits(document, edits) {
- var text = document.getText();
- var sortedEdits = mergeSort(edits, function (a, b) {
- var diff = a.range.start.line - b.range.start.line;
- if (diff === 0) {
- return a.range.start.character - b.range.start.character;
- }
- return diff;
- });
- var lastModifiedOffset = text.length;
- for (var i = sortedEdits.length - 1; i >= 0; i--) {
- var e = sortedEdits[i];
- var startOffset = document.offsetAt(e.range.start);
- var endOffset = document.offsetAt(e.range.end);
- if (endOffset <= lastModifiedOffset) {
- text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
- }
- else {
- throw new Error('Ovelapping edit');
- }
- lastModifiedOffset = startOffset;
- }
- return text;
- }
- TextDocument.applyEdits = applyEdits;
- function mergeSort(data, compare) {
- if (data.length <= 1) {
- // sorted
- return data;
- }
- var p = (data.length / 2) | 0;
- var left = data.slice(0, p);
- var right = data.slice(p);
- mergeSort(left, compare);
- mergeSort(right, compare);
- var leftIdx = 0;
- var rightIdx = 0;
- var i = 0;
- while (leftIdx < left.length && rightIdx < right.length) {
- var ret = compare(left[leftIdx], right[rightIdx]);
- if (ret <= 0) {
- // smaller_equal -> take left to preserve order
- data[i++] = left[leftIdx++];
- }
- else {
- // greater -> take right
- data[i++] = right[rightIdx++];
- }
- }
- while (leftIdx < left.length) {
- data[i++] = left[leftIdx++];
- }
- while (rightIdx < right.length) {
- data[i++] = right[rightIdx++];
- }
- return data;
- }
- })(TextDocument = exports.TextDocument || (exports.TextDocument = {}));
- /**
- * Represents reasons why a text document is saved.
- */
- var TextDocumentSaveReason;
- (function (TextDocumentSaveReason) {
- /**
- * Manually triggered, e.g. by the user pressing save, by starting debugging,
- * or by an API call.
- */
- TextDocumentSaveReason.Manual = 1;
- /**
- * Automatic after a delay.
- */
- TextDocumentSaveReason.AfterDelay = 2;
- /**
- * When the editor lost focus.
- */
- TextDocumentSaveReason.FocusOut = 3;
- })(TextDocumentSaveReason = exports.TextDocumentSaveReason || (exports.TextDocumentSaveReason = {}));
- var FullTextDocument = /** @class */ (function () {
- function FullTextDocument(uri, languageId, version, content) {
- this._uri = uri;
- this._languageId = languageId;
- this._version = version;
- this._content = content;
- this._lineOffsets = null;
- }
- Object.defineProperty(FullTextDocument.prototype, "uri", {
- get: function () {
- return this._uri;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(FullTextDocument.prototype, "languageId", {
- get: function () {
- return this._languageId;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(FullTextDocument.prototype, "version", {
- get: function () {
- return this._version;
- },
- enumerable: true,
- configurable: true
- });
- FullTextDocument.prototype.getText = function (range) {
- if (range) {
- var start = this.offsetAt(range.start);
- var end = this.offsetAt(range.end);
- return this._content.substring(start, end);
- }
- return this._content;
- };
- FullTextDocument.prototype.update = function (event, version) {
- this._content = event.text;
- this._version = version;
- this._lineOffsets = null;
- };
- FullTextDocument.prototype.getLineOffsets = function () {
- if (this._lineOffsets === null) {
- var lineOffsets = [];
- var text = this._content;
- var isLineStart = true;
- for (var i = 0; i < text.length; i++) {
- if (isLineStart) {
- lineOffsets.push(i);
- isLineStart = false;
- }
- var ch = text.charAt(i);
- isLineStart = (ch === '\r' || ch === '\n');
- if (ch === '\r' && i + 1 < text.length && text.charAt(i + 1) === '\n') {
- i++;
- }
- }
- if (isLineStart && text.length > 0) {
- lineOffsets.push(text.length);
- }
- this._lineOffsets = lineOffsets;
- }
- return this._lineOffsets;
- };
- FullTextDocument.prototype.positionAt = function (offset) {
- offset = Math.max(Math.min(offset, this._content.length), 0);
- var lineOffsets = this.getLineOffsets();
- var low = 0, high = lineOffsets.length;
- if (high === 0) {
- return Position.create(0, offset);
- }
- while (low < high) {
- var mid = Math.floor((low + high) / 2);
- if (lineOffsets[mid] > offset) {
- high = mid;
- }
- else {
- low = mid + 1;
- }
- }
- // low is the least x for which the line offset is larger than the current offset
- // or array.length if no line offset is larger than the current offset
- var line = low - 1;
- return Position.create(line, offset - lineOffsets[line]);
- };
- FullTextDocument.prototype.offsetAt = function (position) {
- var lineOffsets = this.getLineOffsets();
- if (position.line >= lineOffsets.length) {
- return this._content.length;
- }
- else if (position.line < 0) {
- return 0;
- }
- var lineOffset = lineOffsets[position.line];
- var nextLineOffset = (position.line + 1 < lineOffsets.length) ? lineOffsets[position.line + 1] : this._content.length;
- return Math.max(Math.min(lineOffset + position.character, nextLineOffset), lineOffset);
- };
- Object.defineProperty(FullTextDocument.prototype, "lineCount", {
- get: function () {
- return this.getLineOffsets().length;
- },
- enumerable: true,
- configurable: true
- });
- return FullTextDocument;
- }());
- var Is;
- (function (Is) {
- var toString = Object.prototype.toString;
- function defined(value) {
- return typeof value !== 'undefined';
- }
- Is.defined = defined;
- function undefined(value) {
- return typeof value === 'undefined';
- }
- Is.undefined = undefined;
- function boolean(value) {
- return value === true || value === false;
- }
- Is.boolean = boolean;
- function string(value) {
- return toString.call(value) === '[object String]';
- }
- Is.string = string;
- function number(value) {
- return toString.call(value) === '[object Number]';
- }
- Is.number = number;
- function func(value) {
- return toString.call(value) === '[object Function]';
- }
- Is.func = func;
- function objectLiteral(value) {
- // Strictly speaking class instances pass this check as well. Since the LSP
- // doesn't use classes we ignore this for now. If we do we need to add something
- // like this: `Object.getPrototypeOf(Object.getPrototypeOf(x)) === null`
- return value !== null && typeof value === 'object';
- }
- Is.objectLiteral = objectLiteral;
- function typedArray(value, check) {
- return Array.isArray(value) && value.every(check);
- }
- Is.typedArray = typedArray;
- })(Is || (Is = {}));
- });
- define('vscode-languageserver-types', ['vscode-languageserver-types/main'], function (main) { return main; });
- define('vs/language/json/languageFeatures',["require", "exports", "vscode-languageserver-types"], function (require, exports, ls) {
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- var Uri = monaco.Uri;
- var Range = monaco.Range;
- // --- diagnostics --- ---
- var DiagnosticsAdapter = /** @class */ (function () {
- function DiagnosticsAdapter(_languageId, _worker, defaults) {
- var _this = this;
- this._languageId = _languageId;
- this._worker = _worker;
- this._disposables = [];
- this._listener = Object.create(null);
- var onModelAdd = function (model) {
- var modeId = model.getModeId();
- if (modeId !== _this._languageId) {
- return;
- }
- var handle;
- _this._listener[model.uri.toString()] = model.onDidChangeContent(function () {
- clearTimeout(handle);
- handle = setTimeout(function () { return _this._doValidate(model.uri, modeId); }, 500);
- });
- _this._doValidate(model.uri, modeId);
- };
- var onModelRemoved = function (model) {
- monaco.editor.setModelMarkers(model, _this._languageId, []);
- var uriStr = model.uri.toString();
- var listener = _this._listener[uriStr];
- if (listener) {
- listener.dispose();
- delete _this._listener[uriStr];
- }
- };
- this._disposables.push(monaco.editor.onDidCreateModel(onModelAdd));
- this._disposables.push(monaco.editor.onWillDisposeModel(function (model) {
- onModelRemoved(model);
- _this._resetSchema(model.uri);
- }));
- this._disposables.push(monaco.editor.onDidChangeModelLanguage(function (event) {
- onModelRemoved(event.model);
- onModelAdd(event.model);
- _this._resetSchema(event.model.uri);
- }));
- this._disposables.push(defaults.onDidChange(function (_) {
- monaco.editor.getModels().forEach(function (model) {
- if (model.getModeId() === _this._languageId) {
- onModelRemoved(model);
- onModelAdd(model);
- }
- });
- }));
- this._disposables.push({
- dispose: function () {
- monaco.editor.getModels().forEach(onModelRemoved);
- for (var key in _this._listener) {
- _this._listener[key].dispose();
- }
- }
- });
- monaco.editor.getModels().forEach(onModelAdd);
- }
- DiagnosticsAdapter.prototype.dispose = function () {
- this._disposables.forEach(function (d) { return d && d.dispose(); });
- this._disposables = [];
- };
- DiagnosticsAdapter.prototype._resetSchema = function (resource) {
- this._worker().then(function (worker) {
- worker.resetSchema(resource.toString());
- });
- };
- DiagnosticsAdapter.prototype._doValidate = function (resource, languageId) {
- this._worker(resource).then(function (worker) {
- return worker.doValidation(resource.toString()).then(function (diagnostics) {
- var markers = diagnostics.map(function (d) { return toDiagnostics(resource, d); });
- var model = monaco.editor.getModel(resource);
- if (model.getModeId() === languageId) {
- monaco.editor.setModelMarkers(model, languageId, markers);
- }
- });
- }).then(undefined, function (err) {
- console.error(err);
- });
- };
- return DiagnosticsAdapter;
- }());
- exports.DiagnosticsAdapter = DiagnosticsAdapter;
- function toSeverity(lsSeverity) {
- switch (lsSeverity) {
- case ls.DiagnosticSeverity.Error: return monaco.MarkerSeverity.Error;
- case ls.DiagnosticSeverity.Warning: return monaco.MarkerSeverity.Warning;
- case ls.DiagnosticSeverity.Information: return monaco.MarkerSeverity.Info;
- case ls.DiagnosticSeverity.Hint: return monaco.MarkerSeverity.Hint;
- default:
- return monaco.MarkerSeverity.Info;
- }
- }
- function toDiagnostics(resource, diag) {
- var code = typeof diag.code === 'number' ? String(diag.code) : diag.code;
- return {
- severity: toSeverity(diag.severity),
- startLineNumber: diag.range.start.line + 1,
- startColumn: diag.range.start.character + 1,
- endLineNumber: diag.range.end.line + 1,
- endColumn: diag.range.end.character + 1,
- message: diag.message,
- code: code,
- source: diag.source
- };
- }
- // --- completion ------
- function fromPosition(position) {
- if (!position) {
- return void 0;
- }
- return { character: position.column - 1, line: position.lineNumber - 1 };
- }
- function fromRange(range) {
- if (!range) {
- return void 0;
- }
- return { start: { line: range.startLineNumber - 1, character: range.startColumn - 1 }, end: { line: range.endLineNumber - 1, character: range.endColumn - 1 } };
- }
- function toRange(range) {
- if (!range) {
- return void 0;
- }
- return new Range(range.start.line + 1, range.start.character + 1, range.end.line + 1, range.end.character + 1);
- }
- function toCompletionItemKind(kind) {
- var mItemKind = monaco.languages.CompletionItemKind;
- switch (kind) {
- case ls.CompletionItemKind.Text: return mItemKind.Text;
- case ls.CompletionItemKind.Method: return mItemKind.Method;
- case ls.CompletionItemKind.Function: return mItemKind.Function;
- case ls.CompletionItemKind.Constructor: return mItemKind.Constructor;
- case ls.CompletionItemKind.Field: return mItemKind.Field;
- case ls.CompletionItemKind.Variable: return mItemKind.Variable;
- case ls.CompletionItemKind.Class: return mItemKind.Class;
- case ls.CompletionItemKind.Interface: return mItemKind.Interface;
- case ls.CompletionItemKind.Module: return mItemKind.Module;
- case ls.CompletionItemKind.Property: return mItemKind.Property;
- case ls.CompletionItemKind.Unit: return mItemKind.Unit;
- case ls.CompletionItemKind.Value: return mItemKind.Value;
- case ls.CompletionItemKind.Enum: return mItemKind.Enum;
- case ls.CompletionItemKind.Keyword: return mItemKind.Keyword;
- case ls.CompletionItemKind.Snippet: return mItemKind.Snippet;
- case ls.CompletionItemKind.Color: return mItemKind.Color;
- case ls.CompletionItemKind.File: return mItemKind.File;
- case ls.CompletionItemKind.Reference: return mItemKind.Reference;
- }
- return mItemKind.Property;
- }
- function fromCompletionItemKind(kind) {
- var mItemKind = monaco.languages.CompletionItemKind;
- switch (kind) {
- case mItemKind.Text: return ls.CompletionItemKind.Text;
- case mItemKind.Method: return ls.CompletionItemKind.Method;
- case mItemKind.Function: return ls.CompletionItemKind.Function;
- case mItemKind.Constructor: return ls.CompletionItemKind.Constructor;
- case mItemKind.Field: return ls.CompletionItemKind.Field;
- case mItemKind.Variable: return ls.CompletionItemKind.Variable;
- case mItemKind.Class: return ls.CompletionItemKind.Class;
- case mItemKind.Interface: return ls.CompletionItemKind.Interface;
- case mItemKind.Module: return ls.CompletionItemKind.Module;
- case mItemKind.Property: return ls.CompletionItemKind.Property;
- case mItemKind.Unit: return ls.CompletionItemKind.Unit;
- case mItemKind.Value: return ls.CompletionItemKind.Value;
- case mItemKind.Enum: return ls.CompletionItemKind.Enum;
- case mItemKind.Keyword: return ls.CompletionItemKind.Keyword;
- case mItemKind.Snippet: return ls.CompletionItemKind.Snippet;
- case mItemKind.Color: return ls.CompletionItemKind.Color;
- case mItemKind.File: return ls.CompletionItemKind.File;
- case mItemKind.Reference: return ls.CompletionItemKind.Reference;
- }
- return ls.CompletionItemKind.Property;
- }
- function toTextEdit(textEdit) {
- if (!textEdit) {
- return void 0;
- }
- return {
- range: toRange(textEdit.range),
- text: textEdit.newText
- };
- }
- var CompletionAdapter = /** @class */ (function () {
- function CompletionAdapter(_worker) {
- this._worker = _worker;
- }
- Object.defineProperty(CompletionAdapter.prototype, "triggerCharacters", {
- get: function () {
- return [' ', ':'];
- },
- enumerable: true,
- configurable: true
- });
- CompletionAdapter.prototype.provideCompletionItems = function (model, position, context, token) {
- var wordInfo = model.getWordUntilPosition(position);
- var resource = model.uri;
- return this._worker(resource).then(function (worker) {
- return worker.doComplete(resource.toString(), fromPosition(position));
- }).then(function (info) {
- if (!info) {
- return;
- }
- var items = info.items.map(function (entry) {
- var item = {
- label: entry.label,
- insertText: entry.insertText || entry.label,
- sortText: entry.sortText,
- filterText: entry.filterText,
- documentation: entry.documentation,
- detail: entry.detail,
- kind: toCompletionItemKind(entry.kind),
- };
- if (entry.textEdit) {
- item.range = toRange(entry.textEdit.range);
- item.insertText = entry.textEdit.newText;
- }
- if (entry.additionalTextEdits) {
- item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
- }
- if (entry.insertTextFormat === ls.InsertTextFormat.Snippet) {
- item.insertTextRules = monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet;
- }
- return item;
- });
- return {
- isIncomplete: info.isIncomplete,
- suggestions: items
- };
- });
- };
- return CompletionAdapter;
- }());
- exports.CompletionAdapter = CompletionAdapter;
- function isMarkupContent(thing) {
- return thing && typeof thing === 'object' && typeof thing.kind === 'string';
- }
- function toMarkdownString(entry) {
- if (typeof entry === 'string') {
- return {
- value: entry
- };
- }
- if (isMarkupContent(entry)) {
- if (entry.kind === 'plaintext') {
- return {
- value: entry.value.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&')
- };
- }
- return {
- value: entry.value
- };
- }
- return { value: '```' + entry.language + '\n' + entry.value + '\n```\n' };
- }
- function toMarkedStringArray(contents) {
- if (!contents) {
- return void 0;
- }
- if (Array.isArray(contents)) {
- return contents.map(toMarkdownString);
- }
- return [toMarkdownString(contents)];
- }
- // --- hover ------
- var HoverAdapter = /** @class */ (function () {
- function HoverAdapter(_worker) {
- this._worker = _worker;
- }
- HoverAdapter.prototype.provideHover = function (model, position, token) {
- var resource = model.uri;
- return this._worker(resource).then(function (worker) {
- return worker.doHover(resource.toString(), fromPosition(position));
- }).then(function (info) {
- if (!info) {
- return;
- }
- return {
- range: toRange(info.range),
- contents: toMarkedStringArray(info.contents)
- };
- });
- };
- return HoverAdapter;
- }());
- exports.HoverAdapter = HoverAdapter;
- // --- definition ------
- function toLocation(location) {
- return {
- uri: Uri.parse(location.uri),
- range: toRange(location.range)
- };
- }
- // --- document symbols ------
- function toSymbolKind(kind) {
- var mKind = monaco.languages.SymbolKind;
- switch (kind) {
- case ls.SymbolKind.File: return mKind.Array;
- case ls.SymbolKind.Module: return mKind.Module;
- case ls.SymbolKind.Namespace: return mKind.Namespace;
- case ls.SymbolKind.Package: return mKind.Package;
- case ls.SymbolKind.Class: return mKind.Class;
- case ls.SymbolKind.Method: return mKind.Method;
- case ls.SymbolKind.Property: return mKind.Property;
- case ls.SymbolKind.Field: return mKind.Field;
- case ls.SymbolKind.Constructor: return mKind.Constructor;
- case ls.SymbolKind.Enum: return mKind.Enum;
- case ls.SymbolKind.Interface: return mKind.Interface;
- case ls.SymbolKind.Function: return mKind.Function;
- case ls.SymbolKind.Variable: return mKind.Variable;
- case ls.SymbolKind.Constant: return mKind.Constant;
- case ls.SymbolKind.String: return mKind.String;
- case ls.SymbolKind.Number: return mKind.Number;
- case ls.SymbolKind.Boolean: return mKind.Boolean;
- case ls.SymbolKind.Array: return mKind.Array;
- }
- return mKind.Function;
- }
- var DocumentSymbolAdapter = /** @class */ (function () {
- function DocumentSymbolAdapter(_worker) {
- this._worker = _worker;
- }
- DocumentSymbolAdapter.prototype.provideDocumentSymbols = function (model, token) {
- var resource = model.uri;
- return this._worker(resource).then(function (worker) { return worker.findDocumentSymbols(resource.toString()); }).then(function (items) {
- if (!items) {
- return;
- }
- return items.map(function (item) { return ({
- name: item.name,
- detail: '',
- containerName: item.containerName,
- kind: toSymbolKind(item.kind),
- range: toRange(item.location.range),
- selectionRange: toRange(item.location.range)
- }); });
- });
- };
- return DocumentSymbolAdapter;
- }());
- exports.DocumentSymbolAdapter = DocumentSymbolAdapter;
- function fromFormattingOptions(options) {
- return {
- tabSize: options.tabSize,
- insertSpaces: options.insertSpaces
- };
- }
- var DocumentFormattingEditProvider = /** @class */ (function () {
- function DocumentFormattingEditProvider(_worker) {
- this._worker = _worker;
- }
- DocumentFormattingEditProvider.prototype.provideDocumentFormattingEdits = function (model, options, token) {
- var resource = model.uri;
- return this._worker(resource).then(function (worker) {
- return worker.format(resource.toString(), null, fromFormattingOptions(options)).then(function (edits) {
- if (!edits || edits.length === 0) {
- return;
- }
- return edits.map(toTextEdit);
- });
- });
- };
- return DocumentFormattingEditProvider;
- }());
- exports.DocumentFormattingEditProvider = DocumentFormattingEditProvider;
- var DocumentRangeFormattingEditProvider = /** @class */ (function () {
- function DocumentRangeFormattingEditProvider(_worker) {
- this._worker = _worker;
- }
- DocumentRangeFormattingEditProvider.prototype.provideDocumentRangeFormattingEdits = function (model, range, options, token) {
- var resource = model.uri;
- return this._worker(resource).then(function (worker) {
- return worker.format(resource.toString(), fromRange(range), fromFormattingOptions(options)).then(function (edits) {
- if (!edits || edits.length === 0) {
- return;
- }
- return edits.map(toTextEdit);
- });
- });
- };
- return DocumentRangeFormattingEditProvider;
- }());
- exports.DocumentRangeFormattingEditProvider = DocumentRangeFormattingEditProvider;
- var DocumentColorAdapter = /** @class */ (function () {
- function DocumentColorAdapter(_worker) {
- this._worker = _worker;
- }
- DocumentColorAdapter.prototype.provideDocumentColors = function (model, token) {
- var resource = model.uri;
- return this._worker(resource).then(function (worker) { return worker.findDocumentColors(resource.toString()); }).then(function (infos) {
- if (!infos) {
- return;
- }
- return infos.map(function (item) { return ({
- color: item.color,
- range: toRange(item.range)
- }); });
- });
- };
- DocumentColorAdapter.prototype.provideColorPresentations = function (model, info, token) {
- var resource = model.uri;
- return this._worker(resource).then(function (worker) { return worker.getColorPresentations(resource.toString(), info.color, fromRange(info.range)); }).then(function (presentations) {
- if (!presentations) {
- return;
- }
- return presentations.map(function (presentation) {
- var item = {
- label: presentation.label,
- };
- if (presentation.textEdit) {
- item.textEdit = toTextEdit(presentation.textEdit);
- }
- if (presentation.additionalTextEdits) {
- item.additionalTextEdits = presentation.additionalTextEdits.map(toTextEdit);
- }
- return item;
- });
- });
- };
- return DocumentColorAdapter;
- }());
- exports.DocumentColorAdapter = DocumentColorAdapter;
- var FoldingRangeAdapter = /** @class */ (function () {
- function FoldingRangeAdapter(_worker) {
- this._worker = _worker;
- }
- FoldingRangeAdapter.prototype.provideFoldingRanges = function (model, context, token) {
- var resource = model.uri;
- return this._worker(resource).then(function (worker) { return worker.provideFoldingRanges(resource.toString(), context); }).then(function (ranges) {
- if (!ranges) {
- return;
- }
- return ranges.map(function (range) {
- var result = {
- start: range.startLine + 1,
- end: range.endLine + 1
- };
- if (typeof range.kind !== 'undefined') {
- result.kind = toFoldingRangeKind(range.kind);
- }
- return result;
- });
- });
- };
- return FoldingRangeAdapter;
- }());
- exports.FoldingRangeAdapter = FoldingRangeAdapter;
- function toFoldingRangeKind(kind) {
- switch (kind) {
- case ls.FoldingRangeKind.Comment: return monaco.languages.FoldingRangeKind.Comment;
- case ls.FoldingRangeKind.Imports: return monaco.languages.FoldingRangeKind.Imports;
- case ls.FoldingRangeKind.Region: return monaco.languages.FoldingRangeKind.Region;
- }
- return void 0;
- }
- });
- (function (factory) {
- if (typeof module === "object" && typeof module.exports === "object") {
- var v = factory(require, exports);
- if (v !== undefined) module.exports = v;
- }
- else if (typeof define === "function" && define.amd) {
- define('jsonc-parser/impl/scanner',["require", "exports"], factory);
- }
- })(function (require, exports) {
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- /**
- * Creates a JSON scanner on the given text.
- * If ignoreTrivia is set, whitespaces or comments are ignored.
- */
- function createScanner(text, ignoreTrivia) {
- if (ignoreTrivia === void 0) { ignoreTrivia = false; }
- var pos = 0, len = text.length, value = '', tokenOffset = 0, token = 16 /* Unknown */, scanError = 0 /* None */;
- function scanHexDigits(count, exact) {
- var digits = 0;
- var value = 0;
- while (digits < count || !exact) {
- var ch = text.charCodeAt(pos);
- if (ch >= 48 /* _0 */ && ch <= 57 /* _9 */) {
- value = value * 16 + ch - 48 /* _0 */;
- }
- else if (ch >= 65 /* A */ && ch <= 70 /* F */) {
- value = value * 16 + ch - 65 /* A */ + 10;
- }
- else if (ch >= 97 /* a */ && ch <= 102 /* f */) {
- value = value * 16 + ch - 97 /* a */ + 10;
- }
- else {
- break;
- }
- pos++;
- digits++;
- }
- if (digits < count) {
- value = -1;
- }
- return value;
- }
- function setPosition(newPosition) {
- pos = newPosition;
- value = '';
- tokenOffset = 0;
- token = 16 /* Unknown */;
- scanError = 0 /* None */;
- }
- function scanNumber() {
- var start = pos;
- if (text.charCodeAt(pos) === 48 /* _0 */) {
- pos++;
- }
- else {
- pos++;
- while (pos < text.length && isDigit(text.charCodeAt(pos))) {
- pos++;
- }
- }
- if (pos < text.length && text.charCodeAt(pos) === 46 /* dot */) {
- pos++;
- if (pos < text.length && isDigit(text.charCodeAt(pos))) {
- pos++;
- while (pos < text.length && isDigit(text.charCodeAt(pos))) {
- pos++;
- }
- }
- else {
- scanError = 3 /* UnexpectedEndOfNumber */;
- return text.substring(start, pos);
- }
- }
- var end = pos;
- if (pos < text.length && (text.charCodeAt(pos) === 69 /* E */ || text.charCodeAt(pos) === 101 /* e */)) {
- pos++;
- if (pos < text.length && text.charCodeAt(pos) === 43 /* plus */ || text.charCodeAt(pos) === 45 /* minus */) {
- pos++;
- }
- if (pos < text.length && isDigit(text.charCodeAt(pos))) {
- pos++;
- while (pos < text.length && isDigit(text.charCodeAt(pos))) {
- pos++;
- }
- end = pos;
- }
- else {
- scanError = 3 /* UnexpectedEndOfNumber */;
- }
- }
- return text.substring(start, end);
- }
- function scanString() {
- var result = '', start = pos;
- while (true) {
- if (pos >= len) {
- result += text.substring(start, pos);
- scanError = 2 /* UnexpectedEndOfString */;
- break;
- }
- var ch = text.charCodeAt(pos);
- if (ch === 34 /* doubleQuote */) {
- result += text.substring(start, pos);
- pos++;
- break;
- }
- if (ch === 92 /* backslash */) {
- result += text.substring(start, pos);
- pos++;
- if (pos >= len) {
- scanError = 2 /* UnexpectedEndOfString */;
- break;
- }
- ch = text.charCodeAt(pos++);
- switch (ch) {
- case 34 /* doubleQuote */:
- result += '\"';
- break;
- case 92 /* backslash */:
- result += '\\';
- break;
- case 47 /* slash */:
- result += '/';
- break;
- case 98 /* b */:
- result += '\b';
- break;
- case 102 /* f */:
- result += '\f';
- break;
- case 110 /* n */:
- result += '\n';
- break;
- case 114 /* r */:
- result += '\r';
- break;
- case 116 /* t */:
- result += '\t';
- break;
- case 117 /* u */:
- var ch_1 = scanHexDigits(4, true);
- if (ch_1 >= 0) {
- result += String.fromCharCode(ch_1);
- }
- else {
- scanError = 4 /* InvalidUnicode */;
- }
- break;
- default:
- scanError = 5 /* InvalidEscapeCharacter */;
- }
- start = pos;
- continue;
- }
- if (ch >= 0 && ch <= 0x1f) {
- if (isLineBreak(ch)) {
- result += text.substring(start, pos);
- scanError = 2 /* UnexpectedEndOfString */;
- break;
- }
- else {
- scanError = 6 /* InvalidCharacter */;
- // mark as error but continue with string
- }
- }
- pos++;
- }
- return result;
- }
- function scanNext() {
- value = '';
- scanError = 0 /* None */;
- tokenOffset = pos;
- if (pos >= len) {
- // at the end
- tokenOffset = len;
- return token = 17 /* EOF */;
- }
- var code = text.charCodeAt(pos);
- // trivia: whitespace
- if (isWhiteSpace(code)) {
- do {
- pos++;
- value += String.fromCharCode(code);
- code = text.charCodeAt(pos);
- } while (isWhiteSpace(code));
- return token = 15 /* Trivia */;
- }
- // trivia: newlines
- if (isLineBreak(code)) {
- pos++;
- value += String.fromCharCode(code);
- if (code === 13 /* carriageReturn */ && text.charCodeAt(pos) === 10 /* lineFeed */) {
- pos++;
- value += '\n';
- }
- return token = 14 /* LineBreakTrivia */;
- }
- switch (code) {
- // tokens: []{}:,
- case 123 /* openBrace */:
- pos++;
- return token = 1 /* OpenBraceToken */;
- case 125 /* closeBrace */:
- pos++;
- return token = 2 /* CloseBraceToken */;
- case 91 /* openBracket */:
- pos++;
- return token = 3 /* OpenBracketToken */;
- case 93 /* closeBracket */:
- pos++;
- return token = 4 /* CloseBracketToken */;
- case 58 /* colon */:
- pos++;
- return token = 6 /* ColonToken */;
- case 44 /* comma */:
- pos++;
- return token = 5 /* CommaToken */;
- // strings
- case 34 /* doubleQuote */:
- pos++;
- value = scanString();
- return token = 10 /* StringLiteral */;
- // comments
- case 47 /* slash */:
- var start = pos - 1;
- // Single-line comment
- if (text.charCodeAt(pos + 1) === 47 /* slash */) {
- pos += 2;
- while (pos < len) {
- if (isLineBreak(text.charCodeAt(pos))) {
- break;
- }
- pos++;
- }
- value = text.substring(start, pos);
- return token = 12 /* LineCommentTrivia */;
- }
- // Multi-line comment
- if (text.charCodeAt(pos + 1) === 42 /* asterisk */) {
- pos += 2;
- var commentClosed = false;
- while (pos < len) {
- var ch = text.charCodeAt(pos);
- if (ch === 42 /* asterisk */ && (pos + 1 < len) && text.charCodeAt(pos + 1) === 47 /* slash */) {
- pos += 2;
- commentClosed = true;
- break;
- }
- pos++;
- }
- if (!commentClosed) {
- pos++;
- scanError = 1 /* UnexpectedEndOfComment */;
- }
- value = text.substring(start, pos);
- return token = 13 /* BlockCommentTrivia */;
- }
- // just a single slash
- value += String.fromCharCode(code);
- pos++;
- return token = 16 /* Unknown */;
- // numbers
- case 45 /* minus */:
- value += String.fromCharCode(code);
- pos++;
- if (pos === len || !isDigit(text.charCodeAt(pos))) {
- return token = 16 /* Unknown */;
- }
- // found a minus, followed by a number so
- // we fall through to proceed with scanning
- // numbers
- case 48 /* _0 */:
- case 49 /* _1 */:
- case 50 /* _2 */:
- case 51 /* _3 */:
- case 52 /* _4 */:
- case 53 /* _5 */:
- case 54 /* _6 */:
- case 55 /* _7 */:
- case 56 /* _8 */:
- case 57 /* _9 */:
- value += scanNumber();
- return token = 11 /* NumericLiteral */;
- // literals and unknown symbols
- default:
- // is a literal? Read the full word.
- while (pos < len && isUnknownContentCharacter(code)) {
- pos++;
- code = text.charCodeAt(pos);
- }
- if (tokenOffset !== pos) {
- value = text.substring(tokenOffset, pos);
- // keywords: true, false, null
- switch (value) {
- case 'true': return token = 8 /* TrueKeyword */;
- case 'false': return token = 9 /* FalseKeyword */;
- case 'null': return token = 7 /* NullKeyword */;
- }
- return token = 16 /* Unknown */;
- }
- // some
- value += String.fromCharCode(code);
- pos++;
- return token = 16 /* Unknown */;
- }
- }
- function isUnknownContentCharacter(code) {
- if (isWhiteSpace(code) || isLineBreak(code)) {
- return false;
- }
- switch (code) {
- case 125 /* closeBrace */:
- case 93 /* closeBracket */:
- case 123 /* openBrace */:
- case 91 /* openBracket */:
- case 34 /* doubleQuote */:
- case 58 /* colon */:
- case 44 /* comma */:
- case 47 /* slash */:
- return false;
- }
- return true;
- }
- function scanNextNonTrivia() {
- var result;
- do {
- result = scanNext();
- } while (result >= 12 /* LineCommentTrivia */ && result <= 15 /* Trivia */);
- return result;
- }
- return {
- setPosition: setPosition,
- getPosition: function () { return pos; },
- scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
- getToken: function () { return token; },
- getTokenValue: function () { return value; },
- getTokenOffset: function () { return tokenOffset; },
- getTokenLength: function () { return pos - tokenOffset; },
- getTokenError: function () { return scanError; }
- };
- }
- exports.createScanner = createScanner;
- function isWhiteSpace(ch) {
- return ch === 32 /* space */ || ch === 9 /* tab */ || ch === 11 /* verticalTab */ || ch === 12 /* formFeed */ ||
- ch === 160 /* nonBreakingSpace */ || ch === 5760 /* ogham */ || ch >= 8192 /* enQuad */ && ch <= 8203 /* zeroWidthSpace */ ||
- ch === 8239 /* narrowNoBreakSpace */ || ch === 8287 /* mathematicalSpace */ || ch === 12288 /* ideographicSpace */ || ch === 65279 /* byteOrderMark */;
- }
- function isLineBreak(ch) {
- return ch === 10 /* lineFeed */ || ch === 13 /* carriageReturn */ || ch === 8232 /* lineSeparator */ || ch === 8233 /* paragraphSeparator */;
- }
- function isDigit(ch) {
- return ch >= 48 /* _0 */ && ch <= 57 /* _9 */;
- }
- });
- //# sourceMappingURL=scanner.js.map;
- (function (factory) {
- if (typeof module === "object" && typeof module.exports === "object") {
- var v = factory(require, exports);
- if (v !== undefined) module.exports = v;
- }
- else if (typeof define === "function" && define.amd) {
- define('jsonc-parser/impl/format',["require", "exports", "./scanner"], factory);
- }
- })(function (require, exports) {
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- var scanner_1 = require("./scanner");
- function format(documentText, range, options) {
- var initialIndentLevel;
- var formatText;
- var formatTextStart;
- var rangeStart;
- var rangeEnd;
- if (range) {
- rangeStart = range.offset;
- rangeEnd = rangeStart + range.length;
- formatTextStart = rangeStart;
- while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
- formatTextStart--;
- }
- var endOffset = rangeEnd;
- while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
- endOffset++;
- }
- formatText = documentText.substring(formatTextStart, endOffset);
- initialIndentLevel = computeIndentLevel(formatText, options);
- }
- else {
- formatText = documentText;
- initialIndentLevel = 0;
- formatTextStart = 0;
- rangeStart = 0;
- rangeEnd = documentText.length;
- }
- var eol = getEOL(options, documentText);
- var lineBreak = false;
- var indentLevel = 0;
- var indentValue;
- if (options.insertSpaces) {
- indentValue = repeat(' ', options.tabSize || 4);
- }
- else {
- indentValue = '\t';
- }
- var scanner = scanner_1.createScanner(formatText, false);
- var hasError = false;
- function newLineAndIndent() {
- return eol + repeat(indentValue, initialIndentLevel + indentLevel);
- }
- function scanNext() {
- var token = scanner.scan();
- lineBreak = false;
- while (token === 15 /* Trivia */ || token === 14 /* LineBreakTrivia */) {
- lineBreak = lineBreak || (token === 14 /* LineBreakTrivia */);
- token = scanner.scan();
- }
- hasError = token === 16 /* Unknown */ || scanner.getTokenError() !== 0 /* None */;
- return token;
- }
- var editOperations = [];
- function addEdit(text, startOffset, endOffset) {
- if (!hasError && startOffset < rangeEnd && endOffset > rangeStart && documentText.substring(startOffset, endOffset) !== text) {
- editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
- }
- }
- var firstToken = scanNext();
- if (firstToken !== 17 /* EOF */) {
- var firstTokenStart = scanner.getTokenOffset() + formatTextStart;
- var initialIndent = repeat(indentValue, initialIndentLevel);
- addEdit(initialIndent, formatTextStart, firstTokenStart);
- }
- while (firstToken !== 17 /* EOF */) {
- var firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
- var secondToken = scanNext();
- var replaceContent = '';
- while (!lineBreak && (secondToken === 12 /* LineCommentTrivia */ || secondToken === 13 /* BlockCommentTrivia */)) {
- // comments on the same line: keep them on the same line, but ignore them otherwise
- var commentTokenStart = scanner.getTokenOffset() + formatTextStart;
- addEdit(' ', firstTokenEnd, commentTokenStart);
- firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
- replaceContent = secondToken === 12 /* LineCommentTrivia */ ? newLineAndIndent() : '';
- secondToken = scanNext();
- }
- if (secondToken === 2 /* CloseBraceToken */) {
- if (firstToken !== 1 /* OpenBraceToken */) {
- indentLevel--;
- replaceContent = newLineAndIndent();
- }
- }
- else if (secondToken === 4 /* CloseBracketToken */) {
- if (firstToken !== 3 /* OpenBracketToken */) {
- indentLevel--;
- replaceContent = newLineAndIndent();
- }
- }
- else {
- switch (firstToken) {
- case 3 /* OpenBracketToken */:
- case 1 /* OpenBraceToken */:
- indentLevel++;
- replaceContent = newLineAndIndent();
- break;
- case 5 /* CommaToken */:
- case 12 /* LineCommentTrivia */:
- replaceContent = newLineAndIndent();
- break;
- case 13 /* BlockCommentTrivia */:
- if (lineBreak) {
- replaceContent = newLineAndIndent();
- }
- else {
- // symbol following comment on the same line: keep on same line, separate with ' '
- replaceContent = ' ';
- }
- break;
- case 6 /* ColonToken */:
- replaceContent = ' ';
- break;
- case 10 /* StringLiteral */:
- if (secondToken === 6 /* ColonToken */) {
- replaceContent = '';
- break;
- }
- // fall through
- case 7 /* NullKeyword */:
- case 8 /* TrueKeyword */:
- case 9 /* FalseKeyword */:
- case 11 /* NumericLiteral */:
- case 2 /* CloseBraceToken */:
- case 4 /* CloseBracketToken */:
- if (secondToken === 12 /* LineCommentTrivia */ || secondToken === 13 /* BlockCommentTrivia */) {
- replaceContent = ' ';
- }
- else if (secondToken !== 5 /* CommaToken */ && secondToken !== 17 /* EOF */) {
- hasError = true;
- }
- break;
- case 16 /* Unknown */:
- hasError = true;
- break;
- }
- if (lineBreak && (secondToken === 12 /* LineCommentTrivia */ || secondToken === 13 /* BlockCommentTrivia */)) {
- replaceContent = newLineAndIndent();
- }
- }
- var secondTokenStart = scanner.getTokenOffset() + formatTextStart;
- addEdit(replaceContent, firstTokenEnd, secondTokenStart);
- firstToken = secondToken;
- }
- return editOperations;
- }
- exports.format = format;
- function repeat(s, count) {
- var result = '';
- for (var i = 0; i < count; i++) {
- result += s;
- }
- return result;
- }
- function computeIndentLevel(content, options) {
- var i = 0;
- var nChars = 0;
- var tabSize = options.tabSize || 4;
- while (i < content.length) {
- var ch = content.charAt(i);
- if (ch === ' ') {
- nChars++;
- }
- else if (ch === '\t') {
- nChars += tabSize;
- }
- else {
- break;
- }
- i++;
- }
- return Math.floor(nChars / tabSize);
- }
- function getEOL(options, text) {
- for (var i = 0; i < text.length; i++) {
- var ch = text.charAt(i);
- if (ch === '\r') {
- if (i + 1 < text.length && text.charAt(i + 1) === '\n') {
- return '\r\n';
- }
- return '\r';
- }
- else if (ch === '\n') {
- return '\n';
- }
- }
- return (options && options.eol) || '\n';
- }
- function isEOL(text, offset) {
- return '\r\n'.indexOf(text.charAt(offset)) !== -1;
- }
- exports.isEOL = isEOL;
- });
- //# sourceMappingURL=format.js.map;
- (function (factory) {
- if (typeof module === "object" && typeof module.exports === "object") {
- var v = factory(require, exports);
- if (v !== undefined) module.exports = v;
- }
- else if (typeof define === "function" && define.amd) {
- define('jsonc-parser/impl/parser',["require", "exports", "./scanner"], factory);
- }
- })(function (require, exports) {
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- var scanner_1 = require("./scanner");
- /**
- * 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.
- */
- function getLocation(text, position) {
- var segments = []; // strings or numbers
- var earlyReturnException = new Object();
- var previousNode = void 0;
- var previousNodeInst = {
- value: {},
- offset: 0,
- length: 0,
- type: 'object',
- parent: void 0
- };
- var isAtPropertyKey = false;
- function setPreviousNode(value, offset, length, type) {
- previousNodeInst.value = value;
- previousNodeInst.offset = offset;
- previousNodeInst.length = length;
- previousNodeInst.type = type;
- previousNodeInst.colonOffset = void 0;
- previousNode = previousNodeInst;
- }
- try {
- visit(text, {
- onObjectBegin: function (offset, length) {
- if (position <= offset) {
- throw earlyReturnException;
- }
- previousNode = void 0;
- isAtPropertyKey = position > offset;
- segments.push(''); // push a placeholder (will be replaced)
- },
- onObjectProperty: function (name, offset, length) {
- if (position < offset) {
- throw earlyReturnException;
- }
- setPreviousNode(name, offset, length, 'property');
- segments[segments.length - 1] = name;
- if (position <= offset + length) {
- throw earlyReturnException;
- }
- },
- onObjectEnd: function (offset, length) {
- if (position <= offset) {
- throw earlyReturnException;
- }
- previousNode = void 0;
- segments.pop();
- },
- onArrayBegin: function (offset, length) {
- if (position <= offset) {
- throw earlyReturnException;
- }
- previousNode = void 0;
- segments.push(0);
- },
- onArrayEnd: function (offset, length) {
- if (position <= offset) {
- throw earlyReturnException;
- }
- previousNode = void 0;
- segments.pop();
- },
- onLiteralValue: function (value, offset, length) {
- if (position < offset) {
- throw earlyReturnException;
- }
- setPreviousNode(value, offset, length, getLiteralNodeType(value));
- if (position <= offset + length) {
- throw earlyReturnException;
- }
- },
- onSeparator: function (sep, offset, length) {
- if (position <= offset) {
- throw earlyReturnException;
- }
- if (sep === ':' && previousNode && previousNode.type === 'property') {
- previousNode.colonOffset = offset;
- isAtPropertyKey = false;
- previousNode = void 0;
- }
- else if (sep === ',') {
- var last = segments[segments.length - 1];
- if (typeof last === 'number') {
- segments[segments.length - 1] = last + 1;
- }
- else {
- isAtPropertyKey = true;
- segments[segments.length - 1] = '';
- }
- previousNode = void 0;
- }
- }
- });
- }
- catch (e) {
- if (e !== earlyReturnException) {
- throw e;
- }
- }
- return {
- path: segments,
- previousNode: previousNode,
- isAtPropertyKey: isAtPropertyKey,
- matches: function (pattern) {
- var k = 0;
- for (var i = 0; k < pattern.length && i < segments.length; i++) {
- if (pattern[k] === segments[i] || pattern[k] === '*') {
- k++;
- }
- else if (pattern[k] !== '**') {
- return false;
- }
- }
- return k === pattern.length;
- }
- };
- }
- exports.getLocation = getLocation;
- /**
- * 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.
- * Therefore always check the errors list to find out if the input was valid.
- */
- function parse(text, errors, options) {
- if (errors === void 0) { errors = []; }
- var currentProperty = null;
- var currentParent = [];
- var previousParents = [];
- function onValue(value) {
- if (Array.isArray(currentParent)) {
- currentParent.push(value);
- }
- else if (currentProperty) {
- currentParent[currentProperty] = value;
- }
- }
- var visitor = {
- onObjectBegin: function () {
- var object = {};
- onValue(object);
- previousParents.push(currentParent);
- currentParent = object;
- currentProperty = null;
- },
- onObjectProperty: function (name) {
- currentProperty = name;
- },
- onObjectEnd: function () {
- currentParent = previousParents.pop();
- },
- onArrayBegin: function () {
- var array = [];
- onValue(array);
- previousParents.push(currentParent);
- currentParent = array;
- currentProperty = null;
- },
- onArrayEnd: function () {
- currentParent = previousParents.pop();
- },
- onLiteralValue: onValue,
- onError: function (error, offset, length) {
- errors.push({ error: error, offset: offset, length: length });
- }
- };
- visit(text, visitor, options);
- return currentParent[0];
- }
- exports.parse = parse;
- /**
- * 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.
- */
- function parseTree(text, errors, options) {
- if (errors === void 0) { errors = []; }
- var currentParent = { type: 'array', offset: -1, length: -1, children: [], parent: void 0 }; // artificial root
- function ensurePropertyComplete(endOffset) {
- if (currentParent.type === 'property') {
- currentParent.length = endOffset - currentParent.offset;
- currentParent = currentParent.parent;
- }
- }
- function onValue(valueNode) {
- currentParent.children.push(valueNode);
- return valueNode;
- }
- var visitor = {
- onObjectBegin: function (offset) {
- currentParent = onValue({ type: 'object', offset: offset, length: -1, parent: currentParent, children: [] });
- },
- onObjectProperty: function (name, offset, length) {
- currentParent = onValue({ type: 'property', offset: offset, length: -1, parent: currentParent, children: [] });
- currentParent.children.push({ type: 'string', value: name, offset: offset, length: length, parent: currentParent });
- },
- onObjectEnd: function (offset, length) {
- currentParent.length = offset + length - currentParent.offset;
- currentParent = currentParent.parent;
- ensurePropertyComplete(offset + length);
- },
- onArrayBegin: function (offset, length) {
- currentParent = onValue({ type: 'array', offset: offset, length: -1, parent: currentParent, children: [] });
- },
- onArrayEnd: function (offset, length) {
- currentParent.length = offset + length - currentParent.offset;
- currentParent = currentParent.parent;
- ensurePropertyComplete(offset + length);
- },
- onLiteralValue: function (value, offset, length) {
- onValue({ type: getLiteralNodeType(value), offset: offset, length: length, parent: currentParent, value: value });
- ensurePropertyComplete(offset + length);
- },
- onSeparator: function (sep, offset, length) {
- if (currentParent.type === 'property') {
- if (sep === ':') {
- currentParent.colonOffset = offset;
- }
- else if (sep === ',') {
- ensurePropertyComplete(offset);
- }
- }
- },
- onError: function (error, offset, length) {
- errors.push({ error: error, offset: offset, length: length });
- }
- };
- visit(text, visitor, options);
- var result = currentParent.children[0];
- if (result) {
- delete result.parent;
- }
- return result;
- }
- exports.parseTree = parseTree;
- /**
- * Finds the node at the given path in a JSON DOM.
- */
- function findNodeAtLocation(root, path) {
- if (!root) {
- return void 0;
- }
- var node = root;
- for (var _i = 0, path_1 = path; _i < path_1.length; _i++) {
- var segment = path_1[_i];
- if (typeof segment === 'string') {
- if (node.type !== 'object' || !Array.isArray(node.children)) {
- return void 0;
- }
- var found = false;
- for (var _a = 0, _b = node.children; _a < _b.length; _a++) {
- var propertyNode = _b[_a];
- if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment) {
- node = propertyNode.children[1];
- found = true;
- break;
- }
- }
- if (!found) {
- return void 0;
- }
- }
- else {
- var index = segment;
- if (node.type !== 'array' || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
- return void 0;
- }
- node = node.children[index];
- }
- }
- return node;
- }
- exports.findNodeAtLocation = findNodeAtLocation;
- /**
- * Gets the JSON path of the given JSON DOM node
- */
- function getNodePath(node) {
- if (!node.parent || !node.parent.children) {
- return [];
- }
- var path = getNodePath(node.parent);
- if (node.parent.type === 'property') {
- var key = node.parent.children[0].value;
- path.push(key);
- }
- else if (node.parent.type === 'array') {
- var index = node.parent.children.indexOf(node);
- if (index !== -1) {
- path.push(index);
- }
- }
- return path;
- }
- exports.getNodePath = getNodePath;
- /**
- * Evaluates the JavaScript object of the given JSON DOM node
- */
- function getNodeValue(node) {
- switch (node.type) {
- case 'array':
- return node.children.map(getNodeValue);
- case 'object':
- var obj = Object.create(null);
- for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
- var prop = _a[_i];
- var valueNode = prop.children[1];
- if (valueNode) {
- obj[prop.children[0].value] = getNodeValue(valueNode);
- }
- }
- return obj;
- case 'null':
- case 'string':
- case 'number':
- case 'boolean':
- return node.value;
- default:
- return void 0;
- }
- }
- exports.getNodeValue = getNodeValue;
- function contains(node, offset, includeRightBound) {
- if (includeRightBound === void 0) { includeRightBound = false; }
- return (offset >= node.offset && offset < (node.offset + node.length)) || includeRightBound && (offset === (node.offset + node.length));
- }
- exports.contains = contains;
- /**
- * Finds the most inner node at the given offset. If includeRightBound is set, also finds nodes that end at the given offset.
- */
- function findNodeAtOffset(node, offset, includeRightBound) {
- if (includeRightBound === void 0) { includeRightBound = false; }
- if (contains(node, offset, includeRightBound)) {
- var children = node.children;
- if (Array.isArray(children)) {
- for (var i = 0; i < children.length && children[i].offset <= offset; i++) {
- var item = findNodeAtOffset(children[i], offset, includeRightBound);
- if (item) {
- return item;
- }
- }
- }
- return node;
- }
- return void 0;
- }
- exports.findNodeAtOffset = findNodeAtOffset;
- /**
- * Parses the given text and invokes the visitor functions for each object, array and literal reached.
- */
- function visit(text, visitor, options) {
- var _scanner = scanner_1.createScanner(text, false);
- function toNoArgVisit(visitFunction) {
- return visitFunction ? function () { return visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength()); } : function () { return true; };
- }
- function toOneArgVisit(visitFunction) {
- return visitFunction ? function (arg) { return visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength()); } : function () { return true; };
- }
- 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);
- var disallowComments = options && options.disallowComments;
- var allowTrailingComma = options && options.allowTrailingComma;
- function scanNext() {
- while (true) {
- var token = _scanner.scan();
- switch (_scanner.getTokenError()) {
- case 4 /* InvalidUnicode */:
- handleError(14 /* InvalidUnicode */);
- break;
- case 5 /* InvalidEscapeCharacter */:
- handleError(15 /* InvalidEscapeCharacter */);
- break;
- case 3 /* UnexpectedEndOfNumber */:
- handleError(13 /* UnexpectedEndOfNumber */);
- break;
- case 1 /* UnexpectedEndOfComment */:
- if (!disallowComments) {
- handleError(11 /* UnexpectedEndOfComment */);
- }
- break;
- case 2 /* UnexpectedEndOfString */:
- handleError(12 /* UnexpectedEndOfString */);
- break;
- case 6 /* InvalidCharacter */:
- handleError(16 /* InvalidCharacter */);
- break;
- }
- switch (token) {
- case 12 /* LineCommentTrivia */:
- case 13 /* BlockCommentTrivia */:
- if (disallowComments) {
- handleError(10 /* InvalidCommentToken */);
- }
- else {
- onComment();
- }
- break;
- case 16 /* Unknown */:
- handleError(1 /* InvalidSymbol */);
- break;
- case 15 /* Trivia */:
- case 14 /* LineBreakTrivia */:
- break;
- default:
- return token;
- }
- }
- }
- function handleError(error, skipUntilAfter, skipUntil) {
- if (skipUntilAfter === void 0) { skipUntilAfter = []; }
- if (skipUntil === void 0) { skipUntil = []; }
- onError(error);
- if (skipUntilAfter.length + skipUntil.length > 0) {
- var token = _scanner.getToken();
- while (token !== 17 /* EOF */) {
- if (skipUntilAfter.indexOf(token) !== -1) {
- scanNext();
- break;
- }
- else if (skipUntil.indexOf(token) !== -1) {
- break;
- }
- token = scanNext();
- }
- }
- }
- function parseString(isValue) {
- var value = _scanner.getTokenValue();
- if (isValue) {
- onLiteralValue(value);
- }
- else {
- onObjectProperty(value);
- }
- scanNext();
- return true;
- }
- function parseLiteral() {
- switch (_scanner.getToken()) {
- case 11 /* NumericLiteral */:
- var value = 0;
- try {
- value = JSON.parse(_scanner.getTokenValue());
- if (typeof value !== 'number') {
- handleError(2 /* InvalidNumberFormat */);
- value = 0;
- }
- }
- catch (e) {
- handleError(2 /* InvalidNumberFormat */);
- }
- onLiteralValue(value);
- break;
- case 7 /* NullKeyword */:
- onLiteralValue(null);
- break;
- case 8 /* TrueKeyword */:
- onLiteralValue(true);
- break;
- case 9 /* FalseKeyword */:
- onLiteralValue(false);
- break;
- default:
- return false;
- }
- scanNext();
- return true;
- }
- function parseProperty() {
- if (_scanner.getToken() !== 10 /* StringLiteral */) {
- handleError(3 /* PropertyNameExpected */, [], [2 /* CloseBraceToken */, 5 /* CommaToken */]);
- return false;
- }
- parseString(false);
- if (_scanner.getToken() === 6 /* ColonToken */) {
- onSeparator(':');
- scanNext(); // consume colon
- if (!parseValue()) {
- handleError(4 /* ValueExpected */, [], [2 /* CloseBraceToken */, 5 /* CommaToken */]);
- }
- }
- else {
- handleError(5 /* ColonExpected */, [], [2 /* CloseBraceToken */, 5 /* CommaToken */]);
- }
- return true;
- }
- function parseObject() {
- onObjectBegin();
- scanNext(); // consume open brace
- var needsComma = false;
- while (_scanner.getToken() !== 2 /* CloseBraceToken */ && _scanner.getToken() !== 17 /* EOF */) {
- if (_scanner.getToken() === 5 /* CommaToken */) {
- if (!needsComma) {
- handleError(4 /* ValueExpected */, [], []);
- }
- onSeparator(',');
- scanNext(); // consume comma
- if (_scanner.getToken() === 2 /* CloseBraceToken */ && allowTrailingComma) {
- break;
- }
- }
- else if (needsComma) {
- handleError(6 /* CommaExpected */, [], []);
- }
- if (!parseProperty()) {
- handleError(4 /* ValueExpected */, [], [2 /* CloseBraceToken */, 5 /* CommaToken */]);
- }
- needsComma = true;
- }
- onObjectEnd();
- if (_scanner.getToken() !== 2 /* CloseBraceToken */) {
- handleError(7 /* CloseBraceExpected */, [2 /* CloseBraceToken */], []);
- }
- else {
- scanNext(); // consume close brace
- }
- return true;
- }
- function parseArray() {
- onArrayBegin();
- scanNext(); // consume open bracket
- var needsComma = false;
- while (_scanner.getToken() !== 4 /* CloseBracketToken */ && _scanner.getToken() !== 17 /* EOF */) {
- if (_scanner.getToken() === 5 /* CommaToken */) {
- if (!needsComma) {
- handleError(4 /* ValueExpected */, [], []);
- }
- onSeparator(',');
- scanNext(); // consume comma
- if (_scanner.getToken() === 4 /* CloseBracketToken */ && allowTrailingComma) {
- break;
- }
- }
- else if (needsComma) {
- handleError(6 /* CommaExpected */, [], []);
- }
- if (!parseValue()) {
- handleError(4 /* ValueExpected */, [], [4 /* CloseBracketToken */, 5 /* CommaToken */]);
- }
- needsComma = true;
- }
- onArrayEnd();
- if (_scanner.getToken() !== 4 /* CloseBracketToken */) {
- handleError(8 /* CloseBracketExpected */, [4 /* CloseBracketToken */], []);
- }
- else {
- scanNext(); // consume close bracket
- }
- return true;
- }
- function parseValue() {
- switch (_scanner.getToken()) {
- case 3 /* OpenBracketToken */:
- return parseArray();
- case 1 /* OpenBraceToken */:
- return parseObject();
- case 10 /* StringLiteral */:
- return parseString(true);
- default:
- return parseLiteral();
- }
- }
- scanNext();
- if (_scanner.getToken() === 17 /* EOF */) {
- return true;
- }
- if (!parseValue()) {
- handleError(4 /* ValueExpected */, [], []);
- return false;
- }
- if (_scanner.getToken() !== 17 /* EOF */) {
- handleError(9 /* EndOfFileExpected */, [], []);
- }
- return true;
- }
- exports.visit = visit;
- /**
- * Takes JSON with JavaScript-style comments and remove
- * them. Optionally replaces every none-newline character
- * of comments with a replaceCharacter
- */
- function stripComments(text, replaceCh) {
- var _scanner = scanner_1.createScanner(text), parts = [], kind, offset = 0, pos;
- do {
- pos = _scanner.getPosition();
- kind = _scanner.scan();
- switch (kind) {
- case 12 /* LineCommentTrivia */:
- case 13 /* BlockCommentTrivia */:
- case 17 /* EOF */:
- if (offset !== pos) {
- parts.push(text.substring(offset, pos));
- }
- if (replaceCh !== void 0) {
- parts.push(_scanner.getTokenValue().replace(/[^\r\n]/g, replaceCh));
- }
- offset = _scanner.getPosition();
- break;
- }
- } while (kind !== 17 /* EOF */);
- return parts.join('');
- }
- exports.stripComments = stripComments;
- function getLiteralNodeType(value) {
- switch (typeof value) {
- case 'boolean': return 'boolean';
- case 'number': return 'number';
- case 'string': return 'string';
- default: return 'null';
- }
- }
- });
- //# sourceMappingURL=parser.js.map;
- (function (factory) {
- if (typeof module === "object" && typeof module.exports === "object") {
- var v = factory(require, exports);
- if (v !== undefined) module.exports = v;
- }
- else if (typeof define === "function" && define.amd) {
- define('jsonc-parser/impl/edit',["require", "exports", "./format", "./parser"], factory);
- }
- })(function (require, exports) {
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- var format_1 = require("./format");
- var parser_1 = require("./parser");
- function removeProperty(text, path, formattingOptions) {
- return setProperty(text, path, void 0, formattingOptions);
- }
- exports.removeProperty = removeProperty;
- function setProperty(text, originalPath, value, formattingOptions, getInsertionIndex) {
- var path = originalPath.slice();
- var errors = [];
- var root = parser_1.parseTree(text, errors);
- var parent = void 0;
- var lastSegment = void 0;
- while (path.length > 0) {
- lastSegment = path.pop();
- parent = parser_1.findNodeAtLocation(root, path);
- if (parent === void 0 && value !== void 0) {
- if (typeof lastSegment === 'string') {
- value = (_a = {}, _a[lastSegment] = value, _a);
- }
- else {
- value = [value];
- }
- }
- else {
- break;
- }
- }
- if (!parent) {
- // empty document
- if (value === void 0) { // delete
- throw new Error('Can not delete in empty document');
- }
- return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, formattingOptions);
- }
- else if (parent.type === 'object' && typeof lastSegment === 'string' && Array.isArray(parent.children)) {
- var existing = parser_1.findNodeAtLocation(parent, [lastSegment]);
- if (existing !== void 0) {
- if (value === void 0) { // delete
- if (!existing.parent) {
- throw new Error('Malformed AST');
- }
- var propertyIndex = parent.children.indexOf(existing.parent);
- var removeBegin = void 0;
- var removeEnd = existing.parent.offset + existing.parent.length;
- if (propertyIndex > 0) {
- // remove the comma of the previous node
- var previous = parent.children[propertyIndex - 1];
- removeBegin = previous.offset + previous.length;
- }
- else {
- removeBegin = parent.offset + 1;
- if (parent.children.length > 1) {
- // remove the comma of the next node
- var next = parent.children[1];
- removeEnd = next.offset;
- }
- }
- return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: '' }, formattingOptions);
- }
- else {
- // set value of existing property
- return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, formattingOptions);
- }
- }
- else {
- if (value === void 0) { // delete
- return []; // property does not exist, nothing to do
- }
- var newProperty = JSON.stringify(lastSegment) + ": " + JSON.stringify(value);
- var index = getInsertionIndex ? getInsertionIndex(parent.children.map(function (p) { return p.children[0].value; })) : parent.children.length;
- var edit = void 0;
- if (index > 0) {
- var previous = parent.children[index - 1];
- edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
- }
- else if (parent.children.length === 0) {
- edit = { offset: parent.offset + 1, length: 0, content: newProperty };
- }
- else {
- edit = { offset: parent.offset + 1, length: 0, content: newProperty + ',' };
- }
- return withFormatting(text, edit, formattingOptions);
- }
- }
- else if (parent.type === 'array' && typeof lastSegment === 'number' && Array.isArray(parent.children)) {
- var insertIndex = lastSegment;
- if (insertIndex === -1) {
- // Insert
- var newProperty = "" + JSON.stringify(value);
- var edit = void 0;
- if (parent.children.length === 0) {
- edit = { offset: parent.offset + 1, length: 0, content: newProperty };
- }
- else {
- var previous = parent.children[parent.children.length - 1];
- edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
- }
- return withFormatting(text, edit, formattingOptions);
- }
- else {
- if (value === void 0 && parent.children.length >= 0) {
- //Removal
- var removalIndex = lastSegment;
- var toRemove = parent.children[removalIndex];
- var edit = void 0;
- if (parent.children.length === 1) {
- // only item
- edit = { offset: parent.offset + 1, length: parent.length - 2, content: '' };
- }
- else if (parent.children.length - 1 === removalIndex) {
- // last item
- var previous = parent.children[removalIndex - 1];
- var offset = previous.offset + previous.length;
- var parentEndOffset = parent.offset + parent.length;
- edit = { offset: offset, length: parentEndOffset - 2 - offset, content: '' };
- }
- else {
- edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: '' };
- }
- return withFormatting(text, edit, formattingOptions);
- }
- else {
- throw new Error('Array modification not supported yet');
- }
- }
- }
- else {
- throw new Error("Can not add " + (typeof lastSegment !== 'number' ? 'index' : 'property') + " to parent of type " + parent.type);
- }
- var _a;
- }
- exports.setProperty = setProperty;
- function withFormatting(text, edit, formattingOptions) {
- // apply the edit
- var newText = applyEdit(text, edit);
- // format the new text
- var begin = edit.offset;
- var end = edit.offset + edit.content.length;
- if (edit.length === 0 || edit.content.length === 0) { // insert or remove
- while (begin > 0 && !format_1.isEOL(newText, begin - 1)) {
- begin--;
- }
- while (end < newText.length && !format_1.isEOL(newText, end)) {
- end++;
- }
- }
- var edits = format_1.format(newText, { offset: begin, length: end - begin }, formattingOptions);
- // apply the formatting edits and track the begin and end offsets of the changes
- for (var i = edits.length - 1; i >= 0; i--) {
- var edit_1 = edits[i];
- newText = applyEdit(newText, edit_1);
- begin = Math.min(begin, edit_1.offset);
- end = Math.max(end, edit_1.offset + edit_1.length);
- end += edit_1.content.length - edit_1.length;
- }
- // create a single edit with all changes
- var editLength = text.length - (newText.length - end) - begin;
- return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
- }
- function applyEdit(text, edit) {
- return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
- }
- exports.applyEdit = applyEdit;
- function isWS(text, offset) {
- return '\r\n \t'.indexOf(text.charAt(offset)) !== -1;
- }
- exports.isWS = isWS;
- });
- //# sourceMappingURL=edit.js.map;
- (function (factory) {
- if (typeof module === "object" && typeof module.exports === "object") {
- var v = factory(require, exports);
- if (v !== undefined) module.exports = v;
- }
- else if (typeof define === "function" && define.amd) {
- define('jsonc-parser/main',["require", "exports", "./impl/format", "./impl/edit", "./impl/scanner", "./impl/parser"], factory);
- }
- })(function (require, exports) {
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- var formatter = require("./impl/format");
- var edit = require("./impl/edit");
- var scanner = require("./impl/scanner");
- var parser = require("./impl/parser");
- /**
- * Creates a JSON scanner on the given text.
- * If ignoreTrivia is set, whitespaces or comments are ignored.
- */
- exports.createScanner = scanner.createScanner;
- /**
- * 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.
- */
- exports.getLocation = parser.getLocation;
- /**
- * 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.
- * Therefore always check the errors list to find out if the input was valid.
- */
- exports.parse = parser.parse;
- /**
- * 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.
- */
- exports.parseTree = parser.parseTree;
- /**
- * Finds the node at the given path in a JSON DOM.
- */
- exports.findNodeAtLocation = parser.findNodeAtLocation;
- /**
- * Finds the most inner node at the given offset. If includeRightBound is set, also finds nodes that end at the given offset.
- */
- exports.findNodeAtOffset = parser.findNodeAtOffset;
- /**
- * Gets the JSON path of the given JSON DOM node
- */
- exports.getNodePath = parser.getNodePath;
- /**
- * Evaluates the JavaScript object of the given JSON DOM node
- */
- exports.getNodeValue = parser.getNodeValue;
- /**
- * Parses the given text and invokes the visitor functions for each object, array and literal reached.
- */
- exports.visit = parser.visit;
- /**
- * Takes JSON with JavaScript-style comments and remove
- * them. Optionally replaces every none-newline character
- * of comments with a replaceCharacter
- */
- exports.stripComments = parser.stripComments;
- /**
- * Computes the edits needed to format a JSON document.
- *
- * @param documentText The input text
- * @param range The range to format or `undefined` to format the full content
- * @param options The formatting options
- * @returns A list of edit operations describing the formatting changes to the original document. Edits can be either inserts, replacements or
- * 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
- * text in the original document. However, multiple edits can have
- * 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.
- * To apply edits to an input, you can use `applyEdits`
- */
- function format(documentText, range, options) {
- return formatter.format(documentText, range, options);
- }
- exports.format = format;
- /**
- * Computes the edits needed to modify a value in the JSON document.
- *
- * @param documentText The input text
- * @param path The path of the value to change. The path represents either to the document root, a property or an array item.
- * If the path points to an non-existing property or item, it will be created.
- * @param value The new value for the specified property or item. If the value is undefined,
- * the property or item will be removed.
- * @param options Options
- * @returns A list of edit operations describing the formatting changes to the original document. Edits can be either inserts, replacements or
- * 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
- * text in the original document. However, multiple edits can have
- * 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.
- * To apply edits to an input, you can use `applyEdits`
- */
- function modify(text, path, value, options) {
- return edit.setProperty(text, path, value, options.formattingOptions, options.getInsertionIndex);
- }
- exports.modify = modify;
- /**
- * Applies edits to a input string.
- */
- function applyEdits(text, edits) {
- for (var i = edits.length - 1; i >= 0; i--) {
- text = edit.applyEdit(text, edits[i]);
- }
- return text;
- }
- exports.applyEdits = applyEdits;
- });
- //# sourceMappingURL=main.js.map;
- define('jsonc-parser', ['jsonc-parser/main'], function (main) { return main; });
- define('vs/language/json/tokenization',["require", "exports", "jsonc-parser"], function (require, exports, json) {
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- function createTokenizationSupport(supportComments) {
- return {
- getInitialState: function () { return new JSONState(null, null, false); },
- tokenize: function (line, state, offsetDelta, stopAtOffset) { return tokenize(supportComments, line, state, offsetDelta, stopAtOffset); }
- };
- }
- exports.createTokenizationSupport = createTokenizationSupport;
- exports.TOKEN_DELIM_OBJECT = 'delimiter.bracket.json';
- exports.TOKEN_DELIM_ARRAY = 'delimiter.array.json';
- exports.TOKEN_DELIM_COLON = 'delimiter.colon.json';
- exports.TOKEN_DELIM_COMMA = 'delimiter.comma.json';
- exports.TOKEN_VALUE_BOOLEAN = 'keyword.json';
- exports.TOKEN_VALUE_NULL = 'keyword.json';
- exports.TOKEN_VALUE_STRING = 'string.value.json';
- exports.TOKEN_VALUE_NUMBER = 'number.json';
- exports.TOKEN_PROPERTY_NAME = 'string.key.json';
- exports.TOKEN_COMMENT_BLOCK = 'comment.block.json';
- exports.TOKEN_COMMENT_LINE = 'comment.line.json';
- var JSONState = /** @class */ (function () {
- function JSONState(state, scanError, lastWasColon) {
- this._state = state;
- this.scanError = scanError;
- this.lastWasColon = lastWasColon;
- }
- JSONState.prototype.clone = function () {
- return new JSONState(this._state, this.scanError, this.lastWasColon);
- };
- JSONState.prototype.equals = function (other) {
- if (other === this) {
- return true;
- }
- if (!other || !(other instanceof JSONState)) {
- return false;
- }
- return this.scanError === other.scanError &&
- this.lastWasColon === other.lastWasColon;
- };
- JSONState.prototype.getStateData = function () {
- return this._state;
- };
- JSONState.prototype.setStateData = function (state) {
- this._state = state;
- };
- return JSONState;
- }());
- function tokenize(comments, line, state, offsetDelta, stopAtOffset) {
- if (offsetDelta === void 0) { offsetDelta = 0; }
- // handle multiline strings and block comments
- var numberOfInsertedCharacters = 0, adjustOffset = false;
- switch (state.scanError) {
- case 2 /* UnexpectedEndOfString */:
- line = '"' + line;
- numberOfInsertedCharacters = 1;
- break;
- case 1 /* UnexpectedEndOfComment */:
- line = '/*' + line;
- numberOfInsertedCharacters = 2;
- break;
- }
- var scanner = json.createScanner(line), kind, ret, lastWasColon = state.lastWasColon;
- ret = {
- tokens: [],
- endState: state.clone()
- };
- while (true) {
- var offset = offsetDelta + scanner.getPosition(), type = '';
- kind = scanner.scan();
- if (kind === 17 /* EOF */) {
- break;
- }
- // Check that the scanner has advanced
- if (offset === offsetDelta + scanner.getPosition()) {
- throw new Error('Scanner did not advance, next 3 characters are: ' + line.substr(scanner.getPosition(), 3));
- }
- // In case we inserted /* or " character, we need to
- // adjust the offset of all tokens (except the first)
- if (adjustOffset) {
- offset -= numberOfInsertedCharacters;
- }
- adjustOffset = numberOfInsertedCharacters > 0;
- // brackets and type
- switch (kind) {
- case 1 /* OpenBraceToken */:
- type = exports.TOKEN_DELIM_OBJECT;
- lastWasColon = false;
- break;
- case 2 /* CloseBraceToken */:
- type = exports.TOKEN_DELIM_OBJECT;
- lastWasColon = false;
- break;
- case 3 /* OpenBracketToken */:
- type = exports.TOKEN_DELIM_ARRAY;
- lastWasColon = false;
- break;
- case 4 /* CloseBracketToken */:
- type = exports.TOKEN_DELIM_ARRAY;
- lastWasColon = false;
- break;
- case 6 /* ColonToken */:
- type = exports.TOKEN_DELIM_COLON;
- lastWasColon = true;
- break;
- case 5 /* CommaToken */:
- type = exports.TOKEN_DELIM_COMMA;
- lastWasColon = false;
- break;
- case 8 /* TrueKeyword */:
- case 9 /* FalseKeyword */:
- type = exports.TOKEN_VALUE_BOOLEAN;
- lastWasColon = false;
- break;
- case 7 /* NullKeyword */:
- type = exports.TOKEN_VALUE_NULL;
- lastWasColon = false;
- break;
- case 10 /* StringLiteral */:
- type = lastWasColon ? exports.TOKEN_VALUE_STRING : exports.TOKEN_PROPERTY_NAME;
- lastWasColon = false;
- break;
- case 11 /* NumericLiteral */:
- type = exports.TOKEN_VALUE_NUMBER;
- lastWasColon = false;
- break;
- }
- // comments, iff enabled
- if (comments) {
- switch (kind) {
- case 12 /* LineCommentTrivia */:
- type = exports.TOKEN_COMMENT_LINE;
- break;
- case 13 /* BlockCommentTrivia */:
- type = exports.TOKEN_COMMENT_BLOCK;
- break;
- }
- }
- ret.endState = new JSONState(state.getStateData(), scanner.getTokenError(), lastWasColon);
- ret.tokens.push({
- startIndex: offset,
- scopes: type
- });
- }
- return ret;
- }
- });
- define('vs/language/json/jsonMode',["require", "exports", "./workerManager", "./languageFeatures", "./tokenization"], function (require, exports, workerManager_1, languageFeatures, tokenization_1) {
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- function setupMode(defaults) {
- var disposables = [];
- var client = new workerManager_1.WorkerManager(defaults);
- disposables.push(client);
- var worker = function () {
- var uris = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- uris[_i] = arguments[_i];
- }
- return client.getLanguageServiceWorker.apply(client, uris);
- };
- var languageId = defaults.languageId;
- disposables.push(monaco.languages.registerCompletionItemProvider(languageId, new languageFeatures.CompletionAdapter(worker)));
- disposables.push(monaco.languages.registerHoverProvider(languageId, new languageFeatures.HoverAdapter(worker)));
- disposables.push(monaco.languages.registerDocumentSymbolProvider(languageId, new languageFeatures.DocumentSymbolAdapter(worker)));
- disposables.push(monaco.languages.registerDocumentFormattingEditProvider(languageId, new languageFeatures.DocumentFormattingEditProvider(worker)));
- disposables.push(monaco.languages.registerDocumentRangeFormattingEditProvider(languageId, new languageFeatures.DocumentRangeFormattingEditProvider(worker)));
- disposables.push(new languageFeatures.DiagnosticsAdapter(languageId, worker, defaults));
- disposables.push(monaco.languages.setTokensProvider(languageId, tokenization_1.createTokenizationSupport(true)));
- disposables.push(monaco.languages.setLanguageConfiguration(languageId, richEditConfiguration));
- disposables.push(monaco.languages.registerColorProvider(languageId, new languageFeatures.DocumentColorAdapter(worker)));
- disposables.push(monaco.languages.registerFoldingRangeProvider(languageId, new languageFeatures.FoldingRangeAdapter(worker)));
- }
- exports.setupMode = setupMode;
- var richEditConfiguration = {
- wordPattern: /(-?\d*\.\d\w*)|([^\[\{\]\}\:\"\,\s]+)/g,
- comments: {
- lineComment: '//',
- blockComment: ['/*', '*/']
- },
- brackets: [
- ['{', '}'],
- ['[', ']']
- ],
- autoClosingPairs: [
- { open: '{', close: '}', notIn: ['string'] },
- { open: '[', close: ']', notIn: ['string'] },
- { open: '"', close: '"', notIn: ['string'] }
- ]
- };
- });
|