stan-language-server 0.2.0-beta.1 → 0.3.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/README.md CHANGED
@@ -10,45 +10,131 @@ A language server for the Stan probabilistic programming language written in Typ
10
10
  - **Code formatting**: Using the official Stan compiler
11
11
  - **Include file support**: Full `#include` resolution and compilation
12
12
 
13
- To install dependencies:
14
13
 
15
- ```bash
16
- bun install
17
- ```
14
+ ## Editor-specific configuration
18
15
 
19
- To run the language server:
16
+ ### VSCode:
20
17
 
21
- ```bash
22
- bun run src/server.ts
23
- ```
18
+ Install the [extension](https://github.com/WardBrian/vscode-stan-extension)
19
+ from [Marketplace](https://marketplace.visualstudio.com/items?itemName=wardbrian.vscode-stan-extension)
20
+ or [open-vsx](https://open-vsx.org/extension/wardbrian/vscode-stan-extension).
24
21
 
25
- Building a binary executable:
22
+ ### Neovim
26
23
 
27
- ```bash
28
- bun build server.ts --compile --outfile stan-language-server
24
+ There are many ways to install language servers in neovim. Here is one (if you have a different or better way, consider contributing it!):
25
+
26
+ Download the latest language server executable from [GitHub](https://github.com/tomatitito/stan-language-server/tags) and put it somewhere in your PATH. Then in your `nvim` config folder add `lua/lsp/init.lua` with:
27
+ ```lua
28
+ local servers = {
29
+ stan_ls = "lsp.stan",
30
+ }
31
+
32
+ local function setup_server(name, config_module)
33
+ local config = require(config_module)
34
+
35
+ vim.api.nvim_create_autocmd("FileType", {
36
+ pattern = config.filetypes,
37
+ callback = function()
38
+ if #vim.lsp.get_clients({ bufnr = 0, name = name }) > 0 then
39
+ return
40
+ end
41
+
42
+ local root_dir = vim.fs.root(0, config.root_markers)
43
+ print(string.format("Starting %s for buffer %d with root: %s", name, vim.api.nvim_get_current_buf(),
44
+ root_dir or "none"))
45
+
46
+ vim.lsp.start({
47
+ name = name,
48
+ cmd = config.cmd,
49
+ root_dir = root_dir,
50
+ initialization_options = config.settings or {},
51
+ on_exit = function(code, signal)
52
+ print(string.format("%s exited with code %d, signal %d", name, code, signal))
53
+ end,
54
+ })
55
+ end,
56
+ })
57
+ end
58
+
59
+ for server_name, config_path in pairs(servers) do
60
+ setup_server(server_name, config_path)
61
+ end
62
+ ```
63
+
64
+ Then in `lua/lsp/stan.lua` add the following:
65
+ ```lua
66
+ return {
67
+ cmd = { "stan-language-server", "--stdio" },
68
+ filetypes = { "stan" },
69
+ root_markers = { ".git" },
70
+ settings = {
71
+ maxLineLength = 78,
72
+ includePaths = {},
73
+ },
74
+ }
29
75
  ```
30
76
 
31
- ## Configuration
77
+ ### Zed
78
+
79
+ Install the [Stan extension](https://zed.dev/extensions/stan).
80
+
32
81
  ### Sublime Text 4
33
82
 
83
+ Using [LSP for Sublime Text](https://lsp.sublimetext.io/),
84
+ [download the latest release](https://github.com/tomatitito/stan-language-server/releases)
85
+ and add the following to the settings file:
86
+
34
87
  ```json
35
88
  {
36
- "clients": {
37
- "stan-lsp": {
38
- "enabled": true,
39
- "command": ["/YOUR/PATH/TO/stan-language-server"],
40
- "selector": "source.stan | source.stanfunctions",
41
- "initializationOptions": {}
42
- }
43
- }
89
+ "clients": {
90
+ "stan-lsp": {
91
+ "enabled": true,
92
+ "command": ["/YOUR/PATH/TO/stan-language-server", "--stdio"],
93
+ "selector": "source.stan | source.stanfunctions",
94
+ "initializationOptions": {},
95
+ "settings": {
96
+ "stan-language-server": { "includePaths": [], "maxLineLength": 78 }
97
+ }
98
+ }
44
99
  }
100
+
45
101
  ```
46
102
 
47
103
  ### Emacs (eglot)
48
104
 
49
- Assuming you are using stan-ts-mode:
105
+ Assuming you are using [stan-ts-mode](https://github.com/WardBrian/stan-ts-mode),
106
+ [download the latest release](https://github.com/tomatitito/stan-language-server/releases)
107
+ and add the following to your `init.el`:
108
+
50
109
  ```elisp
110
+ ; elgot is built in to emacs 29+, but a similar config would work for lsp-mode
51
111
  (with-eval-after-load 'eglot
52
- (add-to-list 'eglot-server-programs
53
- '(stan-ts-mode . ("/YOUR/PATH/TO/stan-language-server"))))
112
+ (add-to-list 'eglot-server-programs
113
+ '(stan-ts-mode . ("/YOUR/PATH/TO/stan-language-server" "--stdio"))))
114
+ ```
115
+
116
+
117
+ ## For developers
118
+
119
+ To install dependencies:
120
+
121
+ ```bash
122
+ bun install
123
+ ```
124
+
125
+ Building a binary executable:
126
+
127
+ ```bash
128
+ bun build:binary
129
+ ```
130
+
131
+ To run unit tests:
132
+ ```bash
133
+ bun test
134
+ ```
135
+
136
+ To run end-to-end tests:
137
+ ```bash
138
+ pip install pytest pytest-lsp
139
+ bun build:binary && pytest tests/
54
140
  ```
@@ -0,0 +1 @@
1
+ export declare const SERVER_ID = "stan-language-server";
@@ -1,4 +1,10 @@
1
1
  import type { TextDocument } from "vscode-languageserver-textdocument";
2
- import type { TextDocuments, WorkspaceFolder, RemoteConsole } from "vscode-languageserver";
3
- import type { StancReturn } from "../../types/common";
4
- export declare function handleCompilation(document: TextDocument, documentManager: TextDocuments<TextDocument>, workspaceFolders: WorkspaceFolder[], logger: RemoteConsole): Promise<StancReturn>;
2
+ import { type TextDocuments, type WorkspaceFolder, type RemoteConsole } from "vscode-languageserver";
3
+ import type { FileSystemReader } from "../../types/common";
4
+ import { type StancReturn } from "stanc3";
5
+ export interface Settings {
6
+ maxLineLength: number;
7
+ includePaths: string[];
8
+ }
9
+ export declare const defaultSettings: Settings;
10
+ export declare function handleCompilation(document: TextDocument, documentManager: TextDocuments<TextDocument>, workspaceFolders: WorkspaceFolder[], settings: Settings, logger: RemoteConsole, reader?: FileSystemReader): Promise<StancReturn>;
@@ -1,4 +1,11 @@
1
1
  import { TextDocuments, WorkspaceFolder, type RemoteConsole } from "vscode-languageserver";
2
2
  import type { TextDocument } from "vscode-languageserver-textdocument";
3
- import { type Filename, type FileContent } from "../../stanc/includes";
4
- export declare function handleIncludes(document: TextDocument, documentManager: TextDocuments<TextDocument>, workspaceFolders: WorkspaceFolder[], logger: RemoteConsole): Promise<Record<Filename, FileContent>>;
3
+ import type { FileSystemReader } from "../../types";
4
+ export type Filename = string;
5
+ export type FileContent = string;
6
+ export type FilePathError = {
7
+ msg: string;
8
+ };
9
+ export declare function getFilenames(fileContent: string): Filename[];
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>>;
@@ -1,3 +1,5 @@
1
1
  import { Diagnostic, TextDocuments, WorkspaceFolder, type DocumentDiagnosticParams, type RemoteConsole } from "vscode-languageserver";
2
2
  import { TextDocument } from "vscode-languageserver-textdocument";
3
- export declare function handleDiagnostics(params: DocumentDiagnosticParams, documents: TextDocuments<TextDocument>, workspaceFolders: WorkspaceFolder[], logger: RemoteConsole): Promise<Diagnostic[]>;
3
+ import type { FileSystemReader } from "../types";
4
+ import { type Settings } from "./compilation/compilation";
5
+ export declare function handleDiagnostics(params: DocumentDiagnosticParams, documents: TextDocuments<TextDocument>, workspaceFolders: WorkspaceFolder[], settings: Settings, logger: RemoteConsole, reader?: FileSystemReader): Promise<Diagnostic[]>;
@@ -1,4 +1,7 @@
1
1
  import type { DocumentFormattingParams, RemoteConsole, TextDocuments, TextEdit, WorkspaceFolder } from "vscode-languageserver";
2
2
  import type { TextDocument } from "vscode-languageserver-textdocument";
3
- export declare function handleFormatting(params: DocumentFormattingParams, documents: TextDocuments<TextDocument>, workspaceFolders: WorkspaceFolder[], logger: RemoteConsole): Promise<TextEdit[]>;
4
- export declare function getFormattingErrors(params: DocumentFormattingParams, documents: TextDocuments<TextDocument>, workspaceFolders: WorkspaceFolder[], logger: RemoteConsole): Promise<string[]>;
3
+ import { type Settings } from "./compilation/compilation";
4
+ import type { FileSystemReader } from "../types";
5
+ export declare function handleFormatting(params: DocumentFormattingParams, documents: TextDocuments<TextDocument>, workspaceFolders: WorkspaceFolder[], settings: Settings, logger: RemoteConsole, reader?: FileSystemReader): Promise<TextEdit[] | {
6
+ errors: string[];
7
+ }>;
@@ -1,7 +1,5 @@
1
- import type { HoverParams, Hover, MarkupContent } from "vscode-languageserver";
1
+ import type { HoverParams, Hover } from "vscode-languageserver";
2
2
  import type { TextDocument } from "vscode-languageserver-textdocument";
3
- type MarkupLookupMap = Map<string, MarkupContent>;
4
- type GetMarkupLookupMapFn = () => MarkupLookupMap;
5
- export declare const handleHover: (getMarkupLookupFn: GetMarkupLookupMapFn) => (document: TextDocument, params: HoverParams) => Promise<Hover | null>;
6
- declare const _default: (document: TextDocument, params: HoverParams) => Promise<Hover | null>;
7
- export default _default;
3
+ export declare const manual_functions: string[];
4
+ declare function handleHover(document: TextDocument, params: HoverParams): Promise<Hover | null>;
5
+ export default handleHover;
@@ -1,4 +1,4 @@
1
1
  export { handleCompletion } from "./completion";
2
2
  export { handleDiagnostics } from "./diagnostics";
3
3
  export { default as handleHover } from "./hover";
4
- export { handleFormatting, getFormattingErrors } from "./formatting";
4
+ export { handleFormatting } from "./formatting";
@@ -1,3 +1,7 @@
1
- import { type StanDiagnostic } from "../../types/diagnostics";
2
- import type { StancReturn } from "../../types/common";
3
- export declare function provideDiagnostics(compilerResult: StancReturn): StanDiagnostic[];
1
+ import type { StancReturn } from "stanc3";
2
+ import type { Range } from "vscode-languageserver";
3
+ export declare function provideDiagnostics(compilerResult: StancReturn): {
4
+ range: Range;
5
+ severity: string;
6
+ message: string;
7
+ }[];
@@ -1,3 +1,4 @@
1
1
  import { type Connection } from "vscode-languageserver/node";
2
- declare const startLanguageServer: (connection: Connection) => void;
2
+ import { type FileSystemReader } from "../types/common.ts";
3
+ declare const startLanguageServer: (connection: Connection, reader?: FileSystemReader) => void;
3
4
  export default startLanguageServer;