@rohal12/spindle-lsp 0.1.0 → 0.2.0

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
@@ -4453,6 +4453,299 @@ var init_code_actions = __esm({
4453
4453
  }
4454
4454
  });
4455
4455
 
4456
+ // src/plugins/document-symbol.ts
4457
+ import { SymbolKind } from "vscode-languageserver";
4458
+ function computeDocumentSymbols(uri, workspace) {
4459
+ const text = workspace.documents.getText(uri);
4460
+ if (text === void 0) return [];
4461
+ const passages = workspace.passages.getPassagesInDocument(uri);
4462
+ if (passages.length === 0) return [];
4463
+ const storyVarsPassage = workspace.passages.getStoryVariables();
4464
+ const lines = text.split("\n");
4465
+ const symbols = [];
4466
+ for (const passage of passages) {
4467
+ const headerLine = passage.range.start.line;
4468
+ const selectionRange = {
4469
+ start: { line: headerLine, character: 0 },
4470
+ end: { line: headerLine, character: lines[headerLine]?.length ?? 0 }
4471
+ };
4472
+ const passageSymbol = {
4473
+ name: passage.name,
4474
+ kind: SymbolKind.Namespace,
4475
+ range: passage.range,
4476
+ selectionRange,
4477
+ children: []
4478
+ };
4479
+ if (passage.tags?.includes("widget")) {
4480
+ const contentStart = passage.range.start.line + 1;
4481
+ const contentEnd = passage.range.end.line + 1;
4482
+ const widgetDefRegex2 = /\{widget\s+"([^"]+)"[^}]*\}/gi;
4483
+ for (let i = contentStart; i < contentEnd && i < lines.length; i++) {
4484
+ widgetDefRegex2.lastIndex = 0;
4485
+ let match;
4486
+ while ((match = widgetDefRegex2.exec(lines[i])) !== null) {
4487
+ const charStart = match.index;
4488
+ const charEnd = charStart + match[0].length;
4489
+ passageSymbol.children.push({
4490
+ name: match[1],
4491
+ kind: SymbolKind.Function,
4492
+ range: {
4493
+ start: { line: i, character: charStart },
4494
+ end: { line: i, character: charEnd }
4495
+ },
4496
+ selectionRange: {
4497
+ start: { line: i, character: charStart },
4498
+ end: { line: i, character: charEnd }
4499
+ }
4500
+ });
4501
+ }
4502
+ }
4503
+ }
4504
+ if (storyVarsPassage && storyVarsPassage.uri === uri && passage.name === "StoryVariables") {
4505
+ const contentStart = passage.range.start.line + 1;
4506
+ const contentEnd = passage.range.end.line + 1;
4507
+ for (let i = contentStart; i < contentEnd && i < lines.length; i++) {
4508
+ const varMatch = lines[i].match(/^\$([A-Za-z_$][\w$]*)\s*=/);
4509
+ if (varMatch) {
4510
+ const charEnd = varMatch[0].length;
4511
+ passageSymbol.children.push({
4512
+ name: "$" + varMatch[1],
4513
+ kind: SymbolKind.Variable,
4514
+ range: {
4515
+ start: { line: i, character: 0 },
4516
+ end: { line: i, character: lines[i].length }
4517
+ },
4518
+ selectionRange: {
4519
+ start: { line: i, character: 0 },
4520
+ end: { line: i, character: charEnd }
4521
+ }
4522
+ });
4523
+ }
4524
+ }
4525
+ }
4526
+ symbols.push(passageSymbol);
4527
+ }
4528
+ return symbols;
4529
+ }
4530
+ function toLspRange7(r) {
4531
+ return {
4532
+ start: { line: r.start.line, character: r.start.character },
4533
+ end: { line: r.end.line, character: r.end.character }
4534
+ };
4535
+ }
4536
+ function toLspDocumentSymbol(sym) {
4537
+ return {
4538
+ name: sym.name,
4539
+ kind: sym.kind,
4540
+ range: toLspRange7(sym.range),
4541
+ selectionRange: toLspRange7(sym.selectionRange),
4542
+ children: sym.children?.map(toLspDocumentSymbol)
4543
+ };
4544
+ }
4545
+ var documentSymbolPlugin;
4546
+ var init_document_symbol = __esm({
4547
+ "src/plugins/document-symbol.ts"() {
4548
+ "use strict";
4549
+ documentSymbolPlugin = {
4550
+ id: "document-symbol",
4551
+ capabilities: {
4552
+ documentSymbolProvider: true
4553
+ },
4554
+ initialize(ctx) {
4555
+ ctx.connection.onDocumentSymbol((params) => {
4556
+ const symbols = computeDocumentSymbols(params.textDocument.uri, ctx.workspace);
4557
+ return symbols.map(toLspDocumentSymbol);
4558
+ });
4559
+ }
4560
+ };
4561
+ }
4562
+ });
4563
+
4564
+ // src/plugins/workspace-symbol.ts
4565
+ import { SymbolKind as SymbolKind2 } from "vscode-languageserver";
4566
+ function searchWorkspaceSymbols(query, workspace) {
4567
+ const lowerQuery = query.toLowerCase();
4568
+ const results = [];
4569
+ for (const passage of workspace.passages.getAllPassages()) {
4570
+ if (lowerQuery && !passage.name.toLowerCase().includes(lowerQuery)) continue;
4571
+ results.push({
4572
+ name: passage.name,
4573
+ kind: SymbolKind2.Namespace,
4574
+ uri: passage.uri,
4575
+ range: passage.range
4576
+ });
4577
+ }
4578
+ for (const widget of workspace.widgets.getAllWidgets()) {
4579
+ if (lowerQuery && !widget.name.toLowerCase().includes(lowerQuery)) continue;
4580
+ results.push({
4581
+ name: widget.name,
4582
+ kind: SymbolKind2.Function,
4583
+ uri: widget.uri,
4584
+ range: widget.range
4585
+ });
4586
+ }
4587
+ for (const [name, decl] of workspace.variables.getDeclared()) {
4588
+ const displayName = "$" + name;
4589
+ if (lowerQuery && !displayName.toLowerCase().includes(lowerQuery)) continue;
4590
+ results.push({
4591
+ name: displayName,
4592
+ kind: SymbolKind2.Variable,
4593
+ uri: decl.declarationUri ?? "",
4594
+ range: decl.declarationRange ?? { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } }
4595
+ });
4596
+ }
4597
+ return results;
4598
+ }
4599
+ function toLspRange8(r) {
4600
+ return {
4601
+ start: { line: r.start.line, character: r.start.character },
4602
+ end: { line: r.end.line, character: r.end.character }
4603
+ };
4604
+ }
4605
+ var workspaceSymbolPlugin;
4606
+ var init_workspace_symbol = __esm({
4607
+ "src/plugins/workspace-symbol.ts"() {
4608
+ "use strict";
4609
+ workspaceSymbolPlugin = {
4610
+ id: "workspace-symbol",
4611
+ capabilities: {
4612
+ workspaceSymbolProvider: true
4613
+ },
4614
+ initialize(ctx) {
4615
+ ctx.connection.onWorkspaceSymbol((params) => {
4616
+ const symbols = searchWorkspaceSymbols(params.query, ctx.workspace);
4617
+ return symbols.map((s) => ({
4618
+ name: s.name,
4619
+ kind: s.kind,
4620
+ location: {
4621
+ uri: s.uri,
4622
+ range: toLspRange8(s.range)
4623
+ }
4624
+ }));
4625
+ });
4626
+ }
4627
+ };
4628
+ }
4629
+ });
4630
+
4631
+ // src/plugins/folding-range.ts
4632
+ import { FoldingRangeKind } from "vscode-languageserver";
4633
+ function computeFoldingRanges(uri, workspace) {
4634
+ const text = workspace.documents.getText(uri);
4635
+ if (text === void 0) return [];
4636
+ const ranges = [];
4637
+ const passages = workspace.passages.getPassagesInDocument(uri);
4638
+ for (const passage of passages) {
4639
+ const startLine = passage.range.start.line;
4640
+ const endLine = passage.range.end.line;
4641
+ if (endLine > startLine) {
4642
+ ranges.push({
4643
+ startLine,
4644
+ endLine,
4645
+ kind: "region"
4646
+ });
4647
+ }
4648
+ }
4649
+ const macros = parseMacros(text);
4650
+ pairMacros(macros, (name) => workspace.macros.isBlock(name));
4651
+ for (const macro of macros) {
4652
+ if (macro.open && macro.pair !== -1) {
4653
+ const closingMacro = macros[macro.pair];
4654
+ const startLine = macro.range.start.line;
4655
+ const endLine = closingMacro.range.start.line;
4656
+ if (endLine > startLine) {
4657
+ ranges.push({
4658
+ startLine,
4659
+ endLine
4660
+ });
4661
+ }
4662
+ }
4663
+ }
4664
+ return ranges;
4665
+ }
4666
+ var foldingRangePlugin;
4667
+ var init_folding_range = __esm({
4668
+ "src/plugins/folding-range.ts"() {
4669
+ "use strict";
4670
+ init_macro_parser();
4671
+ foldingRangePlugin = {
4672
+ id: "folding-range",
4673
+ capabilities: {
4674
+ foldingRangeProvider: true
4675
+ },
4676
+ initialize(ctx) {
4677
+ ctx.connection.onFoldingRanges((params) => {
4678
+ const ranges = computeFoldingRanges(params.textDocument.uri, ctx.workspace);
4679
+ return ranges.map((r) => ({
4680
+ startLine: r.startLine,
4681
+ endLine: r.endLine,
4682
+ kind: r.kind === "region" ? FoldingRangeKind.Region : void 0
4683
+ }));
4684
+ });
4685
+ }
4686
+ };
4687
+ }
4688
+ });
4689
+
4690
+ // src/plugins/document-link.ts
4691
+ function computeDocumentLinks(uri, workspace) {
4692
+ const text = workspace.documents.getText(uri);
4693
+ if (text === void 0) return [];
4694
+ const passages = workspace.passages.getPassagesInDocument(uri);
4695
+ if (passages.length === 0) return [];
4696
+ const links = [];
4697
+ for (const passage of passages) {
4698
+ const contentStartLine = passage.range.start.line + 1;
4699
+ const contentEndLine = passage.range.end.line + 1;
4700
+ const lines = text.split("\n");
4701
+ const contentLines = lines.slice(contentStartLine, contentEndLine);
4702
+ const content = contentLines.join("\n");
4703
+ const passageLinks = parseLinks(content, contentStartLine);
4704
+ for (const ref of passageLinks) {
4705
+ const targetPassage = workspace.passages.getPassage(ref.name);
4706
+ let target;
4707
+ if (targetPassage) {
4708
+ target = `${targetPassage.uri}#L${targetPassage.range.start.line + 1}`;
4709
+ }
4710
+ links.push({
4711
+ range: ref.range,
4712
+ target
4713
+ });
4714
+ }
4715
+ }
4716
+ return links;
4717
+ }
4718
+ function toLspRange9(r) {
4719
+ return {
4720
+ start: { line: r.start.line, character: r.start.character },
4721
+ end: { line: r.end.line, character: r.end.character }
4722
+ };
4723
+ }
4724
+ var documentLinkPlugin;
4725
+ var init_document_link = __esm({
4726
+ "src/plugins/document-link.ts"() {
4727
+ "use strict";
4728
+ init_link_parser();
4729
+ documentLinkPlugin = {
4730
+ id: "document-link",
4731
+ capabilities: {
4732
+ documentLinkProvider: {
4733
+ resolveProvider: false
4734
+ }
4735
+ },
4736
+ initialize(ctx) {
4737
+ ctx.connection.onDocumentLinks((params) => {
4738
+ const links = computeDocumentLinks(params.textDocument.uri, ctx.workspace);
4739
+ return links.map((l) => ({
4740
+ range: toLspRange9(l.range),
4741
+ target: l.target
4742
+ }));
4743
+ });
4744
+ }
4745
+ };
4746
+ }
4747
+ });
4748
+
4456
4749
  // src/plugins/index.ts
4457
4750
  var allPlugins;
4458
4751
  var init_plugins = __esm({
@@ -4470,6 +4763,10 @@ var init_plugins = __esm({
4470
4763
  init_semantic_tokens();
4471
4764
  init_code_actions();
4472
4765
  init_format();
4766
+ init_document_symbol();
4767
+ init_workspace_symbol();
4768
+ init_folding_range();
4769
+ init_document_link();
4473
4770
  allPlugins = [
4474
4771
  diagnosticsPlugin,
4475
4772
  completionsPlugin,
@@ -4482,7 +4779,11 @@ var init_plugins = __esm({
4482
4779
  inlayHintsPlugin,
4483
4780
  semanticTokensPlugin,
4484
4781
  codeActionsPlugin,
4485
- formatPlugin
4782
+ formatPlugin,
4783
+ documentSymbolPlugin,
4784
+ workspaceSymbolPlugin,
4785
+ foldingRangePlugin,
4786
+ documentLinkPlugin
4486
4787
  ];
4487
4788
  }
4488
4789
  });