@rohal12/spindle-lsp 0.3.0 → 0.3.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.
package/dist/bin.js CHANGED
@@ -244,6 +244,7 @@ var init_passage_index = __esm({
244
244
 
245
245
  // src/core/workspace/macro-registry.ts
246
246
  import { existsSync, readFileSync as readFileSync2 } from "node:fs";
247
+ import { createRequire } from "node:module";
247
248
  import { dirname, join, parse as parsePath } from "node:path";
248
249
  import { fileURLToPath } from "node:url";
249
250
  var MacroRegistry;
@@ -262,7 +263,7 @@ var init_macro_registry = __esm({
262
263
  let builtinMacros = [];
263
264
  try {
264
265
  const thisDir = dirname(fileURLToPath(import.meta.url));
265
- const registryPath = this.resolveRegistryPath(thisDir);
266
+ const registryPath = this.resolveRegistryPathViaRequire(thisDir) ?? this.resolveRegistryPath(thisDir);
266
267
  if (registryPath) {
267
268
  const raw = readFileSync2(registryPath, "utf-8");
268
269
  const parsed = JSON.parse(raw);
@@ -352,6 +353,20 @@ var init_macro_registry = __esm({
352
353
  * Walk up directory tree from `startDir` to find the
353
354
  * @rohal12/spindle/dist/pkg/macro-registry.json file.
354
355
  */
356
+ /**
357
+ * Resolve macro-registry.json using Node's require resolution.
358
+ * Works in bundled contexts where import.meta.url may not be near node_modules.
359
+ */
360
+ resolveRegistryPathViaRequire(startDir) {
361
+ try {
362
+ const require2 = createRequire(join(startDir, "_"));
363
+ const toolingPath = require2.resolve("@rohal12/spindle/tooling");
364
+ const candidate = join(dirname(toolingPath), "macro-registry.json");
365
+ if (existsSync(candidate)) return candidate;
366
+ } catch {
367
+ }
368
+ return null;
369
+ }
355
370
  resolveRegistryPath(startDir) {
356
371
  const target = join("node_modules", "@rohal12", "spindle", "dist", "pkg", "macro-registry.json");
357
372
  let dir = startDir;
@@ -1033,6 +1048,8 @@ var init_workspace_model = __esm({
1033
1048
  this.macros = new MacroRegistry();
1034
1049
  this.variables = new VariableTracker();
1035
1050
  this.widgets = new WidgetRegistry();
1051
+ this.macros.loadBuiltins();
1052
+ this.macros.loadSupplements(macro_supplements_default);
1036
1053
  this.onDocumentChanged = (uri) => this.handleDocumentChange(uri);
1037
1054
  this.onDocumentOpened = (uri) => this.handleDocumentChange(uri);
1038
1055
  this.onDocumentClosed = (uri) => this.handleDocumentClose(uri);
@@ -1045,8 +1062,6 @@ var init_workspace_model = __esm({
1045
1062
  * Loads all file contents, builds indices, and emits 'modelReady'.
1046
1063
  */
1047
1064
  initialize(fileContents) {
1048
- this.macros.loadBuiltins();
1049
- this.macros.loadSupplements(macro_supplements_default);
1050
1065
  this.documents.removeListener("documentOpened", this.onDocumentOpened);
1051
1066
  this.documents.removeListener("documentChanged", this.onDocumentChanged);
1052
1067
  for (const [uri, text] of fileContents) {
@@ -4845,6 +4860,7 @@ function startServer(_args) {
4845
4860
  let activePlugins = [];
4846
4861
  let workspaceRoot;
4847
4862
  connection.onInitialize((params) => {
4863
+ console.error("[spindle-lsp] onInitialize called");
4848
4864
  const initOptions = params.initializationOptions ?? {};
4849
4865
  workspaceRoot = initOptions.workspaceRoot ?? (params.workspaceFolders?.[0]?.uri ? uriToFsPath(params.workspaceFolders[0].uri) : void 0);
4850
4866
  const projectConfig = workspaceRoot ? loadConfigFromDisk(workspaceRoot) : { macros: {} };
@@ -4854,12 +4870,15 @@ function startServer(_args) {
4854
4870
  workspaceRoot
4855
4871
  };
4856
4872
  workspace = new WorkspaceModel();
4873
+ console.error("[spindle-lsp] workspaceRoot:", workspaceRoot ?? "undefined");
4857
4874
  activePlugins = loadPlugins(allPlugins, config);
4875
+ console.error("[spindle-lsp] plugins loaded:", activePlugins.map((p) => p.id).join(", "));
4858
4876
  for (const plugin of activePlugins) {
4859
4877
  plugin.initialize({ connection, workspace, config });
4860
4878
  }
4861
4879
  if (Object.keys(projectConfig.macros).length > 0) {
4862
4880
  workspace.macros.loadSupplements(projectConfig.macros);
4881
+ console.error("[spindle-lsp] loaded config macros:", Object.keys(projectConfig.macros).length);
4863
4882
  }
4864
4883
  return {
4865
4884
  capabilities: buildCapabilities(activePlugins)
@@ -4878,7 +4897,9 @@ function startServer(_args) {
4878
4897
  });
4879
4898
  if (workspace) {
4880
4899
  const fileContents = await scanWorkspaceFiles(workspaceRoot);
4900
+ console.error("[spindle-lsp] onInitialized: scanned", fileContents.size, "files from root:", workspaceRoot ?? "undefined");
4881
4901
  workspace.initialize(fileContents);
4902
+ console.error("[spindle-lsp] workspace initialized, macros:", workspace.macros.getAllMacros().length, "warnings:", workspace.macros.warnings);
4882
4903
  }
4883
4904
  });
4884
4905
  connection.onDidOpenTextDocument(({ textDocument }) => {