UNPKG

qingkuai-language-service

Version:

The language service for qingkuai

201 lines (191 loc) 6.29 kB
import { constants } from 'qingkuai/compiler'; function escapeRegExp(text) { return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); } function generatePromiseAndResolver() { let resolver; const promise = new Promise((resolve) => { resolver = (value) => { resolve(value); promise.state = "fullfilled"; }; }); promise.state = "pending"; return [promise, resolver]; } function debounce(fn, delay, getId) { const timers = /* @__PURE__ */ new Map(); return function(...args) { const id = getId?.(...args); if (timers.has(id)) { clearTimeout(timers.get(id)); } timers.set( id, setTimeout(() => { fn.apply(this, args); timers.delete(id); }, delay) ); }; } function traverseObject(o, callback) { const keys = Object.keys(o); for (let i = 0; i < keys.length; i++) { callback(keys[i], o[keys[i]], i); } } function typedKeys(obj) { return Object.keys(obj); } var QingkuaiCommands = /* @__PURE__ */ ((QingkuaiCommands2) => { QingkuaiCommands2["TriggerSuggest"] = "editor.action.triggerSuggest"; return QingkuaiCommands2; })(QingkuaiCommands || {}); const COMPLETION_TRIGGER_CHARS = [ ["<", ">", "!", "@", "#", "&", "-", "=", "|", "/"], // scripts [".", "'", '"', "`", ":", ",", "_", " "], // styles ["["], // prettier-ignore // emmet needs trigger characters [".", "+", "*", "]", "^", "$", ")", "}", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] ].flat(); const SIGNATURE_RETRIGGER_CHARS = [")"]; const SIGNATURE_TRIGGER_CHARS = ["(", "<", ","]; const KEY_RELATED_EVENT_MODIFIERS = /* @__PURE__ */ new Set([ "enter", "tab", "del", "esc", "up", "down", "left", "right", "space", "shift" ]); const INVALID_COMPLETION_TEXT_LABELS = /* @__PURE__ */ new Set([ "EmptyObject", "QingkuaiComponent", "anyValue", "sign", "defineComponent", "confirmComponent", "getListPair", "getTypeDelayMarking", "getPromiseResolve", "validateString", "validateNumber", "validateBoolean", "validateHtmlBlockOptions", "validateReferenceGroup", "validateTargetDirectiveValue", "validateDomReceiver", "validateEventHandler" ]); const INVLALID_COMPLETION_PACKAGES = /* @__PURE__ */ new Set([ "qingkuai/internal", "qingkuai/language-service" ]); const GLOBAL_TYPE_IDS = /* @__PURE__ */ new Set(["Props", "Refs"]); const SCRIPT_EXTENSIONS = /* @__PURE__ */ new Set([".d.ts", ".ts", ".tsx", ".js", ".jsx", ".json"]); const RETRIGGER_SUGGEST_COMMAND = { title: "retrigger suggest", command: QingkuaiCommands.TriggerSuggest }; const LSU_AND_DOT = constants.LSC.UTIL + "."; const SOURCE_SPAN_MARK = /* @__PURE__ */ Symbol( "has been converted to source text span by qingkuai-language-service" ); const PROXIED_MARK = /* @__PURE__ */ Symbol("has been proxied by qingkuai-language-service"); function debugAssert(v) { if (!v) { debugger; } return !!v; } function isNull(v) { return v === null; } function isString(v) { return typeof v === "string"; } function isEmptyString(v) { return v === ""; } function isUndefined(v) { return v === void 0; } function isQingkuaiFileName(fileName) { return fileName.endsWith(".qk"); } function mdCodeBlockGen(lang, code) { return "```" + lang + "\n" + code + "\n```"; } function compressNumberArray(arr) { const compressed = []; for (let i = 1, count = 1; i <= arr.length; i++) { if (arr[i] === arr[i - 1]) { count++; } else { compressed.push([arr[i - 1], count]); count = 1; } } return compressed; } function recoverNumberArray(compressed) { const recovered = []; for (const [value, count] of compressed) { for (let i = 0; i < count; i++) { recovered.push(value); } } return recovered; } function recoverPositions(compressed) { const recovered = []; const recoveredFlags = recoverNumberArray(compressed.flags); for (let i = 0; i < compressed.lineCharacters.length; i++) { for (let j = 0; j < compressed.lineCharacters[i]; j++) { const index = recoveredFlags.length; recovered.push({ line: i + 1, column: j, index, flag: recoveredFlags[index] }); } } return recovered; } function isIndexesInvalid(...items) { return items.some((item) => { return !item || item === -1; }); } const nonWhitespaceRE = /[^\s]/; const qkExtInImportRE = /\.qk(['"]\s*)$/; const inEntityCharacterRE = /^[a-zA-Z\d]+;/; const completeEntityCharacterRE = /&[a-zA-Z\d]*$/; const jsValidIdentifierRE = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/; const emmetTagNameRE = /(?:^|\s|<)[a-zA-z][a-zA-Z\d\-_.:]*$/; const CompletionImportTextEditRE = /^\s*(?:(?:update|add) )?import .* from/; const badComponentAttrMessageRE = /^Object literal may only specify known properties, and .*? does not exist in type '(Props|Refs)'\.$/; const GlobalTypeIsNonObjectJs = (name) => { return [ 7001, `The global type "${name}" must satisfy the constraint of being an object type.`, "https://qingkuai.dev/misc/typescript.html#component-attribute-types" ]; }; const KeyframeWillNotBeScoped = () => { return [ 7002, "The @keyframes rule is not scoped. It is recommended to define it in an external stylesheet and import it from the application entry file." ]; }; export { INVLALID_COMPLETION_PACKAGES as A, qkExtInImportRE as B, CompletionImportTextEditRE as C, SCRIPT_EXTENSIONS as D, SOURCE_SPAN_MARK as E, GLOBAL_TYPE_IDS as G, INVALID_COMPLETION_TEXT_LABELS as I, KeyframeWillNotBeScoped as K, LSU_AND_DOT as L, PROXIED_MARK as P, QingkuaiCommands as Q, RETRIGGER_SUGGEST_COMMAND as R, SIGNATURE_RETRIGGER_CHARS as S, isUndefined as a, isString as b, isIndexesInvalid as c, debugAssert as d, badComponentAttrMessageRE as e, isNull as f, traverseObject as g, inEntityCharacterRE as h, isEmptyString as i, jsValidIdentifierRE as j, completeEntityCharacterRE as k, emmetTagNameRE as l, mdCodeBlockGen as m, nonWhitespaceRE as n, KEY_RELATED_EVENT_MODIFIERS as o, escapeRegExp as p, generatePromiseAndResolver as q, debounce as r, COMPLETION_TRIGGER_CHARS as s, typedKeys as t, SIGNATURE_TRIGGER_CHARS as u, GlobalTypeIsNonObjectJs as v, recoverNumberArray as w, recoverPositions as x, compressNumberArray as y, isQingkuaiFileName as z }; //# sourceMappingURL=shared.js.map