@soda-gql/lsp 0.12.0 → 0.12.2

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.
@@ -393,10 +393,21 @@ const createDocumentManager = (helper, swcOptions) => {
393
393
  let parseSyncFn = swcOptions?.parseSync !== undefined ? swcOptions.parseSync ?? null : null;
394
394
  let swcLoadAttempted = swcOptions?.parseSync !== undefined;
395
395
  let swcUnavailable = swcOptions?.parseSync === null;
396
+ /** Get this module's base path for createRequire fallback (works in both CJS and ESM). */
397
+ const getModuleBase = () => {
398
+ try {
399
+ if (typeof __filename !== "undefined") return __filename;
400
+ } catch {}
401
+ try {
402
+ if (import.meta.url) return import.meta.url;
403
+ } catch {}
404
+ return undefined;
405
+ };
396
406
  const getParseSync = () => {
397
407
  if (!swcLoadAttempted) {
398
408
  swcLoadAttempted = true;
399
- const resolveBases = swcOptions?.resolveFrom ? [swcOptions.resolveFrom, import.meta.url] : [import.meta.url];
409
+ const fallback = getModuleBase();
410
+ const resolveBases = [...swcOptions?.resolveFrom ? [swcOptions.resolveFrom] : [], ...fallback ? [fallback] : []];
400
411
  for (const base of resolveBases) {
401
412
  try {
402
413
  const localRequire = createRequire(base);
@@ -794,6 +805,9 @@ const createConfigRegistry = (configPaths) => {
794
805
  };
795
806
  return ok({
796
807
  resolveForUri: (uri) => {
808
+ if (!uri.startsWith("file://") && !uri.startsWith("/")) {
809
+ return undefined;
810
+ }
797
811
  const filePath = uri.startsWith("file://") ? fileURLToPath(uri) : uri;
798
812
  const dirPath = dirname(filePath);
799
813
  const configPath = resolveConfigPath(dirPath);
@@ -3987,20 +4001,15 @@ const createLspServer = (options) => {
3987
4001
  }
3988
4002
  };
3989
4003
  connection.onInitialize((params) => {
3990
- const rootUri = params.rootUri ?? params.rootPath;
3991
- if (!rootUri) {
4004
+ const roots = resolveWorkspaceRoots(params);
4005
+ if (roots.length === 0) {
3992
4006
  connection.window.showErrorMessage("soda-gql LSP: no workspace root provided");
3993
4007
  return { capabilities: {} };
3994
4008
  }
3995
- const rootPath = rootUri.startsWith("file://") ? fileURLToPath(rootUri) : rootUri;
3996
- let configPaths = findAllConfigFiles(rootPath);
4009
+ const configPaths = discoverConfigs(roots);
3997
4010
  if (configPaths.length === 0) {
3998
- const singleConfigPath = findConfigFile(rootPath);
3999
- if (!singleConfigPath) {
4000
- connection.window.showErrorMessage("soda-gql LSP: no config file found");
4001
- return { capabilities: {} };
4002
- }
4003
- configPaths = [singleConfigPath];
4011
+ connection.window.showErrorMessage("soda-gql LSP: no config file found");
4012
+ return { capabilities: {} };
4004
4013
  }
4005
4014
  const registryResult = createConfigRegistry(configPaths);
4006
4015
  if (registryResult.isErr()) {
@@ -4327,6 +4336,40 @@ const checkSwcUnavailable = (swcUnavailable, state, showError) => {
4327
4336
  showError(`soda-gql LSP: ${lspErrors.swcResolutionFailed().message}`);
4328
4337
  }
4329
4338
  };
4339
+ /** Extract workspace root paths from LSP initialize params. */
4340
+ const resolveWorkspaceRoots = (params) => {
4341
+ if (params.workspaceFolders && params.workspaceFolders.length > 0) {
4342
+ return params.workspaceFolders.map((f) => f.uri.startsWith("file://") ? fileURLToPath(f.uri) : f.uri);
4343
+ }
4344
+ const rootUri = params.rootUri ?? params.rootPath;
4345
+ if (rootUri) {
4346
+ return [rootUri.startsWith("file://") ? fileURLToPath(rootUri) : rootUri];
4347
+ }
4348
+ return [];
4349
+ };
4350
+ /** Discover config files across multiple workspace roots (deduplicated). */
4351
+ const discoverConfigs = (roots) => {
4352
+ const seen = new Set();
4353
+ const result = [];
4354
+ for (const root of roots) {
4355
+ const fromRoot = findAllConfigFiles(root);
4356
+ if (fromRoot.length > 0) {
4357
+ for (const p of fromRoot) {
4358
+ if (!seen.has(p)) {
4359
+ seen.add(p);
4360
+ result.push(p);
4361
+ }
4362
+ }
4363
+ } else {
4364
+ const single = findConfigFile(root);
4365
+ if (single && !seen.has(single)) {
4366
+ seen.add(single);
4367
+ result.push(single);
4368
+ }
4369
+ }
4370
+ }
4371
+ return result;
4372
+ };
4330
4373
  /** Convert LSP Position to byte offset in source text. */
4331
4374
  const positionToOffset = (source, position) => {
4332
4375
  let line = 0;
@@ -4342,4 +4385,4 @@ const positionToOffset = (source, position) => {
4342
4385
 
4343
4386
  //#endregion
4344
4387
  export { createDocumentManager as a, lspErrors as i, createSchemaResolver as n, preprocessFragmentArgs as o, createPositionMapper as r, createLspServer as t };
4345
- //# sourceMappingURL=server-BgXl3W41.mjs.map
4388
+ //# sourceMappingURL=server-lBJEHSZu.mjs.map