stan-language-server 0.3.0 → 0.3.1

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/README.md CHANGED
@@ -116,6 +116,8 @@ and add the following to your `init.el`:
116
116
 
117
117
  ## For developers
118
118
 
119
+ Development uses [bun](https://bun.sh/)
120
+
119
121
  To install dependencies:
120
122
 
121
123
  ```bash
@@ -1,5 +1,5 @@
1
1
  import { TextDocuments, WorkspaceFolder, type RemoteConsole } from "vscode-languageserver";
2
- import type { TextDocument } from "vscode-languageserver-textdocument";
2
+ import { TextDocument } from "vscode-languageserver-textdocument";
3
3
  import type { FileSystemReader } from "../../types";
4
4
  export type Filename = string;
5
5
  export type FileContent = string;
@@ -8,4 +8,4 @@ export type FilePathError = {
8
8
  };
9
9
  export declare function getFilenames(fileContent: string): Filename[];
10
10
  export declare function isFilePathError(value: unknown): value is FilePathError;
11
- export declare function handleIncludes(document: TextDocument, documentManager: TextDocuments<TextDocument>, workspaceFolders: WorkspaceFolder[], includePaths: string[], logger: RemoteConsole, reader?: FileSystemReader): Promise<Record<Filename, FileContent>>;
11
+ export declare function handleIncludes(document: TextDocument, documentManager: TextDocuments<TextDocument>, workspaceFolders: WorkspaceFolder[], includePaths: string[], logger: RemoteConsole, reader?: FileSystemReader, alreadyIncluded?: Set<Filename>): Promise<Record<Filename, FileContent>>;
@@ -1,5 +1,5 @@
1
1
  // src/server/index.ts
2
- import { TextDocument } from "vscode-languageserver-textdocument";
2
+ import { TextDocument as TextDocument2 } from "vscode-languageserver-textdocument";
3
3
  import {
4
4
  DiagnosticRefreshRequest,
5
5
  DidChangeConfigurationNotification,
@@ -566,6 +566,7 @@ function provideDiagnostics(compilerResult) {
566
566
 
567
567
  // src/handlers/compilation/includes.ts
568
568
  import { join } from "path";
569
+ import { TextDocument } from "vscode-languageserver-textdocument";
569
570
  import { URI, Utils } from "vscode-uri";
570
571
  function getFilenames(fileContent) {
571
572
  const includePattern = /#include\s*[<"]?([^>"\s]*)[>"]?/g;
@@ -576,13 +577,16 @@ function getFilenames(fileContent) {
576
577
  function isFilePathError(value) {
577
578
  return typeof value === "object" && value !== null && "msg" in value;
578
579
  }
579
- async function handleIncludes(document, documentManager, workspaceFolders, includePaths, logger, reader) {
580
+ async function handleIncludes(document, documentManager, workspaceFolders, includePaths, logger, reader, alreadyIncluded = new Set) {
580
581
  try {
581
582
  const includeFilenames = getFilenames(document.getText());
582
583
  if (includeFilenames.length === 0) {
583
584
  return {};
584
585
  }
585
586
  const allResults = await Promise.all(includeFilenames.map(async (filename) => {
587
+ if (alreadyIncluded.has(filename)) {
588
+ return [filename, { msg: `File already included: ${filename}` }];
589
+ }
586
590
  try {
587
591
  const content = await readIncludedFile(document, documentManager, workspaceFolders, includePaths, filename, reader);
588
592
  return [filename, content];
@@ -591,7 +595,10 @@ async function handleIncludes(document, documentManager, workspaceFolders, inclu
591
595
  }
592
596
  }));
593
597
  const validResults = allResults.filter(([_, content]) => !isFilePathError(content));
594
- return Object.fromEntries(validResults);
598
+ const currentlyIncluded = new Set(validResults.map(([filename, _]) => filename)).union(alreadyIncluded);
599
+ const recursiveIncludes = await Promise.all(validResults.map(async ([_, content]) => await handleIncludes(content, documentManager, workspaceFolders, includePaths, logger, reader, currentlyIncluded)));
600
+ const results = validResults.map(([filename, contents]) => [filename, contents.getText()]).concat(recursiveIncludes.map(Object.entries).flat());
601
+ return Object.fromEntries(results);
595
602
  } catch (error) {
596
603
  logger.warn(`Resolving included files failed: ${error}`);
597
604
  return Promise.resolve({});
@@ -604,10 +611,7 @@ var readIncludedFile = async (document, documentManager, workspaceFolders, inclu
604
611
  return Promise.resolve(includedFileContent);
605
612
  }
606
613
  if (reader) {
607
- includedFileContent = await readIncludedFileFromFileSystem(filename, [
608
- currentDir.fsPath,
609
- ...includePaths
610
- ], reader);
614
+ includedFileContent = await readIncludedFileFromFileSystem(filename, [currentDir.fsPath, ...includePaths], reader);
611
615
  }
612
616
  if (!isFilePathError(includedFileContent)) {
613
617
  return Promise.resolve(includedFileContent);
@@ -628,13 +632,14 @@ var readIncludedFileFromWorkspace = (documentManager, workspaceFolders, filename
628
632
  if (!includedFile) {
629
633
  return Promise.resolve({ msg: `File not found: ${filename}` });
630
634
  }
631
- return Promise.resolve(includedFile.getText());
635
+ return Promise.resolve(includedFile);
632
636
  };
633
637
  var readIncludedFileFromFileSystem = async (filename, dirs, fileSystemReader) => {
634
638
  for (const currentDir of dirs) {
635
639
  try {
636
640
  const localPath = join(currentDir, filename);
637
- return await fileSystemReader(localPath);
641
+ const content = await fileSystemReader(localPath);
642
+ return TextDocument.create(URI.file(localPath).toString(), "stan", 0, content);
638
643
  } catch (error) {}
639
644
  }
640
645
  return Promise.resolve({ msg: `File not found: ${filename}` });
@@ -786,7 +791,7 @@ var startLanguageServer = (connection, reader) => {
786
791
  documentSettings.set(resource, docSettings);
787
792
  return docSettings;
788
793
  };
789
- const documents = new TextDocuments3(TextDocument);
794
+ const documents = new TextDocuments3(TextDocument2);
790
795
  connection.onCompletion((params) => {
791
796
  return handleCompletion(params, documents);
792
797
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stan-language-server",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Language Server Protocol implementation for the Stan probabilistic programming language",
5
5
  "main": "dist/server/index.js",
6
6
  "module": "src/server/index.ts",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "devDependencies": {
66
66
  "@types/bun": "latest",
67
- "@types/node": "24.7.0",
67
+ "@types/node": "24.8.1",
68
68
  "@typescript-eslint/eslint-plugin": "^8.0.0",
69
69
  "@typescript-eslint/parser": "^8.0.0",
70
70
  "eslint": "^9.0.0",