htmlMode.js 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051
  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/html/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/html/htmlWorker",
  67. createData: {
  68. languageSettings: this._defaults.options,
  69. languageId: this._defaults.languageId
  70. },
  71. label: this._defaults.languageId
  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/html/htmlMode.ts
  1945. var HTMLCompletionAdapter = class extends CompletionAdapter {
  1946. constructor(worker) {
  1947. super(worker, [".", ":", "<", '"', "=", "/"]);
  1948. }
  1949. };
  1950. function setupMode1(defaults) {
  1951. const client = new WorkerManager(defaults);
  1952. const worker = (...uris) => {
  1953. return client.getLanguageServiceWorker(...uris);
  1954. };
  1955. let languageId = defaults.languageId;
  1956. monaco_editor_core_exports.languages.registerCompletionItemProvider(languageId, new HTMLCompletionAdapter(worker));
  1957. monaco_editor_core_exports.languages.registerHoverProvider(languageId, new HoverAdapter(worker));
  1958. monaco_editor_core_exports.languages.registerDocumentHighlightProvider(languageId, new DocumentHighlightAdapter(worker));
  1959. monaco_editor_core_exports.languages.registerLinkProvider(languageId, new DocumentLinkAdapter(worker));
  1960. monaco_editor_core_exports.languages.registerFoldingRangeProvider(languageId, new FoldingRangeAdapter(worker));
  1961. monaco_editor_core_exports.languages.registerDocumentSymbolProvider(languageId, new DocumentSymbolAdapter(worker));
  1962. monaco_editor_core_exports.languages.registerSelectionRangeProvider(languageId, new SelectionRangeAdapter(worker));
  1963. monaco_editor_core_exports.languages.registerRenameProvider(languageId, new RenameAdapter(worker));
  1964. if (languageId === "html") {
  1965. monaco_editor_core_exports.languages.registerDocumentFormattingEditProvider(languageId, new DocumentFormattingEditProvider(worker));
  1966. monaco_editor_core_exports.languages.registerDocumentRangeFormattingEditProvider(languageId, new DocumentRangeFormattingEditProvider(worker));
  1967. }
  1968. }
  1969. function setupMode(defaults) {
  1970. const disposables = [];
  1971. const providers = [];
  1972. const client = new WorkerManager(defaults);
  1973. disposables.push(client);
  1974. const worker = (...uris) => {
  1975. return client.getLanguageServiceWorker(...uris);
  1976. };
  1977. function registerProviders() {
  1978. const { languageId, modeConfiguration } = defaults;
  1979. disposeAll(providers);
  1980. if (modeConfiguration.completionItems) {
  1981. providers.push(monaco_editor_core_exports.languages.registerCompletionItemProvider(languageId, new HTMLCompletionAdapter(worker)));
  1982. }
  1983. if (modeConfiguration.hovers) {
  1984. providers.push(monaco_editor_core_exports.languages.registerHoverProvider(languageId, new HoverAdapter(worker)));
  1985. }
  1986. if (modeConfiguration.documentHighlights) {
  1987. providers.push(monaco_editor_core_exports.languages.registerDocumentHighlightProvider(languageId, new DocumentHighlightAdapter(worker)));
  1988. }
  1989. if (modeConfiguration.links) {
  1990. providers.push(monaco_editor_core_exports.languages.registerLinkProvider(languageId, new DocumentLinkAdapter(worker)));
  1991. }
  1992. if (modeConfiguration.documentSymbols) {
  1993. providers.push(monaco_editor_core_exports.languages.registerDocumentSymbolProvider(languageId, new DocumentSymbolAdapter(worker)));
  1994. }
  1995. if (modeConfiguration.rename) {
  1996. providers.push(monaco_editor_core_exports.languages.registerRenameProvider(languageId, new RenameAdapter(worker)));
  1997. }
  1998. if (modeConfiguration.foldingRanges) {
  1999. providers.push(monaco_editor_core_exports.languages.registerFoldingRangeProvider(languageId, new FoldingRangeAdapter(worker)));
  2000. }
  2001. if (modeConfiguration.selectionRanges) {
  2002. providers.push(monaco_editor_core_exports.languages.registerSelectionRangeProvider(languageId, new SelectionRangeAdapter(worker)));
  2003. }
  2004. if (modeConfiguration.documentFormattingEdits) {
  2005. providers.push(monaco_editor_core_exports.languages.registerDocumentFormattingEditProvider(languageId, new DocumentFormattingEditProvider(worker)));
  2006. }
  2007. if (modeConfiguration.documentRangeFormattingEdits) {
  2008. providers.push(monaco_editor_core_exports.languages.registerDocumentRangeFormattingEditProvider(languageId, new DocumentRangeFormattingEditProvider(worker)));
  2009. }
  2010. }
  2011. registerProviders();
  2012. disposables.push(asDisposable(providers));
  2013. return asDisposable(disposables);
  2014. }
  2015. function asDisposable(disposables) {
  2016. return { dispose: () => disposeAll(disposables) };
  2017. }
  2018. function disposeAll(disposables) {
  2019. while (disposables.length) {
  2020. disposables.pop().dispose();
  2021. }
  2022. }
  2023. export {
  2024. CompletionAdapter,
  2025. DefinitionAdapter,
  2026. DiagnosticsAdapter,
  2027. DocumentColorAdapter,
  2028. DocumentFormattingEditProvider,
  2029. DocumentHighlightAdapter,
  2030. DocumentLinkAdapter,
  2031. DocumentRangeFormattingEditProvider,
  2032. DocumentSymbolAdapter,
  2033. FoldingRangeAdapter,
  2034. HoverAdapter,
  2035. ReferenceAdapter,
  2036. RenameAdapter,
  2037. SelectionRangeAdapter,
  2038. WorkerManager,
  2039. fromPosition,
  2040. fromRange,
  2041. setupMode,
  2042. setupMode1,
  2043. toRange,
  2044. toTextEdit
  2045. };