stan-language-server-bin 0.4.6 → 0.4.8
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/bin/cli.js +35 -42
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -9897,6 +9897,8 @@ var DATATYPES = [
|
|
|
9897
9897
|
"int",
|
|
9898
9898
|
"real",
|
|
9899
9899
|
"complex",
|
|
9900
|
+
"array",
|
|
9901
|
+
"tuple",
|
|
9900
9902
|
"vector",
|
|
9901
9903
|
"row_vector",
|
|
9902
9904
|
"matrix",
|
|
@@ -9928,17 +9930,12 @@ var KEYWORDS = [
|
|
|
9928
9930
|
"for",
|
|
9929
9931
|
"in",
|
|
9930
9932
|
"while",
|
|
9931
|
-
"repeat",
|
|
9932
|
-
"until",
|
|
9933
9933
|
"if",
|
|
9934
9934
|
"then",
|
|
9935
9935
|
"else",
|
|
9936
9936
|
"break",
|
|
9937
9937
|
"continue",
|
|
9938
9938
|
"return",
|
|
9939
|
-
"true",
|
|
9940
|
-
"false",
|
|
9941
|
-
"target",
|
|
9942
9939
|
"functions",
|
|
9943
9940
|
"data",
|
|
9944
9941
|
"transformed",
|
|
@@ -9950,21 +9947,11 @@ var KEYWORDS = [
|
|
|
9950
9947
|
"reject",
|
|
9951
9948
|
"fatal_error",
|
|
9952
9949
|
"profile",
|
|
9953
|
-
"get_lp",
|
|
9954
|
-
"struct",
|
|
9955
|
-
"typedef",
|
|
9956
|
-
"export",
|
|
9957
|
-
"auto",
|
|
9958
|
-
"extern",
|
|
9959
|
-
"var",
|
|
9960
|
-
"static",
|
|
9961
|
-
"array",
|
|
9962
9950
|
"lower",
|
|
9963
9951
|
"upper",
|
|
9964
9952
|
"offset",
|
|
9965
9953
|
"multiplier",
|
|
9966
|
-
"
|
|
9967
|
-
"truncate",
|
|
9954
|
+
"target",
|
|
9968
9955
|
"jacobian"
|
|
9969
9956
|
].map(keywordToCompletionItem);
|
|
9970
9957
|
|
|
@@ -30274,6 +30261,12 @@ var getFunctions = () => {
|
|
|
30274
30261
|
var FUNCTIONS = getFunctions();
|
|
30275
30262
|
|
|
30276
30263
|
// src/handlers/completion.ts
|
|
30264
|
+
var addTextEdit = (item, position, prefix_length) => {
|
|
30265
|
+
const start = { line: position.line, character: position.character - prefix_length };
|
|
30266
|
+
const end = position;
|
|
30267
|
+
const textEdit = { range: { start, end }, newText: item.insertText || item.label };
|
|
30268
|
+
return { ...item, textEdit };
|
|
30269
|
+
};
|
|
30277
30270
|
var COMPLETION_TRIE = new import_trie_search.default("label", {
|
|
30278
30271
|
splitOnRegEx: /[\s_]/g,
|
|
30279
30272
|
min: 0
|
|
@@ -30285,7 +30278,7 @@ COMPLETION_TRIE.addAll([
|
|
|
30285
30278
|
...FUNCTIONS,
|
|
30286
30279
|
...SNIPPETS
|
|
30287
30280
|
]);
|
|
30288
|
-
var searchWords = (textUpToCursor, supportsSnippets) => {
|
|
30281
|
+
var searchWords = (position, textUpToCursor, supportsSnippets) => {
|
|
30289
30282
|
const match = textUpToCursor.match(/(?:^|\s)([\w_]+)$/);
|
|
30290
30283
|
if (match) {
|
|
30291
30284
|
const word = match[1] || "";
|
|
@@ -30293,7 +30286,7 @@ var searchWords = (textUpToCursor, supportsSnippets) => {
|
|
|
30293
30286
|
if (!supportsSnippets) {
|
|
30294
30287
|
return completionProposals.filter((item) => item.kind !== import_vscode_languageserver7.CompletionItemKind.Snippet);
|
|
30295
30288
|
}
|
|
30296
|
-
return completionProposals;
|
|
30289
|
+
return completionProposals.map((item) => addTextEdit(item, position, word.length));
|
|
30297
30290
|
}
|
|
30298
30291
|
return [];
|
|
30299
30292
|
};
|
|
@@ -30302,7 +30295,7 @@ var DISTRIBUTION_TRIE = new import_trie_search.default("label", {
|
|
|
30302
30295
|
min: 0
|
|
30303
30296
|
});
|
|
30304
30297
|
DISTRIBUTION_TRIE.addAll(DISTRIBUTIONS);
|
|
30305
|
-
var searchDistributions = (textUpToCursor) => {
|
|
30298
|
+
var searchDistributions = (position, textUpToCursor) => {
|
|
30306
30299
|
const match = textUpToCursor.match(/.*~\s*([\w_]*)$/);
|
|
30307
30300
|
if (match) {
|
|
30308
30301
|
const distName = match[1] || "";
|
|
@@ -30312,7 +30305,7 @@ var searchDistributions = (textUpToCursor) => {
|
|
|
30312
30305
|
} else {
|
|
30313
30306
|
completionProposals = DISTRIBUTION_TRIE.search(distName);
|
|
30314
30307
|
}
|
|
30315
|
-
return completionProposals;
|
|
30308
|
+
return completionProposals.map((item) => addTextEdit(item, position, distName.length));
|
|
30316
30309
|
}
|
|
30317
30310
|
return [];
|
|
30318
30311
|
};
|
|
@@ -30322,15 +30315,15 @@ var getTextUpToCursor = (text, position) => {
|
|
|
30322
30315
|
const currentLine = lines[position.line] || "";
|
|
30323
30316
|
return currentLine.substring(0, position.character);
|
|
30324
30317
|
};
|
|
30325
|
-
function handleCompletion(
|
|
30326
|
-
const document = documents.get(
|
|
30327
|
-
if (!document) {
|
|
30318
|
+
function handleCompletion({ position, textDocument }, documents, supportsSnippets) {
|
|
30319
|
+
const document = documents.get(textDocument.uri);
|
|
30320
|
+
if (!document || !document.languageId.startsWith("stan")) {
|
|
30328
30321
|
return [];
|
|
30329
30322
|
}
|
|
30330
|
-
const textUpToCursor = getTextUpToCursor(document.getText(),
|
|
30323
|
+
const textUpToCursor = getTextUpToCursor(document.getText(), position);
|
|
30331
30324
|
return [
|
|
30332
|
-
...searchDistributions(textUpToCursor),
|
|
30333
|
-
...searchWords(textUpToCursor, supportsSnippets)
|
|
30325
|
+
...searchDistributions(position, textUpToCursor),
|
|
30326
|
+
...searchWords(position, textUpToCursor, supportsSnippets)
|
|
30334
30327
|
];
|
|
30335
30328
|
}
|
|
30336
30329
|
// src/handlers/diagnostics.ts
|
|
@@ -30369,7 +30362,7 @@ function getRangeFromMessage(message) {
|
|
|
30369
30362
|
}
|
|
30370
30363
|
function getWarningMessage(message) {
|
|
30371
30364
|
const msg = String(message);
|
|
30372
|
-
let warning = msg.replace(/Warning.*column \d
|
|
30365
|
+
let warning = msg.replace(/Warning.*column \d+:/s, "");
|
|
30373
30366
|
warning = warning.replace(/\s+/gs, " ");
|
|
30374
30367
|
warning = warning.trim();
|
|
30375
30368
|
warning = msg.includes("included from") ? `Warning in included file:
|
|
@@ -30880,32 +30873,32 @@ var readIncludedFileFromFileSystem = async (filename, dirs, fileSystemReader) =>
|
|
|
30880
30873
|
// src/handlers/compilation/compilation.ts
|
|
30881
30874
|
var defaultSettings = {
|
|
30882
30875
|
maxLineLength: 78,
|
|
30883
|
-
includePaths: []
|
|
30876
|
+
includePaths: [],
|
|
30877
|
+
warnPedantic: false
|
|
30884
30878
|
};
|
|
30885
|
-
async function handleCompilation(document, documentManager, workspaceFolders, settings, logger, reader) {
|
|
30879
|
+
async function handleCompilation(document, documentManager, workspaceFolders, settings, purpose, logger, reader) {
|
|
30886
30880
|
const filename = URI.parse(document.uri).fsPath;
|
|
30887
30881
|
const code = document.getText();
|
|
30888
30882
|
const includes = await handleIncludes(document, documentManager, workspaceFolders, settings.includePaths, logger, reader);
|
|
30889
|
-
const stanc_args = [
|
|
30890
|
-
"auto-format",
|
|
30891
|
-
`filename-in-msg=${filename}`,
|
|
30892
|
-
`max-line-length=${settings.maxLineLength}`,
|
|
30893
|
-
"canonicalze=deprecations",
|
|
30894
|
-
"allow-undefined"
|
|
30895
|
-
];
|
|
30883
|
+
const stanc_args = [`filename-in-msg=${filename}`, "allow-undefined"];
|
|
30896
30884
|
if (filename.endsWith(".stanfunctions")) {
|
|
30897
30885
|
stanc_args.push("functions-only");
|
|
30898
30886
|
}
|
|
30887
|
+
if (purpose === "formatting") {
|
|
30888
|
+
stanc_args.push("auto-format", `max-line-length=${settings.maxLineLength}`, "canonicalze=deprecations");
|
|
30889
|
+
} else if (settings.warnPedantic) {
|
|
30890
|
+
stanc_args.push("warn-pedantic");
|
|
30891
|
+
}
|
|
30899
30892
|
return Promise.resolve(stanc(filename, code, stanc_args, includes));
|
|
30900
30893
|
}
|
|
30901
30894
|
|
|
30902
30895
|
// src/handlers/diagnostics.ts
|
|
30903
30896
|
async function handleDiagnostics(params, documents, workspaceFolders, settings, logger, reader) {
|
|
30904
30897
|
const document = documents.get(params.textDocument.uri);
|
|
30905
|
-
if (!document) {
|
|
30898
|
+
if (!document || !document.languageId.startsWith("stan")) {
|
|
30906
30899
|
return [];
|
|
30907
30900
|
}
|
|
30908
|
-
const compilerResult = await handleCompilation(document, documents, workspaceFolders, settings, logger, reader);
|
|
30901
|
+
const compilerResult = await handleCompilation(document, documents, workspaceFolders, settings, "linting", logger, reader);
|
|
30909
30902
|
const diagnostics = provideDiagnostics(compilerResult).map((diagnostic) => {
|
|
30910
30903
|
if (diagnostic.severity === "error") {
|
|
30911
30904
|
return {
|
|
@@ -30928,10 +30921,10 @@ async function handleDiagnostics(params, documents, workspaceFolders, settings,
|
|
|
30928
30921
|
// src/handlers/formatting.ts
|
|
30929
30922
|
async function handleFormatting(params, documents, workspaceFolders, settings, logger, reader) {
|
|
30930
30923
|
const document = documents.get(params.textDocument.uri);
|
|
30931
|
-
if (!document) {
|
|
30924
|
+
if (!document || !document.languageId.startsWith("stan")) {
|
|
30932
30925
|
return [];
|
|
30933
30926
|
}
|
|
30934
|
-
const result = await handleCompilation(document, documents, workspaceFolders, settings, logger, reader);
|
|
30927
|
+
const result = await handleCompilation(document, documents, workspaceFolders, settings, "formatting", logger, reader);
|
|
30935
30928
|
if (result.errors && result.errors.length > 0) {
|
|
30936
30929
|
return { errors: result.errors };
|
|
30937
30930
|
} else if (result.result) {
|
|
@@ -30963,7 +30956,7 @@ var startLanguageServer = (connection, reader) => {
|
|
|
30963
30956
|
hasConfigurationCapability = Boolean(capabilities.workspace?.configuration);
|
|
30964
30957
|
hasDynamicConfigurationRequestCapability = Boolean(capabilities.workspace?.configuration && capabilities.workspace?.didChangeConfiguration?.dynamicRegistration);
|
|
30965
30958
|
hasWorkspaceFolderCapability = Boolean(capabilities.workspace?.workspaceFolders);
|
|
30966
|
-
hasSnippetSupport = Boolean(capabilities.textDocument?.completion?.completionItem?.snippetSupport);
|
|
30959
|
+
hasSnippetSupport = Boolean(capabilities.textDocument?.completion?.completionItem?.snippetSupport || capabilities.textDocument?.completion?.completionItemKind?.valueSet?.some((kind) => kind === import_node.CompletionItemKind.Snippet));
|
|
30967
30960
|
return {
|
|
30968
30961
|
capabilities: {
|
|
30969
30962
|
textDocumentSync: import_node.TextDocumentSyncKind.Incremental,
|
|
@@ -31061,7 +31054,7 @@ var startLanguageServer = (connection, reader) => {
|
|
|
31061
31054
|
});
|
|
31062
31055
|
connection.onHover((params) => {
|
|
31063
31056
|
const document = documents.get(params.textDocument.uri);
|
|
31064
|
-
if (!document) {
|
|
31057
|
+
if (!document || !document.languageId.startsWith("stan")) {
|
|
31065
31058
|
return null;
|
|
31066
31059
|
}
|
|
31067
31060
|
return hover_default(document, params);
|