cssMode.js 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.34.1(547870b6881302c5b4ff32173c16d06009e3588f)
  4. * Released under the MIT license
  5. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  6. *-----------------------------------------------------------------------------*/
  7. var __defProp = Object.defineProperty;
  8. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  9. var __getOwnPropNames = Object.getOwnPropertyNames;
  10. var __hasOwnProp = Object.prototype.hasOwnProperty;
  11. var __copyProps = (to, from, except, desc) => {
  12. if (from && typeof from === "object" || typeof from === "function") {
  13. for (let key of __getOwnPropNames(from))
  14. if (!__hasOwnProp.call(to, key) && key !== except)
  15. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  16. }
  17. return to;
  18. };
  19. var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
  20. // src/fillers/monaco-editor-core.ts
  21. var monaco_editor_core_exports = {};
  22. __reExport(monaco_editor_core_exports, monaco_editor_core_star);
  23. import * as monaco_editor_core_star from "../../editor/editor.api.js";
  24. // src/language/css/workerManager.ts
  25. var STOP_WHEN_IDLE_FOR = 2 * 60 * 1e3;
  26. var WorkerManager = class {
  27. _defaults;
  28. _idleCheckInterval;
  29. _lastUsedTime;
  30. _configChangeListener;
  31. _worker;
  32. _client;
  33. constructor(defaults) {
  34. this._defaults = defaults;
  35. this._worker = null;
  36. this._client = null;
  37. this._idleCheckInterval = window.setInterval(() => this._checkIfIdle(), 30 * 1e3);
  38. this._lastUsedTime = 0;
  39. this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());
  40. }
  41. _stopWorker() {
  42. if (this._worker) {
  43. this._worker.dispose();
  44. this._worker = null;
  45. }
  46. this._client = null;
  47. }
  48. dispose() {
  49. clearInterval(this._idleCheckInterval);
  50. this._configChangeListener.dispose();
  51. this._stopWorker();
  52. }
  53. _checkIfIdle() {
  54. if (!this._worker) {
  55. return;
  56. }
  57. let timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
  58. if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
  59. this._stopWorker();
  60. }
  61. }
  62. _getClient() {
  63. this._lastUsedTime = Date.now();
  64. if (!this._client) {
  65. this._worker = monaco_editor_core_exports.editor.createWebWorker({
  66. moduleId: "vs/language/css/cssWorker",
  67. label: this._defaults.languageId,
  68. createData: {
  69. options: this._defaults.options,
  70. languageId: this._defaults.languageId
  71. }
  72. });
  73. this._client = this._worker.getProxy();
  74. }
  75. return this._client;
  76. }
  77. getLanguageServiceWorker(...resources) {
  78. let _client;
  79. return this._getClient().then((client) => {
  80. _client = client;
  81. }).then((_) => {
  82. if (this._worker) {
  83. return this._worker.withSyncedResources(resources);
  84. }
  85. }).then((_) => _client);
  86. }
  87. };
  88. // node_modules/vscode-languageserver-types/lib/esm/main.js
  89. var integer;
  90. (function(integer2) {
  91. integer2.MIN_VALUE = -2147483648;
  92. integer2.MAX_VALUE = 2147483647;
  93. })(integer || (integer = {}));
  94. var uinteger;
  95. (function(uinteger2) {
  96. uinteger2.MIN_VALUE = 0;
  97. uinteger2.MAX_VALUE = 2147483647;
  98. })(uinteger || (uinteger = {}));
  99. var Position;
  100. (function(Position3) {
  101. function create(line, character) {
  102. if (line === Number.MAX_VALUE) {
  103. line = uinteger.MAX_VALUE;
  104. }
  105. if (character === Number.MAX_VALUE) {
  106. character = uinteger.MAX_VALUE;
  107. }
  108. return { line, character };
  109. }
  110. Position3.create = create;
  111. function is(value) {
  112. var candidate = value;
  113. return Is.objectLiteral(candidate) && Is.uinteger(candidate.line) && Is.uinteger(candidate.character);
  114. }
  115. Position3.is = is;
  116. })(Position || (Position = {}));
  117. var Range;
  118. (function(Range3) {
  119. function create(one, two, three, four) {
  120. if (Is.uinteger(one) && Is.uinteger(two) && Is.uinteger(three) && Is.uinteger(four)) {
  121. return { start: Position.create(one, two), end: Position.create(three, four) };
  122. } else if (Position.is(one) && Position.is(two)) {
  123. return { start: one, end: two };
  124. } else {
  125. throw new Error("Range#create called with invalid arguments[" + one + ", " + two + ", " + three + ", " + four + "]");
  126. }
  127. }
  128. Range3.create = create;
  129. function is(value) {
  130. var candidate = value;
  131. return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
  132. }
  133. Range3.is = is;
  134. })(Range || (Range = {}));
  135. var Location;
  136. (function(Location2) {
  137. function create(uri, range) {
  138. return { uri, range };
  139. }
  140. Location2.create = create;
  141. function is(value) {
  142. var candidate = value;
  143. return Is.defined(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
  144. }
  145. Location2.is = is;
  146. })(Location || (Location = {}));
  147. var LocationLink;
  148. (function(LocationLink2) {
  149. function create(targetUri, targetRange, targetSelectionRange, originSelectionRange) {
  150. return { targetUri, targetRange, targetSelectionRange, originSelectionRange };
  151. }
  152. LocationLink2.create = create;
  153. function is(value) {
  154. var candidate = value;
  155. return Is.defined(candidate) && Range.is(candidate.targetRange) && Is.string(candidate.targetUri) && (Range.is(candidate.targetSelectionRange) || Is.undefined(candidate.targetSelectionRange)) && (Range.is(candidate.originSelectionRange) || Is.undefined(candidate.originSelectionRange));
  156. }
  157. LocationLink2.is = is;
  158. })(LocationLink || (LocationLink = {}));
  159. var Color;
  160. (function(Color2) {
  161. function create(red, green, blue, alpha) {
  162. return {
  163. red,
  164. green,
  165. blue,
  166. alpha
  167. };
  168. }
  169. Color2.create = create;
  170. function is(value) {
  171. var candidate = value;
  172. return Is.numberRange(candidate.red, 0, 1) && Is.numberRange(candidate.green, 0, 1) && Is.numberRange(candidate.blue, 0, 1) && Is.numberRange(candidate.alpha, 0, 1);
  173. }
  174. Color2.is = is;
  175. })(Color || (Color = {}));
  176. var ColorInformation;
  177. (function(ColorInformation2) {
  178. function create(range, color) {
  179. return {
  180. range,
  181. color
  182. };
  183. }
  184. ColorInformation2.create = create;
  185. function is(value) {
  186. var candidate = value;
  187. return Range.is(candidate.range) && Color.is(candidate.color);
  188. }
  189. ColorInformation2.is = is;
  190. })(ColorInformation || (ColorInformation = {}));
  191. var ColorPresentation;
  192. (function(ColorPresentation2) {
  193. function create(label, textEdit, additionalTextEdits) {
  194. return {
  195. label,
  196. textEdit,
  197. additionalTextEdits
  198. };
  199. }
  200. ColorPresentation2.create = create;
  201. function is(value) {
  202. var candidate = value;
  203. return Is.string(candidate.label) && (Is.undefined(candidate.textEdit) || TextEdit.is(candidate)) && (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is));
  204. }
  205. ColorPresentation2.is = is;
  206. })(ColorPresentation || (ColorPresentation = {}));
  207. var FoldingRangeKind;
  208. (function(FoldingRangeKind2) {
  209. FoldingRangeKind2["Comment"] = "comment";
  210. FoldingRangeKind2["Imports"] = "imports";
  211. FoldingRangeKind2["Region"] = "region";
  212. })(FoldingRangeKind || (FoldingRangeKind = {}));
  213. var FoldingRange;
  214. (function(FoldingRange2) {
  215. function create(startLine, endLine, startCharacter, endCharacter, kind) {
  216. var result = {
  217. startLine,
  218. endLine
  219. };
  220. if (Is.defined(startCharacter)) {
  221. result.startCharacter = startCharacter;
  222. }
  223. if (Is.defined(endCharacter)) {
  224. result.endCharacter = endCharacter;
  225. }
  226. if (Is.defined(kind)) {
  227. result.kind = kind;
  228. }
  229. return result;
  230. }
  231. FoldingRange2.create = create;
  232. function is(value) {
  233. var candidate = value;
  234. return Is.uinteger(candidate.startLine) && Is.uinteger(candidate.startLine) && (Is.undefined(candidate.startCharacter) || Is.uinteger(candidate.startCharacter)) && (Is.undefined(candidate.endCharacter) || Is.uinteger(candidate.endCharacter)) && (Is.undefined(candidate.kind) || Is.string(candidate.kind));
  235. }
  236. FoldingRange2.is = is;
  237. })(FoldingRange || (FoldingRange = {}));
  238. var DiagnosticRelatedInformation;
  239. (function(DiagnosticRelatedInformation2) {
  240. function create(location, message) {
  241. return {
  242. location,
  243. message
  244. };
  245. }
  246. DiagnosticRelatedInformation2.create = create;
  247. function is(value) {
  248. var candidate = value;
  249. return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message);
  250. }
  251. DiagnosticRelatedInformation2.is = is;
  252. })(DiagnosticRelatedInformation || (DiagnosticRelatedInformation = {}));
  253. var DiagnosticSeverity;
  254. (function(DiagnosticSeverity2) {
  255. DiagnosticSeverity2.Error = 1;
  256. DiagnosticSeverity2.Warning = 2;
  257. DiagnosticSeverity2.Information = 3;
  258. DiagnosticSeverity2.Hint = 4;
  259. })(DiagnosticSeverity || (DiagnosticSeverity = {}));
  260. var DiagnosticTag;
  261. (function(DiagnosticTag2) {
  262. DiagnosticTag2.Unnecessary = 1;
  263. DiagnosticTag2.Deprecated = 2;
  264. })(DiagnosticTag || (DiagnosticTag = {}));
  265. var CodeDescription;
  266. (function(CodeDescription2) {
  267. function is(value) {
  268. var candidate = value;
  269. return candidate !== void 0 && candidate !== null && Is.string(candidate.href);
  270. }
  271. CodeDescription2.is = is;
  272. })(CodeDescription || (CodeDescription = {}));
  273. var Diagnostic;
  274. (function(Diagnostic2) {
  275. function create(range, message, severity, code, source, relatedInformation) {
  276. var result = { range, message };
  277. if (Is.defined(severity)) {
  278. result.severity = severity;
  279. }
  280. if (Is.defined(code)) {
  281. result.code = code;
  282. }
  283. if (Is.defined(source)) {
  284. result.source = source;
  285. }
  286. if (Is.defined(relatedInformation)) {
  287. result.relatedInformation = relatedInformation;
  288. }
  289. return result;
  290. }
  291. Diagnostic2.create = create;
  292. function is(value) {
  293. var _a;
  294. var candidate = value;
  295. return Is.defined(candidate) && Range.is(candidate.range) && Is.string(candidate.message) && (Is.number(candidate.severity) || Is.undefined(candidate.severity)) && (Is.integer(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code)) && (Is.undefined(candidate.codeDescription) || Is.string((_a = candidate.codeDescription) === null || _a === void 0 ? void 0 : _a.href)) && (Is.string(candidate.source) || Is.undefined(candidate.source)) && (Is.undefined(candidate.relatedInformation) || Is.typedArray(candidate.relatedInformation, DiagnosticRelatedInformation.is));
  296. }
  297. Diagnostic2.is = is;
  298. })(Diagnostic || (Diagnostic = {}));
  299. var Command;
  300. (function(Command2) {
  301. function create(title, command) {
  302. var args = [];
  303. for (var _i = 2; _i < arguments.length; _i++) {
  304. args[_i - 2] = arguments[_i];
  305. }
  306. var result = { title, command };
  307. if (Is.defined(args) && args.length > 0) {
  308. result.arguments = args;
  309. }
  310. return result;
  311. }
  312. Command2.create = create;
  313. function is(value) {
  314. var candidate = value;
  315. return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command);
  316. }
  317. Command2.is = is;
  318. })(Command || (Command = {}));
  319. var TextEdit;
  320. (function(TextEdit2) {
  321. function replace(range, newText) {
  322. return { range, newText };
  323. }
  324. TextEdit2.replace = replace;
  325. function insert(position, newText) {
  326. return { range: { start: position, end: position }, newText };
  327. }
  328. TextEdit2.insert = insert;
  329. function del(range) {
  330. return { range, newText: "" };
  331. }
  332. TextEdit2.del = del;
  333. function is(value) {
  334. var candidate = value;
  335. return Is.objectLiteral(candidate) && Is.string(candidate.newText) && Range.is(candidate.range);
  336. }
  337. TextEdit2.is = is;
  338. })(TextEdit || (TextEdit = {}));
  339. var ChangeAnnotation;
  340. (function(ChangeAnnotation2) {
  341. function create(label, needsConfirmation, description) {
  342. var result = { label };
  343. if (needsConfirmation !== void 0) {
  344. result.needsConfirmation = needsConfirmation;
  345. }
  346. if (description !== void 0) {
  347. result.description = description;
  348. }
  349. return result;
  350. }
  351. ChangeAnnotation2.create = create;
  352. function is(value) {
  353. var candidate = value;
  354. return candidate !== void 0 && Is.objectLiteral(candidate) && Is.string(candidate.label) && (Is.boolean(candidate.needsConfirmation) || candidate.needsConfirmation === void 0) && (Is.string(candidate.description) || candidate.description === void 0);
  355. }
  356. ChangeAnnotation2.is = is;
  357. })(ChangeAnnotation || (ChangeAnnotation = {}));
  358. var ChangeAnnotationIdentifier;
  359. (function(ChangeAnnotationIdentifier2) {
  360. function is(value) {
  361. var candidate = value;
  362. return typeof candidate === "string";
  363. }
  364. ChangeAnnotationIdentifier2.is = is;
  365. })(ChangeAnnotationIdentifier || (ChangeAnnotationIdentifier = {}));
  366. var AnnotatedTextEdit;
  367. (function(AnnotatedTextEdit2) {
  368. function replace(range, newText, annotation) {
  369. return { range, newText, annotationId: annotation };
  370. }
  371. AnnotatedTextEdit2.replace = replace;
  372. function insert(position, newText, annotation) {
  373. return { range: { start: position, end: position }, newText, annotationId: annotation };
  374. }
  375. AnnotatedTextEdit2.insert = insert;
  376. function del(range, annotation) {
  377. return { range, newText: "", annotationId: annotation };
  378. }
  379. AnnotatedTextEdit2.del = del;
  380. function is(value) {
  381. var candidate = value;
  382. return TextEdit.is(candidate) && (ChangeAnnotation.is(candidate.annotationId) || ChangeAnnotationIdentifier.is(candidate.annotationId));
  383. }
  384. AnnotatedTextEdit2.is = is;
  385. })(AnnotatedTextEdit || (AnnotatedTextEdit = {}));
  386. var TextDocumentEdit;
  387. (function(TextDocumentEdit2) {
  388. function create(textDocument, edits) {
  389. return { textDocument, edits };
  390. }
  391. TextDocumentEdit2.create = create;
  392. function is(value) {
  393. var candidate = value;
  394. return Is.defined(candidate) && OptionalVersionedTextDocumentIdentifier.is(candidate.textDocument) && Array.isArray(candidate.edits);
  395. }
  396. TextDocumentEdit2.is = is;
  397. })(TextDocumentEdit || (TextDocumentEdit = {}));
  398. var CreateFile;
  399. (function(CreateFile2) {
  400. function create(uri, options, annotation) {
  401. var result = {
  402. kind: "create",
  403. uri
  404. };
  405. if (options !== void 0 && (options.overwrite !== void 0 || options.ignoreIfExists !== void 0)) {
  406. result.options = options;
  407. }
  408. if (annotation !== void 0) {
  409. result.annotationId = annotation;
  410. }
  411. return result;
  412. }
  413. CreateFile2.create = create;
  414. function is(value) {
  415. var candidate = value;
  416. return candidate && candidate.kind === "create" && Is.string(candidate.uri) && (candidate.options === void 0 || (candidate.options.overwrite === void 0 || Is.boolean(candidate.options.overwrite)) && (candidate.options.ignoreIfExists === void 0 || Is.boolean(candidate.options.ignoreIfExists))) && (candidate.annotationId === void 0 || ChangeAnnotationIdentifier.is(candidate.annotationId));
  417. }
  418. CreateFile2.is = is;
  419. })(CreateFile || (CreateFile = {}));
  420. var RenameFile;
  421. (function(RenameFile2) {
  422. function create(oldUri, newUri, options, annotation) {
  423. var result = {
  424. kind: "rename",
  425. oldUri,
  426. newUri
  427. };
  428. if (options !== void 0 && (options.overwrite !== void 0 || options.ignoreIfExists !== void 0)) {
  429. result.options = options;
  430. }
  431. if (annotation !== void 0) {
  432. result.annotationId = annotation;
  433. }
  434. return result;
  435. }
  436. RenameFile2.create = create;
  437. function is(value) {
  438. var candidate = value;
  439. return candidate && candidate.kind === "rename" && Is.string(candidate.oldUri) && Is.string(candidate.newUri) && (candidate.options === void 0 || (candidate.options.overwrite === void 0 || Is.boolean(candidate.options.overwrite)) && (candidate.options.ignoreIfExists === void 0 || Is.boolean(candidate.options.ignoreIfExists))) && (candidate.annotationId === void 0 || ChangeAnnotationIdentifier.is(candidate.annotationId));
  440. }
  441. RenameFile2.is = is;
  442. })(RenameFile || (RenameFile = {}));
  443. var DeleteFile;
  444. (function(DeleteFile2) {
  445. function create(uri, options, annotation) {
  446. var result = {
  447. kind: "delete",
  448. uri
  449. };
  450. if (options !== void 0 && (options.recursive !== void 0 || options.ignoreIfNotExists !== void 0)) {
  451. result.options = options;
  452. }
  453. if (annotation !== void 0) {
  454. result.annotationId = annotation;
  455. }
  456. return result;
  457. }
  458. DeleteFile2.create = create;
  459. function is(value) {
  460. var candidate = value;
  461. return candidate && candidate.kind === "delete" && Is.string(candidate.uri) && (candidate.options === void 0 || (candidate.options.recursive === void 0 || Is.boolean(candidate.options.recursive)) && (candidate.options.ignoreIfNotExists === void 0 || Is.boolean(candidate.options.ignoreIfNotExists))) && (candidate.annotationId === void 0 || ChangeAnnotationIdentifier.is(candidate.annotationId));
  462. }
  463. DeleteFile2.is = is;
  464. })(DeleteFile || (DeleteFile = {}));
  465. var WorkspaceEdit;
  466. (function(WorkspaceEdit2) {
  467. function is(value) {
  468. var candidate = value;
  469. return candidate && (candidate.changes !== void 0 || candidate.documentChanges !== void 0) && (candidate.documentChanges === void 0 || candidate.documentChanges.every(function(change) {
  470. if (Is.string(change.kind)) {
  471. return CreateFile.is(change) || RenameFile.is(change) || DeleteFile.is(change);
  472. } else {
  473. return TextDocumentEdit.is(change);
  474. }
  475. }));
  476. }
  477. WorkspaceEdit2.is = is;
  478. })(WorkspaceEdit || (WorkspaceEdit = {}));
  479. var TextEditChangeImpl = function() {
  480. function TextEditChangeImpl2(edits, changeAnnotations) {
  481. this.edits = edits;
  482. this.changeAnnotations = changeAnnotations;
  483. }
  484. TextEditChangeImpl2.prototype.insert = function(position, newText, annotation) {
  485. var edit;
  486. var id;
  487. if (annotation === void 0) {
  488. edit = TextEdit.insert(position, newText);
  489. } else if (ChangeAnnotationIdentifier.is(annotation)) {
  490. id = annotation;
  491. edit = AnnotatedTextEdit.insert(position, newText, annotation);
  492. } else {
  493. this.assertChangeAnnotations(this.changeAnnotations);
  494. id = this.changeAnnotations.manage(annotation);
  495. edit = AnnotatedTextEdit.insert(position, newText, id);
  496. }
  497. this.edits.push(edit);
  498. if (id !== void 0) {
  499. return id;
  500. }
  501. };
  502. TextEditChangeImpl2.prototype.replace = function(range, newText, annotation) {
  503. var edit;
  504. var id;
  505. if (annotation === void 0) {
  506. edit = TextEdit.replace(range, newText);
  507. } else if (ChangeAnnotationIdentifier.is(annotation)) {
  508. id = annotation;
  509. edit = AnnotatedTextEdit.replace(range, newText, annotation);
  510. } else {
  511. this.assertChangeAnnotations(this.changeAnnotations);
  512. id = this.changeAnnotations.manage(annotation);
  513. edit = AnnotatedTextEdit.replace(range, newText, id);
  514. }
  515. this.edits.push(edit);
  516. if (id !== void 0) {
  517. return id;
  518. }
  519. };
  520. TextEditChangeImpl2.prototype.delete = function(range, annotation) {
  521. var edit;
  522. var id;
  523. if (annotation === void 0) {
  524. edit = TextEdit.del(range);
  525. } else if (ChangeAnnotationIdentifier.is(annotation)) {
  526. id = annotation;
  527. edit = AnnotatedTextEdit.del(range, annotation);
  528. } else {
  529. this.assertChangeAnnotations(this.changeAnnotations);
  530. id = this.changeAnnotations.manage(annotation);
  531. edit = AnnotatedTextEdit.del(range, id);
  532. }
  533. this.edits.push(edit);
  534. if (id !== void 0) {
  535. return id;
  536. }
  537. };
  538. TextEditChangeImpl2.prototype.add = function(edit) {
  539. this.edits.push(edit);
  540. };
  541. TextEditChangeImpl2.prototype.all = function() {
  542. return this.edits;
  543. };
  544. TextEditChangeImpl2.prototype.clear = function() {
  545. this.edits.splice(0, this.edits.length);
  546. };
  547. TextEditChangeImpl2.prototype.assertChangeAnnotations = function(value) {
  548. if (value === void 0) {
  549. throw new Error("Text edit change is not configured to manage change annotations.");
  550. }
  551. };
  552. return TextEditChangeImpl2;
  553. }();
  554. var ChangeAnnotations = function() {
  555. function ChangeAnnotations2(annotations) {
  556. this._annotations = annotations === void 0 ? /* @__PURE__ */ Object.create(null) : annotations;
  557. this._counter = 0;
  558. this._size = 0;
  559. }
  560. ChangeAnnotations2.prototype.all = function() {
  561. return this._annotations;
  562. };
  563. Object.defineProperty(ChangeAnnotations2.prototype, "size", {
  564. get: function() {
  565. return this._size;
  566. },
  567. enumerable: false,
  568. configurable: true
  569. });
  570. ChangeAnnotations2.prototype.manage = function(idOrAnnotation, annotation) {
  571. var id;
  572. if (ChangeAnnotationIdentifier.is(idOrAnnotation)) {
  573. id = idOrAnnotation;
  574. } else {
  575. id = this.nextId();
  576. annotation = idOrAnnotation;
  577. }
  578. if (this._annotations[id] !== void 0) {
  579. throw new Error("Id " + id + " is already in use.");
  580. }
  581. if (annotation === void 0) {
  582. throw new Error("No annotation provided for id " + id);
  583. }
  584. this._annotations[id] = annotation;
  585. this._size++;
  586. return id;
  587. };
  588. ChangeAnnotations2.prototype.nextId = function() {
  589. this._counter++;
  590. return this._counter.toString();
  591. };
  592. return ChangeAnnotations2;
  593. }();
  594. var WorkspaceChange = function() {
  595. function WorkspaceChange2(workspaceEdit) {
  596. var _this = this;
  597. this._textEditChanges = /* @__PURE__ */ Object.create(null);
  598. if (workspaceEdit !== void 0) {
  599. this._workspaceEdit = workspaceEdit;
  600. if (workspaceEdit.documentChanges) {
  601. this._changeAnnotations = new ChangeAnnotations(workspaceEdit.changeAnnotations);
  602. workspaceEdit.changeAnnotations = this._changeAnnotations.all();
  603. workspaceEdit.documentChanges.forEach(function(change) {
  604. if (TextDocumentEdit.is(change)) {
  605. var textEditChange = new TextEditChangeImpl(change.edits, _this._changeAnnotations);
  606. _this._textEditChanges[change.textDocument.uri] = textEditChange;
  607. }
  608. });
  609. } else if (workspaceEdit.changes) {
  610. Object.keys(workspaceEdit.changes).forEach(function(key) {
  611. var textEditChange = new TextEditChangeImpl(workspaceEdit.changes[key]);
  612. _this._textEditChanges[key] = textEditChange;
  613. });
  614. }
  615. } else {
  616. this._workspaceEdit = {};
  617. }
  618. }
  619. Object.defineProperty(WorkspaceChange2.prototype, "edit", {
  620. get: function() {
  621. this.initDocumentChanges();
  622. if (this._changeAnnotations !== void 0) {
  623. if (this._changeAnnotations.size === 0) {
  624. this._workspaceEdit.changeAnnotations = void 0;
  625. } else {
  626. this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
  627. }
  628. }
  629. return this._workspaceEdit;
  630. },
  631. enumerable: false,
  632. configurable: true
  633. });
  634. WorkspaceChange2.prototype.getTextEditChange = function(key) {
  635. if (OptionalVersionedTextDocumentIdentifier.is(key)) {
  636. this.initDocumentChanges();
  637. if (this._workspaceEdit.documentChanges === void 0) {
  638. throw new Error("Workspace edit is not configured for document changes.");
  639. }
  640. var textDocument = { uri: key.uri, version: key.version };
  641. var result = this._textEditChanges[textDocument.uri];
  642. if (!result) {
  643. var edits = [];
  644. var textDocumentEdit = {
  645. textDocument,
  646. edits
  647. };
  648. this._workspaceEdit.documentChanges.push(textDocumentEdit);
  649. result = new TextEditChangeImpl(edits, this._changeAnnotations);
  650. this._textEditChanges[textDocument.uri] = result;
  651. }
  652. return result;
  653. } else {
  654. this.initChanges();
  655. if (this._workspaceEdit.changes === void 0) {
  656. throw new Error("Workspace edit is not configured for normal text edit changes.");
  657. }
  658. var result = this._textEditChanges[key];
  659. if (!result) {
  660. var edits = [];
  661. this._workspaceEdit.changes[key] = edits;
  662. result = new TextEditChangeImpl(edits);
  663. this._textEditChanges[key] = result;
  664. }
  665. return result;
  666. }
  667. };
  668. WorkspaceChange2.prototype.initDocumentChanges = function() {
  669. if (this._workspaceEdit.documentChanges === void 0 && this._workspaceEdit.changes === void 0) {
  670. this._changeAnnotations = new ChangeAnnotations();
  671. this._workspaceEdit.documentChanges = [];
  672. this._workspaceEdit.changeAnnotations = this._changeAnnotations.all();
  673. }
  674. };
  675. WorkspaceChange2.prototype.initChanges = function() {
  676. if (this._workspaceEdit.documentChanges === void 0 && this._workspaceEdit.changes === void 0) {
  677. this._workspaceEdit.changes = /* @__PURE__ */ Object.create(null);
  678. }
  679. };
  680. WorkspaceChange2.prototype.createFile = function(uri, optionsOrAnnotation, options) {
  681. this.initDocumentChanges();
  682. if (this._workspaceEdit.documentChanges === void 0) {
  683. throw new Error("Workspace edit is not configured for document changes.");
  684. }
  685. var annotation;
  686. if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
  687. annotation = optionsOrAnnotation;
  688. } else {
  689. options = optionsOrAnnotation;
  690. }
  691. var operation;
  692. var id;
  693. if (annotation === void 0) {
  694. operation = CreateFile.create(uri, options);
  695. } else {
  696. id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
  697. operation = CreateFile.create(uri, options, id);
  698. }
  699. this._workspaceEdit.documentChanges.push(operation);
  700. if (id !== void 0) {
  701. return id;
  702. }
  703. };
  704. WorkspaceChange2.prototype.renameFile = function(oldUri, newUri, optionsOrAnnotation, options) {
  705. this.initDocumentChanges();
  706. if (this._workspaceEdit.documentChanges === void 0) {
  707. throw new Error("Workspace edit is not configured for document changes.");
  708. }
  709. var annotation;
  710. if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
  711. annotation = optionsOrAnnotation;
  712. } else {
  713. options = optionsOrAnnotation;
  714. }
  715. var operation;
  716. var id;
  717. if (annotation === void 0) {
  718. operation = RenameFile.create(oldUri, newUri, options);
  719. } else {
  720. id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
  721. operation = RenameFile.create(oldUri, newUri, options, id);
  722. }
  723. this._workspaceEdit.documentChanges.push(operation);
  724. if (id !== void 0) {
  725. return id;
  726. }
  727. };
  728. WorkspaceChange2.prototype.deleteFile = function(uri, optionsOrAnnotation, options) {
  729. this.initDocumentChanges();
  730. if (this._workspaceEdit.documentChanges === void 0) {
  731. throw new Error("Workspace edit is not configured for document changes.");
  732. }
  733. var annotation;
  734. if (ChangeAnnotation.is(optionsOrAnnotation) || ChangeAnnotationIdentifier.is(optionsOrAnnotation)) {
  735. annotation = optionsOrAnnotation;
  736. } else {
  737. options = optionsOrAnnotation;
  738. }
  739. var operation;
  740. var id;
  741. if (annotation === void 0) {
  742. operation = DeleteFile.create(uri, options);
  743. } else {
  744. id = ChangeAnnotationIdentifier.is(annotation) ? annotation : this._changeAnnotations.manage(annotation);
  745. operation = DeleteFile.create(uri, options, id);
  746. }
  747. this._workspaceEdit.documentChanges.push(operation);
  748. if (id !== void 0) {
  749. return id;
  750. }
  751. };
  752. return WorkspaceChange2;
  753. }();
  754. var TextDocumentIdentifier;
  755. (function(TextDocumentIdentifier2) {
  756. function create(uri) {
  757. return { uri };
  758. }
  759. TextDocumentIdentifier2.create = create;
  760. function is(value) {
  761. var candidate = value;
  762. return Is.defined(candidate) && Is.string(candidate.uri);
  763. }
  764. TextDocumentIdentifier2.is = is;
  765. })(TextDocumentIdentifier || (TextDocumentIdentifier = {}));
  766. var VersionedTextDocumentIdentifier;
  767. (function(VersionedTextDocumentIdentifier2) {
  768. function create(uri, version) {
  769. return { uri, version };
  770. }
  771. VersionedTextDocumentIdentifier2.create = create;
  772. function is(value) {
  773. var candidate = value;
  774. return Is.defined(candidate) && Is.string(candidate.uri) && Is.integer(candidate.version);
  775. }
  776. VersionedTextDocumentIdentifier2.is = is;
  777. })(VersionedTextDocumentIdentifier || (VersionedTextDocumentIdentifier = {}));
  778. var OptionalVersionedTextDocumentIdentifier;
  779. (function(OptionalVersionedTextDocumentIdentifier2) {
  780. function create(uri, version) {
  781. return { uri, version };
  782. }
  783. OptionalVersionedTextDocumentIdentifier2.create = create;
  784. function is(value) {
  785. var candidate = value;
  786. return Is.defined(candidate) && Is.string(candidate.uri) && (candidate.version === null || Is.integer(candidate.version));
  787. }
  788. OptionalVersionedTextDocumentIdentifier2.is = is;
  789. })(OptionalVersionedTextDocumentIdentifier || (OptionalVersionedTextDocumentIdentifier = {}));
  790. var TextDocumentItem;
  791. (function(TextDocumentItem2) {
  792. function create(uri, languageId, version, text) {
  793. return { uri, languageId, version, text };
  794. }
  795. TextDocumentItem2.create = create;
  796. function is(value) {
  797. var candidate = value;
  798. return Is.defined(candidate) && Is.string(candidate.uri) && Is.string(candidate.languageId) && Is.integer(candidate.version) && Is.string(candidate.text);
  799. }
  800. TextDocumentItem2.is = is;
  801. })(TextDocumentItem || (TextDocumentItem = {}));
  802. var MarkupKind;
  803. (function(MarkupKind2) {
  804. MarkupKind2.PlainText = "plaintext";
  805. MarkupKind2.Markdown = "markdown";
  806. })(MarkupKind || (MarkupKind = {}));
  807. (function(MarkupKind2) {
  808. function is(value) {
  809. var candidate = value;
  810. return candidate === MarkupKind2.PlainText || candidate === MarkupKind2.Markdown;
  811. }
  812. MarkupKind2.is = is;
  813. })(MarkupKind || (MarkupKind = {}));
  814. var MarkupContent;
  815. (function(MarkupContent2) {
  816. function is(value) {
  817. var candidate = value;
  818. return Is.objectLiteral(value) && MarkupKind.is(candidate.kind) && Is.string(candidate.value);
  819. }
  820. MarkupContent2.is = is;
  821. })(MarkupContent || (MarkupContent = {}));
  822. var CompletionItemKind;
  823. (function(CompletionItemKind2) {
  824. CompletionItemKind2.Text = 1;
  825. CompletionItemKind2.Method = 2;
  826. CompletionItemKind2.Function = 3;
  827. CompletionItemKind2.Constructor = 4;
  828. CompletionItemKind2.Field = 5;
  829. CompletionItemKind2.Variable = 6;
  830. CompletionItemKind2.Class = 7;
  831. CompletionItemKind2.Interface = 8;
  832. CompletionItemKind2.Module = 9;
  833. CompletionItemKind2.Property = 10;
  834. CompletionItemKind2.Unit = 11;
  835. CompletionItemKind2.Value = 12;
  836. CompletionItemKind2.Enum = 13;
  837. CompletionItemKind2.Keyword = 14;
  838. CompletionItemKind2.Snippet = 15;
  839. CompletionItemKind2.Color = 16;
  840. CompletionItemKind2.File = 17;
  841. CompletionItemKind2.Reference = 18;
  842. CompletionItemKind2.Folder = 19;
  843. CompletionItemKind2.EnumMember = 20;
  844. CompletionItemKind2.Constant = 21;
  845. CompletionItemKind2.Struct = 22;
  846. CompletionItemKind2.Event = 23;
  847. CompletionItemKind2.Operator = 24;
  848. CompletionItemKind2.TypeParameter = 25;
  849. })(CompletionItemKind || (CompletionItemKind = {}));
  850. var InsertTextFormat;
  851. (function(InsertTextFormat2) {
  852. InsertTextFormat2.PlainText = 1;
  853. InsertTextFormat2.Snippet = 2;
  854. })(InsertTextFormat || (InsertTextFormat = {}));
  855. var CompletionItemTag;
  856. (function(CompletionItemTag2) {
  857. CompletionItemTag2.Deprecated = 1;
  858. })(CompletionItemTag || (CompletionItemTag = {}));
  859. var InsertReplaceEdit;
  860. (function(InsertReplaceEdit2) {
  861. function create(newText, insert, replace) {
  862. return { newText, insert, replace };
  863. }
  864. InsertReplaceEdit2.create = create;
  865. function is(value) {
  866. var candidate = value;
  867. return candidate && Is.string(candidate.newText) && Range.is(candidate.insert) && Range.is(candidate.replace);
  868. }
  869. InsertReplaceEdit2.is = is;
  870. })(InsertReplaceEdit || (InsertReplaceEdit = {}));
  871. var InsertTextMode;
  872. (function(InsertTextMode2) {
  873. InsertTextMode2.asIs = 1;
  874. InsertTextMode2.adjustIndentation = 2;
  875. })(InsertTextMode || (InsertTextMode = {}));
  876. var CompletionItem;
  877. (function(CompletionItem2) {
  878. function create(label) {
  879. return { label };
  880. }
  881. CompletionItem2.create = create;
  882. })(CompletionItem || (CompletionItem = {}));
  883. var CompletionList;
  884. (function(CompletionList2) {
  885. function create(items, isIncomplete) {
  886. return { items: items ? items : [], isIncomplete: !!isIncomplete };
  887. }
  888. CompletionList2.create = create;
  889. })(CompletionList || (CompletionList = {}));
  890. var MarkedString;
  891. (function(MarkedString2) {
  892. function fromPlainText(plainText) {
  893. return plainText.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&");
  894. }
  895. MarkedString2.fromPlainText = fromPlainText;
  896. function is(value) {
  897. var candidate = value;
  898. return Is.string(candidate) || Is.objectLiteral(candidate) && Is.string(candidate.language) && Is.string(candidate.value);
  899. }
  900. MarkedString2.is = is;
  901. })(MarkedString || (MarkedString = {}));
  902. var Hover;
  903. (function(Hover2) {
  904. function is(value) {
  905. var candidate = value;
  906. return !!candidate && Is.objectLiteral(candidate) && (MarkupContent.is(candidate.contents) || MarkedString.is(candidate.contents) || Is.typedArray(candidate.contents, MarkedString.is)) && (value.range === void 0 || Range.is(value.range));
  907. }
  908. Hover2.is = is;
  909. })(Hover || (Hover = {}));
  910. var ParameterInformation;
  911. (function(ParameterInformation2) {
  912. function create(label, documentation) {
  913. return documentation ? { label, documentation } : { label };
  914. }
  915. ParameterInformation2.create = create;
  916. })(ParameterInformation || (ParameterInformation = {}));
  917. var SignatureInformation;
  918. (function(SignatureInformation2) {
  919. function create(label, documentation) {
  920. var parameters = [];
  921. for (var _i = 2; _i < arguments.length; _i++) {
  922. parameters[_i - 2] = arguments[_i];
  923. }
  924. var result = { label };
  925. if (Is.defined(documentation)) {
  926. result.documentation = documentation;
  927. }
  928. if (Is.defined(parameters)) {
  929. result.parameters = parameters;
  930. } else {
  931. result.parameters = [];
  932. }
  933. return result;
  934. }
  935. SignatureInformation2.create = create;
  936. })(SignatureInformation || (SignatureInformation = {}));
  937. var DocumentHighlightKind;
  938. (function(DocumentHighlightKind2) {
  939. DocumentHighlightKind2.Text = 1;
  940. DocumentHighlightKind2.Read = 2;
  941. DocumentHighlightKind2.Write = 3;
  942. })(DocumentHighlightKind || (DocumentHighlightKind = {}));
  943. var DocumentHighlight;
  944. (function(DocumentHighlight2) {
  945. function create(range, kind) {
  946. var result = { range };
  947. if (Is.number(kind)) {
  948. result.kind = kind;
  949. }
  950. return result;
  951. }
  952. DocumentHighlight2.create = create;
  953. })(DocumentHighlight || (DocumentHighlight = {}));
  954. var SymbolKind;
  955. (function(SymbolKind2) {
  956. SymbolKind2.File = 1;
  957. SymbolKind2.Module = 2;
  958. SymbolKind2.Namespace = 3;
  959. SymbolKind2.Package = 4;
  960. SymbolKind2.Class = 5;
  961. SymbolKind2.Method = 6;
  962. SymbolKind2.Property = 7;
  963. SymbolKind2.Field = 8;
  964. SymbolKind2.Constructor = 9;
  965. SymbolKind2.Enum = 10;
  966. SymbolKind2.Interface = 11;
  967. SymbolKind2.Function = 12;
  968. SymbolKind2.Variable = 13;
  969. SymbolKind2.Constant = 14;
  970. SymbolKind2.String = 15;
  971. SymbolKind2.Number = 16;
  972. SymbolKind2.Boolean = 17;
  973. SymbolKind2.Array = 18;
  974. SymbolKind2.Object = 19;
  975. SymbolKind2.Key = 20;
  976. SymbolKind2.Null = 21;
  977. SymbolKind2.EnumMember = 22;
  978. SymbolKind2.Struct = 23;
  979. SymbolKind2.Event = 24;
  980. SymbolKind2.Operator = 25;
  981. SymbolKind2.TypeParameter = 26;
  982. })(SymbolKind || (SymbolKind = {}));
  983. var SymbolTag;
  984. (function(SymbolTag2) {
  985. SymbolTag2.Deprecated = 1;
  986. })(SymbolTag || (SymbolTag = {}));
  987. var SymbolInformation;
  988. (function(SymbolInformation2) {
  989. function create(name, kind, range, uri, containerName) {
  990. var result = {
  991. name,
  992. kind,
  993. location: { uri, range }
  994. };
  995. if (containerName) {
  996. result.containerName = containerName;
  997. }
  998. return result;
  999. }
  1000. SymbolInformation2.create = create;
  1001. })(SymbolInformation || (SymbolInformation = {}));
  1002. var DocumentSymbol;
  1003. (function(DocumentSymbol2) {
  1004. function create(name, detail, kind, range, selectionRange, children) {
  1005. var result = {
  1006. name,
  1007. detail,
  1008. kind,
  1009. range,
  1010. selectionRange
  1011. };
  1012. if (children !== void 0) {
  1013. result.children = children;
  1014. }
  1015. return result;
  1016. }
  1017. DocumentSymbol2.create = create;
  1018. function is(value) {
  1019. var candidate = value;
  1020. return candidate && Is.string(candidate.name) && Is.number(candidate.kind) && Range.is(candidate.range) && Range.is(candidate.selectionRange) && (candidate.detail === void 0 || Is.string(candidate.detail)) && (candidate.deprecated === void 0 || Is.boolean(candidate.deprecated)) && (candidate.children === void 0 || Array.isArray(candidate.children)) && (candidate.tags === void 0 || Array.isArray(candidate.tags));
  1021. }
  1022. DocumentSymbol2.is = is;
  1023. })(DocumentSymbol || (DocumentSymbol = {}));
  1024. var CodeActionKind;
  1025. (function(CodeActionKind2) {
  1026. CodeActionKind2.Empty = "";
  1027. CodeActionKind2.QuickFix = "quickfix";
  1028. CodeActionKind2.Refactor = "refactor";
  1029. CodeActionKind2.RefactorExtract = "refactor.extract";
  1030. CodeActionKind2.RefactorInline = "refactor.inline";
  1031. CodeActionKind2.RefactorRewrite = "refactor.rewrite";
  1032. CodeActionKind2.Source = "source";
  1033. CodeActionKind2.SourceOrganizeImports = "source.organizeImports";
  1034. CodeActionKind2.SourceFixAll = "source.fixAll";
  1035. })(CodeActionKind || (CodeActionKind = {}));
  1036. var CodeActionContext;
  1037. (function(CodeActionContext2) {
  1038. function create(diagnostics, only) {
  1039. var result = { diagnostics };
  1040. if (only !== void 0 && only !== null) {
  1041. result.only = only;
  1042. }
  1043. return result;
  1044. }
  1045. CodeActionContext2.create = create;
  1046. function is(value) {
  1047. var candidate = value;
  1048. return Is.defined(candidate) && Is.typedArray(candidate.diagnostics, Diagnostic.is) && (candidate.only === void 0 || Is.typedArray(candidate.only, Is.string));
  1049. }
  1050. CodeActionContext2.is = is;
  1051. })(CodeActionContext || (CodeActionContext = {}));
  1052. var CodeAction;
  1053. (function(CodeAction2) {
  1054. function create(title, kindOrCommandOrEdit, kind) {
  1055. var result = { title };
  1056. var checkKind = true;
  1057. if (typeof kindOrCommandOrEdit === "string") {
  1058. checkKind = false;
  1059. result.kind = kindOrCommandOrEdit;
  1060. } else if (Command.is(kindOrCommandOrEdit)) {
  1061. result.command = kindOrCommandOrEdit;
  1062. } else {
  1063. result.edit = kindOrCommandOrEdit;
  1064. }
  1065. if (checkKind && kind !== void 0) {
  1066. result.kind = kind;
  1067. }
  1068. return result;
  1069. }
  1070. CodeAction2.create = create;
  1071. function is(value) {
  1072. var candidate = value;
  1073. return candidate && Is.string(candidate.title) && (candidate.diagnostics === void 0 || Is.typedArray(candidate.diagnostics, Diagnostic.is)) && (candidate.kind === void 0 || Is.string(candidate.kind)) && (candidate.edit !== void 0 || candidate.command !== void 0) && (candidate.command === void 0 || Command.is(candidate.command)) && (candidate.isPreferred === void 0 || Is.boolean(candidate.isPreferred)) && (candidate.edit === void 0 || WorkspaceEdit.is(candidate.edit));
  1074. }
  1075. CodeAction2.is = is;
  1076. })(CodeAction || (CodeAction = {}));
  1077. var CodeLens;
  1078. (function(CodeLens2) {
  1079. function create(range, data) {
  1080. var result = { range };
  1081. if (Is.defined(data)) {
  1082. result.data = data;
  1083. }
  1084. return result;
  1085. }
  1086. CodeLens2.create = create;
  1087. function is(value) {
  1088. var candidate = value;
  1089. return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command));
  1090. }
  1091. CodeLens2.is = is;
  1092. })(CodeLens || (CodeLens = {}));
  1093. var FormattingOptions;
  1094. (function(FormattingOptions2) {
  1095. function create(tabSize, insertSpaces) {
  1096. return { tabSize, insertSpaces };
  1097. }
  1098. FormattingOptions2.create = create;
  1099. function is(value) {
  1100. var candidate = value;
  1101. return Is.defined(candidate) && Is.uinteger(candidate.tabSize) && Is.boolean(candidate.insertSpaces);
  1102. }
  1103. FormattingOptions2.is = is;
  1104. })(FormattingOptions || (FormattingOptions = {}));
  1105. var DocumentLink;
  1106. (function(DocumentLink2) {
  1107. function create(range, target, data) {
  1108. return { range, target, data };
  1109. }
  1110. DocumentLink2.create = create;
  1111. function is(value) {
  1112. var candidate = value;
  1113. return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.target) || Is.string(candidate.target));
  1114. }
  1115. DocumentLink2.is = is;
  1116. })(DocumentLink || (DocumentLink = {}));
  1117. var SelectionRange;
  1118. (function(SelectionRange2) {
  1119. function create(range, parent) {
  1120. return { range, parent };
  1121. }
  1122. SelectionRange2.create = create;
  1123. function is(value) {
  1124. var candidate = value;
  1125. return candidate !== void 0 && Range.is(candidate.range) && (candidate.parent === void 0 || SelectionRange2.is(candidate.parent));
  1126. }
  1127. SelectionRange2.is = is;
  1128. })(SelectionRange || (SelectionRange = {}));
  1129. var TextDocument;
  1130. (function(TextDocument2) {
  1131. function create(uri, languageId, version, content) {
  1132. return new FullTextDocument(uri, languageId, version, content);
  1133. }
  1134. TextDocument2.create = create;
  1135. function is(value) {
  1136. var candidate = value;
  1137. return Is.defined(candidate) && Is.string(candidate.uri) && (Is.undefined(candidate.languageId) || Is.string(candidate.languageId)) && Is.uinteger(candidate.lineCount) && Is.func(candidate.getText) && Is.func(candidate.positionAt) && Is.func(candidate.offsetAt) ? true : false;
  1138. }
  1139. TextDocument2.is = is;
  1140. function applyEdits(document, edits) {
  1141. var text = document.getText();
  1142. var sortedEdits = mergeSort(edits, function(a, b) {
  1143. var diff = a.range.start.line - b.range.start.line;
  1144. if (diff === 0) {
  1145. return a.range.start.character - b.range.start.character;
  1146. }
  1147. return diff;
  1148. });
  1149. var lastModifiedOffset = text.length;
  1150. for (var i = sortedEdits.length - 1; i >= 0; i--) {
  1151. var e = sortedEdits[i];
  1152. var startOffset = document.offsetAt(e.range.start);
  1153. var endOffset = document.offsetAt(e.range.end);
  1154. if (endOffset <= lastModifiedOffset) {
  1155. text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
  1156. } else {
  1157. throw new Error("Overlapping edit");
  1158. }
  1159. lastModifiedOffset = startOffset;
  1160. }
  1161. return text;
  1162. }
  1163. TextDocument2.applyEdits = applyEdits;
  1164. function mergeSort(data, compare) {
  1165. if (data.length <= 1) {
  1166. return data;
  1167. }
  1168. var p = data.length / 2 | 0;
  1169. var left = data.slice(0, p);
  1170. var right = data.slice(p);
  1171. mergeSort(left, compare);
  1172. mergeSort(right, compare);
  1173. var leftIdx = 0;
  1174. var rightIdx = 0;
  1175. var i = 0;
  1176. while (leftIdx < left.length && rightIdx < right.length) {
  1177. var ret = compare(left[leftIdx], right[rightIdx]);
  1178. if (ret <= 0) {
  1179. data[i++] = left[leftIdx++];
  1180. } else {
  1181. data[i++] = right[rightIdx++];
  1182. }
  1183. }
  1184. while (leftIdx < left.length) {
  1185. data[i++] = left[leftIdx++];
  1186. }
  1187. while (rightIdx < right.length) {
  1188. data[i++] = right[rightIdx++];
  1189. }
  1190. return data;
  1191. }
  1192. })(TextDocument || (TextDocument = {}));
  1193. var FullTextDocument = function() {
  1194. function FullTextDocument2(uri, languageId, version, content) {
  1195. this._uri = uri;
  1196. this._languageId = languageId;
  1197. this._version = version;
  1198. this._content = content;
  1199. this._lineOffsets = void 0;
  1200. }
  1201. Object.defineProperty(FullTextDocument2.prototype, "uri", {
  1202. get: function() {
  1203. return this._uri;
  1204. },
  1205. enumerable: false,
  1206. configurable: true
  1207. });
  1208. Object.defineProperty(FullTextDocument2.prototype, "languageId", {
  1209. get: function() {
  1210. return this._languageId;
  1211. },
  1212. enumerable: false,
  1213. configurable: true
  1214. });
  1215. Object.defineProperty(FullTextDocument2.prototype, "version", {
  1216. get: function() {
  1217. return this._version;
  1218. },
  1219. enumerable: false,
  1220. configurable: true
  1221. });
  1222. FullTextDocument2.prototype.getText = function(range) {
  1223. if (range) {
  1224. var start = this.offsetAt(range.start);
  1225. var end = this.offsetAt(range.end);
  1226. return this._content.substring(start, end);
  1227. }
  1228. return this._content;
  1229. };
  1230. FullTextDocument2.prototype.update = function(event, version) {
  1231. this._content = event.text;
  1232. this._version = version;
  1233. this._lineOffsets = void 0;
  1234. };
  1235. FullTextDocument2.prototype.getLineOffsets = function() {
  1236. if (this._lineOffsets === void 0) {
  1237. var lineOffsets = [];
  1238. var text = this._content;
  1239. var isLineStart = true;
  1240. for (var i = 0; i < text.length; i++) {
  1241. if (isLineStart) {
  1242. lineOffsets.push(i);
  1243. isLineStart = false;
  1244. }
  1245. var ch = text.charAt(i);
  1246. isLineStart = ch === "\r" || ch === "\n";
  1247. if (ch === "\r" && i + 1 < text.length && text.charAt(i + 1) === "\n") {
  1248. i++;
  1249. }
  1250. }
  1251. if (isLineStart && text.length > 0) {
  1252. lineOffsets.push(text.length);
  1253. }
  1254. this._lineOffsets = lineOffsets;
  1255. }
  1256. return this._lineOffsets;
  1257. };
  1258. FullTextDocument2.prototype.positionAt = function(offset) {
  1259. offset = Math.max(Math.min(offset, this._content.length), 0);
  1260. var lineOffsets = this.getLineOffsets();
  1261. var low = 0, high = lineOffsets.length;
  1262. if (high === 0) {
  1263. return Position.create(0, offset);
  1264. }
  1265. while (low < high) {
  1266. var mid = Math.floor((low + high) / 2);
  1267. if (lineOffsets[mid] > offset) {
  1268. high = mid;
  1269. } else {
  1270. low = mid + 1;
  1271. }
  1272. }
  1273. var line = low - 1;
  1274. return Position.create(line, offset - lineOffsets[line]);
  1275. };
  1276. FullTextDocument2.prototype.offsetAt = function(position) {
  1277. var lineOffsets = this.getLineOffsets();
  1278. if (position.line >= lineOffsets.length) {
  1279. return this._content.length;
  1280. } else if (position.line < 0) {
  1281. return 0;
  1282. }
  1283. var lineOffset = lineOffsets[position.line];
  1284. var nextLineOffset = position.line + 1 < lineOffsets.length ? lineOffsets[position.line + 1] : this._content.length;
  1285. return Math.max(Math.min(lineOffset + position.character, nextLineOffset), lineOffset);
  1286. };
  1287. Object.defineProperty(FullTextDocument2.prototype, "lineCount", {
  1288. get: function() {
  1289. return this.getLineOffsets().length;
  1290. },
  1291. enumerable: false,
  1292. configurable: true
  1293. });
  1294. return FullTextDocument2;
  1295. }();
  1296. var Is;
  1297. (function(Is2) {
  1298. var toString = Object.prototype.toString;
  1299. function defined(value) {
  1300. return typeof value !== "undefined";
  1301. }
  1302. Is2.defined = defined;
  1303. function undefined2(value) {
  1304. return typeof value === "undefined";
  1305. }
  1306. Is2.undefined = undefined2;
  1307. function boolean(value) {
  1308. return value === true || value === false;
  1309. }
  1310. Is2.boolean = boolean;
  1311. function string(value) {
  1312. return toString.call(value) === "[object String]";
  1313. }
  1314. Is2.string = string;
  1315. function number(value) {
  1316. return toString.call(value) === "[object Number]";
  1317. }
  1318. Is2.number = number;
  1319. function numberRange(value, min, max) {
  1320. return toString.call(value) === "[object Number]" && min <= value && value <= max;
  1321. }
  1322. Is2.numberRange = numberRange;
  1323. function integer2(value) {
  1324. return toString.call(value) === "[object Number]" && -2147483648 <= value && value <= 2147483647;
  1325. }
  1326. Is2.integer = integer2;
  1327. function uinteger2(value) {
  1328. return toString.call(value) === "[object Number]" && 0 <= value && value <= 2147483647;
  1329. }
  1330. Is2.uinteger = uinteger2;
  1331. function func(value) {
  1332. return toString.call(value) === "[object Function]";
  1333. }
  1334. Is2.func = func;
  1335. function objectLiteral(value) {
  1336. return value !== null && typeof value === "object";
  1337. }
  1338. Is2.objectLiteral = objectLiteral;
  1339. function typedArray(value, check) {
  1340. return Array.isArray(value) && value.every(check);
  1341. }
  1342. Is2.typedArray = typedArray;
  1343. })(Is || (Is = {}));
  1344. // src/language/common/lspLanguageFeatures.ts
  1345. var DiagnosticsAdapter = class {
  1346. constructor(_languageId, _worker, configChangeEvent) {
  1347. this._languageId = _languageId;
  1348. this._worker = _worker;
  1349. const onModelAdd = (model) => {
  1350. let modeId = model.getLanguageId();
  1351. if (modeId !== this._languageId) {
  1352. return;
  1353. }
  1354. let handle;
  1355. this._listener[model.uri.toString()] = model.onDidChangeContent(() => {
  1356. window.clearTimeout(handle);
  1357. handle = window.setTimeout(() => this._doValidate(model.uri, modeId), 500);
  1358. });
  1359. this._doValidate(model.uri, modeId);
  1360. };
  1361. const onModelRemoved = (model) => {
  1362. monaco_editor_core_exports.editor.setModelMarkers(model, this._languageId, []);
  1363. let uriStr = model.uri.toString();
  1364. let listener = this._listener[uriStr];
  1365. if (listener) {
  1366. listener.dispose();
  1367. delete this._listener[uriStr];
  1368. }
  1369. };
  1370. this._disposables.push(monaco_editor_core_exports.editor.onDidCreateModel(onModelAdd));
  1371. this._disposables.push(monaco_editor_core_exports.editor.onWillDisposeModel(onModelRemoved));
  1372. this._disposables.push(monaco_editor_core_exports.editor.onDidChangeModelLanguage((event) => {
  1373. onModelRemoved(event.model);
  1374. onModelAdd(event.model);
  1375. }));
  1376. this._disposables.push(configChangeEvent((_) => {
  1377. monaco_editor_core_exports.editor.getModels().forEach((model) => {
  1378. if (model.getLanguageId() === this._languageId) {
  1379. onModelRemoved(model);
  1380. onModelAdd(model);
  1381. }
  1382. });
  1383. }));
  1384. this._disposables.push({
  1385. dispose: () => {
  1386. monaco_editor_core_exports.editor.getModels().forEach(onModelRemoved);
  1387. for (let key in this._listener) {
  1388. this._listener[key].dispose();
  1389. }
  1390. }
  1391. });
  1392. monaco_editor_core_exports.editor.getModels().forEach(onModelAdd);
  1393. }
  1394. _disposables = [];
  1395. _listener = /* @__PURE__ */ Object.create(null);
  1396. dispose() {
  1397. this._disposables.forEach((d) => d && d.dispose());
  1398. this._disposables.length = 0;
  1399. }
  1400. _doValidate(resource, languageId) {
  1401. this._worker(resource).then((worker) => {
  1402. return worker.doValidation(resource.toString());
  1403. }).then((diagnostics) => {
  1404. const markers = diagnostics.map((d) => toDiagnostics(resource, d));
  1405. let model = monaco_editor_core_exports.editor.getModel(resource);
  1406. if (model && model.getLanguageId() === languageId) {
  1407. monaco_editor_core_exports.editor.setModelMarkers(model, languageId, markers);
  1408. }
  1409. }).then(void 0, (err) => {
  1410. console.error(err);
  1411. });
  1412. }
  1413. };
  1414. function toSeverity(lsSeverity) {
  1415. switch (lsSeverity) {
  1416. case DiagnosticSeverity.Error:
  1417. return monaco_editor_core_exports.MarkerSeverity.Error;
  1418. case DiagnosticSeverity.Warning:
  1419. return monaco_editor_core_exports.MarkerSeverity.Warning;
  1420. case DiagnosticSeverity.Information:
  1421. return monaco_editor_core_exports.MarkerSeverity.Info;
  1422. case DiagnosticSeverity.Hint:
  1423. return monaco_editor_core_exports.MarkerSeverity.Hint;
  1424. default:
  1425. return monaco_editor_core_exports.MarkerSeverity.Info;
  1426. }
  1427. }
  1428. function toDiagnostics(resource, diag) {
  1429. let code = typeof diag.code === "number" ? String(diag.code) : diag.code;
  1430. return {
  1431. severity: toSeverity(diag.severity),
  1432. startLineNumber: diag.range.start.line + 1,
  1433. startColumn: diag.range.start.character + 1,
  1434. endLineNumber: diag.range.end.line + 1,
  1435. endColumn: diag.range.end.character + 1,
  1436. message: diag.message,
  1437. code,
  1438. source: diag.source
  1439. };
  1440. }
  1441. var CompletionAdapter = class {
  1442. constructor(_worker, _triggerCharacters) {
  1443. this._worker = _worker;
  1444. this._triggerCharacters = _triggerCharacters;
  1445. }
  1446. get triggerCharacters() {
  1447. return this._triggerCharacters;
  1448. }
  1449. provideCompletionItems(model, position, context, token) {
  1450. const resource = model.uri;
  1451. return this._worker(resource).then((worker) => {
  1452. return worker.doComplete(resource.toString(), fromPosition(position));
  1453. }).then((info) => {
  1454. if (!info) {
  1455. return;
  1456. }
  1457. const wordInfo = model.getWordUntilPosition(position);
  1458. const wordRange = new monaco_editor_core_exports.Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn);
  1459. const items = info.items.map((entry) => {
  1460. const item = {
  1461. label: entry.label,
  1462. insertText: entry.insertText || entry.label,
  1463. sortText: entry.sortText,
  1464. filterText: entry.filterText,
  1465. documentation: entry.documentation,
  1466. detail: entry.detail,
  1467. command: toCommand(entry.command),
  1468. range: wordRange,
  1469. kind: toCompletionItemKind(entry.kind)
  1470. };
  1471. if (entry.textEdit) {
  1472. if (isInsertReplaceEdit(entry.textEdit)) {
  1473. item.range = {
  1474. insert: toRange(entry.textEdit.insert),
  1475. replace: toRange(entry.textEdit.replace)
  1476. };
  1477. } else {
  1478. item.range = toRange(entry.textEdit.range);
  1479. }
  1480. item.insertText = entry.textEdit.newText;
  1481. }
  1482. if (entry.additionalTextEdits) {
  1483. item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
  1484. }
  1485. if (entry.insertTextFormat === InsertTextFormat.Snippet) {
  1486. item.insertTextRules = monaco_editor_core_exports.languages.CompletionItemInsertTextRule.InsertAsSnippet;
  1487. }
  1488. return item;
  1489. });
  1490. return {
  1491. isIncomplete: info.isIncomplete,
  1492. suggestions: items
  1493. };
  1494. });
  1495. }
  1496. };
  1497. function fromPosition(position) {
  1498. if (!position) {
  1499. return void 0;
  1500. }
  1501. return { character: position.column - 1, line: position.lineNumber - 1 };
  1502. }
  1503. function fromRange(range) {
  1504. if (!range) {
  1505. return void 0;
  1506. }
  1507. return {
  1508. start: {
  1509. line: range.startLineNumber - 1,
  1510. character: range.startColumn - 1
  1511. },
  1512. end: { line: range.endLineNumber - 1, character: range.endColumn - 1 }
  1513. };
  1514. }
  1515. function toRange(range) {
  1516. if (!range) {
  1517. return void 0;
  1518. }
  1519. return new monaco_editor_core_exports.Range(range.start.line + 1, range.start.character + 1, range.end.line + 1, range.end.character + 1);
  1520. }
  1521. function isInsertReplaceEdit(edit) {
  1522. return typeof edit.insert !== "undefined" && typeof edit.replace !== "undefined";
  1523. }
  1524. function toCompletionItemKind(kind) {
  1525. const mItemKind = monaco_editor_core_exports.languages.CompletionItemKind;
  1526. switch (kind) {
  1527. case CompletionItemKind.Text:
  1528. return mItemKind.Text;
  1529. case CompletionItemKind.Method:
  1530. return mItemKind.Method;
  1531. case CompletionItemKind.Function:
  1532. return mItemKind.Function;
  1533. case CompletionItemKind.Constructor:
  1534. return mItemKind.Constructor;
  1535. case CompletionItemKind.Field:
  1536. return mItemKind.Field;
  1537. case CompletionItemKind.Variable:
  1538. return mItemKind.Variable;
  1539. case CompletionItemKind.Class:
  1540. return mItemKind.Class;
  1541. case CompletionItemKind.Interface:
  1542. return mItemKind.Interface;
  1543. case CompletionItemKind.Module:
  1544. return mItemKind.Module;
  1545. case CompletionItemKind.Property:
  1546. return mItemKind.Property;
  1547. case CompletionItemKind.Unit:
  1548. return mItemKind.Unit;
  1549. case CompletionItemKind.Value:
  1550. return mItemKind.Value;
  1551. case CompletionItemKind.Enum:
  1552. return mItemKind.Enum;
  1553. case CompletionItemKind.Keyword:
  1554. return mItemKind.Keyword;
  1555. case CompletionItemKind.Snippet:
  1556. return mItemKind.Snippet;
  1557. case CompletionItemKind.Color:
  1558. return mItemKind.Color;
  1559. case CompletionItemKind.File:
  1560. return mItemKind.File;
  1561. case CompletionItemKind.Reference:
  1562. return mItemKind.Reference;
  1563. }
  1564. return mItemKind.Property;
  1565. }
  1566. function toTextEdit(textEdit) {
  1567. if (!textEdit) {
  1568. return void 0;
  1569. }
  1570. return {
  1571. range: toRange(textEdit.range),
  1572. text: textEdit.newText
  1573. };
  1574. }
  1575. function toCommand(c) {
  1576. return c && c.command === "editor.action.triggerSuggest" ? { id: c.command, title: c.title, arguments: c.arguments } : void 0;
  1577. }
  1578. var HoverAdapter = class {
  1579. constructor(_worker) {
  1580. this._worker = _worker;
  1581. }
  1582. provideHover(model, position, token) {
  1583. let resource = model.uri;
  1584. return this._worker(resource).then((worker) => {
  1585. return worker.doHover(resource.toString(), fromPosition(position));
  1586. }).then((info) => {
  1587. if (!info) {
  1588. return;
  1589. }
  1590. return {
  1591. range: toRange(info.range),
  1592. contents: toMarkedStringArray(info.contents)
  1593. };
  1594. });
  1595. }
  1596. };
  1597. function isMarkupContent(thing) {
  1598. return thing && typeof thing === "object" && typeof thing.kind === "string";
  1599. }
  1600. function toMarkdownString(entry) {
  1601. if (typeof entry === "string") {
  1602. return {
  1603. value: entry
  1604. };
  1605. }
  1606. if (isMarkupContent(entry)) {
  1607. if (entry.kind === "plaintext") {
  1608. return {
  1609. value: entry.value.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&")
  1610. };
  1611. }
  1612. return {
  1613. value: entry.value
  1614. };
  1615. }
  1616. return { value: "```" + entry.language + "\n" + entry.value + "\n```\n" };
  1617. }
  1618. function toMarkedStringArray(contents) {
  1619. if (!contents) {
  1620. return void 0;
  1621. }
  1622. if (Array.isArray(contents)) {
  1623. return contents.map(toMarkdownString);
  1624. }
  1625. return [toMarkdownString(contents)];
  1626. }
  1627. var DocumentHighlightAdapter = class {
  1628. constructor(_worker) {
  1629. this._worker = _worker;
  1630. }
  1631. provideDocumentHighlights(model, position, token) {
  1632. const resource = model.uri;
  1633. return this._worker(resource).then((worker) => worker.findDocumentHighlights(resource.toString(), fromPosition(position))).then((entries) => {
  1634. if (!entries) {
  1635. return;
  1636. }
  1637. return entries.map((entry) => {
  1638. return {
  1639. range: toRange(entry.range),
  1640. kind: toDocumentHighlightKind(entry.kind)
  1641. };
  1642. });
  1643. });
  1644. }
  1645. };
  1646. function toDocumentHighlightKind(kind) {
  1647. switch (kind) {
  1648. case DocumentHighlightKind.Read:
  1649. return monaco_editor_core_exports.languages.DocumentHighlightKind.Read;
  1650. case DocumentHighlightKind.Write:
  1651. return monaco_editor_core_exports.languages.DocumentHighlightKind.Write;
  1652. case DocumentHighlightKind.Text:
  1653. return monaco_editor_core_exports.languages.DocumentHighlightKind.Text;
  1654. }
  1655. return monaco_editor_core_exports.languages.DocumentHighlightKind.Text;
  1656. }
  1657. var DefinitionAdapter = class {
  1658. constructor(_worker) {
  1659. this._worker = _worker;
  1660. }
  1661. provideDefinition(model, position, token) {
  1662. const resource = model.uri;
  1663. return this._worker(resource).then((worker) => {
  1664. return worker.findDefinition(resource.toString(), fromPosition(position));
  1665. }).then((definition) => {
  1666. if (!definition) {
  1667. return;
  1668. }
  1669. return [toLocation(definition)];
  1670. });
  1671. }
  1672. };
  1673. function toLocation(location) {
  1674. return {
  1675. uri: monaco_editor_core_exports.Uri.parse(location.uri),
  1676. range: toRange(location.range)
  1677. };
  1678. }
  1679. var ReferenceAdapter = class {
  1680. constructor(_worker) {
  1681. this._worker = _worker;
  1682. }
  1683. provideReferences(model, position, context, token) {
  1684. const resource = model.uri;
  1685. return this._worker(resource).then((worker) => {
  1686. return worker.findReferences(resource.toString(), fromPosition(position));
  1687. }).then((entries) => {
  1688. if (!entries) {
  1689. return;
  1690. }
  1691. return entries.map(toLocation);
  1692. });
  1693. }
  1694. };
  1695. var RenameAdapter = class {
  1696. constructor(_worker) {
  1697. this._worker = _worker;
  1698. }
  1699. provideRenameEdits(model, position, newName, token) {
  1700. const resource = model.uri;
  1701. return this._worker(resource).then((worker) => {
  1702. return worker.doRename(resource.toString(), fromPosition(position), newName);
  1703. }).then((edit) => {
  1704. return toWorkspaceEdit(edit);
  1705. });
  1706. }
  1707. };
  1708. function toWorkspaceEdit(edit) {
  1709. if (!edit || !edit.changes) {
  1710. return void 0;
  1711. }
  1712. let resourceEdits = [];
  1713. for (let uri in edit.changes) {
  1714. const _uri = monaco_editor_core_exports.Uri.parse(uri);
  1715. for (let e of edit.changes[uri]) {
  1716. resourceEdits.push({
  1717. resource: _uri,
  1718. versionId: void 0,
  1719. textEdit: {
  1720. range: toRange(e.range),
  1721. text: e.newText
  1722. }
  1723. });
  1724. }
  1725. }
  1726. return {
  1727. edits: resourceEdits
  1728. };
  1729. }
  1730. var DocumentSymbolAdapter = class {
  1731. constructor(_worker) {
  1732. this._worker = _worker;
  1733. }
  1734. provideDocumentSymbols(model, token) {
  1735. const resource = model.uri;
  1736. return this._worker(resource).then((worker) => worker.findDocumentSymbols(resource.toString())).then((items) => {
  1737. if (!items) {
  1738. return;
  1739. }
  1740. return items.map((item) => ({
  1741. name: item.name,
  1742. detail: "",
  1743. containerName: item.containerName,
  1744. kind: toSymbolKind(item.kind),
  1745. range: toRange(item.location.range),
  1746. selectionRange: toRange(item.location.range),
  1747. tags: []
  1748. }));
  1749. });
  1750. }
  1751. };
  1752. function toSymbolKind(kind) {
  1753. let mKind = monaco_editor_core_exports.languages.SymbolKind;
  1754. switch (kind) {
  1755. case SymbolKind.File:
  1756. return mKind.Array;
  1757. case SymbolKind.Module:
  1758. return mKind.Module;
  1759. case SymbolKind.Namespace:
  1760. return mKind.Namespace;
  1761. case SymbolKind.Package:
  1762. return mKind.Package;
  1763. case SymbolKind.Class:
  1764. return mKind.Class;
  1765. case SymbolKind.Method:
  1766. return mKind.Method;
  1767. case SymbolKind.Property:
  1768. return mKind.Property;
  1769. case SymbolKind.Field:
  1770. return mKind.Field;
  1771. case SymbolKind.Constructor:
  1772. return mKind.Constructor;
  1773. case SymbolKind.Enum:
  1774. return mKind.Enum;
  1775. case SymbolKind.Interface:
  1776. return mKind.Interface;
  1777. case SymbolKind.Function:
  1778. return mKind.Function;
  1779. case SymbolKind.Variable:
  1780. return mKind.Variable;
  1781. case SymbolKind.Constant:
  1782. return mKind.Constant;
  1783. case SymbolKind.String:
  1784. return mKind.String;
  1785. case SymbolKind.Number:
  1786. return mKind.Number;
  1787. case SymbolKind.Boolean:
  1788. return mKind.Boolean;
  1789. case SymbolKind.Array:
  1790. return mKind.Array;
  1791. }
  1792. return mKind.Function;
  1793. }
  1794. var DocumentLinkAdapter = class {
  1795. constructor(_worker) {
  1796. this._worker = _worker;
  1797. }
  1798. provideLinks(model, token) {
  1799. const resource = model.uri;
  1800. return this._worker(resource).then((worker) => worker.findDocumentLinks(resource.toString())).then((items) => {
  1801. if (!items) {
  1802. return;
  1803. }
  1804. return {
  1805. links: items.map((item) => ({
  1806. range: toRange(item.range),
  1807. url: item.target
  1808. }))
  1809. };
  1810. });
  1811. }
  1812. };
  1813. var DocumentFormattingEditProvider = class {
  1814. constructor(_worker) {
  1815. this._worker = _worker;
  1816. }
  1817. provideDocumentFormattingEdits(model, options, token) {
  1818. const resource = model.uri;
  1819. return this._worker(resource).then((worker) => {
  1820. return worker.format(resource.toString(), null, fromFormattingOptions(options)).then((edits) => {
  1821. if (!edits || edits.length === 0) {
  1822. return;
  1823. }
  1824. return edits.map(toTextEdit);
  1825. });
  1826. });
  1827. }
  1828. };
  1829. var DocumentRangeFormattingEditProvider = class {
  1830. constructor(_worker) {
  1831. this._worker = _worker;
  1832. }
  1833. provideDocumentRangeFormattingEdits(model, range, options, token) {
  1834. const resource = model.uri;
  1835. return this._worker(resource).then((worker) => {
  1836. return worker.format(resource.toString(), fromRange(range), fromFormattingOptions(options)).then((edits) => {
  1837. if (!edits || edits.length === 0) {
  1838. return;
  1839. }
  1840. return edits.map(toTextEdit);
  1841. });
  1842. });
  1843. }
  1844. };
  1845. function fromFormattingOptions(options) {
  1846. return {
  1847. tabSize: options.tabSize,
  1848. insertSpaces: options.insertSpaces
  1849. };
  1850. }
  1851. var DocumentColorAdapter = class {
  1852. constructor(_worker) {
  1853. this._worker = _worker;
  1854. }
  1855. provideDocumentColors(model, token) {
  1856. const resource = model.uri;
  1857. return this._worker(resource).then((worker) => worker.findDocumentColors(resource.toString())).then((infos) => {
  1858. if (!infos) {
  1859. return;
  1860. }
  1861. return infos.map((item) => ({
  1862. color: item.color,
  1863. range: toRange(item.range)
  1864. }));
  1865. });
  1866. }
  1867. provideColorPresentations(model, info, token) {
  1868. const resource = model.uri;
  1869. return this._worker(resource).then((worker) => worker.getColorPresentations(resource.toString(), info.color, fromRange(info.range))).then((presentations) => {
  1870. if (!presentations) {
  1871. return;
  1872. }
  1873. return presentations.map((presentation) => {
  1874. let item = {
  1875. label: presentation.label
  1876. };
  1877. if (presentation.textEdit) {
  1878. item.textEdit = toTextEdit(presentation.textEdit);
  1879. }
  1880. if (presentation.additionalTextEdits) {
  1881. item.additionalTextEdits = presentation.additionalTextEdits.map(toTextEdit);
  1882. }
  1883. return item;
  1884. });
  1885. });
  1886. }
  1887. };
  1888. var FoldingRangeAdapter = class {
  1889. constructor(_worker) {
  1890. this._worker = _worker;
  1891. }
  1892. provideFoldingRanges(model, context, token) {
  1893. const resource = model.uri;
  1894. return this._worker(resource).then((worker) => worker.getFoldingRanges(resource.toString(), context)).then((ranges) => {
  1895. if (!ranges) {
  1896. return;
  1897. }
  1898. return ranges.map((range) => {
  1899. const result = {
  1900. start: range.startLine + 1,
  1901. end: range.endLine + 1
  1902. };
  1903. if (typeof range.kind !== "undefined") {
  1904. result.kind = toFoldingRangeKind(range.kind);
  1905. }
  1906. return result;
  1907. });
  1908. });
  1909. }
  1910. };
  1911. function toFoldingRangeKind(kind) {
  1912. switch (kind) {
  1913. case FoldingRangeKind.Comment:
  1914. return monaco_editor_core_exports.languages.FoldingRangeKind.Comment;
  1915. case FoldingRangeKind.Imports:
  1916. return monaco_editor_core_exports.languages.FoldingRangeKind.Imports;
  1917. case FoldingRangeKind.Region:
  1918. return monaco_editor_core_exports.languages.FoldingRangeKind.Region;
  1919. }
  1920. return void 0;
  1921. }
  1922. var SelectionRangeAdapter = class {
  1923. constructor(_worker) {
  1924. this._worker = _worker;
  1925. }
  1926. provideSelectionRanges(model, positions, token) {
  1927. const resource = model.uri;
  1928. return this._worker(resource).then((worker) => worker.getSelectionRanges(resource.toString(), positions.map(fromPosition))).then((selectionRanges) => {
  1929. if (!selectionRanges) {
  1930. return;
  1931. }
  1932. return selectionRanges.map((selectionRange) => {
  1933. const result = [];
  1934. while (selectionRange) {
  1935. result.push({ range: toRange(selectionRange.range) });
  1936. selectionRange = selectionRange.parent;
  1937. }
  1938. return result;
  1939. });
  1940. });
  1941. }
  1942. };
  1943. // src/language/css/cssMode.ts
  1944. function setupMode(defaults) {
  1945. const disposables = [];
  1946. const providers = [];
  1947. const client = new WorkerManager(defaults);
  1948. disposables.push(client);
  1949. const worker = (...uris) => {
  1950. return client.getLanguageServiceWorker(...uris);
  1951. };
  1952. function registerProviders() {
  1953. const { languageId, modeConfiguration } = defaults;
  1954. disposeAll(providers);
  1955. if (modeConfiguration.completionItems) {
  1956. providers.push(monaco_editor_core_exports.languages.registerCompletionItemProvider(languageId, new CompletionAdapter(worker, ["/", "-", ":"])));
  1957. }
  1958. if (modeConfiguration.hovers) {
  1959. providers.push(monaco_editor_core_exports.languages.registerHoverProvider(languageId, new HoverAdapter(worker)));
  1960. }
  1961. if (modeConfiguration.documentHighlights) {
  1962. providers.push(monaco_editor_core_exports.languages.registerDocumentHighlightProvider(languageId, new DocumentHighlightAdapter(worker)));
  1963. }
  1964. if (modeConfiguration.definitions) {
  1965. providers.push(monaco_editor_core_exports.languages.registerDefinitionProvider(languageId, new DefinitionAdapter(worker)));
  1966. }
  1967. if (modeConfiguration.references) {
  1968. providers.push(monaco_editor_core_exports.languages.registerReferenceProvider(languageId, new ReferenceAdapter(worker)));
  1969. }
  1970. if (modeConfiguration.documentSymbols) {
  1971. providers.push(monaco_editor_core_exports.languages.registerDocumentSymbolProvider(languageId, new DocumentSymbolAdapter(worker)));
  1972. }
  1973. if (modeConfiguration.rename) {
  1974. providers.push(monaco_editor_core_exports.languages.registerRenameProvider(languageId, new RenameAdapter(worker)));
  1975. }
  1976. if (modeConfiguration.colors) {
  1977. providers.push(monaco_editor_core_exports.languages.registerColorProvider(languageId, new DocumentColorAdapter(worker)));
  1978. }
  1979. if (modeConfiguration.foldingRanges) {
  1980. providers.push(monaco_editor_core_exports.languages.registerFoldingRangeProvider(languageId, new FoldingRangeAdapter(worker)));
  1981. }
  1982. if (modeConfiguration.diagnostics) {
  1983. providers.push(new DiagnosticsAdapter(languageId, worker, defaults.onDidChange));
  1984. }
  1985. if (modeConfiguration.selectionRanges) {
  1986. providers.push(monaco_editor_core_exports.languages.registerSelectionRangeProvider(languageId, new SelectionRangeAdapter(worker)));
  1987. }
  1988. if (modeConfiguration.documentFormattingEdits) {
  1989. providers.push(monaco_editor_core_exports.languages.registerDocumentFormattingEditProvider(languageId, new DocumentFormattingEditProvider(worker)));
  1990. }
  1991. if (modeConfiguration.documentRangeFormattingEdits) {
  1992. providers.push(monaco_editor_core_exports.languages.registerDocumentRangeFormattingEditProvider(languageId, new DocumentRangeFormattingEditProvider(worker)));
  1993. }
  1994. }
  1995. registerProviders();
  1996. disposables.push(asDisposable(providers));
  1997. return asDisposable(disposables);
  1998. }
  1999. function asDisposable(disposables) {
  2000. return { dispose: () => disposeAll(disposables) };
  2001. }
  2002. function disposeAll(disposables) {
  2003. while (disposables.length) {
  2004. disposables.pop().dispose();
  2005. }
  2006. }
  2007. export {
  2008. CompletionAdapter,
  2009. DefinitionAdapter,
  2010. DiagnosticsAdapter,
  2011. DocumentColorAdapter,
  2012. DocumentFormattingEditProvider,
  2013. DocumentHighlightAdapter,
  2014. DocumentLinkAdapter,
  2015. DocumentRangeFormattingEditProvider,
  2016. DocumentSymbolAdapter,
  2017. FoldingRangeAdapter,
  2018. HoverAdapter,
  2019. ReferenceAdapter,
  2020. RenameAdapter,
  2021. SelectionRangeAdapter,
  2022. WorkerManager,
  2023. fromPosition,
  2024. fromRange,
  2025. setupMode,
  2026. toRange,
  2027. toTextEdit
  2028. };