@birdcc/lsp 0.0.1-alpha.1 → 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -23
- package/dist/asn-completion.d.ts +21 -0
- package/dist/asn-completion.d.ts.map +1 -0
- package/dist/asn-completion.js +42 -0
- package/dist/asn-completion.js.map +1 -0
- package/dist/asn-context.d.ts +9 -0
- package/dist/asn-context.d.ts.map +1 -0
- package/dist/asn-context.js +203 -0
- package/dist/asn-context.js.map +1 -0
- package/dist/asn-hover.d.ts +11 -0
- package/dist/asn-hover.d.ts.map +1 -0
- package/dist/asn-hover.js +33 -0
- package/dist/asn-hover.js.map +1 -0
- package/dist/asn-inlay-hints.d.ts +13 -0
- package/dist/asn-inlay-hints.d.ts.map +1 -0
- package/dist/asn-inlay-hints.js +47 -0
- package/dist/asn-inlay-hints.js.map +1 -0
- package/dist/diagnostic.d.ts.map +1 -1
- package/dist/diagnostic.js +2 -10
- package/dist/diagnostic.js.map +1 -1
- package/dist/document-symbol.js +1 -1
- package/dist/document-symbol.js.map +1 -1
- package/dist/hover-context.d.ts +31 -0
- package/dist/hover-context.d.ts.map +1 -0
- package/dist/hover-context.js +125 -0
- package/dist/hover-context.js.map +1 -0
- package/dist/hover-docs/00-base.yaml +5 -0
- package/dist/hover-docs/10-global-options.yaml +442 -0
- package/dist/hover-docs/20-filter-language.yaml +209 -0
- package/dist/hover-docs/30-channel-options.yaml +244 -0
- package/dist/hover-docs/40-protocol-common.yaml +59 -0
- package/dist/hover-docs/41-protocol-igp.yaml +305 -0
- package/dist/hover-docs/42-protocol-kernel-static.yaml +220 -0
- package/dist/hover-docs/43-protocol-mpls.yaml +40 -0
- package/dist/hover-docs/44-protocol-extended.yaml +635 -0
- package/dist/hover-docs/50-protocol-bgp.yaml +482 -0
- package/dist/hover-docs/60-protocol-ospf.yaml +527 -0
- package/dist/hover-docs.d.ts +5 -1
- package/dist/hover-docs.d.ts.map +1 -1
- package/dist/hover-docs.js +376 -51
- package/dist/hover-docs.js.map +1 -1
- package/dist/hover-usage/00-base.yaml +2 -0
- package/dist/hover-usage/10-global-usage.yaml +73 -0
- package/dist/hover-usage/20-filter-usage.yaml +41 -0
- package/dist/hover-usage/30-channel-usage.yaml +41 -0
- package/dist/hover-usage/40-protocol-usage.yaml +258 -0
- package/dist/hover-usage/50-bgp-usage.yaml +254 -0
- package/dist/hover-usage/60-ospf-usage.yaml +340 -0
- package/dist/hover.d.ts +10 -0
- package/dist/hover.d.ts.map +1 -1
- package/dist/hover.js +152 -46
- package/dist/hover.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/init/workspace-init.d.ts +28 -0
- package/dist/init/workspace-init.d.ts.map +1 -0
- package/dist/init/workspace-init.js +72 -0
- package/dist/init/workspace-init.js.map +1 -0
- package/dist/lsp-server.d.ts +7 -1
- package/dist/lsp-server.d.ts.map +1 -1
- package/dist/lsp-server.js +277 -65
- package/dist/lsp-server.js.map +1 -1
- package/dist/project-config.d.ts +22 -0
- package/dist/project-config.d.ts.map +1 -0
- package/dist/project-config.js +307 -0
- package/dist/project-config.js.map +1 -0
- package/dist/shared.d.ts +1 -0
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +4 -24
- package/dist/shared.js.map +1 -1
- package/dist/symbol-utils.d.ts +6 -6
- package/dist/symbol-utils.d.ts.map +1 -1
- package/dist/symbol-utils.js +24 -25
- package/dist/symbol-utils.js.map +1 -1
- package/dist/type-hint-inlay.d.ts +4 -0
- package/dist/type-hint-inlay.d.ts.map +1 -0
- package/dist/type-hint-inlay.js +27 -0
- package/dist/type-hint-inlay.js.map +1 -0
- package/dist/utils.d.ts +65 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +97 -0
- package/dist/utils.js.map +1 -0
- package/package.json +11 -7
- package/dist/hover-docs.yaml +0 -600
package/README.md
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
</div>
|
|
6
6
|
|
|
7
|
+
<div align="center">
|
|
8
|
+
|
|
9
|
+
> ⚠️ **Alpha Stage**: This package is in early development. APIs may change frequently, and unexpected issues may occur. Please evaluate carefully before deploying in production environments.
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
7
13
|
[](https://www.npmjs.com/package/@birdcc/lsp) [](https://www.gnu.org/licenses/gpl-3.0) [](https://www.typescriptlang.org/) [](https://github.com/microsoft/vscode-languageserver-node)
|
|
8
14
|
|
|
9
15
|
> [Overview](#overview) · [Features](#features) · [Installation](#installation) · [Usage](#usage) · [Editor Integration](#editor-integration) · [API Reference](#api-reference) · [Architecture](#architecture)
|
|
@@ -12,9 +18,9 @@
|
|
|
12
18
|
|
|
13
19
|
**@birdcc/lsp** is the Language Server Protocol implementation for BIRD2 configuration files, delivering real-time diagnostics, intelligent code completion, hover tooltips, and more for editor integration.
|
|
14
20
|
|
|
15
|
-
| Package
|
|
16
|
-
|
|
|
17
|
-
| `@birdcc/lsp` | 0.1.0
|
|
21
|
+
| Package | Version | Description |
|
|
22
|
+
| ------------- | ------- | ---------------------------------------------------- |
|
|
23
|
+
| `@birdcc/lsp` | 0.1.0 | LSP server implementation with real-time diagnostics |
|
|
18
24
|
|
|
19
25
|
---
|
|
20
26
|
|
|
@@ -133,11 +139,7 @@ args = ["birdcc", "lsp", "--stdio"]
|
|
|
133
139
|
### Exports
|
|
134
140
|
|
|
135
141
|
```typescript
|
|
136
|
-
import {
|
|
137
|
-
startLspServer,
|
|
138
|
-
toLspDiagnostic,
|
|
139
|
-
createConnection,
|
|
140
|
-
} from "@birdcc/lsp";
|
|
142
|
+
import { startLspServer, toLspDiagnostic, createConnection } from "@birdcc/lsp";
|
|
141
143
|
```
|
|
142
144
|
|
|
143
145
|
### `startLspServer(): void`
|
|
@@ -294,26 +296,26 @@ flowchart LR
|
|
|
294
296
|
|
|
295
297
|
### Server Capabilities
|
|
296
298
|
|
|
297
|
-
| Capability
|
|
298
|
-
|
|
|
299
|
-
| `textDocumentSync`
|
|
300
|
-
| `documentSymbolProvider` | ✅
|
|
301
|
-
| `hoverProvider`
|
|
302
|
-
| `definitionProvider`
|
|
303
|
-
| `referencesProvider`
|
|
304
|
-
| `completionProvider`
|
|
299
|
+
| Capability | Status |
|
|
300
|
+
| ------------------------ | ----------- |
|
|
301
|
+
| `textDocumentSync` | Incremental |
|
|
302
|
+
| `documentSymbolProvider` | ✅ |
|
|
303
|
+
| `hoverProvider` | ✅ |
|
|
304
|
+
| `definitionProvider` | ✅ |
|
|
305
|
+
| `referencesProvider` | ✅ |
|
|
306
|
+
| `completionProvider` | ✅ |
|
|
305
307
|
|
|
306
308
|
---
|
|
307
309
|
|
|
308
310
|
## Related Packages
|
|
309
311
|
|
|
310
|
-
| Package
|
|
311
|
-
|
|
|
312
|
-
| [@birdcc/parser](../parser/)
|
|
313
|
-
| [@birdcc/core](../core/)
|
|
314
|
-
| [@birdcc/linter](../linter/)
|
|
315
|
-
| [@birdcc/formatter](../formatter/) | Code formatting engine
|
|
316
|
-
| [@birdcc/cli](../cli/)
|
|
312
|
+
| Package | Description |
|
|
313
|
+
| ---------------------------------- | ------------------------------ |
|
|
314
|
+
| [@birdcc/parser](../parser/) | Tree-sitter grammar and parser |
|
|
315
|
+
| [@birdcc/core](../core/) | Semantic analysis engine |
|
|
316
|
+
| [@birdcc/linter](../linter/) | 32+ lint rules |
|
|
317
|
+
| [@birdcc/formatter](../formatter/) | Code formatting engine |
|
|
318
|
+
| [@birdcc/cli](../cli/) | Command-line interface |
|
|
317
319
|
|
|
318
320
|
---
|
|
319
321
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ASN-aware completion provider for BIRD2 configuration files.
|
|
3
|
+
*
|
|
4
|
+
* Triggers on numeric input in ASN-relevant contexts:
|
|
5
|
+
* - `# AS<digits>` (comment annotations)
|
|
6
|
+
* - `neighbor ... as <digits>`
|
|
7
|
+
* - `local as <digits>`
|
|
8
|
+
* - `bgp_community.add((<digits>, ...))`
|
|
9
|
+
* - `bgp_path.prepend(<digits>)` / `bgp_path.delete(<digits>)`
|
|
10
|
+
* - `bgp_path ~ [<digits>, ...]`
|
|
11
|
+
* - `define MY_ASN = <digits>`
|
|
12
|
+
*/
|
|
13
|
+
import { type CompletionItem } from "vscode-languageserver/node.js";
|
|
14
|
+
import type { AsnIntel } from "@birdcc/intel";
|
|
15
|
+
export { extractAsnPrefix } from "./asn-context.js";
|
|
16
|
+
/**
|
|
17
|
+
* Generate ASN completion items with progressive matching.
|
|
18
|
+
* As the user types digits (e.g., "1" → "12" → "123"), results narrow down.
|
|
19
|
+
*/
|
|
20
|
+
export declare const createAsnCompletionItems: (intel: AsnIntel, linePrefix: string, limit?: number) => CompletionItem[];
|
|
21
|
+
//# sourceMappingURL=asn-completion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asn-completion.d.ts","sourceRoot":"","sources":["../src/asn-completion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;GAGG;AACH,eAAO,MAAM,wBAAwB,GACnC,OAAO,QAAQ,EACf,YAAY,MAAM,EAClB,cAAU,KACT,cAAc,EAsBhB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ASN-aware completion provider for BIRD2 configuration files.
|
|
3
|
+
*
|
|
4
|
+
* Triggers on numeric input in ASN-relevant contexts:
|
|
5
|
+
* - `# AS<digits>` (comment annotations)
|
|
6
|
+
* - `neighbor ... as <digits>`
|
|
7
|
+
* - `local as <digits>`
|
|
8
|
+
* - `bgp_community.add((<digits>, ...))`
|
|
9
|
+
* - `bgp_path.prepend(<digits>)` / `bgp_path.delete(<digits>)`
|
|
10
|
+
* - `bgp_path ~ [<digits>, ...]`
|
|
11
|
+
* - `define MY_ASN = <digits>`
|
|
12
|
+
*/
|
|
13
|
+
import { CompletionItemKind, } from "vscode-languageserver/node.js";
|
|
14
|
+
import { extractAsnPrefix } from "./asn-context.js";
|
|
15
|
+
export { extractAsnPrefix } from "./asn-context.js";
|
|
16
|
+
/**
|
|
17
|
+
* Generate ASN completion items with progressive matching.
|
|
18
|
+
* As the user types digits (e.g., "1" → "12" → "123"), results narrow down.
|
|
19
|
+
*/
|
|
20
|
+
export const createAsnCompletionItems = (intel, linePrefix, limit = 10) => {
|
|
21
|
+
if (!intel.available)
|
|
22
|
+
return [];
|
|
23
|
+
const prefix = extractAsnPrefix(linePrefix);
|
|
24
|
+
if (!prefix)
|
|
25
|
+
return [];
|
|
26
|
+
const entries = intel.prefixSearch(prefix, limit);
|
|
27
|
+
return entries.map((entry, index) => {
|
|
28
|
+
const display = intel.formatDisplay(entry);
|
|
29
|
+
return {
|
|
30
|
+
label: String(entry.asn),
|
|
31
|
+
kind: CompletionItemKind.Value,
|
|
32
|
+
detail: display.completionDetail,
|
|
33
|
+
documentation: {
|
|
34
|
+
kind: "markdown",
|
|
35
|
+
value: display.hoverMarkdown,
|
|
36
|
+
},
|
|
37
|
+
sortText: String(index).padStart(4, "0"),
|
|
38
|
+
filterText: String(entry.asn),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=asn-completion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asn-completion.js","sourceRoot":"","sources":["../src/asn-completion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,kBAAkB,GAEnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,KAAe,EACf,UAAkB,EAClB,KAAK,GAAG,EAAE,EACQ,EAAE;IACpB,IAAI,CAAC,KAAK,CAAC,SAAS;QAAE,OAAO,EAAE,CAAC;IAEhC,MAAM,MAAM,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC5C,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAEvB,MAAM,OAAO,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAElD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAClC,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC3C,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;YACxB,IAAI,EAAE,kBAAkB,CAAC,KAAK;YAC9B,MAAM,EAAE,OAAO,CAAC,gBAAgB;YAChC,aAAa,EAAE;gBACb,IAAI,EAAE,UAAmB;gBACzB,KAAK,EAAE,OAAO,CAAC,aAAa;aAC7B;YACD,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;YACxC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;SAC9B,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type AsnMatch = {
|
|
2
|
+
asn: number;
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const findAsnMatchesInLine: (lineText: string) => AsnMatch[];
|
|
7
|
+
export declare const extractAsnPrefix: (linePrefix: string) => string | undefined;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=asn-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asn-context.d.ts","sourceRoot":"","sources":["../src/asn-context.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAyNF,eAAO,MAAM,oBAAoB,GAAI,UAAU,MAAM,KAAG,QAAQ,EAc/D,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,YAAY,MAAM,KAAG,MAAM,GAAG,SAmB9D,CAAC"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
const ASN_LIKE_DEFINE_NAME = /(?:^|_)(?:ASN|COMMUNITY)(?:_|$)/i;
|
|
2
|
+
const COMMENT_ASN_CONTEXT = /(?:^|\s)#\s*AS(\d+)$/i;
|
|
3
|
+
const SHORT_ASN_EXEMPTIONS = new Set([42]);
|
|
4
|
+
const MIN_REGULAR_ASN = 100;
|
|
5
|
+
const COMPLETION_CONTEXT_PATTERNS = [
|
|
6
|
+
/\blocal\s+as\s+(\d+)$/i,
|
|
7
|
+
/\b(?:bgp_)?community\.add\(\(\s*(\d+)$/i,
|
|
8
|
+
/\b(?:bgp_)?large_community\.add\(\(\s*(\d+)$/i,
|
|
9
|
+
/\bbgp_path\.(?:prepend|delete)\(\s*(\d+)$/i,
|
|
10
|
+
/\bbgp_path\s*~\s*\[[^\]]*?(\d+)$/i,
|
|
11
|
+
];
|
|
12
|
+
const CODE_ASN_PATTERNS = [
|
|
13
|
+
[/\blocal\s+as\s+(\d+)\b/gi],
|
|
14
|
+
[
|
|
15
|
+
/\bdefine\s+([A-Za-z_]\w*)\s*=\s*(\d+)\b/gi,
|
|
16
|
+
{
|
|
17
|
+
captureGroup: 2,
|
|
18
|
+
isAllowed: (match, asn) => ASN_LIKE_DEFINE_NAME.test(match[1] ?? "") && isLikelyAsn(asn),
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
/\b(?:bgp_)?community\.add\(\(\s*(\d+)\s*,/gi,
|
|
23
|
+
{
|
|
24
|
+
isAllowed: (_match, asn) => asn !== 0 && asn !== 65535 && isLikelyAsn(asn),
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
[
|
|
28
|
+
/\b(?:bgp_)?large_community\.add\(\(\s*(\d+)\s*,/gi,
|
|
29
|
+
{
|
|
30
|
+
isAllowed: (_match, asn) => isLikelyAsn(asn),
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
/\(\s*(\d+)\s*,\s*\d+\s*\)\s*~\s*(?:bgp_)?community\b/gi,
|
|
35
|
+
{
|
|
36
|
+
isAllowed: (_match, asn) => asn !== 0 && asn !== 65535 && isLikelyAsn(asn),
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
[
|
|
40
|
+
/\bbgp_path\.(?:prepend|delete)\(\s*(\d+)\b/gi,
|
|
41
|
+
{
|
|
42
|
+
isAllowed: (_match, asn) => isLikelyAsn(asn),
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
];
|
|
46
|
+
const BGP_PATH_ARRAY_PATTERN = /\bbgp_path\s*~\s*\[([^\]]*)\]/gi;
|
|
47
|
+
const BGP_PATH_ARRAY_NUMBER_PATTERN = /\d+/g;
|
|
48
|
+
const isLikelyAsn = (asn) => SHORT_ASN_EXEMPTIONS.has(asn) || asn >= MIN_REGULAR_ASN;
|
|
49
|
+
const findNeighborAsMatch = (lineText) => {
|
|
50
|
+
const neighborIndex = lineText.search(/\bneighbor\b/i);
|
|
51
|
+
if (neighborIndex === -1)
|
|
52
|
+
return null;
|
|
53
|
+
const asMatch = /\bas\s+(\d+)\b/i.exec(lineText.slice(neighborIndex));
|
|
54
|
+
if (!asMatch || !asMatch[1])
|
|
55
|
+
return null;
|
|
56
|
+
return {
|
|
57
|
+
digits: asMatch[1],
|
|
58
|
+
digitStart: neighborIndex +
|
|
59
|
+
(asMatch.index ?? 0) +
|
|
60
|
+
asMatch[0].length -
|
|
61
|
+
asMatch[1].length,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
const collectNeighborAsMatches = (lineText) => {
|
|
65
|
+
const matches = [];
|
|
66
|
+
const match = findNeighborAsMatch(lineText);
|
|
67
|
+
if (!match)
|
|
68
|
+
return matches;
|
|
69
|
+
const asn = Number.parseInt(match.digits, 10);
|
|
70
|
+
if (!isLikelyAsn(asn))
|
|
71
|
+
return matches;
|
|
72
|
+
matches.push({
|
|
73
|
+
asn,
|
|
74
|
+
start: match.digitStart,
|
|
75
|
+
end: match.digitStart + match.digits.length,
|
|
76
|
+
});
|
|
77
|
+
return matches;
|
|
78
|
+
};
|
|
79
|
+
const maskNonCodeSegments = (lineText) => {
|
|
80
|
+
let masked = "";
|
|
81
|
+
let quote = null;
|
|
82
|
+
let escaped = false;
|
|
83
|
+
for (let index = 0; index < lineText.length; index++) {
|
|
84
|
+
const char = lineText[index];
|
|
85
|
+
const next = lineText[index + 1];
|
|
86
|
+
if (quote) {
|
|
87
|
+
masked += " ";
|
|
88
|
+
if (escaped) {
|
|
89
|
+
escaped = false;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (char === "\\") {
|
|
93
|
+
escaped = true;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (char === quote) {
|
|
97
|
+
quote = null;
|
|
98
|
+
}
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (char === "'" || char === '"') {
|
|
102
|
+
quote = char;
|
|
103
|
+
masked += " ";
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (char === "#" || (char === "/" && next === "/")) {
|
|
107
|
+
masked += " ".repeat(lineText.length - index);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
masked += char;
|
|
111
|
+
}
|
|
112
|
+
return masked.padEnd(lineText.length, " ");
|
|
113
|
+
};
|
|
114
|
+
const collectMatchesFromPattern = (lineText, pattern, config) => {
|
|
115
|
+
const matches = [];
|
|
116
|
+
const captureGroup = config?.captureGroup ?? 1;
|
|
117
|
+
pattern.lastIndex = 0;
|
|
118
|
+
let match;
|
|
119
|
+
while ((match = pattern.exec(lineText)) !== null) {
|
|
120
|
+
const digits = match[captureGroup];
|
|
121
|
+
if (!digits)
|
|
122
|
+
continue;
|
|
123
|
+
const asn = Number.parseInt(digits, 10);
|
|
124
|
+
if (Number.isNaN(asn) || asn <= 0)
|
|
125
|
+
continue;
|
|
126
|
+
if (!config?.isAllowed && !isLikelyAsn(asn))
|
|
127
|
+
continue;
|
|
128
|
+
if (config?.isAllowed && !config.isAllowed(match, asn))
|
|
129
|
+
continue;
|
|
130
|
+
const digitStart = match.index + match[0].lastIndexOf(digits);
|
|
131
|
+
matches.push({
|
|
132
|
+
asn,
|
|
133
|
+
start: digitStart,
|
|
134
|
+
end: digitStart + digits.length,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return matches;
|
|
138
|
+
};
|
|
139
|
+
const collectBgpPathArrayMatches = (lineText) => {
|
|
140
|
+
const matches = [];
|
|
141
|
+
BGP_PATH_ARRAY_PATTERN.lastIndex = 0;
|
|
142
|
+
let arrayMatch;
|
|
143
|
+
while ((arrayMatch = BGP_PATH_ARRAY_PATTERN.exec(lineText)) !== null) {
|
|
144
|
+
const arrayBody = arrayMatch[1] ?? "";
|
|
145
|
+
const bodyOffset = arrayMatch.index + arrayMatch[0].indexOf(arrayBody);
|
|
146
|
+
BGP_PATH_ARRAY_NUMBER_PATTERN.lastIndex = 0;
|
|
147
|
+
let numberMatch;
|
|
148
|
+
while ((numberMatch = BGP_PATH_ARRAY_NUMBER_PATTERN.exec(arrayBody)) !== null) {
|
|
149
|
+
const digits = numberMatch[0];
|
|
150
|
+
const asn = Number.parseInt(digits, 10);
|
|
151
|
+
if (Number.isNaN(asn) || asn <= 0)
|
|
152
|
+
continue;
|
|
153
|
+
if (!isLikelyAsn(asn))
|
|
154
|
+
continue;
|
|
155
|
+
const start = bodyOffset + numberMatch.index;
|
|
156
|
+
matches.push({
|
|
157
|
+
asn,
|
|
158
|
+
start,
|
|
159
|
+
end: start + digits.length,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return matches;
|
|
164
|
+
};
|
|
165
|
+
const extractDefineAsnPrefix = (linePrefix) => {
|
|
166
|
+
const match = /\bdefine\s+([A-Za-z_]\w*)\s*=\s*(\d+)$/i.exec(linePrefix);
|
|
167
|
+
if (!match)
|
|
168
|
+
return undefined;
|
|
169
|
+
if (!ASN_LIKE_DEFINE_NAME.test(match[1] ?? ""))
|
|
170
|
+
return undefined;
|
|
171
|
+
if (!isLikelyAsn(Number.parseInt(match[2], 10)))
|
|
172
|
+
return undefined;
|
|
173
|
+
return match[2];
|
|
174
|
+
};
|
|
175
|
+
export const findAsnMatchesInLine = (lineText) => {
|
|
176
|
+
const matches = [];
|
|
177
|
+
const maskedLine = maskNonCodeSegments(lineText);
|
|
178
|
+
matches.push(...collectNeighborAsMatches(maskedLine));
|
|
179
|
+
for (const [pattern, config] of CODE_ASN_PATTERNS) {
|
|
180
|
+
matches.push(...collectMatchesFromPattern(maskedLine, pattern, config));
|
|
181
|
+
}
|
|
182
|
+
matches.push(...collectBgpPathArrayMatches(maskedLine));
|
|
183
|
+
matches.sort((left, right) => left.start - right.start);
|
|
184
|
+
return matches;
|
|
185
|
+
};
|
|
186
|
+
export const extractAsnPrefix = (linePrefix) => {
|
|
187
|
+
const commentMatch = COMMENT_ASN_CONTEXT.exec(linePrefix);
|
|
188
|
+
if (commentMatch && isLikelyAsn(Number.parseInt(commentMatch[1], 10))) {
|
|
189
|
+
return commentMatch[1];
|
|
190
|
+
}
|
|
191
|
+
const neighborMatch = /\bneighbor\b[^\n;#{}]*\bas\s+(\d+)$/i.exec(linePrefix);
|
|
192
|
+
if (neighborMatch && isLikelyAsn(Number.parseInt(neighborMatch[1], 10))) {
|
|
193
|
+
return neighborMatch[1];
|
|
194
|
+
}
|
|
195
|
+
for (const pattern of COMPLETION_CONTEXT_PATTERNS) {
|
|
196
|
+
const match = pattern.exec(linePrefix);
|
|
197
|
+
if (match && isLikelyAsn(Number.parseInt(match[1], 10))) {
|
|
198
|
+
return match[1];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return extractDefineAsnPrefix(linePrefix);
|
|
202
|
+
};
|
|
203
|
+
//# sourceMappingURL=asn-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asn-context.js","sourceRoot":"","sources":["../src/asn-context.ts"],"names":[],"mappings":"AAWA,MAAM,oBAAoB,GAAG,kCAAkC,CAAC;AAChE,MAAM,mBAAmB,GAAG,uBAAuB,CAAC;AACpD,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,MAAM,2BAA2B,GAAG;IAClC,wBAAwB;IACxB,yCAAyC;IACzC,+CAA+C;IAC/C,4CAA4C;IAC5C,mCAAmC;CACpC,CAAC;AAEF,MAAM,iBAAiB,GAAyC;IAC9D,CAAC,0BAA0B,CAAC;IAC5B;QACE,2CAA2C;QAC3C;YACE,YAAY,EAAE,CAAC;YACf,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACxB,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC;SAChE;KACF;IACD;QACE,6CAA6C;QAC7C;YACE,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CACzB,GAAG,KAAK,CAAC,IAAI,GAAG,KAAK,KAAK,IAAI,WAAW,CAAC,GAAG,CAAC;SACjD;KACF;IACD;QACE,mDAAmD;QACnD;YACE,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,C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EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IAExD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,UAAkB,EAAsB,EAAE;IACzE,MAAM,YAAY,GAAG,mBAAmB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC1D,IAAI,YAAY,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC;QACtE,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC;IAED,MAAM,aAAa,GAAG,sCAAsC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9E,IAAI,aAAa,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC;QACxE,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK,MAAM,OAAO,IAAI,2BAA2B,EAAE,CAAC;QAClD,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACvC,IAAI,KAAK,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC;YACxD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,OAAO,sBAAsB,CAAC,UAAU,CAAC,CAAC;AAC5C,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ASN hover — shows rich ASN info when hovering over an integer in an ASN-relevant context.
|
|
3
|
+
*/
|
|
4
|
+
import { type Hover, type Position } from "vscode-languageserver/node.js";
|
|
5
|
+
import type { AsnIntel } from "@birdcc/intel";
|
|
6
|
+
/**
|
|
7
|
+
* Try to produce an ASN hover for the given position.
|
|
8
|
+
* Returns null if the cursor is not over an ASN integer.
|
|
9
|
+
*/
|
|
10
|
+
export declare const createAsnHover: (intel: AsnIntel, lineText: string, position: Position) => Hover | null;
|
|
11
|
+
//# sourceMappingURL=asn-hover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asn-hover.d.ts","sourceRoot":"","sources":["../src/asn-hover.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C;;;GAGG;AACH,eAAO,MAAM,cAAc,GACzB,OAAO,QAAQ,EACf,UAAU,MAAM,EAChB,UAAU,QAAQ,KACjB,KAAK,GAAG,IA0BV,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ASN hover — shows rich ASN info when hovering over an integer in an ASN-relevant context.
|
|
3
|
+
*/
|
|
4
|
+
import { findAsnMatchesInLine } from "./asn-context.js";
|
|
5
|
+
/**
|
|
6
|
+
* Try to produce an ASN hover for the given position.
|
|
7
|
+
* Returns null if the cursor is not over an ASN integer.
|
|
8
|
+
*/
|
|
9
|
+
export const createAsnHover = (intel, lineText, position) => {
|
|
10
|
+
if (!intel.available)
|
|
11
|
+
return null;
|
|
12
|
+
const character = position.character;
|
|
13
|
+
for (const match of findAsnMatchesInLine(lineText)) {
|
|
14
|
+
if (character < match.start || character > match.end) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const display = intel.lookupDisplay(match.asn);
|
|
18
|
+
if (!display)
|
|
19
|
+
return null;
|
|
20
|
+
return {
|
|
21
|
+
contents: {
|
|
22
|
+
kind: "markdown",
|
|
23
|
+
value: display.hoverMarkdown,
|
|
24
|
+
},
|
|
25
|
+
range: {
|
|
26
|
+
start: { line: position.line, character: match.start },
|
|
27
|
+
end: { line: position.line, character: match.end },
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=asn-hover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asn-hover.js","sourceRoot":"","sources":["../src/asn-hover.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAe,EACf,QAAgB,EAChB,QAAkB,EACJ,EAAE;IAChB,IAAI,CAAC,KAAK,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAElC,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC;IAErC,KAAK,MAAM,KAAK,IAAI,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnD,IAAI,SAAS,GAAG,KAAK,CAAC,KAAK,IAAI,SAAS,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;YACrD,SAAS;QACX,CAAC;QAED,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QAE1B,OAAO;YACL,QAAQ,EAAE;gBACR,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,OAAO,CAAC,aAAa;aAC7B;YACD,KAAK,EAAE;gBACL,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,KAAK,EAAE;gBACtD,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,GAAG,EAAE;aACnD;SACF,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ASN inlay hints — shows flag + AS number next to integer literals in ASN-relevant positions.
|
|
3
|
+
*
|
|
4
|
+
* Scans lines for patterns like `local as 65001`, `neighbor ... as 4134`,
|
|
5
|
+
* `define MY_ASN = 13335`, `bgp_path ~ [174, 701]`, etc. and produces InlayHint items.
|
|
6
|
+
*/
|
|
7
|
+
import { InlayHint, type Range } from "vscode-languageserver/node.js";
|
|
8
|
+
import type { AsnIntel } from "@birdcc/intel";
|
|
9
|
+
/**
|
|
10
|
+
* Generate inlay hints for ASN integers within the given text range.
|
|
11
|
+
*/
|
|
12
|
+
export declare const createAsnInlayHints: (intel: AsnIntel, text: string, range: Range) => InlayHint[];
|
|
13
|
+
//# sourceMappingURL=asn-inlay-hints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asn-inlay-hints.d.ts","sourceRoot":"","sources":["../src/asn-inlay-hints.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,SAAS,EAET,KAAK,KAAK,EACX,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,QAAQ,EACf,MAAM,MAAM,EACZ,OAAO,KAAK,KACX,SAAS,EAqCX,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ASN inlay hints — shows flag + AS number next to integer literals in ASN-relevant positions.
|
|
3
|
+
*
|
|
4
|
+
* Scans lines for patterns like `local as 65001`, `neighbor ... as 4134`,
|
|
5
|
+
* `define MY_ASN = 13335`, `bgp_path ~ [174, 701]`, etc. and produces InlayHint items.
|
|
6
|
+
*/
|
|
7
|
+
import { InlayHintKind, } from "vscode-languageserver/node.js";
|
|
8
|
+
import { findAsnMatchesInLine } from "./asn-context.js";
|
|
9
|
+
/**
|
|
10
|
+
* Generate inlay hints for ASN integers within the given text range.
|
|
11
|
+
*/
|
|
12
|
+
export const createAsnInlayHints = (intel, text, range) => {
|
|
13
|
+
if (!intel.available)
|
|
14
|
+
return [];
|
|
15
|
+
const hints = [];
|
|
16
|
+
const lines = text.split("\n");
|
|
17
|
+
const startLine = range.start.line;
|
|
18
|
+
const endLine = Math.min(range.end.line, lines.length - 1);
|
|
19
|
+
// Track which (line, column) positions we've already hinted to avoid duplicates
|
|
20
|
+
const seen = new Set();
|
|
21
|
+
for (let lineIdx = startLine; lineIdx <= endLine; lineIdx++) {
|
|
22
|
+
const lineText = lines[lineIdx];
|
|
23
|
+
if (!lineText)
|
|
24
|
+
continue;
|
|
25
|
+
for (const match of findAsnMatchesInLine(lineText)) {
|
|
26
|
+
const key = `${lineIdx}:${match.end}`;
|
|
27
|
+
if (seen.has(key))
|
|
28
|
+
continue;
|
|
29
|
+
seen.add(key);
|
|
30
|
+
const display = intel.lookupDisplay(match.asn);
|
|
31
|
+
if (!display)
|
|
32
|
+
continue;
|
|
33
|
+
hints.push({
|
|
34
|
+
position: { line: lineIdx, character: match.end },
|
|
35
|
+
label: ` ${display.inlayLabel}`,
|
|
36
|
+
kind: InlayHintKind.Parameter,
|
|
37
|
+
paddingLeft: true,
|
|
38
|
+
tooltip: {
|
|
39
|
+
kind: "markdown",
|
|
40
|
+
value: display.hoverMarkdown,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return hints;
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=asn-inlay-hints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asn-inlay-hints.js","sourceRoot":"","sources":["../src/asn-inlay-hints.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAEL,aAAa,GAEd,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBA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UAAU,EAAE;gBAC/B,IAAI,EAAE,aAAa,CAAC,SAAS;gBAC7B,WAAW,EAAE,IAAI;gBACjB,OAAO,EAAE;oBACP,IAAI,EAAE,UAAU;oBAChB,KAAK,EAAE,OAAO,CAAC,aAAa;iBAC7B;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
package/dist/diagnostic.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostic.d.ts","sourceRoot":"","sources":["../src/diagnostic.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EAChB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"diagnostic.d.ts","sourceRoot":"","sources":["../src/diagnostic.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EAChB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAiBnD,8DAA8D;AAC9D,eAAO,MAAM,eAAe,GAAI,YAAY,cAAc,KAAG,UAM3D,CAAC;AAEH,eAAO,MAAM,yBAAyB,GAAI,OAAO,OAAO,KAAG,UASzD,CAAC"}
|
package/dist/diagnostic.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DiagnosticSeverity, } from "vscode-languageserver/node.js";
|
|
2
|
+
import { toLspRange } from "./utils.js";
|
|
2
3
|
const toLspSeverity = (severity) => {
|
|
3
4
|
if (severity === "error") {
|
|
4
5
|
return DiagnosticSeverity.Error;
|
|
@@ -14,16 +15,7 @@ export const toLspDiagnostic = (diagnostic) => ({
|
|
|
14
15
|
message: diagnostic.message,
|
|
15
16
|
severity: toLspSeverity(diagnostic.severity),
|
|
16
17
|
source: diagnostic.source,
|
|
17
|
-
range:
|
|
18
|
-
start: {
|
|
19
|
-
line: Math.max(diagnostic.range.line - 1, 0),
|
|
20
|
-
character: Math.max(diagnostic.range.column - 1, 0),
|
|
21
|
-
},
|
|
22
|
-
end: {
|
|
23
|
-
line: Math.max(diagnostic.range.endLine - 1, 0),
|
|
24
|
-
character: Math.max(diagnostic.range.endColumn - 1, 0),
|
|
25
|
-
},
|
|
26
|
-
},
|
|
18
|
+
range: toLspRange(diagnostic.range),
|
|
27
19
|
});
|
|
28
20
|
export const toInternalErrorDiagnostic = (error) => ({
|
|
29
21
|
code: "lsp/internal-error",
|
package/dist/diagnostic.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostic.js","sourceRoot":"","sources":["../src/diagnostic.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAEnB,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"diagnostic.js","sourceRoot":"","sources":["../src/diagnostic.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAEnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,aAAa,GAAG,CACpB,QAAoC,EAChB,EAAE;IACtB,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QACzB,OAAO,kBAAkB,CAAC,KAAK,CAAC;IAClC,CAAC;IAED,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,kBAAkB,CAAC,OAAO,CAAC;IACpC,CAAC;IAED,OAAO,kBAAkB,CAAC,WAAW,CAAC;AACxC,CAAC,CAAC;AAEF,8DAA8D;AAC9D,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,UAA0B,EAAc,EAAE,CAAC,CAAC;IAC1E,IAAI,EAAE,UAAU,CAAC,IAAI;IACrB,OAAO,EAAE,UAAU,CAAC,OAAO;IAC3B,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC;IAC5C,MAAM,EAAE,UAAU,CAAC,MAAM;IACzB,KAAK,EAAE,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC;CACpC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,KAAc,EAAc,EAAE,CAAC,CAAC;IACxE,IAAI,EAAE,oBAAoB;IAC1B,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;IAC/D,QAAQ,EAAE,kBAAkB,CAAC,KAAK;IAClC,MAAM,EAAE,KAAK;IACb,KAAK,EAAE;QACL,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE;QAChC,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE;KAC/B;CACF,CAAC,CAAC"}
|
package/dist/document-symbol.js
CHANGED
|
@@ -3,7 +3,7 @@ export const createDocumentSymbolsFromParsed = (parsed) => {
|
|
|
3
3
|
const symbols = [];
|
|
4
4
|
for (const declaration of parsed.program.declarations) {
|
|
5
5
|
const metadata = declarationMetadata(declaration);
|
|
6
|
-
if (!metadata) {
|
|
6
|
+
if (!metadata || !metadata.symbolName) {
|
|
7
7
|
continue;
|
|
8
8
|
}
|
|
9
9
|
symbols.push({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-symbol.js","sourceRoot":"","sources":["../src/document-symbol.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAC7C,MAA0B,EACR,EAAE;IACpB,MAAM,OAAO,GAAqB,EAAE,CAAC;IAErC,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QACtD,MAAM,QAAQ,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"document-symbol.js","sourceRoot":"","sources":["../src/document-symbol.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAC7C,MAA0B,EACR,EAAE;IACpB,MAAM,OAAO,GAAqB,EAAE,CAAC;IAErC,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QACtD,MAAM,QAAQ,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;YACtC,SAAS;QACX,CAAC;QAED,OAAO,CAAC,IAAI,CAAC;YACX,IAAI,EAAE,QAAQ,CAAC,UAAU;YACzB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,IAAI,EAAE,QAAQ,CAAC,UAAU;YACzB,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC;YAC9B,cAAc,EAAE,UAAU,CAAC,QAAQ,CAAC,cAAc,CAAC;YACnD,QAAQ,EAAE,EAAE;SACb,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
interface HoverContextLineDocumentLike {
|
|
2
|
+
readonly uri: string | {
|
|
3
|
+
toString: () => string;
|
|
4
|
+
};
|
|
5
|
+
readonly version: number;
|
|
6
|
+
readonly lineCount: number;
|
|
7
|
+
lineAt(line: number): {
|
|
8
|
+
readonly text: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
interface HoverContextRangeDocumentLike {
|
|
12
|
+
readonly uri: string | {
|
|
13
|
+
toString: () => string;
|
|
14
|
+
};
|
|
15
|
+
readonly version: number;
|
|
16
|
+
readonly lineCount: number;
|
|
17
|
+
getText(range?: {
|
|
18
|
+
readonly start: {
|
|
19
|
+
readonly line: number;
|
|
20
|
+
readonly character: number;
|
|
21
|
+
};
|
|
22
|
+
readonly end: {
|
|
23
|
+
readonly line: number;
|
|
24
|
+
readonly character: number;
|
|
25
|
+
};
|
|
26
|
+
}): string;
|
|
27
|
+
}
|
|
28
|
+
export type HoverContextDocumentLike = HoverContextLineDocumentLike | HoverContextRangeDocumentLike;
|
|
29
|
+
export declare const resolveHoverContextPath: (document: HoverContextDocumentLike, targetLine: number, targetCharacter: number) => readonly string[];
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=hover-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hover-context.d.ts","sourceRoot":"","sources":["../src/hover-context.ts"],"names":[],"mappings":"AAMA,UAAU,4BAA4B;IACpC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;KAAE,CAAC;IAClD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD;AAED,UAAU,6BAA6B;IACrC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;KAAE,CAAC;IAClD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,KAAK,CAAC,EAAE;QACd,QAAQ,CAAC,KAAK,EAAE;YAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;SAAE,CAAC;QACtE,QAAQ,CAAC,GAAG,EAAE;YAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;SAAE,CAAC;KACrE,GAAG,MAAM,CAAC;CACZ;AAED,MAAM,MAAM,wBAAwB,GAChC,4BAA4B,GAC5B,6BAA6B,CAAC;AAgKlC,eAAO,MAAM,uBAAuB,GAClC,UAAU,wBAAwB,EAClC,YAAY,MAAM,EAClB,iBAAiB,MAAM,KACtB,SAAS,MAAM,EAYjB,CAAC"}
|