cssMode.js 68 KB

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