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 +109 -23
- package/dist/constants/index.d.ts +1 -0
- package/dist/handlers/compilation/compilation.d.ts +9 -3
- package/dist/handlers/compilation/includes.d.ts +9 -2
- package/dist/handlers/diagnostics.d.ts +3 -1
- package/dist/handlers/formatting.d.ts +5 -2
- package/dist/handlers/hover.d.ts +4 -6
- package/dist/handlers/index.d.ts +1 -1
- package/dist/language/diagnostics/provider.d.ts +7 -3
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +407 -89319
- package/dist/types/common.d.ts +2 -13
- package/dist/types/index.d.ts +0 -2
- package/package.json +6 -5
- package/dist/__tests__/handlers/formatting.test.d.ts +0 -1
- package/dist/__tests__/includes.test.d.ts +0 -1
- package/dist/__tests__/language/diagnostics/linter.test.d.ts +0 -1
- package/dist/__tests__/language/formatting/integration.test.d.ts +0 -1
- package/dist/language/diagnostics/index.d.ts +0 -2
- package/dist/language/diagnostics/linter.d.ts +0 -5
- package/dist/language/formatting/index.d.ts +0 -1
- package/dist/language/formatting/provider.d.ts +0 -2
- package/dist/server/cli.js +0 -89754
- package/dist/stanc/compiler.d.ts +0 -9
- package/dist/stanc/includes.d.ts +0 -10
- package/dist/stanc/provider.d.ts +0 -2
- package/dist/stanc/stanc.d.ts +0 -2
- package/dist/types/diagnostics.d.ts +0 -18
- package/dist/types/formatting.d.ts +0 -26
- package/dist/types/index.js +0 -11
- /package/dist/__tests__/{compiler.test.d.ts → language/diagnostics/provider.test.d.ts} +0 -0
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
|
-
|
|
16
|
-
bun install
|
|
17
|
-
```
|
|
14
|
+
## Editor-specific configuration
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
### VSCode:
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
22
|
+
### Neovim
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
3
|
-
import type {
|
|
4
|
-
|
|
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
|
|
4
|
-
export
|
|
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
|
-
|
|
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
|
-
|
|
4
|
-
|
|
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
|
+
}>;
|
package/dist/handlers/hover.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type { HoverParams, Hover
|
|
1
|
+
import type { HoverParams, Hover } from "vscode-languageserver";
|
|
2
2
|
import type { TextDocument } from "vscode-languageserver-textdocument";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
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;
|
package/dist/handlers/index.d.ts
CHANGED
|
@@ -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
|
|
4
|
+
export { handleFormatting } from "./formatting";
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
export declare function provideDiagnostics(compilerResult: StancReturn):
|
|
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
|
+
}[];
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type Connection } from "vscode-languageserver/node";
|
|
2
|
-
|
|
2
|
+
import { type FileSystemReader } from "../types/common.ts";
|
|
3
|
+
declare const startLanguageServer: (connection: Connection, reader?: FileSystemReader) => void;
|
|
3
4
|
export default startLanguageServer;
|