12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859 |
- define('vs/language/html/workerManager',["require", "exports"], function (require, exports) {
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- var STOP_WHEN_IDLE_FOR = 2 * 60 * 1000; // 2min
- var WorkerManager = /** @class */ (function () {
- function WorkerManager(defaults) {
- var _this = this;
- this._defaults = defaults;
- this._worker = null;
- this._idleCheckInterval = setInterval(function () { return _this._checkIfIdle(); }, 30 * 1000);
- this._lastUsedTime = 0;
- this._configChangeListener = this._defaults.onDidChange(function () { return _this._stopWorker(); });
- }
- WorkerManager.prototype._stopWorker = function () {
- if (this._worker) {
- this._worker.dispose();
- this._worker = null;
- }
- this._client = null;
- };
- WorkerManager.prototype.dispose = function () {
- clearInterval(this._idleCheckInterval);
- this._configChangeListener.dispose();
- this._stopWorker();
- };
- WorkerManager.prototype._checkIfIdle = function () {
- if (!this._worker) {
- return;
- }
- var timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
- if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
- this._stopWorker();
- }
- };
- WorkerManager.prototype._getClient = function () {
- this._lastUsedTime = Date.now();
- if (!this._client) {
- this._worker = monaco.editor.createWebWorker({
- // module that exports the create() method and returns a `HTMLWorker` instance
- moduleId: 'vs/language/html/htmlWorker',
- // passed in to the create() method
- createData: {
- languageSettings: this._defaults.options,
- languageId: this._defaults.languageId
- },
- label: this._defaults.languageId
- });
- this._client = this._worker.getProxy();
- }
- return this._client;
- };
- WorkerManager.prototype.getLanguageServiceWorker = function () {
- var _this = this;
- var resources = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- resources[_i] = arguments[_i];
- }
- var _client;
- return this._getClient().then(function (client) {
- _client = client;
- }).then(function (_) {
- return _this._worker.withSyncedResources(resources);
- }).then(function (_) { return _client; });
- };
- return WorkerManager;
- }());
- exports.WorkerManager = WorkerManager;
- });
- (function (factory) {
- if (typeof module === "object" && typeof module.exports === "object") {
- var v = factory(require, exports);
- if (v !== undefined) module.exports = v;
- }
- else if (typeof define === "function" && define.amd) {
- define('vscode-languageserver-types/main',["require", "exports"], factory);
- }
- })(function (require, exports) {
- /* --------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- * ------------------------------------------------------------------------------------------ */
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- /**
- * The Position namespace provides helper functions to work with
- * [Position](#Position) literals.
- */
- var Position;
- (function (Position) {
- /**
- * Creates a new Position literal from the given line and character.
- * @param line The position's line.
- * @param character The position's character.
- */
- function create(line, character) {
- return { line: line, character: character };
- }
- Position.create = create;
- /**
- * Checks whether the given liternal conforms to the [Position](#Position) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.objectLiteral(candidate) && Is.number(candidate.line) && Is.number(candidate.character);
- }
- Position.is = is;
- })(Position = exports.Position || (exports.Position = {}));
- /**
- * The Range namespace provides helper functions to work with
- * [Range](#Range) literals.
- */
- var Range;
- (function (Range) {
- function create(one, two, three, four) {
- if (Is.number(one) && Is.number(two) && Is.number(three) && Is.number(four)) {
- return { start: Position.create(one, two), end: Position.create(three, four) };
- }
- else if (Position.is(one) && Position.is(two)) {
- return { start: one, end: two };
- }
- else {
- throw new Error("Range#create called with invalid arguments[" + one + ", " + two + ", " + three + ", " + four + "]");
- }
- }
- Range.create = create;
- /**
- * Checks whether the given literal conforms to the [Range](#Range) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.objectLiteral(candidate) && Position.is(candidate.start) && Position.is(candidate.end);
- }
- Range.is = is;
- })(Range = exports.Range || (exports.Range = {}));
- /**
- * The Location namespace provides helper functions to work with
- * [Location](#Location) literals.
- */
- var Location;
- (function (Location) {
- /**
- * Creates a Location literal.
- * @param uri The location's uri.
- * @param range The location's range.
- */
- function create(uri, range) {
- return { uri: uri, range: range };
- }
- Location.create = create;
- /**
- * Checks whether the given literal conforms to the [Location](#Location) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Range.is(candidate.range) && (Is.string(candidate.uri) || Is.undefined(candidate.uri));
- }
- Location.is = is;
- })(Location = exports.Location || (exports.Location = {}));
- /**
- * The Color namespace provides helper functions to work with
- * [Color](#Color) literals.
- */
- var Color;
- (function (Color) {
- /**
- * Creates a new Color literal.
- */
- function create(red, green, blue, alpha) {
- return {
- red: red,
- green: green,
- blue: blue,
- alpha: alpha,
- };
- }
- Color.create = create;
- /**
- * Checks whether the given literal conforms to the [Color](#Color) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.number(candidate.red)
- && Is.number(candidate.green)
- && Is.number(candidate.blue)
- && Is.number(candidate.alpha);
- }
- Color.is = is;
- })(Color = exports.Color || (exports.Color = {}));
- /**
- * The ColorInformation namespace provides helper functions to work with
- * [ColorInformation](#ColorInformation) literals.
- */
- var ColorInformation;
- (function (ColorInformation) {
- /**
- * Creates a new ColorInformation literal.
- */
- function create(range, color) {
- return {
- range: range,
- color: color,
- };
- }
- ColorInformation.create = create;
- /**
- * Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
- */
- function is(value) {
- var candidate = value;
- return Range.is(candidate.range) && Color.is(candidate.color);
- }
- ColorInformation.is = is;
- })(ColorInformation = exports.ColorInformation || (exports.ColorInformation = {}));
- /**
- * The Color namespace provides helper functions to work with
- * [ColorPresentation](#ColorPresentation) literals.
- */
- var ColorPresentation;
- (function (ColorPresentation) {
- /**
- * Creates a new ColorInformation literal.
- */
- function create(label, textEdit, additionalTextEdits) {
- return {
- label: label,
- textEdit: textEdit,
- additionalTextEdits: additionalTextEdits,
- };
- }
- ColorPresentation.create = create;
- /**
- * Checks whether the given literal conforms to the [ColorInformation](#ColorInformation) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.string(candidate.label)
- && (Is.undefined(candidate.textEdit) || TextEdit.is(candidate))
- && (Is.undefined(candidate.additionalTextEdits) || Is.typedArray(candidate.additionalTextEdits, TextEdit.is));
- }
- ColorPresentation.is = is;
- })(ColorPresentation = exports.ColorPresentation || (exports.ColorPresentation = {}));
- /**
- * Enum of known range kinds
- */
- var FoldingRangeKind;
- (function (FoldingRangeKind) {
- /**
- * Folding range for a comment
- */
- FoldingRangeKind["Comment"] = "comment";
- /**
- * Folding range for a imports or includes
- */
- FoldingRangeKind["Imports"] = "imports";
- /**
- * Folding range for a region (e.g. `#region`)
- */
- FoldingRangeKind["Region"] = "region";
- })(FoldingRangeKind = exports.FoldingRangeKind || (exports.FoldingRangeKind = {}));
- /**
- * The folding range namespace provides helper functions to work with
- * [FoldingRange](#FoldingRange) literals.
- */
- var FoldingRange;
- (function (FoldingRange) {
- /**
- * Creates a new FoldingRange literal.
- */
- function create(startLine, endLine, startCharacter, endCharacter, kind) {
- var result = {
- startLine: startLine,
- endLine: endLine
- };
- if (Is.defined(startCharacter)) {
- result.startCharacter = startCharacter;
- }
- if (Is.defined(endCharacter)) {
- result.endCharacter = endCharacter;
- }
- if (Is.defined(kind)) {
- result.kind = kind;
- }
- return result;
- }
- FoldingRange.create = create;
- /**
- * Checks whether the given literal conforms to the [FoldingRange](#FoldingRange) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.number(candidate.startLine) && Is.number(candidate.startLine)
- && (Is.undefined(candidate.startCharacter) || Is.number(candidate.startCharacter))
- && (Is.undefined(candidate.endCharacter) || Is.number(candidate.endCharacter))
- && (Is.undefined(candidate.kind) || Is.string(candidate.kind));
- }
- FoldingRange.is = is;
- })(FoldingRange = exports.FoldingRange || (exports.FoldingRange = {}));
- /**
- * The DiagnosticRelatedInformation namespace provides helper functions to work with
- * [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) literals.
- */
- var DiagnosticRelatedInformation;
- (function (DiagnosticRelatedInformation) {
- /**
- * Creates a new DiagnosticRelatedInformation literal.
- */
- function create(location, message) {
- return {
- location: location,
- message: message
- };
- }
- DiagnosticRelatedInformation.create = create;
- /**
- * Checks whether the given literal conforms to the [DiagnosticRelatedInformation](#DiagnosticRelatedInformation) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Location.is(candidate.location) && Is.string(candidate.message);
- }
- DiagnosticRelatedInformation.is = is;
- })(DiagnosticRelatedInformation = exports.DiagnosticRelatedInformation || (exports.DiagnosticRelatedInformation = {}));
- /**
- * The diagnostic's severity.
- */
- var DiagnosticSeverity;
- (function (DiagnosticSeverity) {
- /**
- * Reports an error.
- */
- DiagnosticSeverity.Error = 1;
- /**
- * Reports a warning.
- */
- DiagnosticSeverity.Warning = 2;
- /**
- * Reports an information.
- */
- DiagnosticSeverity.Information = 3;
- /**
- * Reports a hint.
- */
- DiagnosticSeverity.Hint = 4;
- })(DiagnosticSeverity = exports.DiagnosticSeverity || (exports.DiagnosticSeverity = {}));
- /**
- * The Diagnostic namespace provides helper functions to work with
- * [Diagnostic](#Diagnostic) literals.
- */
- var Diagnostic;
- (function (Diagnostic) {
- /**
- * Creates a new Diagnostic literal.
- */
- function create(range, message, severity, code, source, relatedInformation) {
- var result = { range: range, message: message };
- if (Is.defined(severity)) {
- result.severity = severity;
- }
- if (Is.defined(code)) {
- result.code = code;
- }
- if (Is.defined(source)) {
- result.source = source;
- }
- if (Is.defined(relatedInformation)) {
- result.relatedInformation = relatedInformation;
- }
- return result;
- }
- Diagnostic.create = create;
- /**
- * Checks whether the given literal conforms to the [Diagnostic](#Diagnostic) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate)
- && Range.is(candidate.range)
- && Is.string(candidate.message)
- && (Is.number(candidate.severity) || Is.undefined(candidate.severity))
- && (Is.number(candidate.code) || Is.string(candidate.code) || Is.undefined(candidate.code))
- && (Is.string(candidate.source) || Is.undefined(candidate.source))
- && (Is.undefined(candidate.relatedInformation) || Is.typedArray(candidate.relatedInformation, DiagnosticRelatedInformation.is));
- }
- Diagnostic.is = is;
- })(Diagnostic = exports.Diagnostic || (exports.Diagnostic = {}));
- /**
- * The Command namespace provides helper functions to work with
- * [Command](#Command) literals.
- */
- var Command;
- (function (Command) {
- /**
- * Creates a new Command literal.
- */
- function create(title, command) {
- var args = [];
- for (var _i = 2; _i < arguments.length; _i++) {
- args[_i - 2] = arguments[_i];
- }
- var result = { title: title, command: command };
- if (Is.defined(args) && args.length > 0) {
- result.arguments = args;
- }
- return result;
- }
- Command.create = create;
- /**
- * Checks whether the given literal conforms to the [Command](#Command) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Is.string(candidate.title) && Is.string(candidate.command);
- }
- Command.is = is;
- })(Command = exports.Command || (exports.Command = {}));
- /**
- * The TextEdit namespace provides helper function to create replace,
- * insert and delete edits more easily.
- */
- var TextEdit;
- (function (TextEdit) {
- /**
- * Creates a replace text edit.
- * @param range The range of text to be replaced.
- * @param newText The new text.
- */
- function replace(range, newText) {
- return { range: range, newText: newText };
- }
- TextEdit.replace = replace;
- /**
- * Creates a insert text edit.
- * @param position The position to insert the text at.
- * @param newText The text to be inserted.
- */
- function insert(position, newText) {
- return { range: { start: position, end: position }, newText: newText };
- }
- TextEdit.insert = insert;
- /**
- * Creates a delete text edit.
- * @param range The range of text to be deleted.
- */
- function del(range) {
- return { range: range, newText: '' };
- }
- TextEdit.del = del;
- function is(value) {
- var candidate = value;
- return Is.objectLiteral(candidate)
- && Is.string(candidate.newText)
- && Range.is(candidate.range);
- }
- TextEdit.is = is;
- })(TextEdit = exports.TextEdit || (exports.TextEdit = {}));
- /**
- * The TextDocumentEdit namespace provides helper function to create
- * an edit that manipulates a text document.
- */
- var TextDocumentEdit;
- (function (TextDocumentEdit) {
- /**
- * Creates a new `TextDocumentEdit`
- */
- function create(textDocument, edits) {
- return { textDocument: textDocument, edits: edits };
- }
- TextDocumentEdit.create = create;
- function is(value) {
- var candidate = value;
- return Is.defined(candidate)
- && VersionedTextDocumentIdentifier.is(candidate.textDocument)
- && Array.isArray(candidate.edits);
- }
- TextDocumentEdit.is = is;
- })(TextDocumentEdit = exports.TextDocumentEdit || (exports.TextDocumentEdit = {}));
- var WorkspaceEdit;
- (function (WorkspaceEdit) {
- function is(value) {
- var candidate = value;
- return candidate &&
- (candidate.changes !== void 0 || candidate.documentChanges !== void 0) &&
- (candidate.documentChanges === void 0 || Is.typedArray(candidate.documentChanges, TextDocumentEdit.is));
- }
- WorkspaceEdit.is = is;
- })(WorkspaceEdit = exports.WorkspaceEdit || (exports.WorkspaceEdit = {}));
- var TextEditChangeImpl = /** @class */ (function () {
- function TextEditChangeImpl(edits) {
- this.edits = edits;
- }
- TextEditChangeImpl.prototype.insert = function (position, newText) {
- this.edits.push(TextEdit.insert(position, newText));
- };
- TextEditChangeImpl.prototype.replace = function (range, newText) {
- this.edits.push(TextEdit.replace(range, newText));
- };
- TextEditChangeImpl.prototype.delete = function (range) {
- this.edits.push(TextEdit.del(range));
- };
- TextEditChangeImpl.prototype.add = function (edit) {
- this.edits.push(edit);
- };
- TextEditChangeImpl.prototype.all = function () {
- return this.edits;
- };
- TextEditChangeImpl.prototype.clear = function () {
- this.edits.splice(0, this.edits.length);
- };
- return TextEditChangeImpl;
- }());
- /**
- * A workspace change helps constructing changes to a workspace.
- */
- var WorkspaceChange = /** @class */ (function () {
- function WorkspaceChange(workspaceEdit) {
- var _this = this;
- this._textEditChanges = Object.create(null);
- if (workspaceEdit) {
- this._workspaceEdit = workspaceEdit;
- if (workspaceEdit.documentChanges) {
- workspaceEdit.documentChanges.forEach(function (textDocumentEdit) {
- var textEditChange = new TextEditChangeImpl(textDocumentEdit.edits);
- _this._textEditChanges[textDocumentEdit.textDocument.uri] = textEditChange;
- });
- }
- else if (workspaceEdit.changes) {
- Object.keys(workspaceEdit.changes).forEach(function (key) {
- var textEditChange = new TextEditChangeImpl(workspaceEdit.changes[key]);
- _this._textEditChanges[key] = textEditChange;
- });
- }
- }
- }
- Object.defineProperty(WorkspaceChange.prototype, "edit", {
- /**
- * Returns the underlying [WorkspaceEdit](#WorkspaceEdit) literal
- * use to be returned from a workspace edit operation like rename.
- */
- get: function () {
- return this._workspaceEdit;
- },
- enumerable: true,
- configurable: true
- });
- WorkspaceChange.prototype.getTextEditChange = function (key) {
- if (VersionedTextDocumentIdentifier.is(key)) {
- if (!this._workspaceEdit) {
- this._workspaceEdit = {
- documentChanges: []
- };
- }
- if (!this._workspaceEdit.documentChanges) {
- throw new Error('Workspace edit is not configured for versioned document changes.');
- }
- var textDocument = key;
- var result = this._textEditChanges[textDocument.uri];
- if (!result) {
- var edits = [];
- var textDocumentEdit = {
- textDocument: textDocument,
- edits: edits
- };
- this._workspaceEdit.documentChanges.push(textDocumentEdit);
- result = new TextEditChangeImpl(edits);
- this._textEditChanges[textDocument.uri] = result;
- }
- return result;
- }
- else {
- if (!this._workspaceEdit) {
- this._workspaceEdit = {
- changes: Object.create(null)
- };
- }
- if (!this._workspaceEdit.changes) {
- throw new Error('Workspace edit is not configured for normal text edit changes.');
- }
- var result = this._textEditChanges[key];
- if (!result) {
- var edits = [];
- this._workspaceEdit.changes[key] = edits;
- result = new TextEditChangeImpl(edits);
- this._textEditChanges[key] = result;
- }
- return result;
- }
- };
- return WorkspaceChange;
- }());
- exports.WorkspaceChange = WorkspaceChange;
- /**
- * The TextDocumentIdentifier namespace provides helper functions to work with
- * [TextDocumentIdentifier](#TextDocumentIdentifier) literals.
- */
- var TextDocumentIdentifier;
- (function (TextDocumentIdentifier) {
- /**
- * Creates a new TextDocumentIdentifier literal.
- * @param uri The document's uri.
- */
- function create(uri) {
- return { uri: uri };
- }
- TextDocumentIdentifier.create = create;
- /**
- * Checks whether the given literal conforms to the [TextDocumentIdentifier](#TextDocumentIdentifier) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Is.string(candidate.uri);
- }
- TextDocumentIdentifier.is = is;
- })(TextDocumentIdentifier = exports.TextDocumentIdentifier || (exports.TextDocumentIdentifier = {}));
- /**
- * The VersionedTextDocumentIdentifier namespace provides helper functions to work with
- * [VersionedTextDocumentIdentifier](#VersionedTextDocumentIdentifier) literals.
- */
- var VersionedTextDocumentIdentifier;
- (function (VersionedTextDocumentIdentifier) {
- /**
- * Creates a new VersionedTextDocumentIdentifier literal.
- * @param uri The document's uri.
- * @param uri The document's text.
- */
- function create(uri, version) {
- return { uri: uri, version: version };
- }
- VersionedTextDocumentIdentifier.create = create;
- /**
- * Checks whether the given literal conforms to the [VersionedTextDocumentIdentifier](#VersionedTextDocumentIdentifier) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Is.string(candidate.uri) && Is.number(candidate.version);
- }
- VersionedTextDocumentIdentifier.is = is;
- })(VersionedTextDocumentIdentifier = exports.VersionedTextDocumentIdentifier || (exports.VersionedTextDocumentIdentifier = {}));
- /**
- * The TextDocumentItem namespace provides helper functions to work with
- * [TextDocumentItem](#TextDocumentItem) literals.
- */
- var TextDocumentItem;
- (function (TextDocumentItem) {
- /**
- * Creates a new TextDocumentItem literal.
- * @param uri The document's uri.
- * @param languageId The document's language identifier.
- * @param version The document's version number.
- * @param text The document's text.
- */
- function create(uri, languageId, version, text) {
- return { uri: uri, languageId: languageId, version: version, text: text };
- }
- TextDocumentItem.create = create;
- /**
- * Checks whether the given literal conforms to the [TextDocumentItem](#TextDocumentItem) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Is.string(candidate.uri) && Is.string(candidate.languageId) && Is.number(candidate.version) && Is.string(candidate.text);
- }
- TextDocumentItem.is = is;
- })(TextDocumentItem = exports.TextDocumentItem || (exports.TextDocumentItem = {}));
- /**
- * Describes the content type that a client supports in various
- * result literals like `Hover`, `ParameterInfo` or `CompletionItem`.
- *
- * Please note that `MarkupKinds` must not start with a `$`. This kinds
- * are reserved for internal usage.
- */
- var MarkupKind;
- (function (MarkupKind) {
- /**
- * Plain text is supported as a content format
- */
- MarkupKind.PlainText = 'plaintext';
- /**
- * Markdown is supported as a content format
- */
- MarkupKind.Markdown = 'markdown';
- })(MarkupKind = exports.MarkupKind || (exports.MarkupKind = {}));
- (function (MarkupKind) {
- /**
- * Checks whether the given value is a value of the [MarkupKind](#MarkupKind) type.
- */
- function is(value) {
- var candidate = value;
- return candidate === MarkupKind.PlainText || candidate === MarkupKind.Markdown;
- }
- MarkupKind.is = is;
- })(MarkupKind = exports.MarkupKind || (exports.MarkupKind = {}));
- var MarkupContent;
- (function (MarkupContent) {
- /**
- * Checks whether the given value conforms to the [MarkupContent](#MarkupContent) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.objectLiteral(value) && MarkupKind.is(candidate.kind) && Is.string(candidate.value);
- }
- MarkupContent.is = is;
- })(MarkupContent = exports.MarkupContent || (exports.MarkupContent = {}));
- /**
- * The kind of a completion entry.
- */
- var CompletionItemKind;
- (function (CompletionItemKind) {
- CompletionItemKind.Text = 1;
- CompletionItemKind.Method = 2;
- CompletionItemKind.Function = 3;
- CompletionItemKind.Constructor = 4;
- CompletionItemKind.Field = 5;
- CompletionItemKind.Variable = 6;
- CompletionItemKind.Class = 7;
- CompletionItemKind.Interface = 8;
- CompletionItemKind.Module = 9;
- CompletionItemKind.Property = 10;
- CompletionItemKind.Unit = 11;
- CompletionItemKind.Value = 12;
- CompletionItemKind.Enum = 13;
- CompletionItemKind.Keyword = 14;
- CompletionItemKind.Snippet = 15;
- CompletionItemKind.Color = 16;
- CompletionItemKind.File = 17;
- CompletionItemKind.Reference = 18;
- CompletionItemKind.Folder = 19;
- CompletionItemKind.EnumMember = 20;
- CompletionItemKind.Constant = 21;
- CompletionItemKind.Struct = 22;
- CompletionItemKind.Event = 23;
- CompletionItemKind.Operator = 24;
- CompletionItemKind.TypeParameter = 25;
- })(CompletionItemKind = exports.CompletionItemKind || (exports.CompletionItemKind = {}));
- /**
- * Defines whether the insert text in a completion item should be interpreted as
- * plain text or a snippet.
- */
- var InsertTextFormat;
- (function (InsertTextFormat) {
- /**
- * The primary text to be inserted is treated as a plain string.
- */
- InsertTextFormat.PlainText = 1;
- /**
- * The primary text to be inserted is treated as a snippet.
- *
- * A snippet can define tab stops and placeholders with `$1`, `$2`
- * and `${3:foo}`. `$0` defines the final tab stop, it defaults to
- * the end of the snippet. Placeholders with equal identifiers are linked,
- * that is typing in one will update others too.
- *
- * See also: https://github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/snippet/common/snippet.md
- */
- InsertTextFormat.Snippet = 2;
- })(InsertTextFormat = exports.InsertTextFormat || (exports.InsertTextFormat = {}));
- /**
- * The CompletionItem namespace provides functions to deal with
- * completion items.
- */
- var CompletionItem;
- (function (CompletionItem) {
- /**
- * Create a completion item and seed it with a label.
- * @param label The completion item's label
- */
- function create(label) {
- return { label: label };
- }
- CompletionItem.create = create;
- })(CompletionItem = exports.CompletionItem || (exports.CompletionItem = {}));
- /**
- * The CompletionList namespace provides functions to deal with
- * completion lists.
- */
- var CompletionList;
- (function (CompletionList) {
- /**
- * Creates a new completion list.
- *
- * @param items The completion items.
- * @param isIncomplete The list is not complete.
- */
- function create(items, isIncomplete) {
- return { items: items ? items : [], isIncomplete: !!isIncomplete };
- }
- CompletionList.create = create;
- })(CompletionList = exports.CompletionList || (exports.CompletionList = {}));
- var MarkedString;
- (function (MarkedString) {
- /**
- * Creates a marked string from plain text.
- *
- * @param plainText The plain text.
- */
- function fromPlainText(plainText) {
- return plainText.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&"); // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
- }
- MarkedString.fromPlainText = fromPlainText;
- /**
- * Checks whether the given value conforms to the [MarkedString](#MarkedString) type.
- */
- function is(value) {
- var candidate = value;
- return Is.string(candidate) || (Is.objectLiteral(candidate) && Is.string(candidate.language) && Is.string(candidate.value));
- }
- MarkedString.is = is;
- })(MarkedString = exports.MarkedString || (exports.MarkedString = {}));
- var Hover;
- (function (Hover) {
- /**
- * Checks whether the given value conforms to the [Hover](#Hover) interface.
- */
- function is(value) {
- var candidate = value;
- return 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));
- }
- Hover.is = is;
- })(Hover = exports.Hover || (exports.Hover = {}));
- /**
- * The ParameterInformation namespace provides helper functions to work with
- * [ParameterInformation](#ParameterInformation) literals.
- */
- var ParameterInformation;
- (function (ParameterInformation) {
- /**
- * Creates a new parameter information literal.
- *
- * @param label A label string.
- * @param documentation A doc string.
- */
- function create(label, documentation) {
- return documentation ? { label: label, documentation: documentation } : { label: label };
- }
- ParameterInformation.create = create;
- ;
- })(ParameterInformation = exports.ParameterInformation || (exports.ParameterInformation = {}));
- /**
- * The SignatureInformation namespace provides helper functions to work with
- * [SignatureInformation](#SignatureInformation) literals.
- */
- var SignatureInformation;
- (function (SignatureInformation) {
- function create(label, documentation) {
- var parameters = [];
- for (var _i = 2; _i < arguments.length; _i++) {
- parameters[_i - 2] = arguments[_i];
- }
- var result = { label: label };
- if (Is.defined(documentation)) {
- result.documentation = documentation;
- }
- if (Is.defined(parameters)) {
- result.parameters = parameters;
- }
- else {
- result.parameters = [];
- }
- return result;
- }
- SignatureInformation.create = create;
- })(SignatureInformation = exports.SignatureInformation || (exports.SignatureInformation = {}));
- /**
- * A document highlight kind.
- */
- var DocumentHighlightKind;
- (function (DocumentHighlightKind) {
- /**
- * A textual occurrence.
- */
- DocumentHighlightKind.Text = 1;
- /**
- * Read-access of a symbol, like reading a variable.
- */
- DocumentHighlightKind.Read = 2;
- /**
- * Write-access of a symbol, like writing to a variable.
- */
- DocumentHighlightKind.Write = 3;
- })(DocumentHighlightKind = exports.DocumentHighlightKind || (exports.DocumentHighlightKind = {}));
- /**
- * DocumentHighlight namespace to provide helper functions to work with
- * [DocumentHighlight](#DocumentHighlight) literals.
- */
- var DocumentHighlight;
- (function (DocumentHighlight) {
- /**
- * Create a DocumentHighlight object.
- * @param range The range the highlight applies to.
- */
- function create(range, kind) {
- var result = { range: range };
- if (Is.number(kind)) {
- result.kind = kind;
- }
- return result;
- }
- DocumentHighlight.create = create;
- })(DocumentHighlight = exports.DocumentHighlight || (exports.DocumentHighlight = {}));
- /**
- * A symbol kind.
- */
- var SymbolKind;
- (function (SymbolKind) {
- SymbolKind.File = 1;
- SymbolKind.Module = 2;
- SymbolKind.Namespace = 3;
- SymbolKind.Package = 4;
- SymbolKind.Class = 5;
- SymbolKind.Method = 6;
- SymbolKind.Property = 7;
- SymbolKind.Field = 8;
- SymbolKind.Constructor = 9;
- SymbolKind.Enum = 10;
- SymbolKind.Interface = 11;
- SymbolKind.Function = 12;
- SymbolKind.Variable = 13;
- SymbolKind.Constant = 14;
- SymbolKind.String = 15;
- SymbolKind.Number = 16;
- SymbolKind.Boolean = 17;
- SymbolKind.Array = 18;
- SymbolKind.Object = 19;
- SymbolKind.Key = 20;
- SymbolKind.Null = 21;
- SymbolKind.EnumMember = 22;
- SymbolKind.Struct = 23;
- SymbolKind.Event = 24;
- SymbolKind.Operator = 25;
- SymbolKind.TypeParameter = 26;
- })(SymbolKind = exports.SymbolKind || (exports.SymbolKind = {}));
- var SymbolInformation;
- (function (SymbolInformation) {
- /**
- * Creates a new symbol information literal.
- *
- * @param name The name of the symbol.
- * @param kind The kind of the symbol.
- * @param range The range of the location of the symbol.
- * @param uri The resource of the location of symbol, defaults to the current document.
- * @param containerName The name of the symbol containing the symbol.
- */
- function create(name, kind, range, uri, containerName) {
- var result = {
- name: name,
- kind: kind,
- location: { uri: uri, range: range }
- };
- if (containerName) {
- result.containerName = containerName;
- }
- return result;
- }
- SymbolInformation.create = create;
- })(SymbolInformation = exports.SymbolInformation || (exports.SymbolInformation = {}));
- /**
- * Represents programming constructs like variables, classes, interfaces etc.
- * that appear in a document. Document symbols can be hierarchical and they
- * have two ranges: one that encloses its definition and one that points to
- * its most interesting range, e.g. the range of an identifier.
- */
- var DocumentSymbol = /** @class */ (function () {
- function DocumentSymbol() {
- }
- return DocumentSymbol;
- }());
- exports.DocumentSymbol = DocumentSymbol;
- (function (DocumentSymbol) {
- /**
- * Creates a new symbol information literal.
- *
- * @param name The name of the symbol.
- * @param detail The detail of the symbol.
- * @param kind The kind of the symbol.
- * @param range The range of the symbol.
- * @param selectionRange The selectionRange of the symbol.
- * @param children Children of the symbol.
- */
- function create(name, detail, kind, range, selectionRange, children) {
- var result = {
- name: name,
- detail: detail,
- kind: kind,
- range: range,
- selectionRange: selectionRange
- };
- if (children !== void 0) {
- result.children = children;
- }
- return result;
- }
- DocumentSymbol.create = create;
- /**
- * Checks whether the given literal conforms to the [DocumentSymbol](#DocumentSymbol) interface.
- */
- function is(value) {
- var candidate = value;
- return candidate &&
- Is.string(candidate.name) && Is.string(candidate.detail) && Is.number(candidate.kind) &&
- Range.is(candidate.range) && Range.is(candidate.selectionRange) &&
- (candidate.deprecated === void 0 || Is.boolean(candidate.deprecated)) &&
- (candidate.children === void 0 || Array.isArray(candidate.children));
- }
- DocumentSymbol.is = is;
- })(DocumentSymbol = exports.DocumentSymbol || (exports.DocumentSymbol = {}));
- exports.DocumentSymbol = DocumentSymbol;
- /**
- * A set of predefined code action kinds
- */
- var CodeActionKind;
- (function (CodeActionKind) {
- /**
- * Base kind for quickfix actions: 'quickfix'
- */
- CodeActionKind.QuickFix = 'quickfix';
- /**
- * Base kind for refactoring actions: 'refactor'
- */
- CodeActionKind.Refactor = 'refactor';
- /**
- * Base kind for refactoring extraction actions: 'refactor.extract'
- *
- * Example extract actions:
- *
- * - Extract method
- * - Extract function
- * - Extract variable
- * - Extract interface from class
- * - ...
- */
- CodeActionKind.RefactorExtract = 'refactor.extract';
- /**
- * Base kind for refactoring inline actions: 'refactor.inline'
- *
- * Example inline actions:
- *
- * - Inline function
- * - Inline variable
- * - Inline constant
- * - ...
- */
- CodeActionKind.RefactorInline = 'refactor.inline';
- /**
- * Base kind for refactoring rewrite actions: 'refactor.rewrite'
- *
- * Example rewrite actions:
- *
- * - Convert JavaScript function to class
- * - Add or remove parameter
- * - Encapsulate field
- * - Make method static
- * - Move method to base class
- * - ...
- */
- CodeActionKind.RefactorRewrite = 'refactor.rewrite';
- /**
- * Base kind for source actions: `source`
- *
- * Source code actions apply to the entire file.
- */
- CodeActionKind.Source = 'source';
- /**
- * Base kind for an organize imports source action: `source.organizeImports`
- */
- CodeActionKind.SourceOrganizeImports = 'source.organizeImports';
- })(CodeActionKind = exports.CodeActionKind || (exports.CodeActionKind = {}));
- /**
- * The CodeActionContext namespace provides helper functions to work with
- * [CodeActionContext](#CodeActionContext) literals.
- */
- var CodeActionContext;
- (function (CodeActionContext) {
- /**
- * Creates a new CodeActionContext literal.
- */
- function create(diagnostics, only) {
- var result = { diagnostics: diagnostics };
- if (only !== void 0 && only !== null) {
- result.only = only;
- }
- return result;
- }
- CodeActionContext.create = create;
- /**
- * Checks whether the given literal conforms to the [CodeActionContext](#CodeActionContext) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Is.typedArray(candidate.diagnostics, Diagnostic.is) && (candidate.only === void 0 || Is.typedArray(candidate.only, Is.string));
- }
- CodeActionContext.is = is;
- })(CodeActionContext = exports.CodeActionContext || (exports.CodeActionContext = {}));
- var CodeAction;
- (function (CodeAction) {
- function create(title, commandOrEdit, kind) {
- var result = { title: title };
- if (Command.is(commandOrEdit)) {
- result.command = commandOrEdit;
- }
- else {
- result.edit = commandOrEdit;
- }
- if (kind !== void null) {
- result.kind = kind;
- }
- return result;
- }
- CodeAction.create = create;
- function is(value) {
- var candidate = value;
- 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.edit === void 0 || WorkspaceEdit.is(candidate.edit));
- }
- CodeAction.is = is;
- })(CodeAction = exports.CodeAction || (exports.CodeAction = {}));
- /**
- * The CodeLens namespace provides helper functions to work with
- * [CodeLens](#CodeLens) literals.
- */
- var CodeLens;
- (function (CodeLens) {
- /**
- * Creates a new CodeLens literal.
- */
- function create(range, data) {
- var result = { range: range };
- if (Is.defined(data))
- result.data = data;
- return result;
- }
- CodeLens.create = create;
- /**
- * Checks whether the given literal conforms to the [CodeLens](#CodeLens) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.command) || Command.is(candidate.command));
- }
- CodeLens.is = is;
- })(CodeLens = exports.CodeLens || (exports.CodeLens = {}));
- /**
- * The FormattingOptions namespace provides helper functions to work with
- * [FormattingOptions](#FormattingOptions) literals.
- */
- var FormattingOptions;
- (function (FormattingOptions) {
- /**
- * Creates a new FormattingOptions literal.
- */
- function create(tabSize, insertSpaces) {
- return { tabSize: tabSize, insertSpaces: insertSpaces };
- }
- FormattingOptions.create = create;
- /**
- * Checks whether the given literal conforms to the [FormattingOptions](#FormattingOptions) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Is.number(candidate.tabSize) && Is.boolean(candidate.insertSpaces);
- }
- FormattingOptions.is = is;
- })(FormattingOptions = exports.FormattingOptions || (exports.FormattingOptions = {}));
- /**
- * A document link is a range in a text document that links to an internal or external resource, like another
- * text document or a web site.
- */
- var DocumentLink = /** @class */ (function () {
- function DocumentLink() {
- }
- return DocumentLink;
- }());
- exports.DocumentLink = DocumentLink;
- /**
- * The DocumentLink namespace provides helper functions to work with
- * [DocumentLink](#DocumentLink) literals.
- */
- (function (DocumentLink) {
- /**
- * Creates a new DocumentLink literal.
- */
- function create(range, target, data) {
- return { range: range, target: target, data: data };
- }
- DocumentLink.create = create;
- /**
- * Checks whether the given literal conforms to the [DocumentLink](#DocumentLink) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Range.is(candidate.range) && (Is.undefined(candidate.target) || Is.string(candidate.target));
- }
- DocumentLink.is = is;
- })(DocumentLink = exports.DocumentLink || (exports.DocumentLink = {}));
- exports.DocumentLink = DocumentLink;
- exports.EOL = ['\n', '\r\n', '\r'];
- var TextDocument;
- (function (TextDocument) {
- /**
- * Creates a new ITextDocument literal from the given uri and content.
- * @param uri The document's uri.
- * @param languageId The document's language Id.
- * @param content The document's content.
- */
- function create(uri, languageId, version, content) {
- return new FullTextDocument(uri, languageId, version, content);
- }
- TextDocument.create = create;
- /**
- * Checks whether the given literal conforms to the [ITextDocument](#ITextDocument) interface.
- */
- function is(value) {
- var candidate = value;
- return Is.defined(candidate) && Is.string(candidate.uri) && (Is.undefined(candidate.languageId) || Is.string(candidate.languageId)) && Is.number(candidate.lineCount)
- && Is.func(candidate.getText) && Is.func(candidate.positionAt) && Is.func(candidate.offsetAt) ? true : false;
- }
- TextDocument.is = is;
- function applyEdits(document, edits) {
- var text = document.getText();
- var sortedEdits = mergeSort(edits, function (a, b) {
- var diff = a.range.start.line - b.range.start.line;
- if (diff === 0) {
- return a.range.start.character - b.range.start.character;
- }
- return diff;
- });
- var lastModifiedOffset = text.length;
- for (var i = sortedEdits.length - 1; i >= 0; i--) {
- var e = sortedEdits[i];
- var startOffset = document.offsetAt(e.range.start);
- var endOffset = document.offsetAt(e.range.end);
- if (endOffset <= lastModifiedOffset) {
- text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
- }
- else {
- throw new Error('Ovelapping edit');
- }
- lastModifiedOffset = startOffset;
- }
- return text;
- }
- TextDocument.applyEdits = applyEdits;
- function mergeSort(data, compare) {
- if (data.length <= 1) {
- // sorted
- return data;
- }
- var p = (data.length / 2) | 0;
- var left = data.slice(0, p);
- var right = data.slice(p);
- mergeSort(left, compare);
- mergeSort(right, compare);
- var leftIdx = 0;
- var rightIdx = 0;
- var i = 0;
- while (leftIdx < left.length && rightIdx < right.length) {
- var ret = compare(left[leftIdx], right[rightIdx]);
- if (ret <= 0) {
- // smaller_equal -> take left to preserve order
- data[i++] = left[leftIdx++];
- }
- else {
- // greater -> take right
- data[i++] = right[rightIdx++];
- }
- }
- while (leftIdx < left.length) {
- data[i++] = left[leftIdx++];
- }
- while (rightIdx < right.length) {
- data[i++] = right[rightIdx++];
- }
- return data;
- }
- })(TextDocument = exports.TextDocument || (exports.TextDocument = {}));
- /**
- * Represents reasons why a text document is saved.
- */
- var TextDocumentSaveReason;
- (function (TextDocumentSaveReason) {
- /**
- * Manually triggered, e.g. by the user pressing save, by starting debugging,
- * or by an API call.
- */
- TextDocumentSaveReason.Manual = 1;
- /**
- * Automatic after a delay.
- */
- TextDocumentSaveReason.AfterDelay = 2;
- /**
- * When the editor lost focus.
- */
- TextDocumentSaveReason.FocusOut = 3;
- })(TextDocumentSaveReason = exports.TextDocumentSaveReason || (exports.TextDocumentSaveReason = {}));
- var FullTextDocument = /** @class */ (function () {
- function FullTextDocument(uri, languageId, version, content) {
- this._uri = uri;
- this._languageId = languageId;
- this._version = version;
- this._content = content;
- this._lineOffsets = null;
- }
- Object.defineProperty(FullTextDocument.prototype, "uri", {
- get: function () {
- return this._uri;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(FullTextDocument.prototype, "languageId", {
- get: function () {
- return this._languageId;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(FullTextDocument.prototype, "version", {
- get: function () {
- return this._version;
- },
- enumerable: true,
- configurable: true
- });
- FullTextDocument.prototype.getText = function (range) {
- if (range) {
- var start = this.offsetAt(range.start);
- var end = this.offsetAt(range.end);
- return this._content.substring(start, end);
- }
- return this._content;
- };
- FullTextDocument.prototype.update = function (event, version) {
- this._content = event.text;
- this._version = version;
- this._lineOffsets = null;
- };
- FullTextDocument.prototype.getLineOffsets = function () {
- if (this._lineOffsets === null) {
- var lineOffsets = [];
- var text = this._content;
- var isLineStart = true;
- for (var i = 0; i < text.length; i++) {
- if (isLineStart) {
- lineOffsets.push(i);
- isLineStart = false;
- }
- var ch = text.charAt(i);
- isLineStart = (ch === '\r' || ch === '\n');
- if (ch === '\r' && i + 1 < text.length && text.charAt(i + 1) === '\n') {
- i++;
- }
- }
- if (isLineStart && text.length > 0) {
- lineOffsets.push(text.length);
- }
- this._lineOffsets = lineOffsets;
- }
- return this._lineOffsets;
- };
- FullTextDocument.prototype.positionAt = function (offset) {
- offset = Math.max(Math.min(offset, this._content.length), 0);
- var lineOffsets = this.getLineOffsets();
- var low = 0, high = lineOffsets.length;
- if (high === 0) {
- return Position.create(0, offset);
- }
- while (low < high) {
- var mid = Math.floor((low + high) / 2);
- if (lineOffsets[mid] > offset) {
- high = mid;
- }
- else {
- low = mid + 1;
- }
- }
- // low is the least x for which the line offset is larger than the current offset
- // or array.length if no line offset is larger than the current offset
- var line = low - 1;
- return Position.create(line, offset - lineOffsets[line]);
- };
- FullTextDocument.prototype.offsetAt = function (position) {
- var lineOffsets = this.getLineOffsets();
- if (position.line >= lineOffsets.length) {
- return this._content.length;
- }
- else if (position.line < 0) {
- return 0;
- }
- var lineOffset = lineOffsets[position.line];
- var nextLineOffset = (position.line + 1 < lineOffsets.length) ? lineOffsets[position.line + 1] : this._content.length;
- return Math.max(Math.min(lineOffset + position.character, nextLineOffset), lineOffset);
- };
- Object.defineProperty(FullTextDocument.prototype, "lineCount", {
- get: function () {
- return this.getLineOffsets().length;
- },
- enumerable: true,
- configurable: true
- });
- return FullTextDocument;
- }());
- var Is;
- (function (Is) {
- var toString = Object.prototype.toString;
- function defined(value) {
- return typeof value !== 'undefined';
- }
- Is.defined = defined;
- function undefined(value) {
- return typeof value === 'undefined';
- }
- Is.undefined = undefined;
- function boolean(value) {
- return value === true || value === false;
- }
- Is.boolean = boolean;
- function string(value) {
- return toString.call(value) === '[object String]';
- }
- Is.string = string;
- function number(value) {
- return toString.call(value) === '[object Number]';
- }
- Is.number = number;
- function func(value) {
- return toString.call(value) === '[object Function]';
- }
- Is.func = func;
- function objectLiteral(value) {
- // Strictly speaking class instances pass this check as well. Since the LSP
- // doesn't use classes we ignore this for now. If we do we need to add something
- // like this: `Object.getPrototypeOf(Object.getPrototypeOf(x)) === null`
- return value !== null && typeof value === 'object';
- }
- Is.objectLiteral = objectLiteral;
- function typedArray(value, check) {
- return Array.isArray(value) && value.every(check);
- }
- Is.typedArray = typedArray;
- })(Is || (Is = {}));
- });
- define('vscode-languageserver-types', ['vscode-languageserver-types/main'], function (main) { return main; });
- define('vs/language/html/languageFeatures',["require", "exports", "vscode-languageserver-types"], function (require, exports, ls) {
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- var Range = monaco.Range;
- // --- diagnostics --- ---
- var DiagnosticsAdapter = /** @class */ (function () {
- function DiagnosticsAdapter(_languageId, _worker, defaults) {
- var _this = this;
- this._languageId = _languageId;
- this._worker = _worker;
- this._disposables = [];
- this._listener = Object.create(null);
- var onModelAdd = function (model) {
- var modeId = model.getModeId();
- if (modeId !== _this._languageId) {
- return;
- }
- var handle;
- _this._listener[model.uri.toString()] = model.onDidChangeContent(function () {
- clearTimeout(handle);
- handle = setTimeout(function () { return _this._doValidate(model.uri, modeId); }, 500);
- });
- _this._doValidate(model.uri, modeId);
- };
- var onModelRemoved = function (model) {
- monaco.editor.setModelMarkers(model, _this._languageId, []);
- var uriStr = model.uri.toString();
- var listener = _this._listener[uriStr];
- if (listener) {
- listener.dispose();
- delete _this._listener[uriStr];
- }
- };
- this._disposables.push(monaco.editor.onDidCreateModel(onModelAdd));
- this._disposables.push(monaco.editor.onWillDisposeModel(function (model) {
- onModelRemoved(model);
- }));
- this._disposables.push(monaco.editor.onDidChangeModelLanguage(function (event) {
- onModelRemoved(event.model);
- onModelAdd(event.model);
- }));
- this._disposables.push(defaults.onDidChange(function (_) {
- monaco.editor.getModels().forEach(function (model) {
- if (model.getModeId() === _this._languageId) {
- onModelRemoved(model);
- onModelAdd(model);
- }
- });
- }));
- this._disposables.push({
- dispose: function () {
- for (var key in _this._listener) {
- _this._listener[key].dispose();
- }
- }
- });
- monaco.editor.getModels().forEach(onModelAdd);
- }
- DiagnosticsAdapter.prototype.dispose = function () {
- this._disposables.forEach(function (d) { return d && d.dispose(); });
- this._disposables = [];
- };
- DiagnosticsAdapter.prototype._doValidate = function (resource, languageId) {
- this._worker(resource).then(function (worker) {
- return worker.doValidation(resource.toString()).then(function (diagnostics) {
- var markers = diagnostics.map(function (d) { return toDiagnostics(resource, d); });
- monaco.editor.setModelMarkers(monaco.editor.getModel(resource), languageId, markers);
- });
- }).then(undefined, function (err) {
- console.error(err);
- });
- };
- return DiagnosticsAdapter;
- }());
- exports.DiagnosticsAdapter = DiagnosticsAdapter;
- function toSeverity(lsSeverity) {
- switch (lsSeverity) {
- case ls.DiagnosticSeverity.Error: return monaco.MarkerSeverity.Error;
- case ls.DiagnosticSeverity.Warning: return monaco.MarkerSeverity.Warning;
- case ls.DiagnosticSeverity.Information: return monaco.MarkerSeverity.Info;
- case ls.DiagnosticSeverity.Hint: return monaco.MarkerSeverity.Hint;
- default:
- return monaco.MarkerSeverity.Info;
- }
- }
- function toDiagnostics(resource, diag) {
- var code = typeof diag.code === 'number' ? String(diag.code) : diag.code;
- return {
- severity: toSeverity(diag.severity),
- startLineNumber: diag.range.start.line + 1,
- startColumn: diag.range.start.character + 1,
- endLineNumber: diag.range.end.line + 1,
- endColumn: diag.range.end.character + 1,
- message: diag.message,
- code: code,
- source: diag.source
- };
- }
- // --- completion ------
- function fromPosition(position) {
- if (!position) {
- return void 0;
- }
- return { character: position.column - 1, line: position.lineNumber - 1 };
- }
- function fromRange(range) {
- if (!range) {
- return void 0;
- }
- return { start: fromPosition(range.getStartPosition()), end: fromPosition(range.getEndPosition()) };
- }
- function toRange(range) {
- if (!range) {
- return void 0;
- }
- return new Range(range.start.line + 1, range.start.character + 1, range.end.line + 1, range.end.character + 1);
- }
- function toCompletionItemKind(kind) {
- var mItemKind = monaco.languages.CompletionItemKind;
- switch (kind) {
- case ls.CompletionItemKind.Text: return mItemKind.Text;
- case ls.CompletionItemKind.Method: return mItemKind.Method;
- case ls.CompletionItemKind.Function: return mItemKind.Function;
- case ls.CompletionItemKind.Constructor: return mItemKind.Constructor;
- case ls.CompletionItemKind.Field: return mItemKind.Field;
- case ls.CompletionItemKind.Variable: return mItemKind.Variable;
- case ls.CompletionItemKind.Class: return mItemKind.Class;
- case ls.CompletionItemKind.Interface: return mItemKind.Interface;
- case ls.CompletionItemKind.Module: return mItemKind.Module;
- case ls.CompletionItemKind.Property: return mItemKind.Property;
- case ls.CompletionItemKind.Unit: return mItemKind.Unit;
- case ls.CompletionItemKind.Value: return mItemKind.Value;
- case ls.CompletionItemKind.Enum: return mItemKind.Enum;
- case ls.CompletionItemKind.Keyword: return mItemKind.Keyword;
- case ls.CompletionItemKind.Snippet: return mItemKind.Snippet;
- case ls.CompletionItemKind.Color: return mItemKind.Color;
- case ls.CompletionItemKind.File: return mItemKind.File;
- case ls.CompletionItemKind.Reference: return mItemKind.Reference;
- }
- return mItemKind.Property;
- }
- function fromCompletionItemKind(kind) {
- var mItemKind = monaco.languages.CompletionItemKind;
- switch (kind) {
- case mItemKind.Text: return ls.CompletionItemKind.Text;
- case mItemKind.Method: return ls.CompletionItemKind.Method;
- case mItemKind.Function: return ls.CompletionItemKind.Function;
- case mItemKind.Constructor: return ls.CompletionItemKind.Constructor;
- case mItemKind.Field: return ls.CompletionItemKind.Field;
- case mItemKind.Variable: return ls.CompletionItemKind.Variable;
- case mItemKind.Class: return ls.CompletionItemKind.Class;
- case mItemKind.Interface: return ls.CompletionItemKind.Interface;
- case mItemKind.Module: return ls.CompletionItemKind.Module;
- case mItemKind.Property: return ls.CompletionItemKind.Property;
- case mItemKind.Unit: return ls.CompletionItemKind.Unit;
- case mItemKind.Value: return ls.CompletionItemKind.Value;
- case mItemKind.Enum: return ls.CompletionItemKind.Enum;
- case mItemKind.Keyword: return ls.CompletionItemKind.Keyword;
- case mItemKind.Snippet: return ls.CompletionItemKind.Snippet;
- case mItemKind.Color: return ls.CompletionItemKind.Color;
- case mItemKind.File: return ls.CompletionItemKind.File;
- case mItemKind.Reference: return ls.CompletionItemKind.Reference;
- }
- return ls.CompletionItemKind.Property;
- }
- function toTextEdit(textEdit) {
- if (!textEdit) {
- return void 0;
- }
- return {
- range: toRange(textEdit.range),
- text: textEdit.newText
- };
- }
- var CompletionAdapter = /** @class */ (function () {
- function CompletionAdapter(_worker) {
- this._worker = _worker;
- }
- Object.defineProperty(CompletionAdapter.prototype, "triggerCharacters", {
- get: function () {
- return ['.', ':', '<', '"', '=', '/'];
- },
- enumerable: true,
- configurable: true
- });
- CompletionAdapter.prototype.provideCompletionItems = function (model, position, context, token) {
- var wordInfo = model.getWordUntilPosition(position);
- var resource = model.uri;
- return this._worker(resource).then(function (worker) {
- return worker.doComplete(resource.toString(), fromPosition(position));
- }).then(function (info) {
- if (!info) {
- return;
- }
- var items = info.items.map(function (entry) {
- var item = {
- label: entry.label,
- insertText: entry.insertText || entry.label,
- sortText: entry.sortText,
- filterText: entry.filterText,
- documentation: entry.documentation,
- detail: entry.detail,
- kind: toCompletionItemKind(entry.kind),
- };
- if (entry.textEdit) {
- item.range = toRange(entry.textEdit.range);
- item.insertText = entry.textEdit.newText;
- }
- if (entry.additionalTextEdits) {
- item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
- }
- if (entry.insertTextFormat === ls.InsertTextFormat.Snippet) {
- item.insertTextRules = monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet;
- }
- return item;
- });
- return {
- isIncomplete: info.isIncomplete,
- suggestions: items
- };
- });
- };
- return CompletionAdapter;
- }());
- exports.CompletionAdapter = CompletionAdapter;
- function isMarkupContent(thing) {
- return thing && typeof thing === 'object' && typeof thing.kind === 'string';
- }
- function toMarkdownString(entry) {
- if (typeof entry === 'string') {
- return {
- value: entry
- };
- }
- if (isMarkupContent(entry)) {
- if (entry.kind === 'plaintext') {
- return {
- value: entry.value.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&')
- };
- }
- return {
- value: entry.value
- };
- }
- return { value: '```' + entry.language + '\n' + entry.value + '\n```\n' };
- }
- function toHighlighKind(kind) {
- var mKind = monaco.languages.DocumentHighlightKind;
- switch (kind) {
- case ls.DocumentHighlightKind.Read: return mKind.Read;
- case ls.DocumentHighlightKind.Write: return mKind.Write;
- case ls.DocumentHighlightKind.Text: return mKind.Text;
- }
- return mKind.Text;
- }
- var DocumentHighlightAdapter = /** @class */ (function () {
- function DocumentHighlightAdapter(_worker) {
- this._worker = _worker;
- }
- DocumentHighlightAdapter.prototype.provideDocumentHighlights = function (model, position, token) {
- var resource = model.uri;
- return this._worker(resource).then(function (worker) { return worker.findDocumentHighlights(resource.toString(), fromPosition(position)); }).then(function (items) {
- if (!items) {
- return;
- }
- return items.map(function (item) { return ({
- range: toRange(item.range),
- kind: toHighlighKind(item.kind)
- }); });
- });
- };
- return DocumentHighlightAdapter;
- }());
- exports.DocumentHighlightAdapter = DocumentHighlightAdapter;
- var DocumentLinkAdapter = /** @class */ (function () {
- function DocumentLinkAdapter(_worker) {
- this._worker = _worker;
- }
- DocumentLinkAdapter.prototype.provideLinks = function (model, token) {
- var resource = model.uri;
- return this._worker(resource).then(function (worker) { return worker.findDocumentLinks(resource.toString()); }).then(function (items) {
- if (!items) {
- return;
- }
- return items.map(function (item) { return ({
- range: toRange(item.range),
- url: item.target
- }); });
- });
- };
- return DocumentLinkAdapter;
- }());
- exports.DocumentLinkAdapter = DocumentLinkAdapter;
- function fromFormattingOptions(options) {
- return {
- tabSize: options.tabSize,
- insertSpaces: options.insertSpaces
- };
- }
- var DocumentFormattingEditProvider = /** @class */ (function () {
- function DocumentFormattingEditProvider(_worker) {
- this._worker = _worker;
- }
- DocumentFormattingEditProvider.prototype.provideDocumentFormattingEdits = function (model, options, token) {
- var resource = model.uri;
- return this._worker(resource).then(function (worker) {
- return worker.format(resource.toString(), null, fromFormattingOptions(options)).then(function (edits) {
- if (!edits || edits.length === 0) {
- return;
- }
- return edits.map(toTextEdit);
- });
- });
- };
- return DocumentFormattingEditProvider;
- }());
- exports.DocumentFormattingEditProvider = DocumentFormattingEditProvider;
- var DocumentRangeFormattingEditProvider = /** @class */ (function () {
- function DocumentRangeFormattingEditProvider(_worker) {
- this._worker = _worker;
- }
- DocumentRangeFormattingEditProvider.prototype.provideDocumentRangeFormattingEdits = function (model, range, options, token) {
- var resource = model.uri;
- return this._worker(resource).then(function (worker) {
- return worker.format(resource.toString(), fromRange(range), fromFormattingOptions(options)).then(function (edits) {
- if (!edits || edits.length === 0) {
- return;
- }
- return edits.map(toTextEdit);
- });
- });
- };
- return DocumentRangeFormattingEditProvider;
- }());
- exports.DocumentRangeFormattingEditProvider = DocumentRangeFormattingEditProvider;
- var FoldingRangeAdapter = /** @class */ (function () {
- function FoldingRangeAdapter(_worker) {
- this._worker = _worker;
- }
- FoldingRangeAdapter.prototype.provideFoldingRanges = function (model, context, token) {
- var resource = model.uri;
- return this._worker(resource).then(function (worker) { return worker.provideFoldingRanges(resource.toString(), context); }).then(function (ranges) {
- if (!ranges) {
- return;
- }
- return ranges.map(function (range) {
- var result = {
- start: range.startLine + 1,
- end: range.endLine + 1
- };
- if (typeof range.kind !== 'undefined') {
- result.kind = toFoldingRangeKind(range.kind);
- }
- return result;
- });
- });
- };
- return FoldingRangeAdapter;
- }());
- exports.FoldingRangeAdapter = FoldingRangeAdapter;
- function toFoldingRangeKind(kind) {
- switch (kind) {
- case ls.FoldingRangeKind.Comment: return monaco.languages.FoldingRangeKind.Comment;
- case ls.FoldingRangeKind.Imports: return monaco.languages.FoldingRangeKind.Imports;
- case ls.FoldingRangeKind.Region: return monaco.languages.FoldingRangeKind.Region;
- }
- return void 0;
- }
- });
- define('vs/language/html/htmlMode',["require", "exports", "./workerManager", "./languageFeatures"], function (require, exports, workerManager_1, languageFeatures) {
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- 'use strict';
- Object.defineProperty(exports, "__esModule", { value: true });
- function setupMode(defaults) {
- var client = new workerManager_1.WorkerManager(defaults);
- var worker = function () {
- var uris = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- uris[_i] = arguments[_i];
- }
- return client.getLanguageServiceWorker.apply(client, uris);
- };
- var languageId = defaults.languageId;
- // all modes
- monaco.languages.registerCompletionItemProvider(languageId, new languageFeatures.CompletionAdapter(worker));
- monaco.languages.registerDocumentHighlightProvider(languageId, new languageFeatures.DocumentHighlightAdapter(worker));
- monaco.languages.registerLinkProvider(languageId, new languageFeatures.DocumentLinkAdapter(worker));
- monaco.languages.registerFoldingRangeProvider(languageId, new languageFeatures.FoldingRangeAdapter(worker));
- // only html
- if (languageId === 'html') {
- monaco.languages.registerDocumentFormattingEditProvider(languageId, new languageFeatures.DocumentFormattingEditProvider(worker));
- monaco.languages.registerDocumentRangeFormattingEditProvider(languageId, new languageFeatures.DocumentRangeFormattingEditProvider(worker));
- new languageFeatures.DiagnosticsAdapter(languageId, worker, defaults);
- }
- }
- exports.setupMode = setupMode;
- });
|