cssMode.js 81 KB

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