cssMode.js 70 KB

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