@eagleoutice/flowr 2.11.1 → 2.12.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 +187 -257
- package/abstract-interpretation/absint-visitor.d.ts +1 -0
- package/abstract-interpretation/data-frame/mappers/arguments.js +7 -1
- package/abstract-interpretation/domains/set-range-domain.js +1 -1
- package/abstract-interpretation/domains/set-upper-bound-domain.js +6 -2
- package/benchmark/slicer.d.ts +1 -1
- package/benchmark/slicer.js +3 -1
- package/benchmark/summarizer/second-phase/graph.js +5 -0
- package/cli/common/options.d.ts +8 -0
- package/cli/common/options.js +2 -0
- package/cli/common/scripts-info.d.ts +8 -0
- package/cli/repl/commands/repl-commands.d.ts +1 -0
- package/cli/repl/commands/repl-commands.js +66 -15
- package/cli/repl/commands/repl-dataflow.js +48 -4
- package/cli/repl/commands/repl-main.d.ts +2 -0
- package/cli/repl/commands/repl-main.js +5 -0
- package/cli/repl/commands/repl-query.d.ts +4 -1
- package/cli/repl/commands/repl-query.js +72 -22
- package/cli/repl/commands/repl-signature.d.ts +7 -0
- package/cli/repl/commands/repl-signature.js +119 -0
- package/cli/repl/core.d.ts +8 -1
- package/cli/repl/core.js +46 -6
- package/cli/repl/ghost-hint.d.ts +37 -0
- package/cli/repl/ghost-hint.js +72 -0
- package/cli/repl/parser/slice-query-parser.d.ts +11 -1
- package/cli/repl/parser/slice-query-parser.js +45 -16
- package/cli/repl/print-version.d.ts +2 -4
- package/cli/repl/print-version.js +41 -23
- package/cli/repl/server/connection.js +19 -17
- package/cli/slicer-app.d.ts +2 -0
- package/cli/slicer-app.js +3 -3
- package/cli/wiki.d.ts +2 -2
- package/cli/wiki.js +2 -2
- package/config.d.ts +63 -2
- package/config.js +64 -8
- package/control-flow/cfg-dead-code.js +0 -1
- package/control-flow/control-flow-graph.js +6 -6
- package/control-flow/diff-cfg.js +2 -2
- package/control-flow/semantic-cfg-guided-visitor.js +2 -0
- package/core/print/slice-diff-ansi.js +8 -8
- package/core/steps/all/core/20-dataflow.d.ts +2 -2
- package/core/steps/all/static-slicing/00-slice.d.ts +5 -0
- package/core/steps/all/static-slicing/00-slice.js +1 -1
- package/core/steps/all/static-slicing/10-reconstruct.d.ts +7 -0
- package/core/steps/all/static-slicing/10-reconstruct.js +6 -2
- package/core/steps/pipeline/default-pipelines.d.ts +20 -16
- package/data/r-base-packages.generated.d.ts +44 -0
- package/data/r-base-packages.generated.js +32 -0
- package/data/r-base-primitives.generated.d.ts +1 -0
- package/data/r-base-primitives.generated.js +15 -0
- package/data/sigdb/sigdb.remote.json +112 -0
- package/dataflow/environments/built-in-proc-name.d.ts +4 -0
- package/dataflow/environments/built-in-proc-name.js +4 -0
- package/dataflow/environments/built-in.d.ts +14 -4
- package/dataflow/environments/built-in.js +13 -2
- package/dataflow/environments/data-masking-functions.d.ts +12 -0
- package/dataflow/environments/data-masking-functions.js +46 -0
- package/dataflow/environments/default-builtin-config.d.ts +72 -19
- package/dataflow/environments/default-builtin-config.js +48 -14
- package/dataflow/environments/diff.js +1 -1
- package/dataflow/environments/environment.js +1 -2
- package/dataflow/environments/identifier.d.ts +11 -4
- package/dataflow/environments/identifier.js +28 -10
- package/dataflow/environments/resolve-by-name.js +16 -2
- package/dataflow/extractor.js +6 -3
- package/dataflow/graph/call-graph.d.ts +2 -2
- package/dataflow/graph/df-helper.d.ts +4 -4
- package/dataflow/graph/diff-dataflow-graph.js +2 -2
- package/dataflow/graph/edge.d.ts +3 -3
- package/dataflow/graph/edge.js +3 -3
- package/dataflow/graph/graph-helper.d.ts +2 -2
- package/dataflow/internal/linker.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +7 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +20 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +1 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +2 -49
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +6 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +7 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +111 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +13 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +2 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +9 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +12 -4
- package/dataflow/internal/process/functions/call/common.js +8 -1
- package/dataflow/internal/process/functions/call/default-call-handling.js +6 -0
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +17 -0
- package/dataflow/internal/process/functions/call/known-call-handling.js +32 -0
- package/dataflow/internal/process/functions/call/named-call-handling.js +29 -7
- package/dataflow/internal/process/functions/process-argument.js +12 -1
- package/dataflow/internal/process/process-named-call.d.ts +18 -1
- package/dataflow/internal/process/process-named-call.js +94 -0
- package/dataflow/processor.d.ts +18 -0
- package/documentation/data/faq/faqs.js +5 -1
- package/documentation/doc-capabilities.js +1 -1
- package/documentation/doc-util/doc-cli-option.d.ts +10 -0
- package/documentation/doc-util/doc-cli-option.js +23 -0
- package/documentation/doc-util/doc-dfg.js +2 -1
- package/documentation/doc-util/doc-query.d.ts +9 -3
- package/documentation/doc-util/doc-query.js +9 -4
- package/documentation/wiki-dataflow-graph.js +8 -5
- package/documentation/wiki-interface.js +4 -2
- package/documentation/wiki-linter.js +1 -1
- package/documentation/wiki-linting-and-testing.js +4 -1
- package/documentation/wiki-mk/doc-context.d.ts +14 -0
- package/documentation/wiki-mk/doc-context.js +3 -0
- package/documentation/wiki-mk/doc-maker.js +3 -1
- package/documentation/wiki-query.js +36 -15
- package/documentation/wiki-setup.js +10 -7
- package/documentation/wiki-signature-database.d.ts +16 -0
- package/documentation/wiki-signature-database.js +293 -0
- package/linter/linter-format.d.ts +7 -0
- package/linter/linter-rules.d.ts +10 -9
- package/linter/rules/naming-convention.d.ts +1 -0
- package/linter/rules/naming-convention.js +2 -0
- package/linter/rules/no-leaked-credentials.js +1 -2
- package/linter/rules/roxygen-arguments.js +18 -5
- package/linter/rules/stop-with-call-arg.js +2 -2
- package/linter/rules/undefined-symbol-util.d.ts +36 -0
- package/linter/rules/undefined-symbol-util.js +149 -0
- package/linter/rules/undefined-symbol.d.ts +58 -17
- package/linter/rules/undefined-symbol.js +143 -33
- package/linter/rules/unused-definition.d.ts +8 -1
- package/linter/rules/unused-definition.js +126 -1
- package/package.json +22 -10
- package/project/context/abstract-flowr-analyzer-context.js +7 -1
- package/project/context/flowr-analyzer-context.d.ts +8 -0
- package/project/context/flowr-analyzer-context.js +10 -0
- package/project/context/flowr-analyzer-dependencies-context.d.ts +28 -4
- package/project/context/flowr-analyzer-dependencies-context.js +51 -2
- package/project/context/flowr-analyzer-files-context.d.ts +1 -0
- package/project/context/flowr-analyzer-files-context.js +2 -1
- package/project/context/flowr-analyzer-functions-context.js +1 -1
- package/project/context/flowr-file.d.ts +5 -0
- package/project/context/flowr-file.js +5 -0
- package/project/flowr-analyzer-builder.js +12 -2
- package/project/plugins/file-plugins/files/flowr-description-file.js +6 -3
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +9 -3
- package/project/plugins/file-plugins/files/flowr-news-file.js +1 -3
- package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.d.ts +26 -0
- package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.js +39 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +1 -1
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +2 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +1 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +18 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +19 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +120 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +518 -0
- package/project/plugins/package-version-plugins/package.d.ts +5 -3
- package/project/plugins/package-version-plugins/package.js +27 -25
- package/project/plugins/plugin-registry.d.ts +3 -2
- package/project/plugins/plugin-registry.js +4 -2
- package/project/plugins/project-discovery/flowr-analyzer-gitignore-project-discovery-plugin.js +7 -2
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +3 -1
- package/project/sigdb/build.d.ts +131 -0
- package/project/sigdb/build.js +628 -0
- package/project/sigdb/codec.d.ts +51 -0
- package/project/sigdb/codec.js +122 -0
- package/project/sigdb/decode.d.ts +58 -0
- package/project/sigdb/decode.js +129 -0
- package/project/sigdb/decompress.d.ts +44 -0
- package/project/sigdb/decompress.js +176 -0
- package/project/sigdb/hash.d.ts +9 -0
- package/project/sigdb/hash.js +54 -0
- package/project/sigdb/index-format.d.ts +40 -0
- package/project/sigdb/index-format.js +28 -0
- package/project/sigdb/manifest.d.ts +68 -0
- package/project/sigdb/manifest.js +146 -0
- package/project/sigdb/reader.d.ts +250 -0
- package/project/sigdb/reader.js +692 -0
- package/project/sigdb/schema.d.ts +196 -0
- package/project/sigdb/schema.js +33 -0
- package/project/sigdb/sigdb-download.d.ts +65 -0
- package/project/sigdb/sigdb-download.js +237 -0
- package/project/sigdb/signature-match.d.ts +26 -0
- package/project/sigdb/signature-match.js +40 -0
- package/project/sigdb/version.d.ts +20 -0
- package/project/sigdb/version.js +55 -0
- package/queries/catalog/absint-query/absint-query-executor.d.ts +6 -0
- package/queries/catalog/absint-query/absint-query-executor.js +63 -0
- package/queries/catalog/absint-query/absint-query-format.d.ts +37 -0
- package/queries/catalog/absint-query/absint-query-format.js +102 -0
- package/queries/catalog/call-context-query/call-context-query-executor.js +1 -3
- package/queries/catalog/config-query/config-query-format.d.ts +3 -1
- package/queries/catalog/config-query/config-query-format.js +68 -9
- package/queries/catalog/dataflow-query/dataflow-query-format.js +11 -1
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +1 -1
- package/queries/catalog/linter-query/linter-query-executor.d.ts +2 -0
- package/queries/catalog/linter-query/linter-query-executor.js +6 -1
- package/queries/catalog/linter-query/linter-query-format.d.ts +2 -1
- package/queries/catalog/linter-query/linter-query-format.js +40 -8
- package/queries/catalog/project-query/project-query-executor.d.ts +15 -0
- package/queries/catalog/project-query/project-query-executor.js +96 -4
- package/queries/catalog/project-query/project-query-format.d.ts +44 -0
- package/queries/catalog/project-query/project-query-format.js +33 -2
- package/queries/catalog/signature-query/signature-query-executor.d.ts +29 -0
- package/queries/catalog/signature-query/signature-query-executor.js +461 -0
- package/queries/catalog/signature-query/signature-query-format.d.ts +138 -0
- package/queries/catalog/signature-query/signature-query-format.js +76 -0
- package/queries/catalog/signature-query/signature-query-render.d.ts +15 -0
- package/queries/catalog/signature-query/signature-query-render.js +155 -0
- package/queries/catalog/static-slice-query/static-slice-query-executor.js +9 -3
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +10 -0
- package/queries/catalog/static-slice-query/static-slice-query-format.js +19 -1
- package/queries/query-print.js +5 -0
- package/queries/query.d.ts +15 -5
- package/queries/query.js +7 -4
- package/r-bridge/init.js +5 -1
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +10 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +55 -0
- package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +16 -0
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +27 -0
- package/r-bridge/lang-4.x/ast/parser/json/format.js +89 -2
- package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.js +2 -4
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +2 -1
- package/r-bridge/parser.d.ts +2 -0
- package/r-bridge/retriever.js +4 -1
- package/r-bridge/roxygen2/documentation-provider.js +2 -1
- package/r-bridge/shell.d.ts +5 -0
- package/r-bridge/shell.js +17 -1
- package/reconstruct/inline/source-inline-map.d.ts +48 -0
- package/reconstruct/inline/source-inline-map.js +94 -0
- package/reconstruct/reconstruct.d.ts +19 -2
- package/reconstruct/reconstruct.js +79 -16
- package/search/search-executor/search-generators.js +5 -22
- package/search/search-executor/search-transformer.js +10 -6
- package/slicing/criterion/parse.d.ts +28 -4
- package/slicing/criterion/parse.js +133 -18
- package/slicing/static/slice-call.d.ts +24 -1
- package/slicing/static/slice-call.js +90 -0
- package/slicing/static/static-slicer.d.ts +7 -0
- package/slicing/static/static-slicer.js +38 -3
- package/util/collections/arrays.d.ts +4 -5
- package/util/collections/arrays.js +7 -18
- package/util/hash.d.ts +14 -0
- package/util/hash.js +31 -0
- package/util/mermaid/dfg.d.ts +7 -2
- package/util/mermaid/dfg.js +53 -13
- package/util/r-base-packages.d.ts +19 -0
- package/util/r-base-packages.js +72 -0
- package/util/r-license.js +2 -10
- package/util/r-version.d.ts +45 -15
- package/util/r-version.js +97 -36
- package/util/range.d.ts +15 -0
- package/util/range.js +39 -0
- package/util/schema.d.ts +10 -0
- package/util/schema.js +22 -0
- package/util/text/ansi.d.ts +3 -0
- package/util/text/ansi.js +10 -0
- package/util/text/args.js +1 -2
- package/util/version.js +28 -8
- package/data/pkgdb/pkgdb-latest.json.br +0 -0
- package/data/pkgdb/pkgdb-tiny.json.br +0 -0
- package/documentation/wiki-package-database.d.ts +0 -9
- package/documentation/wiki-package-database.js +0 -63
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.d.ts +0 -63
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.js +0 -176
- package/project/plugins/package-version-plugins/pkgdb.d.ts +0 -133
- package/project/plugins/package-version-plugins/pkgdb.js +0 -370
- package/queries/catalog/df-shape-query/df-shape-query-executor.d.ts +0 -6
- package/queries/catalog/df-shape-query/df-shape-query-executor.js +0 -58
- package/queries/catalog/df-shape-query/df-shape-query-format.d.ts +0 -27
- package/queries/catalog/df-shape-query/df-shape-query-format.js +0 -56
|
@@ -7,6 +7,87 @@ const retriever_1 = require("../../../../retriever");
|
|
|
7
7
|
const assert_1 = require("../../../../../util/assert");
|
|
8
8
|
const type_1 = require("../../model/type");
|
|
9
9
|
exports.RootId = 0;
|
|
10
|
+
/**
|
|
11
|
+
* R's `getParseData` escapes the lexeme `text` with `encodeString`, whose escaping is locale-dependent: under a
|
|
12
|
+
* non-UTF-8 locale (a common CI setup) non-ASCII bytes come out as octal (`\303\264`) or hex (`\xc3`) escapes that
|
|
13
|
+
* are not valid JSON. Valid JSON escapes (`\n`, `\"`, `\uXXXX`, ...) are left untouched.
|
|
14
|
+
*/
|
|
15
|
+
function jsonSafeRParseData(data) {
|
|
16
|
+
let out = '';
|
|
17
|
+
for (let i = 0; i < data.length;) {
|
|
18
|
+
if (data[i] !== '\\') {
|
|
19
|
+
out += data[i++];
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const next = data[i + 1];
|
|
23
|
+
if (next !== undefined && (next === '\\' || next === '"' || next === '/' || next === 'b' || next === 'f' || next === 'n' || next === 'r' || next === 't' || next === 'u')) {
|
|
24
|
+
out += data[i] + next;
|
|
25
|
+
i += 2;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (next !== undefined && next >= '0' && next <= '7') {
|
|
29
|
+
const run = readByteRun(data, i, collectOctal);
|
|
30
|
+
out += bytesToUtf8Json(run.bytes);
|
|
31
|
+
i = run.next;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (next === 'x') {
|
|
35
|
+
const run = readByteRun(data, i, collectHex);
|
|
36
|
+
out += bytesToUtf8Json(run.bytes);
|
|
37
|
+
i = run.next;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (next === undefined) {
|
|
41
|
+
out += data[i];
|
|
42
|
+
i += 1;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
out += `\\u${next.charCodeAt(0).toString(16).padStart(4, '0')}`;
|
|
46
|
+
i += 2;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
/** Reads a run of consecutive `\NNN` octal (or `\xNN` hex) escapes starting at `start` (which points at a `\`). */
|
|
52
|
+
function readByteRun(data, start, collect) {
|
|
53
|
+
const bytes = [];
|
|
54
|
+
let pos = start;
|
|
55
|
+
for (;;) {
|
|
56
|
+
const read = collect(data, pos);
|
|
57
|
+
if (read === undefined) {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
bytes.push(read.value & 0xff);
|
|
61
|
+
pos = read.next;
|
|
62
|
+
}
|
|
63
|
+
return { bytes, next: pos };
|
|
64
|
+
}
|
|
65
|
+
function collectOctal(data, pos) {
|
|
66
|
+
if (data[pos] !== '\\' || !(data[pos + 1] >= '0' && data[pos + 1] <= '7')) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
let oct = '', j = pos + 1;
|
|
70
|
+
while (j < data.length && oct.length < 3 && data[j] >= '0' && data[j] <= '7') {
|
|
71
|
+
oct += data[j++];
|
|
72
|
+
}
|
|
73
|
+
return { value: parseInt(oct, 8), next: j };
|
|
74
|
+
}
|
|
75
|
+
function collectHex(data, pos) {
|
|
76
|
+
if (data[pos] !== '\\' || data[pos + 1] !== 'x' || !/[0-9a-fA-F]/.test(data[pos + 2] ?? '')) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
let hex = '', j = pos + 2;
|
|
80
|
+
while (j < data.length && hex.length < 2 && /[0-9a-fA-F]/.test(data[j])) {
|
|
81
|
+
hex += data[j++];
|
|
82
|
+
}
|
|
83
|
+
return { value: parseInt(hex, 16), next: j };
|
|
84
|
+
}
|
|
85
|
+
/** Decodes raw bytes as UTF-8 and re-escapes the result for a JSON string context. */
|
|
86
|
+
function bytesToUtf8Json(bytes) {
|
|
87
|
+
const decoded = Buffer.from(bytes).toString('utf-8');
|
|
88
|
+
// JSON.stringify gives a valid JSON string literal; strip its surrounding quotes to splice back inline
|
|
89
|
+
return JSON.stringify(decoded).slice(1, -1);
|
|
90
|
+
}
|
|
10
91
|
/**
|
|
11
92
|
* Takes the raw {@link RShell} output and extracts the csv information contained
|
|
12
93
|
*/
|
|
@@ -15,8 +96,14 @@ function prepareParsedData(data) {
|
|
|
15
96
|
try {
|
|
16
97
|
json = JSON.parse(`[${data.trim()}]`);
|
|
17
98
|
}
|
|
18
|
-
catch
|
|
19
|
-
|
|
99
|
+
catch {
|
|
100
|
+
// the fast path failed, most likely because a non-UTF-8 R locale produced octal/hex string escapes
|
|
101
|
+
try {
|
|
102
|
+
json = JSON.parse(`[${jsonSafeRParseData(data.trim())}]`);
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
throw new Error(`Failed to parse data [${data}]: ${e?.message}`);
|
|
106
|
+
}
|
|
20
107
|
}
|
|
21
108
|
(0, assert_1.guard)(Array.isArray(json), () => `Expected ${data} to be an array but was not`);
|
|
22
109
|
const ret = new Map(json.map(([line1, col1, line2, col2, id, parent, token, terminal, text]) => {
|
|
@@ -158,10 +158,8 @@ function normalizeExpressions(data, tokens) {
|
|
|
158
158
|
return [processBraces(braces, processed, parsedComments, data)];
|
|
159
159
|
}
|
|
160
160
|
else if (processed.length > 0) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
processed[0].info.adToks.push(...parsedComments);
|
|
164
|
-
}
|
|
161
|
+
processed[0].info.adToks ??= [];
|
|
162
|
+
processed[0].info.adToks.push(...parsedComments);
|
|
165
163
|
return processed;
|
|
166
164
|
}
|
|
167
165
|
else {
|
|
@@ -709,6 +709,7 @@ function findFirstNonCommentSibling(snode, knownNexts) {
|
|
|
709
709
|
function linkCommentsToNextNodes(nodes, comments) {
|
|
710
710
|
const remain = [];
|
|
711
711
|
const cacheMap = new Map();
|
|
712
|
+
const nodeById = new Map(nodes.map(n => [n[0].id, n]));
|
|
712
713
|
for (const [commentSyntaxNode, commentNode] of comments) {
|
|
713
714
|
let sibling;
|
|
714
715
|
const prev = commentSyntaxNode.previousSibling;
|
|
@@ -720,7 +721,7 @@ function linkCommentsToNextNodes(nodes, comments) {
|
|
|
720
721
|
sibling = findFirstNonCommentSibling(commentSyntaxNode, cacheMap);
|
|
721
722
|
}
|
|
722
723
|
// if there is no valid sibling, we just link the comment to the first node (see normalize-expressions.ts)
|
|
723
|
-
const [, node] = (sibling ?
|
|
724
|
+
const [, node] = (sibling ? nodeById.get(sibling.id) : undefined) ?? nodes[0] ?? [];
|
|
724
725
|
if (node) {
|
|
725
726
|
node.info.adToks ??= [];
|
|
726
727
|
node.info.adToks.push(commentNode);
|
package/r-bridge/parser.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export interface RShellInformation extends BaseRShellInformation {
|
|
|
25
25
|
* @param addonConfig - Additional configuration for the output collector.
|
|
26
26
|
*/
|
|
27
27
|
sendCommandWithOutput(command: string, addonConfig?: Partial<OutputCollectorConfiguration>): Promise<string[]>;
|
|
28
|
+
/** Map of every package installed on the system to its version (`installed.packages()`); see `solver.sigdb.versionSelection: 'system'`. */
|
|
29
|
+
installedPackageVersions(): Promise<Map<string, string>>;
|
|
28
30
|
}
|
|
29
31
|
export interface TreeSitterInformation extends BaseParserInformation {
|
|
30
32
|
readonly name: 'tree-sitter';
|
package/r-bridge/retriever.js
CHANGED
|
@@ -128,8 +128,11 @@ function retrieveParseDataFromRCode(request, shell) {
|
|
|
128
128
|
return Promise.resolve('');
|
|
129
129
|
}
|
|
130
130
|
const suffix = request.request === 'file' ? ', encoding="utf-8"' : '';
|
|
131
|
+
/* R's `parse(text=)` (unlike reading a file) rejects a carriage return as an "invalid token", so normalize
|
|
132
|
+
* CRLF/CR line endings to LF for text requests to match R's own file handling and stay robust to Windows sources. */
|
|
133
|
+
const content = request.request === 'text' ? request.content.replace(/\r\n?/g, '\n') : request.content;
|
|
131
134
|
/* call the function with the request */
|
|
132
|
-
const command = `flowr_get_ast(${request.request}=${JSON.stringify(
|
|
135
|
+
const command = `flowr_get_ast(${request.request}=${JSON.stringify(content)}${suffix})`;
|
|
133
136
|
if (shell instanceof shell_executor_1.RShellExecutor) {
|
|
134
137
|
return guardRetrievedOutput(shell.run(command), request);
|
|
135
138
|
}
|
|
@@ -29,6 +29,7 @@ const CommentRetriever = {
|
|
|
29
29
|
return undefined;
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
+
const defaultRetriever = (c, a) => (0, roxygen_parse_1.parseRoxygenCommentsOfNode)(c, a)?.tags;
|
|
32
33
|
/**
|
|
33
34
|
* Given a normalized AST and a node ID, returns the Roxygen documentation (if any) associated with that node.
|
|
34
35
|
* Please note that this does more than {@link parseRoxygenCommentsOfNode}, as it also traverses up the AST to find documentation.
|
|
@@ -44,7 +45,7 @@ function getDocumentationOf(nodeId, idMap) {
|
|
|
44
45
|
else if ('doc' in node.info) {
|
|
45
46
|
return node.info.doc;
|
|
46
47
|
}
|
|
47
|
-
const retriever = CommentRetriever[node.type] ??
|
|
48
|
+
const retriever = CommentRetriever[node.type] ?? defaultRetriever;
|
|
48
49
|
const doc = retriever(node, idMap);
|
|
49
50
|
if (doc) {
|
|
50
51
|
// to avoid endless recursion, we block the caching here once:
|
package/r-bridge/shell.d.ts
CHANGED
|
@@ -109,6 +109,11 @@ export declare class RShell implements AsyncParser<string> {
|
|
|
109
109
|
usedRVersion(): Promise<SemVer | null>;
|
|
110
110
|
injectLibPaths(...paths: readonly string[]): void;
|
|
111
111
|
tryToInjectHomeLibPath(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Map of every package installed on this system to its version (from `installed.packages()`), used by
|
|
114
|
+
* `solver.sigdb.versionSelection: 'system'`. Empty when R reports nothing or fails.
|
|
115
|
+
*/
|
|
116
|
+
installedPackageVersions(): Promise<Map<string, string>>;
|
|
112
117
|
/**
|
|
113
118
|
* checks if a given package is already installed on the system!
|
|
114
119
|
*/
|
package/r-bridge/shell.js
CHANGED
|
@@ -129,7 +129,8 @@ class RShell {
|
|
|
129
129
|
rVersion: async () => await this.rVersion(),
|
|
130
130
|
sendCommandWithOutput: (command, addonConfig) => {
|
|
131
131
|
return this.sendCommandWithOutput(command, addonConfig);
|
|
132
|
-
}
|
|
132
|
+
},
|
|
133
|
+
installedPackageVersions: () => this.installedPackageVersions()
|
|
133
134
|
};
|
|
134
135
|
}
|
|
135
136
|
revive() {
|
|
@@ -195,6 +196,21 @@ class RShell {
|
|
|
195
196
|
this.injectLibPaths(this.options.homeLibPath);
|
|
196
197
|
}
|
|
197
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Map of every package installed on this system to its version (from `installed.packages()`), used by
|
|
201
|
+
* `solver.sigdb.versionSelection: 'system'`. Empty when R reports nothing or fails.
|
|
202
|
+
*/
|
|
203
|
+
async installedPackageVersions() {
|
|
204
|
+
const versions = new Map();
|
|
205
|
+
const result = await this.sendCommandWithOutput(`local({ ip <- installed.packages()[,c("Package","Version"),drop=FALSE]; cat(paste(ip[,1], ip[,2], sep="\t"), sep=${(0, convert_values_1.ts2r)(this.options.eol)}); cat(${(0, convert_values_1.ts2r)(this.options.eol)}) })`);
|
|
206
|
+
for (const line of result) {
|
|
207
|
+
const tab = line.indexOf('\t');
|
|
208
|
+
if (tab > 0) {
|
|
209
|
+
versions.set(line.slice(0, tab).trim(), line.slice(tab + 1).trim());
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return versions;
|
|
213
|
+
}
|
|
198
214
|
/**
|
|
199
215
|
* checks if a given package is already installed on the system!
|
|
200
216
|
*/
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps each `source()` call node to the index of the file it sources in `ast.ast.files`.
|
|
3
|
+
* {@link reconstructToCode} uses it (via `inlineSources`) to splice a sourced file's reconstruction
|
|
4
|
+
* in place of its `source()` call, yielding one self-contained R text.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { NormalizedAst } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
8
|
+
import type { DataflowGraph } from '../../dataflow/graph/graph';
|
|
9
|
+
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
10
|
+
/**
|
|
11
|
+
* A warning raised while inlining `source()` calls during reconstruction.
|
|
12
|
+
* @see {@link reconstructToCode}
|
|
13
|
+
*/
|
|
14
|
+
export interface InlineWarning {
|
|
15
|
+
/**
|
|
16
|
+
* - `cycle`: the `source()` would re-inline a file already being inlined on the current path;
|
|
17
|
+
* the literal call is kept at the cycle edge to break the recursion.
|
|
18
|
+
* - `unresolved`: the `source()` survived the slice but could not be linked to a file
|
|
19
|
+
* (dynamic or missing path); the literal call is kept verbatim.
|
|
20
|
+
*/
|
|
21
|
+
readonly kind: 'cycle' | 'unresolved';
|
|
22
|
+
/** the id of the `source()` function-call node that triggered the warning */
|
|
23
|
+
readonly callId: NodeId;
|
|
24
|
+
/** the (best-effort) path of the file that was meant to be sourced, if known */
|
|
25
|
+
readonly path?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Helper functions to link `source()` calls to the files they source for reconstruction inlining.
|
|
29
|
+
* @see {@link SourceInlineMap.build}
|
|
30
|
+
*/
|
|
31
|
+
export declare const SourceInlineMap: {
|
|
32
|
+
readonly name: "SourceInlineMap";
|
|
33
|
+
/**
|
|
34
|
+
* Connect each `source()` call node to the index of the file it sources in `ast.ast.files` (index 0 is main).
|
|
35
|
+
*
|
|
36
|
+
* A `source()` call lives in its parent file, so we reach its sourced block via the control dependency the
|
|
37
|
+
* dataflow analysis adds (see {@link sourceRequest}): a vertex whose innermost cd (`cds[0]`) is a source call
|
|
38
|
+
* belongs to that call's directly sourced block. Every node carries its resolved file in `info.file`, so the
|
|
39
|
+
* block's `info.file` names the sourced file independent of the call site, and one graph pass resolves all
|
|
40
|
+
* calls via small map lookups. A file sourced from several sites is stored once but each block still tags the
|
|
41
|
+
* same `info.file`, so all sites map to that single index (this also drives cycle detection: a re-sourcing
|
|
42
|
+
* call resolves to an already-visited index).
|
|
43
|
+
* @param ast - the normalized (multi-file) ast
|
|
44
|
+
* @param graph - the dataflow graph for `ast`
|
|
45
|
+
* @returns a map from each `source()` call node id to the index of the sourced file in `ast.ast.files`
|
|
46
|
+
*/
|
|
47
|
+
readonly build: (ast: NormalizedAst, graph: DataflowGraph) => Map<NodeId, number>;
|
|
48
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SourceInlineMap = void 0;
|
|
4
|
+
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
5
|
+
const built_in_proc_name_1 = require("../../dataflow/environments/built-in-proc-name");
|
|
6
|
+
const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
|
|
7
|
+
const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
8
|
+
/** the string-literal path argument of a `source()`-like call node, if it has one (else `undefined`) */
|
|
9
|
+
function sourceArg(ast, callId) {
|
|
10
|
+
const node = ast.idMap.get(callId);
|
|
11
|
+
const arg = node?.type === type_1.RType.FunctionCall ? node.arguments[0] : undefined;
|
|
12
|
+
return arg !== undefined && arg !== r_function_call_1.EmptyArgument && arg.value?.type === type_1.RType.String ? arg.value.content.str : undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Helper functions to link `source()` calls to the files they source for reconstruction inlining.
|
|
16
|
+
* @see {@link SourceInlineMap.build}
|
|
17
|
+
*/
|
|
18
|
+
exports.SourceInlineMap = {
|
|
19
|
+
name: 'SourceInlineMap',
|
|
20
|
+
/**
|
|
21
|
+
* Connect each `source()` call node to the index of the file it sources in `ast.ast.files` (index 0 is main).
|
|
22
|
+
*
|
|
23
|
+
* A `source()` call lives in its parent file, so we reach its sourced block via the control dependency the
|
|
24
|
+
* dataflow analysis adds (see {@link sourceRequest}): a vertex whose innermost cd (`cds[0]`) is a source call
|
|
25
|
+
* belongs to that call's directly sourced block. Every node carries its resolved file in `info.file`, so the
|
|
26
|
+
* block's `info.file` names the sourced file independent of the call site, and one graph pass resolves all
|
|
27
|
+
* calls via small map lookups. A file sourced from several sites is stored once but each block still tags the
|
|
28
|
+
* same `info.file`, so all sites map to that single index (this also drives cycle detection: a re-sourcing
|
|
29
|
+
* call resolves to an already-visited index).
|
|
30
|
+
* @param ast - the normalized (multi-file) ast
|
|
31
|
+
* @param graph - the dataflow graph for `ast`
|
|
32
|
+
* @returns a map from each `source()` call node id to the index of the sourced file in `ast.ast.files`
|
|
33
|
+
*/
|
|
34
|
+
build(ast, graph) {
|
|
35
|
+
const files = ast.ast.files;
|
|
36
|
+
const map = new Map();
|
|
37
|
+
if (files.length <= 1) {
|
|
38
|
+
return map;
|
|
39
|
+
}
|
|
40
|
+
// resolved file path -> its index (paths are unique per stored file)
|
|
41
|
+
const pathToIndex = new Map();
|
|
42
|
+
for (let i = 1; i < files.length; i++) {
|
|
43
|
+
const path = files[i].root.info.file;
|
|
44
|
+
if (path !== undefined) {
|
|
45
|
+
pathToIndex.set(path, i);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// single pass: collect every source call (with its literal path arg, computed once) and, per control
|
|
49
|
+
// dependency, the first vertex under it (its directly sourced block).
|
|
50
|
+
const sourceArgs = new Map();
|
|
51
|
+
const firstVertexByCd = new Map();
|
|
52
|
+
for (const [id, vertex] of graph.vertices(true)) {
|
|
53
|
+
if ((0, vertex_1.isFunctionCallVertex)(vertex) && Array.isArray(vertex.origin) && vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.Source)) {
|
|
54
|
+
sourceArgs.set(id, sourceArg(ast, id));
|
|
55
|
+
}
|
|
56
|
+
const cds = vertex.cds;
|
|
57
|
+
if (cds && cds.length > 0 && !firstVertexByCd.has(cds[0].id)) {
|
|
58
|
+
firstVertexByCd.set(cds[0].id, id);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (sourceArgs.size === 0) {
|
|
62
|
+
return map;
|
|
63
|
+
}
|
|
64
|
+
// resolve each call via the `info.file` of the block it directly sources (if it has one)
|
|
65
|
+
for (const callId of sourceArgs.keys()) {
|
|
66
|
+
const block = firstVertexByCd.get(callId);
|
|
67
|
+
const path = block !== undefined ? ast.idMap.get(block)?.info.file : undefined;
|
|
68
|
+
const idx = path !== undefined ? pathToIndex.get(path) : undefined;
|
|
69
|
+
if (idx !== undefined) {
|
|
70
|
+
map.set(callId, idx);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// a re-source of an already-stored file (a diamond's shared leaf, or a cycle edge) is deduplicated and
|
|
74
|
+
// has no block of its own, so the pass above misses it. Map it by its literal path arg, which another
|
|
75
|
+
// (resolved) call to the same file already fixed.
|
|
76
|
+
const argToIndex = new Map();
|
|
77
|
+
for (const [callId, idx] of map) {
|
|
78
|
+
const arg = sourceArgs.get(callId);
|
|
79
|
+
if (arg !== undefined) {
|
|
80
|
+
argToIndex.set(arg, idx);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
for (const [callId, arg] of sourceArgs) {
|
|
84
|
+
if (arg !== undefined && !map.has(callId)) {
|
|
85
|
+
const idx = argToIndex.get(arg);
|
|
86
|
+
if (idx !== undefined) {
|
|
87
|
+
map.set(callId, idx);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return map;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=source-inline-map.js.map
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import type { NormalizedAst } from '../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
7
7
|
import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
8
8
|
import { type AutoSelectPredicate } from './auto-select/auto-select-defaults';
|
|
9
|
+
import type { InlineWarning } from './inline/source-inline-map';
|
|
9
10
|
interface Selection {
|
|
10
11
|
/**
|
|
11
12
|
* The set of node ids to be reconstructed.
|
|
@@ -15,6 +16,18 @@ interface Selection {
|
|
|
15
16
|
* @see {@link ReconstructRequiredInput#reconstructFiles}
|
|
16
17
|
*/
|
|
17
18
|
reconstructFiles?: 'all' | number[];
|
|
19
|
+
/**
|
|
20
|
+
* If set, selected `source()` calls are replaced by the (spliced) reconstruction of the sourced file,
|
|
21
|
+
* producing a single self-contained reconstruction (`code` will be a `string` for the main file, index 0).
|
|
22
|
+
* Requires {@link Selection#sourceMap} to be provided. Overrides {@link Selection#reconstructFiles}.
|
|
23
|
+
* @see {@link SourceInlineMap.build}
|
|
24
|
+
*/
|
|
25
|
+
inlineSources?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Maps a `source()` call node id to the index of the sourced file in `ast.ast.files`.
|
|
28
|
+
* Only used together with {@link Selection#inlineSources}. Build it via {@link SourceInlineMap.build}.
|
|
29
|
+
*/
|
|
30
|
+
sourceMap?: ReadonlyMap<NodeId, number>;
|
|
18
31
|
}
|
|
19
32
|
export declare const reconstructLogger: import("tslog").Logger<import("tslog").ILogObj>;
|
|
20
33
|
export interface ReconstructionResult {
|
|
@@ -22,10 +35,14 @@ export interface ReconstructionResult {
|
|
|
22
35
|
code: string | string[];
|
|
23
36
|
/** number of lines that contain nodes that triggered the `autoSelectIf` predicate {@link reconstructToCode} */
|
|
24
37
|
linesWithAutoSelected: number;
|
|
38
|
+
/** warnings raised while inlining `source()` calls (only set when {@link Selection#inlineSources} is active) */
|
|
39
|
+
inlineWarnings?: InlineWarning[];
|
|
25
40
|
}
|
|
26
|
-
export declare function reconstructToCode(ast: NormalizedAst, selection: Selection & {
|
|
41
|
+
export declare function reconstructToCode(ast: NormalizedAst, selection: Selection & ({
|
|
42
|
+
inlineSources: true;
|
|
43
|
+
} | {
|
|
27
44
|
reconstructFiles?: [number] | undefined;
|
|
28
|
-
}, autoSelectIf?: AutoSelectPredicate): ReconstructionResult & {
|
|
45
|
+
}), autoSelectIf?: AutoSelectPredicate): ReconstructionResult & {
|
|
29
46
|
code: string;
|
|
30
47
|
};
|
|
31
48
|
export declare function reconstructToCode(ast: NormalizedAst, selection: Selection, autoSelectIf?: AutoSelectPredicate): ReconstructionResult;
|
|
@@ -76,15 +76,10 @@ function reconstructRawBinaryOperator(lhs, n, rhs) {
|
|
|
76
76
|
];
|
|
77
77
|
}
|
|
78
78
|
function reconstructUnaryOp(leaf, operand, configuration) {
|
|
79
|
-
if (configuration.selection.has(leaf.info.id)) {
|
|
80
|
-
return foldToConst(leaf);
|
|
81
|
-
}
|
|
82
|
-
else if (operand.length === 0) {
|
|
79
|
+
if (!configuration.selection.has(leaf.info.id) && operand.length === 0) {
|
|
83
80
|
return [];
|
|
84
81
|
}
|
|
85
|
-
|
|
86
|
-
return foldToConst(leaf);
|
|
87
|
-
}
|
|
82
|
+
return foldToConst(leaf);
|
|
88
83
|
}
|
|
89
84
|
function reconstructBinaryOp(n, lhs, rhs, config) {
|
|
90
85
|
if (lhs.length === 0 && rhs.length === 0) {
|
|
@@ -333,8 +328,49 @@ function reconstructSpecialInfixFunctionCall(args, call) {
|
|
|
333
328
|
}
|
|
334
329
|
return plain(`${getLexeme(call.arguments[0])} ${identifier_1.Identifier.toString(call.functionName.content)} ${getLexeme(call.arguments[1])}`);
|
|
335
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* If `inlineSources` is active and this call is a selected `source()` that we can resolve, this returns the
|
|
333
|
+
* reconstruction to splice in place of the call (or the literal call at a cycle edge). It returns `undefined`
|
|
334
|
+
* to signal that the call should be reconstructed as usual (e.g., an unresolvable `source()`).
|
|
335
|
+
*/
|
|
336
|
+
function tryInlineSourceCall(call, config) {
|
|
337
|
+
const id = call.info.id;
|
|
338
|
+
const targetFile = config.sourceMap?.get(id);
|
|
339
|
+
if (targetFile !== undefined) {
|
|
340
|
+
const visited = config.visited ?? new Set([config.currentFile ?? 0]);
|
|
341
|
+
const path = config.fullAst.ast.files[targetFile]?.filePath;
|
|
342
|
+
if (visited.has(targetFile)) {
|
|
343
|
+
// cyclic source() - keep the literal call and mark the cycle edge
|
|
344
|
+
config.warnings?.push({ kind: 'cycle', callId: id, path });
|
|
345
|
+
exports.reconstructLogger.warn(`cyclic source() not inlined at node ${JSON.stringify(id)}: ${JSON.stringify(path)}`);
|
|
346
|
+
const literal = plain(getLexeme(call));
|
|
347
|
+
literal.push({ line: `# [flowR] cyclic source() not inlined: ${path ?? '<unknown>'}`, indent: 0 });
|
|
348
|
+
return literal;
|
|
349
|
+
}
|
|
350
|
+
const childConfig = {
|
|
351
|
+
...config,
|
|
352
|
+
visited: new Set([...visited, config.currentFile ?? 0, targetFile]),
|
|
353
|
+
currentFile: targetFile
|
|
354
|
+
};
|
|
355
|
+
return stripOuterExpressionList(reconstructFileCode(config.fullAst, targetFile, childConfig));
|
|
356
|
+
}
|
|
357
|
+
// a selected source() that we could not link to a file (dynamic/missing path): keep it verbatim
|
|
358
|
+
if (call.named && call.functionName.lexeme === 'source') {
|
|
359
|
+
const arg = call.arguments[0];
|
|
360
|
+
const path = arg !== undefined && arg !== r_function_call_1.EmptyArgument && arg.value?.type === type_1.RType.String ? arg.value.content.str : undefined;
|
|
361
|
+
config.warnings?.push({ kind: 'unresolved', callId: id, path });
|
|
362
|
+
exports.reconstructLogger.warn(`unresolved source() not inlined at node ${JSON.stringify(id)}: ${JSON.stringify(path)}`);
|
|
363
|
+
}
|
|
364
|
+
return undefined;
|
|
365
|
+
}
|
|
336
366
|
function reconstructFunctionCall(call, functionName, args, configuration) {
|
|
337
367
|
const selected = isSelected(configuration, call);
|
|
368
|
+
if (configuration.inlineSources && selected) {
|
|
369
|
+
const inlined = tryInlineSourceCall(call, configuration);
|
|
370
|
+
if (inlined !== undefined) {
|
|
371
|
+
return inlined;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
338
374
|
if (!selected) {
|
|
339
375
|
const f = args.filter(a => a !== r_function_call_1.EmptyArgument && a.length !== 0);
|
|
340
376
|
if (f.length === 0) {
|
|
@@ -410,14 +446,22 @@ function getIndentString(indent) {
|
|
|
410
446
|
function prettyPrintCodeToString(code, lf = '\n') {
|
|
411
447
|
return code.map(({ line, indent }) => `${getIndentString(indent)}${line}`).join(lf);
|
|
412
448
|
}
|
|
413
|
-
|
|
449
|
+
/** Removes a redundant outer `{ }` block (de-indenting its content) if present. */
|
|
450
|
+
function stripOuterExpressionList(result) {
|
|
414
451
|
if (result.length > 1 && result[0].line === '{' && result[result.length - 1].line === '}') {
|
|
415
|
-
|
|
416
|
-
return prettyPrintCodeToString(indentBy(result.slice(1, result.length - 1), -1));
|
|
452
|
+
return indentBy(result.slice(1, result.length - 1), -1);
|
|
417
453
|
}
|
|
418
|
-
|
|
419
|
-
|
|
454
|
+
return result;
|
|
455
|
+
}
|
|
456
|
+
function removeOuterExpressionListIfApplicable(result) {
|
|
457
|
+
return prettyPrintCodeToString(stripOuterExpressionList(result));
|
|
458
|
+
}
|
|
459
|
+
/** Folds a single file of the project into {@link Code}, reused by the top-level reconstruction and the `source()` inlining recursion. */
|
|
460
|
+
function reconstructFileCode(ast, fileIndex, config) {
|
|
461
|
+
if (exports.reconstructLogger.settings.minLevel <= 1 /* LogLevel.Trace */) {
|
|
462
|
+
exports.reconstructLogger.trace(`reconstructing file index ${fileIndex} with root id ${ast.ast.files[fileIndex].root.info.id}`);
|
|
420
463
|
}
|
|
464
|
+
return (0, stateful_fold_1.foldAstStateful)(ast.ast.files[fileIndex].root, config, reconstructAstFolds);
|
|
421
465
|
}
|
|
422
466
|
/**
|
|
423
467
|
* Reconstructs parts of a normalized R ast into R code on an expression basis.
|
|
@@ -441,15 +485,34 @@ function reconstructToCode(ast, selection, autoSelectIf = auto_select_defaults_1
|
|
|
441
485
|
}
|
|
442
486
|
return result;
|
|
443
487
|
};
|
|
488
|
+
// when inlining sources we produce a single self-contained file (the main file, index 0),
|
|
489
|
+
// splicing every resolvable `source()` in place; this overrides `reconstructFiles`.
|
|
490
|
+
if (selection.inlineSources) {
|
|
491
|
+
const warnings = [];
|
|
492
|
+
const code = removeOuterExpressionListIfApplicable(reconstructFileCode(ast, 0, {
|
|
493
|
+
selection: selection.nodes,
|
|
494
|
+
autoSelectIf: autoSelectIfWrapper,
|
|
495
|
+
fullAst: ast,
|
|
496
|
+
inlineSources: true,
|
|
497
|
+
sourceMap: selection.sourceMap ?? new Map(),
|
|
498
|
+
visited: new Set([0]),
|
|
499
|
+
currentFile: 0,
|
|
500
|
+
warnings
|
|
501
|
+
}));
|
|
502
|
+
return {
|
|
503
|
+
code,
|
|
504
|
+
linesWithAutoSelected: linesWithAutoSelected.size,
|
|
505
|
+
inlineWarnings: warnings
|
|
506
|
+
};
|
|
507
|
+
}
|
|
444
508
|
const indices = selection.reconstructFiles === 'all' ? ast.ast.files.map((_, i) => i) : (selection.reconstructFiles ?? [0]);
|
|
445
509
|
(0, assert_1.guard)(indices.every(i => i >= 0 && i < ast.ast.files.length), `reconstructToCode: reconstructFiles contains invalid file indices: ${JSON.stringify(indices)} for ast with ${ast.ast.files.length} files`);
|
|
446
510
|
const results = [];
|
|
447
511
|
// fold of the normalized ast
|
|
448
512
|
for (const i of indices) {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
}
|
|
452
|
-
results.push(removeOuterExpressionListIfApplicable((0, stateful_fold_1.foldAstStateful)(ast.ast.files[i].root, { selection: selection.nodes, autoSelectIf: autoSelectIfWrapper, fullAst: ast }, reconstructAstFolds)));
|
|
513
|
+
results.push(removeOuterExpressionListIfApplicable(reconstructFileCode(ast, i, {
|
|
514
|
+
selection: selection.nodes, autoSelectIf: autoSelectIfWrapper, fullAst: ast, currentFile: i
|
|
515
|
+
})));
|
|
453
516
|
}
|
|
454
517
|
(0, log_1.expensiveTrace)(exports.reconstructLogger, () => `reconstructed ast before string conversion: ${JSON.stringify(results)}`);
|
|
455
518
|
return {
|
|
@@ -48,27 +48,9 @@ async function generateGet(input, { filter: { line, column, id, name, nameIsRege
|
|
|
48
48
|
}
|
|
49
49
|
if (fuzzy) {
|
|
50
50
|
(0, assert_1.guard)(line, 'Fuzzy location matching requires line to be provided');
|
|
51
|
-
potentials =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
return column === undefined ? (range[0] <= line && line <= range[2]) : range_1.SourceRange.containsPosition(range, line, column);
|
|
57
|
-
});
|
|
58
|
-
if (innermostOnly && potentials.length > 1) {
|
|
59
|
-
potentials = potentials.filter(node => {
|
|
60
|
-
const range = range_1.SourceRange.fromNode(node);
|
|
61
|
-
return range && !potentials.some(other => {
|
|
62
|
-
if (other === node) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
else if (other.info.parent === node.info.id) {
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
const otherRange = range_1.SourceRange.fromNode(other);
|
|
69
|
-
return otherRange && range_1.SourceRange.isStrictSubsetOf(otherRange, range);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
51
|
+
potentials = range_1.SourceRange.nodesContaining(potentials, line, column);
|
|
52
|
+
if (innermostOnly) {
|
|
53
|
+
potentials = range_1.SourceRange.innermostNodes(potentials);
|
|
72
54
|
}
|
|
73
55
|
}
|
|
74
56
|
else if (line && column) {
|
|
@@ -95,6 +77,7 @@ function generateFrom(_input, args) {
|
|
|
95
77
|
async function generateFromQuery(input, args) {
|
|
96
78
|
const result = await (0, query_1.executeQueries)({ analyzer: input }, args.from);
|
|
97
79
|
// collect involved nodes
|
|
80
|
+
const { idMap } = await input.normalize();
|
|
98
81
|
const nodesByQuery = new Map();
|
|
99
82
|
for (const [query, content] of Object.entries(result)) {
|
|
100
83
|
if (query === '.meta') {
|
|
@@ -103,7 +86,7 @@ async function generateFromQuery(input, args) {
|
|
|
103
86
|
const nodes = new Set();
|
|
104
87
|
const queryDef = query_1.SupportedQueries[query];
|
|
105
88
|
for (const node of queryDef.flattenInvolvedNodes(content, args.from, args.certainty)) {
|
|
106
|
-
nodes.add({ node:
|
|
89
|
+
nodes.add({ node: idMap.get(node) });
|
|
107
90
|
}
|
|
108
91
|
nodesByQuery.set(query, nodes);
|
|
109
92
|
}
|
|
@@ -112,11 +112,15 @@ data, elements, other) {
|
|
|
112
112
|
return elements.addAll([...resultOther.getElements()]);
|
|
113
113
|
}
|
|
114
114
|
function getUnique(data, elements) {
|
|
115
|
-
return elements.mutate(e =>
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
return elements.mutate(e => {
|
|
116
|
+
const seen = new Set();
|
|
117
|
+
return e.filter(cur => {
|
|
118
|
+
if (seen.has(cur.node.id)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
seen.add(cur.node.id);
|
|
122
|
+
return true;
|
|
123
|
+
});
|
|
124
|
+
});
|
|
121
125
|
}
|
|
122
126
|
//# sourceMappingURL=search-transformer.js.map
|