dsh-lsp-actions 0.2.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.
Files changed (81) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/LICENSE +201 -0
  3. package/README.es.md +177 -0
  4. package/README.hi.md +177 -0
  5. package/README.md +183 -0
  6. package/README.pt.md +177 -0
  7. package/README.zh-CN.md +181 -0
  8. package/cordis.patch.yml +17 -0
  9. package/lib/abort.d.ts +13 -0
  10. package/lib/abort.d.ts.map +1 -0
  11. package/lib/abort.js +31 -0
  12. package/lib/abort.js.map +1 -0
  13. package/lib/client.d.ts +173 -0
  14. package/lib/client.d.ts.map +1 -0
  15. package/lib/client.js +926 -0
  16. package/lib/client.js.map +1 -0
  17. package/lib/connection.d.ts +103 -0
  18. package/lib/connection.d.ts.map +1 -0
  19. package/lib/connection.js +241 -0
  20. package/lib/connection.js.map +1 -0
  21. package/lib/edits.d.ts +17 -0
  22. package/lib/edits.d.ts.map +1 -0
  23. package/lib/edits.js +76 -0
  24. package/lib/edits.js.map +1 -0
  25. package/lib/extension.d.ts +9 -0
  26. package/lib/extension.d.ts.map +1 -0
  27. package/lib/extension.js +17 -0
  28. package/lib/extension.js.map +1 -0
  29. package/lib/extra-tools.d.ts +45 -0
  30. package/lib/extra-tools.d.ts.map +1 -0
  31. package/lib/extra-tools.js +406 -0
  32. package/lib/extra-tools.js.map +1 -0
  33. package/lib/framing.d.ts +33 -0
  34. package/lib/framing.d.ts.map +1 -0
  35. package/lib/framing.js +80 -0
  36. package/lib/framing.js.map +1 -0
  37. package/lib/host.d.ts +64 -0
  38. package/lib/host.d.ts.map +1 -0
  39. package/lib/host.js +152 -0
  40. package/lib/host.js.map +1 -0
  41. package/lib/index.d.ts +42 -0
  42. package/lib/index.d.ts.map +1 -0
  43. package/lib/index.js +78 -0
  44. package/lib/index.js.map +1 -0
  45. package/lib/render.d.ts +364 -0
  46. package/lib/render.d.ts.map +1 -0
  47. package/lib/render.js +485 -0
  48. package/lib/render.js.map +1 -0
  49. package/lib/runner.d.ts +55 -0
  50. package/lib/runner.d.ts.map +1 -0
  51. package/lib/runner.js +149 -0
  52. package/lib/runner.js.map +1 -0
  53. package/lib/sandbox.d.ts +69 -0
  54. package/lib/sandbox.d.ts.map +1 -0
  55. package/lib/sandbox.js +98 -0
  56. package/lib/sandbox.js.map +1 -0
  57. package/lib/seam.d.ts +67 -0
  58. package/lib/seam.d.ts.map +1 -0
  59. package/lib/seam.js +62 -0
  60. package/lib/seam.js.map +1 -0
  61. package/lib/servers.d.ts +120 -0
  62. package/lib/servers.d.ts.map +1 -0
  63. package/lib/servers.js +216 -0
  64. package/lib/servers.js.map +1 -0
  65. package/lib/session-cwd.d.ts +15 -0
  66. package/lib/session-cwd.d.ts.map +1 -0
  67. package/lib/session-cwd.js +16 -0
  68. package/lib/session-cwd.js.map +1 -0
  69. package/lib/tools.d.ts +150 -0
  70. package/lib/tools.d.ts.map +1 -0
  71. package/lib/tools.js +543 -0
  72. package/lib/tools.js.map +1 -0
  73. package/lib/translate.d.ts +181 -0
  74. package/lib/translate.d.ts.map +1 -0
  75. package/lib/translate.js +715 -0
  76. package/lib/translate.js.map +1 -0
  77. package/lib/vocabulary.d.ts +167 -0
  78. package/lib/vocabulary.d.ts.map +1 -0
  79. package/lib/vocabulary.js +20 -0
  80. package/lib/vocabulary.js.map +1 -0
  81. package/package.json +95 -0
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Pure protocol translation for the LSP action client: method names, capability gating, position
3
+ * encoding negotiation, and the strict normalizers that turn untrusted wire payloads into the
4
+ * action vocabulary. No I/O or process state — every function is a pure transform.
5
+ * @module dsh-lsp-actions/translate
6
+ */
7
+ import type { LspActionOperation, LspCodeActionItem, LspCompletionItem, LspDiagnostic, LspInlayHint, LspPosition, LspRange, LspSignature, LspSymbol, LspTextEdit } from './vocabulary.ts';
8
+ /** The position encodings this client can serve; `utf-16` is the protocol default. */
9
+ export type WirePositionEncoding = 'utf-16' | 'utf-8' | 'utf-32';
10
+ /** Loose wire shape of a server's initialize capabilities; accessed by key. */
11
+ export type WireServerCapabilities = Record<string, unknown>;
12
+ /**
13
+ * A position decoder for result normalizers: rewrites a server-side position into utf-16. Absent
14
+ * for servers speaking utf-16 (the overwhelming default, and the encoding this client prefers).
15
+ */
16
+ export type PositionDecoder = (position: LspPosition) => LspPosition;
17
+ /**
18
+ * The `textDocument/*` request method for one action request.
19
+ * @param request - operation plus the optional formatting range that selects rangeFormatting.
20
+ * @returns the LSP request method name.
21
+ */
22
+ export declare function requestMethod(request: {
23
+ operation: LspActionOperation;
24
+ range?: LspRange;
25
+ }): string;
26
+ /**
27
+ * Whether the server advertises the requested action. Diagnostics is always servable: pull when the
28
+ * server advertises a diagnostic provider, otherwise the open→push→settle path.
29
+ * @param capabilities - the server's initialize capabilities.
30
+ * @param operation - the action to check.
31
+ * @param hasRange - whether a formatDocument request carries a range (selects the range provider).
32
+ * @returns true when the capability is advertised.
33
+ */
34
+ export declare function supportsAction(capabilities: WireServerCapabilities, operation: LspActionOperation, hasRange: boolean): boolean;
35
+ /**
36
+ * Whether the server advertises pull diagnostics (`diagnosticProvider`), selecting the pull request
37
+ * over the open→push→settle path.
38
+ * @param capabilities - the server's initialize capabilities.
39
+ * @returns true when `diagnosticProvider` is present.
40
+ */
41
+ export declare function supportsPullDiagnostics(capabilities: WireServerCapabilities): boolean;
42
+ /**
43
+ * Whether a `textDocumentSync` value permits the transient `didOpen`/`didClose` this client relies
44
+ * on. The legacy enum form implies open/close for `Full` (1)/`Incremental` (2); the options form
45
+ * requires an explicit `openClose: true`.
46
+ * @param sync - the server's advertised `textDocumentSync`.
47
+ * @returns true when transient open/close is supported.
48
+ */
49
+ export declare function supportsTransientOpen(sync: unknown): boolean;
50
+ /**
51
+ * Normalize the negotiated position encoding. An omitted encoding defaults to `utf-16`; the
52
+ * client also serves `utf-8` and `utf-32` servers by converting positions through
53
+ * {@link PositionCodec}. Anything else is a protocol error.
54
+ * @param encoding - the server's advertised `positionEncoding`, if any.
55
+ * @returns the negotiated encoding.
56
+ * @throws Error for an encoding outside the supported set.
57
+ */
58
+ export declare function negotiatePositionEncoding(encoding: unknown): WirePositionEncoding;
59
+ /**
60
+ * Converts zero-based cursor coordinates between position encodings for one document. Line
61
+ * numbers are encoding-independent (newlines are one unit in every encoding); only the character
62
+ * offset INSIDE the line is converted, so the tables map each utf-16 code unit index to its
63
+ * absolute byte (utf-8) or code-point (utf-32) offset, and conversions subtract the line's own
64
+ * base offset on both sides.
65
+ */
66
+ export declare class PositionCodec {
67
+ private readonly utf8;
68
+ private readonly utf32;
69
+ private readonly lineStarts;
70
+ private readonly length;
71
+ /**
72
+ * @param text - the document text positions are converted against.
73
+ */
74
+ constructor(text: string);
75
+ /**
76
+ * Convert a utf-16 position to the server's encoding. A character offset inside a surrogate
77
+ * pair (never legal in any encoding) maps to the code point's own offset.
78
+ * @param position - the utf-16 position.
79
+ * @param encoding - the server's position encoding.
80
+ * @returns the converted position (identical for `utf-16`).
81
+ */
82
+ encode(position: LspPosition, encoding: WirePositionEncoding): LspPosition;
83
+ /**
84
+ * Convert a server-side position back to utf-16. An offset inside a multi-unit code point
85
+ * (illegal per protocol) maps to the code point's first utf-16 unit.
86
+ * @param position - the position in the server's encoding.
87
+ * @param encoding - the server's position encoding.
88
+ * @returns the utf-16 position (identical for `utf-16`).
89
+ */
90
+ decode(position: LspPosition, encoding: WirePositionEncoding): LspPosition;
91
+ }
92
+ /**
93
+ * Normalize a `textDocument/diagnostic` pull report (`{ kind, items }`) or a pushed `Diagnostic[]`
94
+ * into the action vocabulary. `null`/`undefined` items normalize to an empty list.
95
+ * @param payload - the raw diagnostic payload.
96
+ * @param decode - optional server-side position decoder (utf-8/utf-32 servers).
97
+ * @returns the normalized diagnostics.
98
+ * @throws LspActionError LSP_ACTION_MALFORMED_RESPONSE for structurally invalid entries.
99
+ */
100
+ export declare function normalizeDiagnostics(payload: unknown, decode?: PositionDecoder): LspDiagnostic[];
101
+ /**
102
+ * Normalize a formatting result (`TextEdit[]` or `null`) into the action vocabulary.
103
+ * @param payload - the raw `textDocument/formatting|rangeFormatting` result.
104
+ * @param decode - optional server-side position decoder (utf-8/utf-32 servers).
105
+ * @returns the normalized edits (empty for `null`).
106
+ * @throws LspActionError LSP_ACTION_MALFORMED_RESPONSE for structurally invalid entries.
107
+ */
108
+ export declare function normalizeEdits(payload: unknown, decode?: PositionDecoder): LspTextEdit[];
109
+ /**
110
+ * Normalize a completion result (`CompletionItem[]`, a `CompletionList`, or `null`) into the action
111
+ * vocabulary.
112
+ * @param payload - the raw `textDocument/completion` result.
113
+ * @param decode - optional server-side position decoder (utf-8/utf-32 servers).
114
+ * @returns the normalized items (empty for `null`).
115
+ * @throws LspActionError LSP_ACTION_MALFORMED_RESPONSE for structurally invalid entries.
116
+ */
117
+ export declare function normalizeCompletionItems(payload: unknown, decode?: PositionDecoder): LspCompletionItem[];
118
+ /**
119
+ * Normalize a `textDocument/codeAction` result (`(Command | CodeAction)[]` or `null`) into the
120
+ * action vocabulary. Edits are grouped by target document URI; a `Command` form is reported
121
+ * verbatim and never executed. Non-text workspace edits (create/rename/delete) are dropped —
122
+ * applying code actions is the model's own write/edit decision.
123
+ * @param payload - the raw code action result.
124
+ * @param decode - optional server-side position decoder (utf-8/utf-32 servers).
125
+ * @returns the normalized actions (empty for `null`).
126
+ * @throws LspActionError LSP_ACTION_MALFORMED_RESPONSE for structurally invalid entries.
127
+ */
128
+ export declare function normalizeCodeActions(payload: unknown, decode?: PositionDecoder): LspCodeActionItem[];
129
+ /**
130
+ * Normalize a `textDocument/rename` result (`WorkspaceEdit` or `null`) into the raw grouped edit
131
+ * record. Positions stay in the server's encoding — each document's edits are decoded per
132
+ * document by the caller, which owns that document's text. Resource operations (create/rename/
133
+ * delete) are refused: this client only applies text edits.
134
+ * @param payload - the raw WorkspaceEdit payload.
135
+ * @returns the grouped wire edits (empty for `null`).
136
+ * @throws LspActionError LSP_ACTION_MALFORMED_RESPONSE for structurally invalid entries, and
137
+ * LSP_ACTION_UNSUPPORTED for resource operations.
138
+ */
139
+ export declare function normalizeWorkspaceEdit(payload: unknown): Record<string, LspTextEdit[]>;
140
+ /**
141
+ * Decode one document's wire edits from the server's position encoding to utf-16.
142
+ * @param edits - the edits in the server's encoding.
143
+ * @param codec - the document's position codec (undefined for utf-16 servers).
144
+ * @param encoding - the negotiated position encoding.
145
+ * @returns the decoded edits.
146
+ */
147
+ export declare function decodeTextEdits(edits: readonly LspTextEdit[], codec: PositionCodec | undefined, encoding: WirePositionEncoding): LspTextEdit[];
148
+ /**
149
+ * Normalize a `workspace/symbol` or `textDocument/documentSymbol` result into the action
150
+ * vocabulary. DocumentSymbol hierarchies are flattened depth-first, each node carrying its own
151
+ * range; SymbolInformation locations pass through verbatim.
152
+ * @param payload - the raw symbol result.
153
+ * @param documentUri - the URI DocumentSymbol entries belong to.
154
+ * @param decode - optional server-side position decoder (utf-8/utf-32 servers).
155
+ * @returns the normalized symbols (empty for `null`).
156
+ * @throws LspActionError LSP_ACTION_MALFORMED_RESPONSE for structurally invalid entries.
157
+ */
158
+ export declare function normalizeSymbols(payload: unknown, documentUri: string | undefined, decode?: PositionDecoder): LspSymbol[];
159
+ /**
160
+ * Normalize a `textDocument/signatureHelp` result into the action vocabulary. Documentation is
161
+ * normalized from MarkupContent to plain text; tuple parameter labels are sliced out of the
162
+ * signature label.
163
+ * @param payload - the raw signature help result.
164
+ * @returns the normalized signatures, or `{ signatures: [] }`-equivalent null result.
165
+ * @throws LspActionError LSP_ACTION_MALFORMED_RESPONSE for structurally invalid entries.
166
+ */
167
+ export declare function normalizeSignatures(payload: unknown): {
168
+ signatures: LspSignature[];
169
+ activeSignature?: number;
170
+ activeParameter?: number;
171
+ };
172
+ /**
173
+ * Normalize a `textDocument/inlayHint` result into the action vocabulary. Multi-part labels are
174
+ * joined into plain text.
175
+ * @param payload - the raw inlay hint result.
176
+ * @param decode - optional server-side position decoder (utf-8/utf-32 servers).
177
+ * @returns the normalized hints (empty for `null`).
178
+ * @throws LspActionError LSP_ACTION_MALFORMED_RESPONSE for structurally invalid entries.
179
+ */
180
+ export declare function normalizeInlayHints(payload: unknown, decode?: PositionDecoder): LspInlayHint[];
181
+ //# sourceMappingURL=translate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translate.d.ts","sourceRoot":"","sources":["../src/translate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EAEb,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,WAAW,EACZ,MAAM,iBAAiB,CAAA;AAGxB,sFAAsF;AACtF,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAA;AAEhE,+EAA+E;AAC/E,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAQ5D;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,WAAW,KAAK,WAAW,CAAA;AAEpE;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE;IAAE,SAAS,EAAE,kBAAkB,CAAC;IAAC,KAAK,CAAC,EAAE,QAAQ,CAAA;CAAE,GAAG,MAAM,CAYlG;AAOD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,sBAAsB,EAAE,SAAS,EAAE,kBAAkB,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAY9H;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,sBAAsB,GAAG,OAAO,CAErF;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAI5D;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,OAAO,GAAG,oBAAoB,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