cssMode.js 65 KB

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