@ripple-ts/language-server 0.3.93 → 0.3.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const require_server = require('./server-D9tbDqrh.js');
2
+ const require_server = require('./server-DhFWQsiH.js');
3
3
 
4
4
  //#region src/language-server.js
5
5
  require_server.createRippleLanguageServer();
@@ -851,6 +851,32 @@ function getRippleLanguagePlugin() {
851
851
  extension: ".tsx",
852
852
  scriptKind: 4
853
853
  };
854
+ },
855
+ /**
856
+ * Register each embedded `<script>` body as its own TypeScript service
857
+ * script so volar-service-typescript's semantic features (type-aware
858
+ * completions, hover, go-to-definition, diagnostics, imports) run against it
859
+ * and map back to the `.tsrx` source — the same way `<style>` bodies get CSS
860
+ * intellisense, except semantic TS additionally requires a service-script
861
+ * registration (a self-contained languageId is not enough).
862
+ *
863
+ * The returned `code` must be the exact same instance stored in the root's
864
+ * `embeddedCodes` (volar matches it by identity), and each `fileName` must be
865
+ * unique. Only honored on the language-server (`createTypeScriptProject`)
866
+ * path, not the tsserver-plugin path.
867
+ * @param {string} fileName
868
+ * @param {VirtualCode} ripple_code
869
+ */
870
+ getExtraServiceScripts(fileName, ripple_code) {
871
+ /** @type {Array<{ fileName: string, code: VirtualCode, extension: string, scriptKind: number }>} */
872
+ const scripts = [];
873
+ for (const code of (0, import_language_core.forEachEmbeddedCode)(ripple_code)) if (code.languageId === "typescript") scripts.push({
874
+ fileName: `${fileName}.${code.id}.ts`,
875
+ code,
876
+ extension: ".ts",
877
+ scriptKind: typescript.default.ScriptKind.TS
878
+ });
879
+ return scripts;
854
880
  }
855
881
  }
856
882
  };
