UNPKG

@arkts/language-server

Version:
1,533 lines (1,517 loc) 8.46 MB
import { createRequire } from "node:module"; import process$1 from "node:process"; import path, { sep } from "node:path"; import { ProjectDetectorManager, createArkTServices } from "@arkts/language-service"; import { Uri } from "@arkts/project-detector"; import { formatWithOptions } from "node:util"; import { fileURLToPath } from "node:url"; import fs from "node:fs"; //#region rolldown:runtime var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __esm = (fn, res) => function() { return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; }; var __commonJS = (cb, mod) => function() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (all) => { let target = {}; for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); return target; }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i$1 = 0, n$1 = keys.length, key$1; i$1 < n$1; i$1++) { key$1 = keys[i$1]; if (!__hasOwnProp.call(to, key$1) && key$1 !== except) __defProp(to, key$1, { get: ((k) => from[k]).bind(null, key$1), enumerable: !(desc = __getOwnPropDesc(from, key$1)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __require = /* @__PURE__ */ createRequire(import.meta.url); //#endregion //#region ../../node_modules/.pnpm/muggle-string@0.4.1/node_modules/muggle-string/out/binarySearch.js var require_binarySearch$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/muggle-string@0.4.1/node_modules/muggle-string/out/binarySearch.js": ((exports) => { Object.defineProperty(exports, "__esModule", { value: true }); exports.binarySearch = void 0; function binarySearch$2(offsets, start) { let low = 0; let high = offsets.length - 1; while (low <= high) { const mid = Math.floor((low + high) / 2); const midValue = offsets[mid]; if (midValue < start) low = mid + 1; else if (midValue > start) high = mid - 1; else { low = mid; high = mid; break; } } return Math.max(Math.min(low, high, offsets.length - 1), 0); } exports.binarySearch = binarySearch$2; }) }); //#endregion //#region ../../node_modules/.pnpm/muggle-string@0.4.1/node_modules/muggle-string/out/track.js var require_track = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/muggle-string@0.4.1/node_modules/muggle-string/out/track.js": ((exports) => { Object.defineProperty(exports, "__esModule", { value: true }); exports.getStack = exports.track = exports.resetOffsetStack = exports.offsetStack = exports.setTracking = void 0; let tracking = true; let stackOffset = 0; function setTracking(value) { tracking = value; } exports.setTracking = setTracking; function offsetStack() { stackOffset++; } exports.offsetStack = offsetStack; function resetOffsetStack() { stackOffset--; } exports.resetOffsetStack = resetOffsetStack; function track(segments, stacks = []) { return [new Proxy(segments, { get(target, prop, receiver) { if (tracking) { if (prop === "push") return push$1; if (prop === "pop") return pop$1; if (prop === "shift") return shift; if (prop === "unshift") return unshift; if (prop === "splice") return splice; if (prop === "sort") return sort$3; if (prop === "reverse") return reverse; } return Reflect.get(target, prop, receiver); } }), stacks]; function push$1(...items) { stacks.push({ stack: getStack(), length: items.length }); return segments.push(...items); } function pop$1() { if (stacks.length) { const last$1 = stacks[stacks.length - 1]; if (last$1.length > 1) last$1.length--; else stacks.pop(); } return segments.pop(); } function shift() { if (stacks.length) { const first = stacks[0]; if (first.length > 1) first.length--; else stacks.shift(); } return segments.shift(); } function unshift(...items) { stacks.unshift({ stack: getStack(), length: items.length }); return segments.unshift(...items); } function splice(start, deleteCount, ...items) { if (deleteCount === void 0) deleteCount = segments.length - start; let _stackStart = 0; let operateIndex; for (let i$1 = 0; i$1 < stacks.length; i$1++) { const stack$1 = stacks[i$1]; const stackStart = _stackStart; _stackStart = stackStart + stack$1.length; if (start >= stackStart) { operateIndex = i$1 + 1; const originalLength = stack$1.length; stack$1.length = start - stackStart; stacks.splice(operateIndex, 0, { stack: stack$1.stack, length: originalLength - stack$1.length }); break; } } if (operateIndex === void 0) throw new Error("Invalid splice operation"); let _deleteCount = deleteCount; for (let i$1 = operateIndex; i$1 < stacks.length; i$1++) { const stack$1 = stacks[i$1]; while (_deleteCount > 0 && stack$1.length > 0) { stack$1.length--; _deleteCount--; } if (_deleteCount === 0) break; } stacks.splice(operateIndex, 0, { stack: getStack(), length: items.length }); return segments.splice(start, deleteCount, ...items); } function sort$3(compareFn) { stacks.splice(0, stacks.length, { stack: getStack(), length: segments.length }); return segments.sort(compareFn); } function reverse() { stacks.splice(0, stacks.length, { stack: getStack(), length: segments.length }); return segments.reverse(); } } exports.track = track; function getStack() { let source$1 = (/* @__PURE__ */ new Error()).stack.split("\n")[3 + stackOffset].trim(); if (source$1.endsWith(")")) source$1 = source$1.slice(source$1.lastIndexOf("(") + 1, -1); else source$1 = source$1.slice(source$1.lastIndexOf(" ") + 1); return source$1; } exports.getStack = getStack; }) }); //#endregion //#region ../../node_modules/.pnpm/muggle-string@0.4.1/node_modules/muggle-string/out/types.js var require_types$3 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/muggle-string@0.4.1/node_modules/muggle-string/out/types.js": ((exports) => { Object.defineProperty(exports, "__esModule", { value: true }); }) }); //#endregion //#region ../../node_modules/.pnpm/muggle-string@0.4.1/node_modules/muggle-string/out/index.js var require_out$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/muggle-string@0.4.1/node_modules/muggle-string/out/index.js": ((exports) => { var __createBinding$12 = exports && exports.__createBinding || (Object.create ? (function(o$1, m, k, k2) { if (k2 === void 0) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = { enumerable: true, get: function() { return m[k]; } }; Object.defineProperty(o$1, k2, desc); }) : (function(o$1, m, k, k2) { if (k2 === void 0) k2 = k; o$1[k2] = m[k]; })); var __exportStar$12 = exports && exports.__exportStar || function(m, exports$1) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports$1, p)) __createBinding$12(exports$1, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.replaceRange = exports.replaceSourceRange = exports.replaceAll = exports.replace = exports.create = exports.toString = exports.getLength = void 0; const binarySearch_1$1 = require_binarySearch$1(); const track_1 = require_track(); __exportStar$12(require_types$3(), exports); __exportStar$12(require_track(), exports); function getLength(segments) { let length = 0; for (const segment of segments) length += typeof segment == "string" ? segment.length : segment[0].length; return length; } exports.getLength = getLength; function toString$2(segments) { return segments.map((s$1) => typeof s$1 === "string" ? s$1 : s$1[0]).join(""); } exports.toString = toString$2; function create$5(source$1) { return [[ source$1, void 0, 0 ]]; } exports.create = create$5; function replace(segments, pattern, ...replacers) { const match = toString$2(segments).match(pattern); if (match && match.index !== void 0) { const startOffset = match.index; const endOffset = startOffset + match[0].length; (0, track_1.offsetStack)(); replaceRange(segments, startOffset, endOffset, ...replacers.map((replacer) => typeof replacer === "function" ? replacer(match[0]) : replacer)); (0, track_1.resetOffsetStack)(); } } exports.replace = replace; function replaceAll(segments, pattern, ...replacers) { const str = toString$2(segments); const allMatch = str.matchAll(pattern); let length = str.length; let lengthDiff = 0; for (const match of allMatch) if (match.index !== void 0) { const startOffset = match.index + lengthDiff; const endOffset = startOffset + match[0].length; (0, track_1.offsetStack)(); replaceRange(segments, startOffset, endOffset, ...replacers.map((replacer) => typeof replacer === "function" ? replacer(match[0]) : replacer)); (0, track_1.resetOffsetStack)(); const newLength = getLength(segments); lengthDiff += newLength - length; length = newLength; } } exports.replaceAll = replaceAll; function replaceSourceRange(segments, source$1, startOffset, endOffset, ...newSegments) { for (const segment of segments) { if (typeof segment === "string") continue; if (segment[1] === source$1) { const segmentStart = segment[2]; const segmentEnd = segment[2] + segment[0].length; if (segmentStart <= startOffset && segmentEnd >= endOffset) { const inserts = []; if (startOffset > segmentStart) inserts.push(trimSegmentEnd(segment, startOffset - segmentStart)); for (const newSegment of newSegments) inserts.push(newSegment); if (endOffset < segmentEnd) inserts.push(trimSegmentStart(segment, endOffset - segmentEnd)); combineStrings(inserts); (0, track_1.offsetStack)(); segments.splice(segments.indexOf(segment), 1, ...inserts); (0, track_1.resetOffsetStack)(); return true; } } } return false; } exports.replaceSourceRange = replaceSourceRange; function replaceRange(segments, startOffset, endOffset, ...newSegments) { const offsets = toOffsets(segments); const startIndex = (0, binarySearch_1$1.binarySearch)(offsets, startOffset); const endIndex = (0, binarySearch_1$1.binarySearch)(offsets, endOffset); const startSegment = segments[startIndex]; const endSegment = segments[endIndex]; const startSegmentStart = offsets[startIndex]; const endSegmentStart = offsets[endIndex]; const endSegmentEnd = offsets[endIndex] + (typeof endSegment === "string" ? endSegment.length : endSegment[0].length); const inserts = []; if (startOffset > startSegmentStart) inserts.push(trimSegmentEnd(startSegment, startOffset - startSegmentStart)); for (const newSegment of newSegments) inserts.push(newSegment); if (endOffset < endSegmentEnd) inserts.push(trimSegmentStart(endSegment, endOffset - endSegmentStart)); combineStrings(inserts); (0, track_1.offsetStack)(); segments.splice(startIndex, endIndex - startIndex + 1, ...inserts); (0, track_1.resetOffsetStack)(); } exports.replaceRange = replaceRange; function combineStrings(segments) { for (let i$1 = segments.length - 1; i$1 >= 1; i$1--) if (typeof segments[i$1] === "string" && typeof segments[i$1 - 1] === "string") { segments[i$1 - 1] = segments[i$1 - 1] + segments[i$1]; (0, track_1.offsetStack)(); segments.splice(i$1, 1); (0, track_1.resetOffsetStack)(); } } function trimSegmentEnd(segment, trimEnd) { if (typeof segment === "string") return segment.slice(0, trimEnd); return [segment[0].slice(0, trimEnd), ...segment.slice(1)]; } function trimSegmentStart(segment, trimStart) { if (typeof segment === "string") return segment.slice(trimStart); if (trimStart < 0) trimStart += segment[0].length; return [ segment[0].slice(trimStart), segment[1], segment[2] + trimStart, ...segment.slice(3) ]; } function toOffsets(segments) { const offsets = []; let offset = 0; for (const segment of segments) { offsets.push(offset); offset += typeof segment == "string" ? segment.length : segment[0].length; } return offsets; } }) }); //#endregion //#region ../../node_modules/.pnpm/ts-macro@0.3.6/node_modules/ts-macro/dist/index.js var import_out = /* @__PURE__ */ __toESM(require_out$1(), 1); const t$5 = (e, t$6) => (Array.isArray(e) && (typeof e[1] == `number` && e.splice(1, 0, t$6), typeof e.at(-1) != `object` && e.push(l)), e); function n(n$1, r$1, i$1, ...a$1) { return import_out.replaceSourceRange(n$1, void 0, r$1, i$1, ...a$1.map((e) => t$5(e))); } function r(n$1, r$1, i$1, a$1, ...o$1) { return import_out.replaceSourceRange(n$1, r$1, i$1, a$1, ...o$1.map((e) => t$5(e, r$1))); } function i(t$6) { return import_out.toString(t$6); } function a(t$6) { return import_out.getLength(t$6); } function o(n$1, r$1, ...i$1) { return import_out.replace(n$1, r$1, ...i$1.map((e) => typeof e == `function` ? e : t$5(e))); } function s(n$1, r$1, ...i$1) { return import_out.replaceAll(n$1, r$1, ...i$1.map((e) => typeof e == `function` ? e : t$5(e))); } function c$1(e, c$2) { return new Proxy(e, { get: (l$1, u$1, d$1) => u$1 === `replaceRange` ? (t$6, i$1, ...a$1) => c$2 ? r(e, c$2, t$6, i$1, ...a$1) : n(e, t$6, i$1, ...a$1) : u$1 === `replace` ? (t$6, ...n$1) => o(e, t$6, ...n$1) : u$1 === `replaceAll` ? (t$6, ...n$1) => s(e, t$6, ...n$1) : u$1 === `toString` ? () => i(e) : u$1 === `getLength` ? () => a(e) : u$1 === `push` ? (...n$1) => e.push(...n$1.map((e$1) => t$5(e$1, c$2))) : u$1 === `unshift` ? (...n$1) => e.unshift(...n$1.map((e$1) => t$5(e$1, c$2))) : u$1 === `splice` ? (n$1, r$1, ...i$1) => e.splice(n$1, r$1, ...i$1.map((e$1) => t$5(e$1, c$2))) : Reflect.get(l$1, u$1, d$1) }); } const l = { completion: !0, format: !0, navigation: !0, semantic: !0, structure: !0, verification: !0 }; var u = class { id; mappings; embeddedCodes = []; _codes = []; codes = c$1(this._codes); snapshot; source; linkedCodeMappings = []; lang = `tsx`; constructor(e, t$6, n$1 = `typescriptreact`, r$1 = []) { this.filePath = e, this.ast = t$6, this.languageId = n$1, this.plugins = r$1, this.lang = n$1 === `typescriptreact` ? `tsx` : `ts`, this.id = `root_${this.lang}`, this.codes.push([ t$6.text, void 0, 0, l ]); for (let e$1 of this.plugins) try { var _e$resolveVirtualCode; (_e$resolveVirtualCode = e$1.resolveVirtualCode) === null || _e$resolveVirtualCode === void 0 || _e$resolveVirtualCode.call(e$1, this); } catch (t$7) { console.error(`[${e$1.name}]:`, t$7); } this.mappings = d(this.codes); let a$1 = i(this.codes); this.snapshot = { getLength: () => a$1.length, getText: (e$1, t$7) => a$1.slice(e$1, t$7), getChangeRange() {} }; } }; function d(e) { let n$1 = 0, r$1 = []; for (let i$1 of e) typeof i$1 == `string` ? n$1 += i$1.length : (t$5(i$1), r$1.push({ sourceOffsets: [i$1[2]], generatedOffsets: [n$1], lengths: [i$1[0].length], data: i$1[3] }), n$1 += i$1[0].length); return r$1; } //#endregion //#region ../language-plugin/out/index.mjs function $$thisFixerPlugin() { const $$thisRegex = /\$\$this/g; return { name: "ets:$$this-fixer", resolveVirtualCode(virtualCode) { const matches = virtualCode.ast.getText().matchAll($$thisRegex); for (const match of matches) { const start = match.index; const end = start + match[0].length; n(virtualCode.codes, start, end, [ "this", match[0], start + 2, { completion: true, format: true, navigation: true, semantic: true, structure: true, verification: true } ]); } } }; } function ESObjectPlugin() { return { name: "ets:es-object", resolveVirtualCode(virtualCode) { virtualCode.codes.push(`\n/**\n * 应该尽量不使用此类型。\n * ---\n * Should not use this type as much as possible. \n */ \n type ESObject = any`); return virtualCode; } }; } function createVirtualCode(snapshot, languageId, data) { return { id: "root", languageId, snapshot, mappings: [{ sourceOffsets: [0], generatedOffsets: [0], lengths: [snapshot.getLength()], data }] }; } function createEmptyVirtualCode(snapshot, languageId, data, options$1) { return { id: "root", languageId, snapshot: { getText: () => "", getLength: () => 0, getChangeRange: () => void 0 }, mappings: [{ sourceOffsets: [0], generatedOffsets: [0], lengths: [snapshot.getLength()], data }], ...options$1 }; } var ETSVirtualCode = class extends u { filePath; constructor(filePath, sourceFile, languageId, plugins) { super(filePath, sourceFile, languageId, plugins); this.filePath = filePath; } }; function ETSLanguagePlugin(tsOrEts, { excludePaths = [], tsdk = "" } = {}) { const isETSServerMode = isEts(tsOrEts); function getLanguageId(uri) { const filePath = typeof uri === "string" ? uri : uri.fsPath; if (filePath.endsWith(".ets")) return "ets"; if (filePath.endsWith(".ts")) return "typescript"; if (filePath.endsWith(".json") || filePath.endsWith(".json5") || filePath.endsWith(".jsonc") || filePath.endsWith(".tsbuildinfo")) return "json"; } function getScriptKindByFilePath(filePath, defaultExtension = ".ets") { if (!filePath) return [7, defaultExtension]; if (filePath.endsWith(".d.ts")) return [3, ".d.ts"]; if (filePath.endsWith(".d.ets")) return [8, ".d.ets"]; if (filePath.endsWith(".d.cts")) return [3, ".d.cts"]; if (filePath.endsWith(".d.mts")) return [3, ".d.mts"]; const extension = path.extname(filePath); switch (extension) { case ".ts": case ".cts": case ".mts": return [3, extension]; case ".ets": return [8, extension]; default: return [7, extension]; } } if (isETSServerMode) return { getLanguageId, createVirtualCode(uri, languageId, snapshot) { const filePath = path.resolve(typeof uri === "string" ? uri : uri.fsPath); if (languageId === "ets") return new ETSVirtualCode(filePath, tsOrEts.createSourceFile(filePath, snapshot.getText(0, snapshot.getLength()), 99), "typescript", [$$thisFixerPlugin(), ESObjectPlugin()]); if (filePath.endsWith(".json") || filePath.endsWith(".json5") || filePath.endsWith(".jsonc") || languageId === "json" || languageId === "jsonc") return getFullVirtualCode(snapshot, languageId); if (filePath.startsWith(tsdk)) return getDisabledVirtualCode(snapshot, languageId); }, typescript: { extraFileExtensions: [{ extension: "ets", isMixedContent: false, scriptKind: 8 }, { extension: "d.ets", isMixedContent: false, scriptKind: 8 }], resolveHiddenExtensions: true, getServiceScript(root$1) { const [scriptKind, extension] = getScriptKindByFilePath(root$1.filePath); return { code: root$1, extension, scriptKind }; } } }; return { getLanguageId, createVirtualCode(uri, languageId, snapshot) { const filePath = path.resolve(typeof uri === "string" ? uri : uri.fsPath); const isInExcludePath = excludePaths.some((excludePath) => filePath.startsWith(excludePath)); if ((filePath.endsWith(".d.ts") || filePath.endsWith(".d.ets")) && isInExcludePath) return getFullDisabledVirtualCode(snapshot, languageId, { filePath }); }, typescript: { extraFileExtensions: [], getServiceScript(root$1) { const [scriptKind, extension] = getScriptKindByFilePath(root$1.filePath, ".ts"); return { code: root$1, extension, scriptKind }; } } }; } function isEts(tsOrEts) { return "ETS" in tsOrEts.ScriptKind && tsOrEts.ScriptKind.ETS === 8; } function getFullVirtualCode(snapshot, languageId) { return createVirtualCode(snapshot, languageId, { completion: true, format: true, navigation: true, semantic: true, structure: true, verification: true }); } function getDisabledVirtualCode(snapshot, languageId) { return createVirtualCode(snapshot, languageId, { completion: false, format: false, navigation: false, semantic: false, structure: false, verification: false }); } function getFullDisabledVirtualCode(snapshot, languageId, options$1) { return createEmptyVirtualCode(snapshot, languageId, { completion: false, format: false, navigation: false, semantic: false, structure: false, verification: false }, options$1); } //#endregion //#region ../../node_modules/.pnpm/vscode-languageserver@9.0.1/node_modules/vscode-languageserver/lib/common/utils/is.js var require_is$2 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/vscode-languageserver@9.0.1/node_modules/vscode-languageserver/lib/common/utils/is.js": ((exports) => { Object.defineProperty(exports, "__esModule", { value: true }); exports.thenable = exports.typedArray = exports.stringArray = exports.array = exports.func = exports.error = exports.number = exports.string = exports.boolean = void 0; function boolean$2(value) { return value === true || value === false; } exports.boolean = boolean$2; function string$2(value) { return typeof value === "string" || value instanceof String; } exports.string = string$2; function number$2(value) { return typeof value === "number" || value instanceof Number; } exports.number = number$2; function error$2(value) { return value instanceof Error; } exports.error = error$2; function func$2(value) { return typeof value === "function"; } exports.func = func$2; function array$2(value) { return Array.isArray(value); } exports.array = array$2; function stringArray$2(value) { return array$2(value) && value.every((elem) => string$2(elem)); } exports.stringArray = stringArray$2; function typedArray$1(value, check) { return Array.isArray(value) && value.every(check); } exports.typedArray = typedArray$1; function thenable(value) { return value && func$2(value.then); } exports.thenable = thenable; }) }); //#endregion //#region ../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/is.js var require_is$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/is.js": ((exports) => { Object.defineProperty(exports, "__esModule", { value: true }); exports.stringArray = exports.array = exports.func = exports.error = exports.number = exports.string = exports.boolean = void 0; function boolean$1(value) { return value === true || value === false; } exports.boolean = boolean$1; function string$1(value) { return typeof value === "string" || value instanceof String; } exports.string = string$1; function number$1(value) { return typeof value === "number" || value instanceof Number; } exports.number = number$1; function error$1(value) { return value instanceof Error; } exports.error = error$1; function func$1(value) { return typeof value === "function"; } exports.func = func$1; function array$1(value) { return Array.isArray(value); } exports.array = array$1; function stringArray$1(value) { return array$1(value) && value.every((elem) => string$1(elem)); } exports.stringArray = stringArray$1; }) }); //#endregion //#region ../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/messages.js var require_messages$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/messages.js": ((exports) => { Object.defineProperty(exports, "__esModule", { value: true }); exports.Message = exports.NotificationType9 = exports.NotificationType8 = exports.NotificationType7 = exports.NotificationType6 = exports.NotificationType5 = exports.NotificationType4 = exports.NotificationType3 = exports.NotificationType2 = exports.NotificationType1 = exports.NotificationType0 = exports.NotificationType = exports.RequestType9 = exports.RequestType8 = exports.RequestType7 = exports.RequestType6 = exports.RequestType5 = exports.RequestType4 = exports.RequestType3 = exports.RequestType2 = exports.RequestType1 = exports.RequestType = exports.RequestType0 = exports.AbstractMessageSignature = exports.ParameterStructures = exports.ResponseError = exports.ErrorCodes = void 0; const is = require_is$1(); /** * Predefined error codes. */ var ErrorCodes; (function(ErrorCodes$1) { ErrorCodes$1.ParseError = -32700; ErrorCodes$1.InvalidRequest = -32600; ErrorCodes$1.MethodNotFound = -32601; ErrorCodes$1.InvalidParams = -32602; ErrorCodes$1.InternalError = -32603; /** * This is the start range of JSON RPC reserved error codes. * It doesn't denote a real error code. No application error codes should * be defined between the start and end range. For backwards * compatibility the `ServerNotInitialized` and the `UnknownErrorCode` * are left in the range. * * @since 3.16.0 */ ErrorCodes$1.jsonrpcReservedErrorRangeStart = -32099; /** @deprecated use jsonrpcReservedErrorRangeStart */ ErrorCodes$1.serverErrorStart = -32099; /** * An error occurred when write a message to the transport layer. */ ErrorCodes$1.MessageWriteError = -32099; /** * An error occurred when reading a message from the transport layer. */ ErrorCodes$1.MessageReadError = -32098; /** * The connection got disposed or lost and all pending responses got * rejected. */ ErrorCodes$1.PendingResponseRejected = -32097; /** * The connection is inactive and a use of it failed. */ ErrorCodes$1.ConnectionInactive = -32096; /** * Error code indicating that a server received a notification or * request before the server has received the `initialize` request. */ ErrorCodes$1.ServerNotInitialized = -32002; ErrorCodes$1.UnknownErrorCode = -32001; /** * This is the end range of JSON RPC reserved error codes. * It doesn't denote a real error code. * * @since 3.16.0 */ ErrorCodes$1.jsonrpcReservedErrorRangeEnd = -32e3; /** @deprecated use jsonrpcReservedErrorRangeEnd */ ErrorCodes$1.serverErrorEnd = -32e3; })(ErrorCodes || (exports.ErrorCodes = ErrorCodes = {})); /** * An error object return in a response in case a request * has failed. */ var ResponseError = class ResponseError extends Error { constructor(code, message, data) { super(message); this.code = is.number(code) ? code : ErrorCodes.UnknownErrorCode; this.data = data; Object.setPrototypeOf(this, ResponseError.prototype); } toJson() { const result = { code: this.code, message: this.message }; if (this.data !== void 0) result.data = this.data; return result; } }; exports.ResponseError = ResponseError; var ParameterStructures = class ParameterStructures { constructor(kind) { this.kind = kind; } static is(value) { return value === ParameterStructures.auto || value === ParameterStructures.byName || value === ParameterStructures.byPosition; } toString() { return this.kind; } }; exports.ParameterStructures = ParameterStructures; /** * The parameter structure is automatically inferred on the number of parameters * and the parameter type in case of a single param. */ ParameterStructures.auto = new ParameterStructures("auto"); /** * Forces `byPosition` parameter structure. This is useful if you have a single * parameter which has a literal type. */ ParameterStructures.byPosition = new ParameterStructures("byPosition"); /** * Forces `byName` parameter structure. This is only useful when having a single * parameter. The library will report errors if used with a different number of * parameters. */ ParameterStructures.byName = new ParameterStructures("byName"); /** * An abstract implementation of a MessageType. */ var AbstractMessageSignature = class { constructor(method, numberOfParams) { this.method = method; this.numberOfParams = numberOfParams; } get parameterStructures() { return ParameterStructures.auto; } }; exports.AbstractMessageSignature = AbstractMessageSignature; /** * Classes to type request response pairs */ var RequestType0 = class extends AbstractMessageSignature { constructor(method) { super(method, 0); } }; exports.RequestType0 = RequestType0; var RequestType = class extends AbstractMessageSignature { constructor(method, _parameterStructures = ParameterStructures.auto) { super(method, 1); this._parameterStructures = _parameterStructures; } get parameterStructures() { return this._parameterStructures; } }; exports.RequestType = RequestType; var RequestType1 = class extends AbstractMessageSignature { constructor(method, _parameterStructures = ParameterStructures.auto) { super(method, 1); this._parameterStructures = _parameterStructures; } get parameterStructures() { return this._parameterStructures; } }; exports.RequestType1 = RequestType1; var RequestType2 = class extends AbstractMessageSignature { constructor(method) { super(method, 2); } }; exports.RequestType2 = RequestType2; var RequestType3 = class extends AbstractMessageSignature { constructor(method) { super(method, 3); } }; exports.RequestType3 = RequestType3; var RequestType4 = class extends AbstractMessageSignature { constructor(method) { super(method, 4); } }; exports.RequestType4 = RequestType4; var RequestType5 = class extends AbstractMessageSignature { constructor(method) { super(method, 5); } }; exports.RequestType5 = RequestType5; var RequestType6 = class extends AbstractMessageSignature { constructor(method) { super(method, 6); } }; exports.RequestType6 = RequestType6; var RequestType7 = class extends AbstractMessageSignature { constructor(method) { super(method, 7); } }; exports.RequestType7 = RequestType7; var RequestType8 = class extends AbstractMessageSignature { constructor(method) { super(method, 8); } }; exports.RequestType8 = RequestType8; var RequestType9 = class extends AbstractMessageSignature { constructor(method) { super(method, 9); } }; exports.RequestType9 = RequestType9; var NotificationType = class extends AbstractMessageSignature { constructor(method, _parameterStructures = ParameterStructures.auto) { super(method, 1); this._parameterStructures = _parameterStructures; } get parameterStructures() { return this._parameterStructures; } }; exports.NotificationType = NotificationType; var NotificationType0 = class extends AbstractMessageSignature { constructor(method) { super(method, 0); } }; exports.NotificationType0 = NotificationType0; var NotificationType1 = class extends AbstractMessageSignature { constructor(method, _parameterStructures = ParameterStructures.auto) { super(method, 1); this._parameterStructures = _parameterStructures; } get parameterStructures() { return this._parameterStructures; } }; exports.NotificationType1 = NotificationType1; var NotificationType2 = class extends AbstractMessageSignature { constructor(method) { super(method, 2); } }; exports.NotificationType2 = NotificationType2; var NotificationType3 = class extends AbstractMessageSignature { constructor(method) { super(method, 3); } }; exports.NotificationType3 = NotificationType3; var NotificationType4 = class extends AbstractMessageSignature { constructor(method) { super(method, 4); } }; exports.NotificationType4 = NotificationType4; var NotificationType5 = class extends AbstractMessageSignature { constructor(method) { super(method, 5); } }; exports.NotificationType5 = NotificationType5; var NotificationType6 = class extends AbstractMessageSignature { constructor(method) { super(method, 6); } }; exports.NotificationType6 = NotificationType6; var NotificationType7 = class extends AbstractMessageSignature { constructor(method) { super(method, 7); } }; exports.NotificationType7 = NotificationType7; var NotificationType8 = class extends AbstractMessageSignature { constructor(method) { super(method, 8); } }; exports.NotificationType8 = NotificationType8; var NotificationType9 = class extends AbstractMessageSignature { constructor(method) { super(method, 9); } }; exports.NotificationType9 = NotificationType9; var Message; (function(Message$1) { /** * Tests if the given message is a request message */ function isRequest(message) { const candidate = message; return candidate && is.string(candidate.method) && (is.string(candidate.id) || is.number(candidate.id)); } Message$1.isRequest = isRequest; /** * Tests if the given message is a notification message */ function isNotification(message) { const candidate = message; return candidate && is.string(candidate.method) && message.id === void 0; } Message$1.isNotification = isNotification; /** * Tests if the given message is a response message */ function isResponse(message) { const candidate = message; return candidate && (candidate.result !== void 0 || !!candidate.error) && (is.string(candidate.id) || is.number(candidate.id) || candidate.id === null); } Message$1.isResponse = isResponse; })(Message || (exports.Message = Message = {})); }) }); //#endregion //#region ../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/linkedMap.js var require_linkedMap = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/linkedMap.js": ((exports) => { var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.LRUCache = exports.LinkedMap = exports.Touch = void 0; var Touch; (function(Touch$1) { Touch$1.None = 0; Touch$1.First = 1; Touch$1.AsOld = Touch$1.First; Touch$1.Last = 2; Touch$1.AsNew = Touch$1.Last; })(Touch || (exports.Touch = Touch = {})); var LinkedMap = class { constructor() { this[_a] = "LinkedMap"; this._map = /* @__PURE__ */ new Map(); this._head = void 0; this._tail = void 0; this._size = 0; this._state = 0; } clear() { this._map.clear(); this._head = void 0; this._tail = void 0; this._size = 0; this._state++; } isEmpty() { return !this._head && !this._tail; } get size() { return this._size; } get first() { var _this$_head; return (_this$_head = this._head) === null || _this$_head === void 0 ? void 0 : _this$_head.value; } get last() { var _this$_tail; return (_this$_tail = this._tail) === null || _this$_tail === void 0 ? void 0 : _this$_tail.value; } has(key$1) { return this._map.has(key$1); } get(key$1, touch$1 = Touch.None) { const item = this._map.get(key$1); if (!item) return; if (touch$1 !== Touch.None) this.touch(item, touch$1); return item.value; } set(key$1, value, touch$1 = Touch.None) { let item = this._map.get(key$1); if (item) { item.value = value; if (touch$1 !== Touch.None) this.touch(item, touch$1); } else { item = { key: key$1, value, next: void 0, previous: void 0 }; switch (touch$1) { case Touch.None: this.addItemLast(item); break; case Touch.First: this.addItemFirst(item); break; case Touch.Last: this.addItemLast(item); break; default: this.addItemLast(item); break; } this._map.set(key$1, item); this._size++; } return this; } delete(key$1) { return !!this.remove(key$1); } remove(key$1) { const item = this._map.get(key$1); if (!item) return; this._map.delete(key$1); this.removeItem(item); this._size--; return item.value; } shift() { if (!this._head && !this._tail) return; if (!this._head || !this._tail) throw new Error("Invalid list"); const item = this._head; this._map.delete(item.key); this.removeItem(item); this._size--; return item.value; } forEach(callbackfn, thisArg) { const state = this._state; let current = this._head; while (current) { if (thisArg) callbackfn.bind(thisArg)(current.value, current.key, this); else callbackfn(current.value, current.key, this); if (this._state !== state) throw new Error(`LinkedMap got modified during iteration.`); current = current.next; } } keys() { const state = this._state; let current = this._head; const iterator = { [Symbol.iterator]: () => { return iterator; }, next: () => { if (this._state !== state) throw new Error(`LinkedMap got modified during iteration.`); if (current) { const result = { value: current.key, done: false }; current = current.next; return result; } else return { value: void 0, done: true }; } }; return iterator; } values() { const state = this._state; let current = this._head; const iterator = { [Symbol.iterator]: () => { return iterator; }, next: () => { if (this._state !== state) throw new Error(`LinkedMap got modified during iteration.`); if (current) { const result = { value: current.value, done: false }; current = current.next; return result; } else return { value: void 0, done: true }; } }; return iterator; } entries() { const state = this._state; let current = this._head; const iterator = { [Symbol.iterator]: () => { return iterator; }, next: () => { if (this._state !== state) throw new Error(`LinkedMap got modified during iteration.`); if (current) { const result = { value: [current.key, current.value], done: false }; current = current.next; return result; } else return { value: void 0, done: true }; } }; return iterator; } [(_a = Symbol.toStringTag, Symbol.iterator)]() { return this.entries(); } trimOld(newSize) { if (newSize >= this.size) return; if (newSize === 0) { this.clear(); return; } let current = this._head; let currentSize = this.size; while (current && currentSize > newSize) { this._map.delete(current.key); current = current.next; currentSize--; } this._head = current; this._size = currentSize; if (current) current.previous = void 0; this._state++; } addItemFirst(item) { if (!this._head && !this._tail) this._tail = item; else if (!this._head) throw new Error("Invalid list"); else { item.next = this._head; this._head.previous = item; } this._head = item; this._state++; } addItemLast(item) { if (!this._head && !this._tail) this._head = item; else if (!this._tail) throw new Error("Invalid list"); else { item.previous = this._tail; this._tail.next = item; } this._tail = item; this._state++; } removeItem(item) { if (item === this._head && item === this._tail) { this._head = void 0; this._tail = void 0; } else if (item === this._head) { if (!item.next) throw new Error("Invalid list"); item.next.previous = void 0; this._head = item.next; } else if (item === this._tail) { if (!item.previous) throw new Error("Invalid list"); item.previous.next = void 0; this._tail = item.previous; } else { const next = item.next; const previous = item.previous; if (!next || !previous) throw new Error("Invalid list"); next.previous = previous; previous.next = next; } item.next = void 0; item.previous = void 0; this._state++; } touch(item, touch$1) { if (!this._head || !this._tail) throw new Error("Invalid list"); if (touch$1 !== Touch.First && touch$1 !== Touch.Last) return; if (touch$1 === Touch.First) { if (item === this._head) return; const next = item.next; const previous = item.previous; if (item === this._tail) { previous.next = void 0; this._tail = previous; } else { next.previous = previous; previous.next = next; } item.previous = void 0; item.next = this._head; this._head.previous = item; this._head = item; this._state++; } else if (touch$1 === Touch.Last) { if (item === this._tail) return; const next = item.next; const previous = item.previous; if (item === this._head) { next.previous = void 0; this._head = next; } else { next.previous = previous; previous.next = next; } item.next = void 0; item.previous = this._tail; this._tail.next = item; this._tail = item; this._state++; } } toJSON() { const data = []; this.forEach((value, key$1) => { data.push([key$1, value]); }); return data; } fromJSON(data) { this.clear(); for (const [key$1, value] of data) this.set(key$1, value); } }; exports.LinkedMap = LinkedMap; var LRUCache$1 = class extends LinkedMap { constructor(limit, ratio = 1) { super(); this._limit = limit; this._ratio = Math.min(Math.max(0, ratio), 1); } get limit() { return this._limit; } set limit(limit) { this._limit = limit; this.checkTrim(); } get ratio() { return this._ratio; } set ratio(ratio) { this._ratio = Math.min(Math.max(0, ratio), 1); this.checkTrim(); } get(key$1, touch$1 = Touch.AsNew) { return super.get(key$1, touch$1); } peek(key$1) { return super.get(key$1, Touch.None); } set(key$1, value) { super.set(key$1, value, Touch.Last); this.checkTrim(); return this; } checkTrim() { if (this.size > this._limit) this.trimOld(Math.round(this._limit * this._ratio)); } }; exports.LRUCache = LRUCache$1; }) }); //#endregion //#region ../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/disposable.js var require_disposable = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/disposable.js": ((exports) => { Object.defineProperty(exports, "__esModule", { value: true }); exports.Disposable = void 0; var Disposable; (function(Disposable$1) { function create$6(func$3) { return { dispose: func$3 }; } Disposable$1.create = create$6; })(Disposable || (exports.Disposable = Disposable = {})); }) }); //#endregion //#region ../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/ral.js var require_ral$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/ral.js": ((exports) => { Object.defineProperty(exports, "__esModule", { value: true }); let _ral$1; function RAL$1() { if (_ral$1 === void 0) throw new Error(`No runtime abstraction layer installed`); return _ral$1; } (function(RAL$2) { function install(ral) { if (ral === void 0) throw new Error(`No runtime abstraction layer provided`); _ral$1 = ral; } RAL$2.install = install; })(RAL$1 || (RAL$1 = {})); exports.default = RAL$1; }) }); //#endregion //#region ../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/events.js var require_events = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/events.js": ((exports) => { Object.defineProperty(exports, "__esModule", { value: true }); exports.Emitter = exports.Event = void 0; const ral_1$8 = require_ral$1(); var Event; (function(Event$1) { const _disposable = { dispose() {} }; Event$1.None = function() { return _disposable; }; })(Event || (exports.Event = Event = {})); var CallbackList = class { add(callback, context = null, bucket) { if (!this._callbacks) { this._callbacks = []; this._contexts = []; } this._callbacks.push(callback); this._contexts.push(context); if (Array.isArray(bucket)) bucket.push({ dispose: () => this.remove(callback, context) }); } remove(callback, context = null) { if (!this._callbacks) return; let foundCallbackWithDifferentContext = false; for (let i$1 = 0, len = this._callbacks.length; i$1 < len; i$1++) if (this._callbacks[i$1] === callback) if (this._contexts[i$1] === context) { this._callbacks.splice(i$1, 1); this._contexts.splice(i$1, 1); return; } else foundCallbackWithDifferentContext = true; if (foundCallbackWithDifferentContext) throw new Error("When adding a listener with a context, you should remove it with the same context"); } invoke(...args) { if (!this._callbacks) return []; const ret = [], callbacks = this._callbacks.slice(0), contexts = this._contexts.slice(0); for (let i$1 = 0, len = callbacks.length; i$1 < len; i$1++) try { ret.push(callbacks[i$1].apply(contexts[i$1], args)); } catch (e) { (0, ral_1$8.default)().console.error(e); } return ret; } isEmpty() { return !this._callbacks || this._callbacks.length === 0; } dispose() { this._callbacks = void 0; this._contexts = void 0; } }; var Emitter = class Emitter { constructor(_options) { this._options = _options; } /** * For the public to allow to subscribe * to events from this Emitter */ get event() { if (!this._event) this._event = (listener, thisArgs, disposables) => { if (!this._callbacks) this._callbacks = new CallbackList(); if (this._options && this._options.onFirstListenerAdd && this._callbacks.isEmpty()) this._options.onFirstListenerAdd(this); this._callbacks.add(listener, thisArgs); const result = { dispose: () => { if (!this._callbacks) return; this._callbacks.remove(listener, thisArgs); result.dispose = Emitter._noop; if (this._options && this._options.onLastListenerRemove && this._callbacks.isEmpty()) this._options.onLastListenerRemove(this); } }; if (Array.isArray(disposables)) disposables.push(result); return result; }; return this._event; } /** * To be kept private to fire an event to * subscribers */ fire(event) { if (this._callbacks) this._callbacks.invoke.call(this._callbacks, event); } dispose() { if (this._callbacks) { this._callbacks.dispose(); this._callbacks = void 0; } } }; exports.Emitter = Emitter; Emitter._noop = function() {}; }) }); //#endregion //#region ../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/cancellation.js var require_cancellation$1 = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/cancellation.js": ((exports) => { Object.defineProperty(exports, "__esModule", { value: true }); exports.CancellationTokenSource = exports.CancellationToken = void 0; const ral_1$7 = require_ral$1(); const Is$9 = require_is$1(); const events_1$4 = require_events(); var CancellationToken; (function(CancellationToken$1) { CancellationToken$1.None = Object.freeze({ isCancellationRequested: false, onCancellationRequested: events_1$4.Event.None }); CancellationToken$1.Cancelled = Object.freeze({ isCancellationRequested: true, onCancellationRequested: events_1$4.Event.None }); function is$1(value) { const candidate = value; return candidate && (candidate === CancellationToken$1.None || candidate === CancellationToken$1.Cancelled || Is$9.boolean(candidate.isCancellationRequested) && !!candidate.onCancellationRequested); } CancellationToken$1.is = is$1; })(CancellationToken || (exports.CancellationToken = CancellationToken = {})); const shortcutEvent = Object.freeze(function(callback, context) { const handle = (0, ral_1$7.default)().timer.setTimeout(callback.bind(context), 0); return { dispose() { handle.dispose(); } }; }); var MutableToken = class { constructor() { this._isCancelled = false; } cancel() { if (!this._isCancelled) { this._isCancelled = true; if (this._emitter) { this._emitter.fire(void 0); this.dispose(); } } } get isCancellationRequested() { return this._isCancelled; } get onCancellationRequested() { if (this._isCancelled) return shortcutEvent; if (!this._emitter) this._emitter = new events_1$4.Emitter(); return this._emitter.event; } dispose() { if (this._emitter) { this._emitter.dispose(); this._emitter = void 0; } } }; var CancellationTokenSource = class { get token() { if (!this._token) this._token = new MutableToken(); return this._token; } cancel() { if (!this._token) this._token = CancellationToken.Cancelled; else this._token.cancel(); } dispose() { if (!this._token) this._token = CancellationToken.None; else if (this._token instanceof MutableToken) this._token.dispose(); } }; exports.CancellationTokenSource = CancellationTokenSource; }) }); //#endregion //#region ../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/sharedArrayCancellation.js var require_sharedArrayCancellation = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/vscode-jsonrpc@8.2.0/node_modules/vscode-jsonrpc/lib/common/sharedArrayCancellation.js": ((exports) => { Object.defineProperty(exports, "__esModule", { value: true }); exports.SharedArrayReceiverStrategy = exports.SharedArraySenderStrategy = void 0; const cancellation_1$39 = require_cancellation$1(); var CancellationState; (function(CancellationState$1) { CancellationState$1.Continue = 0; CancellationState$1.Cancelled = 1; })(CancellationState || (CancellationState =