@invinite-org/chartlang-language-service 1.1.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/CHANGELOG.md +182 -0
- package/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/_lib/collectCompletions.d.ts +13 -0
- package/dist/_lib/collectCompletions.d.ts.map +1 -0
- package/dist/_lib/collectCompletions.js +51 -0
- package/dist/_lib/collectCompletions.js.map +1 -0
- package/dist/_lib/isInsideIntervalLiteral.d.ts +11 -0
- package/dist/_lib/isInsideIntervalLiteral.d.ts.map +1 -0
- package/dist/_lib/isInsideIntervalLiteral.js +58 -0
- package/dist/_lib/isInsideIntervalLiteral.js.map +1 -0
- package/dist/_lib/mapDiagnostic.d.ts +43 -0
- package/dist/_lib/mapDiagnostic.d.ts.map +1 -0
- package/dist/_lib/mapDiagnostic.js +60 -0
- package/dist/_lib/mapDiagnostic.js.map +1 -0
- package/dist/_lib/resolveFqnAtOffset.d.ts +23 -0
- package/dist/_lib/resolveFqnAtOffset.d.ts.map +1 -0
- package/dist/_lib/resolveFqnAtOffset.js +72 -0
- package/dist/_lib/resolveFqnAtOffset.js.map +1 -0
- package/dist/_lib/toHoverDoc.d.ts +20 -0
- package/dist/_lib/toHoverDoc.d.ts.map +1 -0
- package/dist/_lib/toHoverDoc.js +27 -0
- package/dist/_lib/toHoverDoc.js.map +1 -0
- package/dist/createLanguageService.d.ts +13 -0
- package/dist/createLanguageService.d.ts.map +1 -0
- package/dist/createLanguageService.js +233 -0
- package/dist/createLanguageService.js.map +1 -0
- package/dist/hoverRegistry.generated.d.ts +34 -0
- package/dist/hoverRegistry.generated.d.ts.map +1 -0
- package/dist/hoverRegistry.generated.js +7546 -0
- package/dist/hoverRegistry.generated.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +168 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/package.json +44 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# @invinite-org/chartlang-language-service
|
|
2
|
+
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4d44a9c: Add a `ChartlangLanguageService` interface (exported from `@invinite-org/chartlang-language-service` and re-exported from `@invinite-org/chartlang-editor`) and let `createChartlangEditor({ service })` (and the React `<ChartlangEditor service={...}>` prop) inject a consumer-provided implementation. When a service is injected, `setCapabilities(...)` becomes a no-op because the injected service owns its own capability surface. Editor extension type signatures now reference the named interface instead of `ReturnType<typeof createLanguageService>`, so consumers can build the surface from scratch (e.g. a hybrid local hover / remote `compileToDiagnostics`) without abandoning the editor factory.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 4d44a9c: Surface TypeScript semantic type errors from `compile()` and `createLanguageService().compileToDiagnostics()`.
|
|
12
|
+
|
|
13
|
+
The compiler was creating a `ts.Program` for symbol resolution but never requesting `program.getSemanticDiagnostics(sourceFile)`, so scripts like `const x: number = "oops"` slipped past the gate and reached the runtime. The pipeline now wires the program's semantic diagnostics into `transformAndAnalyse`, filtered to the user's source file and mapped to a new stable `type-error` diagnostic code (with the original `TS<code>` prefix preserved in the message so editor tooling can route to TypeScript documentation).
|
|
14
|
+
|
|
15
|
+
Companion fix: the in-memory `@invinite-org/chartlang-core` ambient shim in `packages/compiler/src/program.ts` was significantly out of lockstep with the real core surface. The shim now ships the full 61-method `DrawNamespace`, every missing `TaNamespace` method (`adx`, `dmi`, `trix`, `ichimoku`, `tsi`, `smi`, `pmo`, `stochRsi`, `ultimateOsc`, `coppock`, `vortex`, `trendStrengthIndex`, `ulcerIndex`, `adr`, `median`), and `ScalarOrSeries`-widened `ta.*` source parameters that match the runtime's `readSourceValue` contract.
|
|
16
|
+
|
|
17
|
+
- d1de692: Fix end-user-blocking Node-ESM packaging bug. Every published `dist/index.js` previously failed to load under Node's strict ESM resolver because `tsc` had been configured with `moduleResolution: "Bundler"` and emitted relative specifiers verbatim, so `dist/index.js` carried `from "./api"` (extensionless) and Node rejected the resolution. Workspace consumers never saw this because tsx / vitest / Vite resolve loosely, but `npm install @invinite-org/chartlang-compiler` followed by `import` failed immediately for any Node consumer, and `examples/react-demo/vite.config.ts`'s server-side compile plugin broke at dev-config-load time.
|
|
18
|
+
|
|
19
|
+
This release switches `tsconfig.base.json` to `module: "NodeNext"` / `moduleResolution: "NodeNext"`, and rewrites every relative import / export / dynamic-import / `typeof import("…")` specifier across all packages' source to carry an explicit `.js` (or `/index.js`) suffix. The new resolution mode also surfaces this bug class as a compile error rather than runtime breakage, so it cannot regress.
|
|
20
|
+
|
|
21
|
+
No behavioural change for runtime consumers — the rewritten specifiers resolve to the same TypeScript sources at build time and the same `dist/<path>.js` files at consumer-load time.
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [4d44a9c]
|
|
24
|
+
- Updated dependencies [4d44a9c]
|
|
25
|
+
- Updated dependencies [d1de692]
|
|
26
|
+
- Updated dependencies [d1de692]
|
|
27
|
+
- Updated dependencies [98599b2]
|
|
28
|
+
- @invinite-org/chartlang-adapter-kit@1.1.0
|
|
29
|
+
- @invinite-org/chartlang-compiler@1.0.1
|
|
30
|
+
- @invinite-org/chartlang-core@1.0.1
|
|
31
|
+
|
|
32
|
+
## 1.0.0
|
|
33
|
+
|
|
34
|
+
### Major Changes
|
|
35
|
+
|
|
36
|
+
- chartlang `1.0.0` -- the `apiVersion: 1` standard.
|
|
37
|
+
|
|
38
|
+
- `apiVersion: 1` frozen: compiler accepts only the frozen language
|
|
39
|
+
version; `STATEFUL_PRIMITIVES` locked at 172 entries by exact
|
|
40
|
+
name-set; every shipping export `@stable`; pre-1.0 deprecations
|
|
41
|
+
removed (`PHASE_1_SCENARIOS`).
|
|
42
|
+
- Canonical language spec published (`docs/spec/`): grammar,
|
|
43
|
+
semantics, manifest, emissions, versioning -- self-contained for
|
|
44
|
+
alternate implementations. The `v1.0.0` tag is the frozen spec
|
|
45
|
+
snapshot.
|
|
46
|
+
- Public conformance reports: `pnpm conformance --report` emits
|
|
47
|
+
`CONFORMANCE.md` + `conformance-report.json`; canvas2d reference
|
|
48
|
+
report published and drift-gated.
|
|
49
|
+
- Adapter-author path proven end-to-end: scaffolded adapters ship a
|
|
50
|
+
wired conformance test; full writing-an-adapter tutorial +
|
|
51
|
+
Lightweight Charts porting walkthrough.
|
|
52
|
+
- Pine migration guide finalised with a pattern-coverage matrix
|
|
53
|
+
audited against the top ~50 Pine scripts.
|
|
54
|
+
|
|
55
|
+
### Minor Changes
|
|
56
|
+
|
|
57
|
+
- d14a034: Add phase 5 server alerts, multi-timeframe request handling, runtime persistence, QuickJS hosting, expanded plot and table rendering, color helpers, alert conditions, and volume profile primitives.
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- Pre-1.0 surface cleanup: remove the deprecated `PHASE_1_SCENARIOS`
|
|
62
|
+
alias (use `ALL_SCENARIOS`) and promote every shipping export from
|
|
63
|
+
`@experimental` to `@stable` ahead of the `apiVersion: 1` freeze.
|
|
64
|
+
- Updated dependencies [d14a034]
|
|
65
|
+
- Updated dependencies [3cfff10]
|
|
66
|
+
- Updated dependencies [3cfff10]
|
|
67
|
+
- Updated dependencies [3cfff10]
|
|
68
|
+
- Updated dependencies [3cfff10]
|
|
69
|
+
- Updated dependencies
|
|
70
|
+
- Updated dependencies
|
|
71
|
+
- Updated dependencies
|
|
72
|
+
- @invinite-org/chartlang-adapter-kit@1.0.0
|
|
73
|
+
- @invinite-org/chartlang-compiler@1.0.0
|
|
74
|
+
- @invinite-org/chartlang-core@1.0.0
|
|
75
|
+
|
|
76
|
+
## 0.5.0
|
|
77
|
+
|
|
78
|
+
### Phase 5
|
|
79
|
+
|
|
80
|
+
#### Patch Changes
|
|
81
|
+
|
|
82
|
+
- Updated dependencies
|
|
83
|
+
- Updated dependencies
|
|
84
|
+
- Updated dependencies
|
|
85
|
+
- Updated dependencies
|
|
86
|
+
- Updated dependencies
|
|
87
|
+
- Updated dependencies
|
|
88
|
+
- Updated dependencies
|
|
89
|
+
- Updated dependencies
|
|
90
|
+
- Updated dependencies
|
|
91
|
+
- Updated dependencies
|
|
92
|
+
- Updated dependencies
|
|
93
|
+
- Updated dependencies
|
|
94
|
+
- @invinite-org/chartlang-core@0.5.0
|
|
95
|
+
- @invinite-org/chartlang-compiler@0.5.0
|
|
96
|
+
- @invinite-org/chartlang-adapter-kit@0.5.0
|
|
97
|
+
|
|
98
|
+
## 0.4.0
|
|
99
|
+
|
|
100
|
+
### Minor Changes
|
|
101
|
+
|
|
102
|
+
- Phase 4 - Editor + Inputs + Timeframes + Tier-1 Pine parity.
|
|
103
|
+
Adds: input._ builders, state._ / state.tick.\* slots,
|
|
104
|
+
barstate / syminfo / timeframe views, request.security typed
|
|
105
|
+
surface (NaN fallback), defineIndicator overrides,
|
|
106
|
+
Capabilities triad (intervals / multiTimeframe / subPanes /
|
|
107
|
+
symInfoFields / maxDrawingsPerScript / alertConditions / logs),
|
|
108
|
+
language-service hover registry + LSP-style API, CodeMirror 6
|
|
109
|
+
editor shell + /react sub-export, Inputs UI ViewModel + React
|
|
110
|
+
form. See tasks/phase-4-editor-tier1/README.md.
|
|
111
|
+
- Ship the Phase 4 headless language service with generated hover registry,
|
|
112
|
+
diagnostics, hovers, completions, signature help, definitions, and interval
|
|
113
|
+
capability helpers.
|
|
114
|
+
|
|
115
|
+
### Patch Changes
|
|
116
|
+
|
|
117
|
+
- Updated dependencies [3f3ce38]
|
|
118
|
+
- Updated dependencies [3f3ce38]
|
|
119
|
+
- Updated dependencies [3f3ce38]
|
|
120
|
+
- Updated dependencies [3f3ce38]
|
|
121
|
+
- Updated dependencies [3f3ce38]
|
|
122
|
+
- Updated dependencies [38fb475]
|
|
123
|
+
- Updated dependencies [38fb475]
|
|
124
|
+
- Updated dependencies [38fb475]
|
|
125
|
+
- Updated dependencies [38fb475]
|
|
126
|
+
- Updated dependencies [38fb475]
|
|
127
|
+
- Updated dependencies [38fb475]
|
|
128
|
+
- Updated dependencies [38fb475]
|
|
129
|
+
- Updated dependencies [38fb475]
|
|
130
|
+
- Updated dependencies [38fb475]
|
|
131
|
+
- Updated dependencies [38fb475]
|
|
132
|
+
- Updated dependencies [38fb475]
|
|
133
|
+
- Updated dependencies [38fb475]
|
|
134
|
+
- Updated dependencies [38fb475]
|
|
135
|
+
- Updated dependencies [38fb475]
|
|
136
|
+
- Updated dependencies [38fb475]
|
|
137
|
+
- Updated dependencies [38fb475]
|
|
138
|
+
- Updated dependencies [38fb475]
|
|
139
|
+
- Updated dependencies [38fb475]
|
|
140
|
+
- Updated dependencies [38fb475]
|
|
141
|
+
- Updated dependencies [38fb475]
|
|
142
|
+
- Updated dependencies [38fb475]
|
|
143
|
+
- Updated dependencies [38fb475]
|
|
144
|
+
- Updated dependencies [38fb475]
|
|
145
|
+
- Updated dependencies [38fb475]
|
|
146
|
+
- Updated dependencies [38fb475]
|
|
147
|
+
- Updated dependencies [38fb475]
|
|
148
|
+
- Updated dependencies [38fb475]
|
|
149
|
+
- Updated dependencies [38fb475]
|
|
150
|
+
- Updated dependencies [b0d296b]
|
|
151
|
+
- Updated dependencies [b0d296b]
|
|
152
|
+
- Updated dependencies [b0d296b]
|
|
153
|
+
- Updated dependencies [b0d296b]
|
|
154
|
+
- Updated dependencies [b0d296b]
|
|
155
|
+
- Updated dependencies [b0d296b]
|
|
156
|
+
- Updated dependencies [b0d296b]
|
|
157
|
+
- Updated dependencies [b0d296b]
|
|
158
|
+
- Updated dependencies [b0d296b]
|
|
159
|
+
- Updated dependencies [b0d296b]
|
|
160
|
+
- Updated dependencies [b0d296b]
|
|
161
|
+
- Updated dependencies [b0d296b]
|
|
162
|
+
- Updated dependencies [b0d296b]
|
|
163
|
+
- Updated dependencies [b0d296b]
|
|
164
|
+
- Updated dependencies [b0d296b]
|
|
165
|
+
- Updated dependencies [b0d296b]
|
|
166
|
+
- Updated dependencies [b0d296b]
|
|
167
|
+
- Updated dependencies [b0d296b]
|
|
168
|
+
- Updated dependencies [b0d296b]
|
|
169
|
+
- Updated dependencies
|
|
170
|
+
- Updated dependencies
|
|
171
|
+
- Updated dependencies
|
|
172
|
+
- Updated dependencies
|
|
173
|
+
- Updated dependencies
|
|
174
|
+
- Updated dependencies
|
|
175
|
+
- Updated dependencies
|
|
176
|
+
- Updated dependencies
|
|
177
|
+
- Updated dependencies
|
|
178
|
+
- Updated dependencies
|
|
179
|
+
- Updated dependencies
|
|
180
|
+
- @invinite-org/chartlang-adapter-kit@0.4.0
|
|
181
|
+
- @invinite-org/chartlang-compiler@0.4.0
|
|
182
|
+
- @invinite-org/chartlang-core@0.4.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Invinite
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @invinite-org/chartlang-language-service
|
|
2
|
+
|
|
3
|
+
`experimental`
|
|
4
|
+
|
|
5
|
+
Headless editor intelligence for chartlang: diagnostics, completions, hover
|
|
6
|
+
docs, signature help, definitions, and interval-aware suggestions.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pnpm add @invinite-org/chartlang-language-service
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Public surface
|
|
15
|
+
|
|
16
|
+
| Export | Purpose |
|
|
17
|
+
|---|---|
|
|
18
|
+
| `createLanguageService(opts?)` | Builds a capability-aware service instance. |
|
|
19
|
+
| `compileToDiagnostics(source, opts)` | Converts compiler diagnostics to LSP-style ranges. |
|
|
20
|
+
| `getCompletions(document, position)` | Returns core symbols and interval completions. |
|
|
21
|
+
| `getHoverDoc(document, position)` | Looks up generated hover docs from core JSDoc. |
|
|
22
|
+
| `getSignatureHelp(document, position)` | Returns call signatures for known symbols. |
|
|
23
|
+
| `getDefinition(document, position)` | Resolves generated source-location metadata. |
|
|
24
|
+
| `getAvailableIntervals()` | Reads intervals from target capabilities. |
|
|
25
|
+
| `HOVER_REGISTRY` | Checked-in generated hover-doc table. |
|
|
26
|
+
|
|
27
|
+
## Minimum-viable API call
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { createLanguageService } from "@invinite-org/chartlang-language-service";
|
|
31
|
+
|
|
32
|
+
const service = createLanguageService({ targetCapabilities: capabilities });
|
|
33
|
+
const diagnostics = service.compileToDiagnostics(source, {
|
|
34
|
+
apiVersion: 1,
|
|
35
|
+
sourcePath: "demo.chart.ts",
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Docs
|
|
40
|
+
|
|
41
|
+
See [`docs/reference/`](../../docs/reference/).
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HoverRegistryEntry } from "../hoverRegistry.generated.js";
|
|
2
|
+
import type { CompletionItem } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Collect registry and source-local completion items for an offset.
|
|
5
|
+
*
|
|
6
|
+
* @since 0.4
|
|
7
|
+
* @stable
|
|
8
|
+
* @example
|
|
9
|
+
* const items = collectCompletions("const length = 20;", 5, {});
|
|
10
|
+
* void items;
|
|
11
|
+
*/
|
|
12
|
+
export declare function collectCompletions(source: string, _offset: number, registry: Readonly<Record<string, HoverRegistryEntry>>): ReadonlyArray<CompletionItem>;
|
|
13
|
+
//# sourceMappingURL=collectCompletions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectCompletions.d.ts","sourceRoot":"","sources":["../../src/_lib/collectCompletions.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,GACvD,aAAa,CAAC,cAAc,CAAC,CAa/B"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Copyright (c) 2026 Invinite. Licensed under the MIT License.
|
|
2
|
+
// See the LICENSE file in the repo root for full license text.
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
import { toHoverDoc } from "./toHoverDoc.js";
|
|
5
|
+
/**
|
|
6
|
+
* Collect registry and source-local completion items for an offset.
|
|
7
|
+
*
|
|
8
|
+
* @since 0.4
|
|
9
|
+
* @stable
|
|
10
|
+
* @example
|
|
11
|
+
* const items = collectCompletions("const length = 20;", 5, {});
|
|
12
|
+
* void items;
|
|
13
|
+
*/
|
|
14
|
+
export function collectCompletions(source, _offset, registry) {
|
|
15
|
+
const registryItems = Object.values(registry).map(registryCompletion);
|
|
16
|
+
const localItems = collectLocalIdentifiers(source).map((label) => Object.freeze({
|
|
17
|
+
label,
|
|
18
|
+
kind: "property",
|
|
19
|
+
insertText: label,
|
|
20
|
+
detail: "local identifier",
|
|
21
|
+
}));
|
|
22
|
+
const byLabel = new Map();
|
|
23
|
+
for (const item of [...registryItems, ...localItems])
|
|
24
|
+
byLabel.set(item.label, item);
|
|
25
|
+
return Object.freeze([...byLabel.values()].sort((a, b) => a.label.localeCompare(b.label)));
|
|
26
|
+
}
|
|
27
|
+
function registryCompletion(entry) {
|
|
28
|
+
return Object.freeze({
|
|
29
|
+
label: entry.fqn,
|
|
30
|
+
kind: entry.kind === "type" ? "property" : entry.kind,
|
|
31
|
+
insertText: entry.fqn,
|
|
32
|
+
detail: entry.title,
|
|
33
|
+
doc: toHoverDoc(entry),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function collectLocalIdentifiers(source) {
|
|
37
|
+
const sourceFile = ts.createSourceFile("script.chart.ts", source, ts.ScriptTarget.Latest, true);
|
|
38
|
+
const names = new Set();
|
|
39
|
+
const visit = (node) => {
|
|
40
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name))
|
|
41
|
+
names.add(node.name.text);
|
|
42
|
+
if (ts.isFunctionDeclaration(node) && node.name !== undefined)
|
|
43
|
+
names.add(node.name.text);
|
|
44
|
+
if (ts.isParameter(node) && ts.isIdentifier(node.name))
|
|
45
|
+
names.add(node.name.text);
|
|
46
|
+
ts.forEachChild(node, visit);
|
|
47
|
+
};
|
|
48
|
+
visit(sourceFile);
|
|
49
|
+
return Object.freeze([...names].sort());
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=collectCompletions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectCompletions.js","sourceRoot":"","sources":["../../src/_lib/collectCompletions.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAAE,MAAM,YAAY,CAAC;AAI5B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAC9B,MAAc,EACd,OAAe,EACf,QAAsD;IAEtD,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACtE,MAAM,UAAU,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAC7D,MAAM,CAAC,MAAM,CAAC;QACV,KAAK;QACL,IAAI,EAAE,UAAmB;QACzB,UAAU,EAAE,KAAK;QACjB,MAAM,EAAE,kBAAkB;KAC7B,CAAC,CACL,CAAC;IACF,MAAM,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;IAClD,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,aAAa,EAAE,GAAG,UAAU,CAAC;QAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACpF,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC/F,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAyB;IACjD,OAAO,MAAM,CAAC,MAAM,CAAC;QACjB,KAAK,EAAE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E,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return true when an offset sits inside a completable interval string.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.4
|
|
5
|
+
* @stable
|
|
6
|
+
* @example
|
|
7
|
+
* const inside = isInsideIntervalLiteral('request.security({ interval: "" })', 31);
|
|
8
|
+
* void inside;
|
|
9
|
+
*/
|
|
10
|
+
export declare function isInsideIntervalLiteral(source: string, offset: number): boolean;
|
|
11
|
+
//# sourceMappingURL=isInsideIntervalLiteral.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isInsideIntervalLiteral.d.ts","sourceRoot":"","sources":["../../src/_lib/isInsideIntervalLiteral.ts"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAkB/E"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Copyright (c) 2026 Invinite. Licensed under the MIT License.
|
|
2
|
+
// See the LICENSE file in the repo root for full license text.
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
/**
|
|
5
|
+
* Return true when an offset sits inside a completable interval string.
|
|
6
|
+
*
|
|
7
|
+
* @since 0.4
|
|
8
|
+
* @stable
|
|
9
|
+
* @example
|
|
10
|
+
* const inside = isInsideIntervalLiteral('request.security({ interval: "" })', 31);
|
|
11
|
+
* void inside;
|
|
12
|
+
*/
|
|
13
|
+
export function isInsideIntervalLiteral(source, offset) {
|
|
14
|
+
const sourceFile = ts.createSourceFile("script.chart.ts", source, ts.ScriptTarget.Latest, true);
|
|
15
|
+
let matched = false;
|
|
16
|
+
const visit = (node) => {
|
|
17
|
+
if (matched)
|
|
18
|
+
return;
|
|
19
|
+
if (ts.isStringLiteral(node) &&
|
|
20
|
+
offset > node.getStart(sourceFile) &&
|
|
21
|
+
offset < node.getEnd()) {
|
|
22
|
+
matched = isIntervalLiteralNode(node, sourceFile);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
ts.forEachChild(node, visit);
|
|
26
|
+
};
|
|
27
|
+
visit(sourceFile);
|
|
28
|
+
return matched;
|
|
29
|
+
}
|
|
30
|
+
function isIntervalLiteralNode(node, sourceFile) {
|
|
31
|
+
const parent = node.parent;
|
|
32
|
+
if (ts.isCallExpression(parent))
|
|
33
|
+
return callName(parent, sourceFile) === "input.interval";
|
|
34
|
+
if (!ts.isPropertyAssignment(parent))
|
|
35
|
+
return false;
|
|
36
|
+
if (!propertyNameIs(parent.name, "interval"))
|
|
37
|
+
return false;
|
|
38
|
+
const objectLiteral = parent.parent;
|
|
39
|
+
/* v8 ignore next -- PropertyAssignment nodes are owned by ObjectLiteralExpression. */
|
|
40
|
+
if (!ts.isObjectLiteralExpression(objectLiteral))
|
|
41
|
+
return false;
|
|
42
|
+
const call = objectLiteral.parent;
|
|
43
|
+
return ts.isCallExpression(call) && callName(call, sourceFile) === "request.security";
|
|
44
|
+
}
|
|
45
|
+
function propertyNameIs(name, expected) {
|
|
46
|
+
return (ts.isIdentifier(name) || ts.isStringLiteral(name)) && name.text === expected;
|
|
47
|
+
}
|
|
48
|
+
function callName(call, sourceFile) {
|
|
49
|
+
const expression = call.expression;
|
|
50
|
+
if (!ts.isPropertyAccessExpression(expression))
|
|
51
|
+
return null;
|
|
52
|
+
const left = expression.expression;
|
|
53
|
+
/* v8 ignore next -- covered defensively for malformed/incremental ASTs. */
|
|
54
|
+
if (!ts.isIdentifier(left))
|
|
55
|
+
return null;
|
|
56
|
+
return `${left.text}.${expression.name.getText(sourceFile)}`;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=isInsideIntervalLiteral.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isInsideIntervalLiteral.js","sourceRoot":"","sources":["../../src/_lib/isInsideIntervalLiteral.ts"],"names":[],"mappings":"AAAA,+DAA+D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EAAE,CAAC,yBAAyB,CAAC,aAAa,CAAC;QAAE,OAAO,KAAK,CAAC;IAC/D,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC;IAClC,OAAO,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,kBAAkB,CAAC;AAC1F,CAAC;AAED,SAAS,cAAc,CAAC,IAAqB,EAAE,QAAgB;IAC3D,OAAO,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC;AACzF,CAAC;AAED,SAAS,QAAQ,CAAC,IAAuB,EAAE,UAAyB;IAChE,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACnC,IAAI,CAAC,EAAE,CAAC,0BAA0B,CAAC,UAAU,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5D,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC;IACnC,2EAA2E;IAC3E,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACxC,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { CompileDiagnostic } from "@invinite-org/chartlang-compiler";
|
|
2
|
+
import type { LspDiagnostic, LspSeverity } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Map a compiler diagnostic into the language-service diagnostic shape.
|
|
5
|
+
*
|
|
6
|
+
* @since 0.4
|
|
7
|
+
* @stable
|
|
8
|
+
* @example
|
|
9
|
+
* const diagnostic = mapDiagnostic({
|
|
10
|
+
* severity: "error",
|
|
11
|
+
* code: "unbounded-loop",
|
|
12
|
+
* message: "while loops are not allowed",
|
|
13
|
+
* file: "demo.chart.ts",
|
|
14
|
+
* line: 1,
|
|
15
|
+
* column: 1,
|
|
16
|
+
* });
|
|
17
|
+
* void diagnostic;
|
|
18
|
+
*/
|
|
19
|
+
export declare function mapDiagnostic(diagnostic: CompileDiagnostic): LspDiagnostic;
|
|
20
|
+
/**
|
|
21
|
+
* Build a language-service diagnostic at a 1-based line/column position.
|
|
22
|
+
*
|
|
23
|
+
* @since 0.4
|
|
24
|
+
* @stable
|
|
25
|
+
* @example
|
|
26
|
+
* const diagnostic = makeDiagnostic({
|
|
27
|
+
* line: 1,
|
|
28
|
+
* column: 1,
|
|
29
|
+
* severity: "hint",
|
|
30
|
+
* code: "unsupported-interval",
|
|
31
|
+
* message: "Unsupported interval",
|
|
32
|
+
* });
|
|
33
|
+
* void diagnostic;
|
|
34
|
+
*/
|
|
35
|
+
export declare function makeDiagnostic(args: {
|
|
36
|
+
readonly line: number;
|
|
37
|
+
readonly column: number;
|
|
38
|
+
readonly severity: LspSeverity;
|
|
39
|
+
readonly code: string;
|
|
40
|
+
readonly message: string;
|
|
41
|
+
readonly relatedCallsite?: string;
|
|
42
|
+
}): LspDiagnostic;
|
|
43
|
+
//# sourceMappingURL=mapDiagnostic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapDiagnostic.d.ts","sourceRoot":"","sources":["../../src/_lib/mapDiagnostic.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAE1E,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE9D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,iBAAiB,GAAG,aAAa,CAW1E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACrC,GAAG,aAAa,CAehB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Copyright (c) 2026 Invinite. Licensed under the MIT License.
|
|
2
|
+
// See the LICENSE file in the repo root for full license text.
|
|
3
|
+
/**
|
|
4
|
+
* Map a compiler diagnostic into the language-service diagnostic shape.
|
|
5
|
+
*
|
|
6
|
+
* @since 0.4
|
|
7
|
+
* @stable
|
|
8
|
+
* @example
|
|
9
|
+
* const diagnostic = mapDiagnostic({
|
|
10
|
+
* severity: "error",
|
|
11
|
+
* code: "unbounded-loop",
|
|
12
|
+
* message: "while loops are not allowed",
|
|
13
|
+
* file: "demo.chart.ts",
|
|
14
|
+
* line: 1,
|
|
15
|
+
* column: 1,
|
|
16
|
+
* });
|
|
17
|
+
* void diagnostic;
|
|
18
|
+
*/
|
|
19
|
+
export function mapDiagnostic(diagnostic) {
|
|
20
|
+
const related = diagnostic.nodeText === undefined ? {} : { relatedCallsite: diagnostic.nodeText };
|
|
21
|
+
return makeDiagnostic({
|
|
22
|
+
line: diagnostic.line,
|
|
23
|
+
column: diagnostic.column,
|
|
24
|
+
severity: diagnostic.severity,
|
|
25
|
+
code: diagnostic.code,
|
|
26
|
+
message: diagnostic.message,
|
|
27
|
+
...related,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Build a language-service diagnostic at a 1-based line/column position.
|
|
32
|
+
*
|
|
33
|
+
* @since 0.4
|
|
34
|
+
* @stable
|
|
35
|
+
* @example
|
|
36
|
+
* const diagnostic = makeDiagnostic({
|
|
37
|
+
* line: 1,
|
|
38
|
+
* column: 1,
|
|
39
|
+
* severity: "hint",
|
|
40
|
+
* code: "unsupported-interval",
|
|
41
|
+
* message: "Unsupported interval",
|
|
42
|
+
* });
|
|
43
|
+
* void diagnostic;
|
|
44
|
+
*/
|
|
45
|
+
export function makeDiagnostic(args) {
|
|
46
|
+
const related = args.relatedCallsite === undefined ? {} : { relatedCallsite: args.relatedCallsite };
|
|
47
|
+
return Object.freeze({
|
|
48
|
+
range: Object.freeze({
|
|
49
|
+
startLine: args.line,
|
|
50
|
+
startColumn: args.column,
|
|
51
|
+
endLine: args.line,
|
|
52
|
+
endColumn: args.column,
|
|
53
|
+
}),
|
|
54
|
+
severity: args.severity,
|
|
55
|
+
code: args.code,
|
|
56
|
+
message: args.message,
|
|
57
|
+
...related,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=mapDiagnostic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapDiagnostic.js","sourceRoot":"","sources":["../../src/_lib/mapDiagnostic.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAM/D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,aAAa,CAAC,UAA6B;IACvD,MAAM,OAAO,GACT,UAAU,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC;IACtF,OAAO,cAAc,CAAC;QAClB,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,GAAG,OAAO;KACb,CAAC,CAAC;AACP,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAAC,IAO9B;IACG,MAAM,OAAO,GACT,IAAI,CAAC,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,IAAI,CAAC,eAAe,EAAE,CAAC;IACxF,OAAO,MAAM,CAAC,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;YACjB,SAAS,EAAE,IAAI,CAAC,IAAI;YACpB,WAAW,EAAE,IAAI,CAAC,MAAM;YACxB,OAAO,EAAE,IAAI,CAAC,IAAI;YAClB,SAAS,EAAE,IAAI,CAAC,MAAM;SACzB,CAAC;QACF,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,GAAG,OAAO;KACb,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the chartlang primitive FQN under a source offset.
|
|
4
|
+
*
|
|
5
|
+
* @since 0.4
|
|
6
|
+
* @stable
|
|
7
|
+
* @example
|
|
8
|
+
* const fqn = resolveFqnAtOffset("ta.ema(bar.close, 20)", 4);
|
|
9
|
+
* void fqn;
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveFqnAtOffset(source: string, offset: number): string | null;
|
|
12
|
+
/**
|
|
13
|
+
* Find the smallest AST token containing an offset.
|
|
14
|
+
*
|
|
15
|
+
* @since 0.4
|
|
16
|
+
* @stable
|
|
17
|
+
* @example
|
|
18
|
+
* const sf = ts.createSourceFile("x.ts", "ta.ema()", ts.ScriptTarget.Latest, true);
|
|
19
|
+
* const token = findTokenAtOffset(sf, 1);
|
|
20
|
+
* void token;
|
|
21
|
+
*/
|
|
22
|
+
export declare function findTokenAtOffset(sourceFile: ts.SourceFile, offset: number): ts.Node | null;
|
|
23
|
+
//# sourceMappingURL=resolveFqnAtOffset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveFqnAtOffset.d.ts","sourceRoot":"","sources":["../../src/_lib/resolveFqnAtOffset.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOhF;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,EAAE,CAAC,IAAI,GAAG,IAAI,CAW3F"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Copyright (c) 2026 Invinite. Licensed under the MIT License.
|
|
2
|
+
// See the LICENSE file in the repo root for full license text.
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
/**
|
|
5
|
+
* Resolve the chartlang primitive FQN under a source offset.
|
|
6
|
+
*
|
|
7
|
+
* @since 0.4
|
|
8
|
+
* @stable
|
|
9
|
+
* @example
|
|
10
|
+
* const fqn = resolveFqnAtOffset("ta.ema(bar.close, 20)", 4);
|
|
11
|
+
* void fqn;
|
|
12
|
+
*/
|
|
13
|
+
export function resolveFqnAtOffset(source, offset) {
|
|
14
|
+
const sourceFile = ts.createSourceFile("script.chart.ts", source, ts.ScriptTarget.Latest, true);
|
|
15
|
+
const token = findTokenAtOffset(sourceFile, offset);
|
|
16
|
+
if (token === null || !ts.isIdentifier(token))
|
|
17
|
+
return null;
|
|
18
|
+
const access = enclosingPropertyAccess(token);
|
|
19
|
+
if (access !== null)
|
|
20
|
+
return propertyAccessToFqn(access);
|
|
21
|
+
return token.text;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Find the smallest AST token containing an offset.
|
|
25
|
+
*
|
|
26
|
+
* @since 0.4
|
|
27
|
+
* @stable
|
|
28
|
+
* @example
|
|
29
|
+
* const sf = ts.createSourceFile("x.ts", "ta.ema()", ts.ScriptTarget.Latest, true);
|
|
30
|
+
* const token = findTokenAtOffset(sf, 1);
|
|
31
|
+
* void token;
|
|
32
|
+
*/
|
|
33
|
+
export function findTokenAtOffset(sourceFile, offset) {
|
|
34
|
+
let best = null;
|
|
35
|
+
const visit = (node) => {
|
|
36
|
+
const start = node.getStart(sourceFile);
|
|
37
|
+
const end = node.getEnd();
|
|
38
|
+
if (offset < start || offset > end)
|
|
39
|
+
return;
|
|
40
|
+
best = node;
|
|
41
|
+
ts.forEachChild(node, visit);
|
|
42
|
+
};
|
|
43
|
+
visit(sourceFile);
|
|
44
|
+
return best;
|
|
45
|
+
}
|
|
46
|
+
function enclosingPropertyAccess(token) {
|
|
47
|
+
let current = token;
|
|
48
|
+
let candidate = null;
|
|
49
|
+
while (current.parent !== undefined) {
|
|
50
|
+
const parent = current.parent;
|
|
51
|
+
if (ts.isPropertyAccessExpression(parent)) {
|
|
52
|
+
candidate = parent;
|
|
53
|
+
current = parent;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
return candidate;
|
|
59
|
+
}
|
|
60
|
+
function propertyAccessToFqn(access) {
|
|
61
|
+
const parts = [];
|
|
62
|
+
let current = access;
|
|
63
|
+
while (ts.isPropertyAccessExpression(current)) {
|
|
64
|
+
parts.unshift(current.name.text);
|
|
65
|
+
current = current.expression;
|
|
66
|
+
}
|
|
67
|
+
if (!ts.isIdentifier(current))
|
|
68
|
+
return null;
|
|
69
|
+
parts.unshift(current.text);
|
|
70
|
+
return parts.join(".");
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=resolveFqnAtOffset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveFqnAtOffset.js","sourceRoot":"","sources":["../../src/_lib/resolveFqnAtOffset.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B;;;;;;;;GAQG;AACH,MAAM,UAAU,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O,CAAC,MAAM,CAAC;QAC9B,IAAI,EAAE,CAAC,0BAA0B,CAAC,MAAM,CAAC,EAAE,CAAC;YACxC,SAAS,GAAG,MAAM,CAAC;YACnB,OAAO,GAAG,MAAM,CAAC;YACjB,SAAS;QACb,CAAC;QACD,MAAM;IACV,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAmC;IAC5D,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,OAAO,GAAkB,MAAM,CAAC;IACpC,OAAO,EAAE,CAAC,0BAA0B,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5C,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjC,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IACjC,CAAC;IACD,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3C,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { HoverRegistryEntry } from "../hoverRegistry.generated.js";
|
|
2
|
+
import type { HoverDoc } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Convert a generated hover-registry entry into the public hover payload.
|
|
5
|
+
*
|
|
6
|
+
* @since 0.4
|
|
7
|
+
* @stable
|
|
8
|
+
* @example
|
|
9
|
+
* const doc = toHoverDoc({
|
|
10
|
+
* fqn: "ta.ema",
|
|
11
|
+
* kind: "function",
|
|
12
|
+
* title: "ta.ema(source, length)",
|
|
13
|
+
* summary: "EMA.",
|
|
14
|
+
* since: "0.1",
|
|
15
|
+
* stability: "stable",
|
|
16
|
+
* });
|
|
17
|
+
* void doc;
|
|
18
|
+
*/
|
|
19
|
+
export declare function toHoverDoc(entry: HoverRegistryEntry): HoverDoc;
|
|
20
|
+
//# sourceMappingURL=toHoverDoc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toHoverDoc.d.ts","sourceRoot":"","sources":["../../src/_lib/toHoverDoc.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,kBAAkB,GAAG,QAAQ,CAO9D"}
|