@@ -983,25 +1009,14 @@ var TSRXVirtualCode = class {
983
1009
  this.sourceAst = transpiled.sourceAst;
984
1010
  if (process.env.TSRX_TSC === "true" && transpiled.errors.length > 0) logTSRXErrors(this.fileName, transpiled.errors);
985
1011
  const cssMappings = transpiled.cssMappings;
986
- if (cssMappings.length > 0) {
987
- log$9("Creating", cssMappings.length, "CSS embedded codes");
988
- this.embeddedCodes = cssMappings.map((mapping, index) => {
989
- const cssContent = mapping.data?.customData?.content;
990
- log$9(`CSS region ${index}: \
991
- offset ${mapping.sourceOffsets[0]}-${mapping.sourceOffsets[0] + mapping.lengths[0]}, \
992
- length ${mapping.lengths[0]}`);
993
- return {
994
- id: mapping.data?.customData?.embeddedId,
995
- languageId: "css",
996
- snapshot: {
997
- getText: (start, end) => cssContent.substring(start, end),
998
- getLength: () => mapping.lengths[0],
999
- getChangeRange: () => void 0
1000
- },
1001
- mappings: [mapping],
1002
- embeddedCodes: []
1003
- };
1004
- });
1012
+ const scriptMappings = transpiled.scriptMappings ?? [];
1013
+ if (cssMappings.length > 0 || scriptMappings.length > 0) {
1014
+ log$9("Creating", cssMappings.length, "CSS and", scriptMappings.length, "script embedded codes");
1015
+ /** @type {VirtualCode[]} */
1016
+ const embedded = [];
1017
+ for (const mapping of cssMappings) embedded.push(create_embedded_code_from_mapping(mapping, "css"));
1018
+ for (const mapping of scriptMappings) embedded.push(create_embedded_code_from_mapping(mapping, "typescript"));
1019
+ this.embeddedCodes = embedded;
1005
1020
  } else this.embeddedCodes = [];
1006
1021
  if (DEBUG) {
1007
1022
  log$9("CSS embedded codes:", (this.embeddedCodes || []).length);
@@ -1037,7 +1052,7 @@ var TSRXVirtualCode = class {
1037
1052
  customData: {}
1038
1053
  }
1039
1054
  }];
1040
- this.embeddedCodes = extractCssFromSource(newCode);
1055
+ this.embeddedCodes = [...extractCssFromSource(newCode), ...extractScriptFromSource(newCode)];
1041
1056
  this.snapshot = {
1042
1057
  getText: (start, end) => this.generatedCode.substring(start, end),
1043
1058
  getLength: () => this.generatedCode.length,
@@ -1201,6 +1216,79 @@ function extractCssFromSource(code) {
1201
1216
  return embeddedCodes;
1202
1217
  }
1203
1218
  /**
1219
+ * Build an embedded virtual code from a single mapping produced by the compiler
1220
+ * (`cssMappings` / `scriptMappings`). The embedded document text is the region's
1221
+ * `customData.content`; `languageId` selects which Volar service handles it
1222
+ * (`css`, `typescript`, or `javascript`).
1223
+ * @param {CodeMapping} mapping
1224
+ * @param {string} languageId
1225
+ * @returns {VirtualCode}
1226
+ */
1227
+ function create_embedded_code_from_mapping(mapping, languageId) {
1228
+ const content = mapping.data?.customData?.content ?? "";
1229
+ return {
1230
+ id: mapping.data?.customData?.embeddedId,
1231
+ languageId,
1232
+ snapshot: {
1233
+ getText: (start, end) => content.substring(start, end),
1234
+ getLength: () => mapping.lengths[0],
1235
+ getChangeRange: () => void 0
1236
+ },
1237
+ mappings: [mapping],
1238
+ embeddedCodes: []
1239
+ };
1240
+ }
1241
+ /**
1242
+ * Extract raw script content from `<script>...<\/script>` tags in source code, used
1243
+ * as a fallback for script intellisense while the file has a fatal compile error
1244
+ * (no AST available — the normal path derives regions from the compiler's
1245
+ * `scriptMappings` instead). Parallels {@link extractCssFromSource}.
1246
+ * Every body is treated as TypeScript (a superset of JS), so the attributes are
1247
+ * never inspected. The opening-tag pattern refuses to match self-closing
1248
+ * `<script src=... />` tags (the `/` before `>` must not close the tag), so they
1249
+ * can't swallow a later real script's body.
1250
+ * @param {string} code - The source code to extract scripts from
1251
+ * @returns {VirtualCode[]} Array of embedded TypeScript virtual codes
1252
+ */
1253
+ function extractScriptFromSource(code) {
1254
+ /** @type {VirtualCode[]} */
1255
+ const embeddedCodes = [];
1256
+ const scriptRegex = /<script\b((?:[^>"'/]|"[^"]*"|'[^']*'|\/(?!>))*)>([\s\S]*?)<\/script>/gi;
1257
+ let match;
1258
+ let index = 0;
1259
+ while ((match = scriptRegex.exec(code)) !== null) {
1260
+ const attrs = match[1];
1261
+ const scriptContent = match[2];
1262
+ const scriptStart = match.index + (7 + attrs.length + 1);
1263
+ const scriptLength = scriptContent.length;
1264
+ const id = `script_${index}`;
1265
+ log$9(`Extracted script region ${index}: offset ${scriptStart}, length ${scriptLength}`);
1266
+ /** @type {CodeMapping} */
1267
+ const mapping = {
1268
+ sourceOffsets: [scriptStart],
1269
+ generatedOffsets: [0],
1270
+ lengths: [scriptLength],
1271
+ generatedLengths: [scriptLength],
1272
+ data: {
1273
+ verification: true,
1274
+ completion: true,
1275
+ semantic: true,
1276
+ navigation: true,
1277
+ structure: true,
1278
+ format: false,
1279
+ customData: {
1280
+ content: scriptContent,
1281
+ embeddedId: id
1282
+ }
1283
+ }
1284
+ };
1285
+ embeddedCodes.push(create_embedded_code_from_mapping(mapping, "typescript"));
1286
+ index++;
1287
+ }
1288
+ if (embeddedCodes.length > 0) log$9(`Extracted ${embeddedCodes.length} script embedded codes from script tags`);
1289
+ return embeddedCodes;
1290
+ }
1291
+ /**
1204
1292
  * Insert a typed dot back into the transpiled code and update mappings so the
1205
1293
  * source and generated offsets stay aligned for completion requests.
1206
1294
  * @param {VolarMappingsResult} transpiled
@@ -22610,4 +22698,4 @@ Object.defineProperty(exports, 'createRippleLanguageServer', {
22610
22698
  return createRippleLanguageServer;
22611
22699
  }
22612
22700
  });
22613
- //# sourceMappingURL=server-D9tbDqrh.js.map
22701
+ //# sourceMappingURL=server-DhFWQsiH.js.map