@tslite/editor 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.
- package/dist/index.cjs +10 -0
- package/dist/index.d.cts +773 -0
- package/dist/index.d.ts +773 -0
- package/dist/index.js +10 -0
- package/package.json +61 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,773 @@
|
|
|
1
|
+
import { TypeOverlay, Env } from '@tslite/checker';
|
|
2
|
+
import { BaseNode } from '@tslite/core';
|
|
3
|
+
import { DiagnosticHelp } from '@tslite/explain';
|
|
4
|
+
|
|
5
|
+
/** Posição na convenção TSLite: linha 1-based, coluna 0-based. */
|
|
6
|
+
interface EditorPosition {
|
|
7
|
+
readonly line: number;
|
|
8
|
+
readonly column: number;
|
|
9
|
+
}
|
|
10
|
+
/** Trecho `[start, end)` — fim exclusivo. */
|
|
11
|
+
interface EditorRange {
|
|
12
|
+
readonly start: EditorPosition;
|
|
13
|
+
readonly end: EditorPosition;
|
|
14
|
+
}
|
|
15
|
+
/** Uma edição aplicável (o quick-fix). */
|
|
16
|
+
interface EditorEdit {
|
|
17
|
+
readonly range: EditorRange;
|
|
18
|
+
readonly newText: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Um diagnóstico SEM posição — o nó não tem `loc` (AST de builders, não de texto).
|
|
22
|
+
* Não vira marker, mas continua sendo um erro real: mostre num painel. Carrega
|
|
23
|
+
* `severity` e `help` porque quem renderiza precisa dos dois tanto quanto no
|
|
24
|
+
* posicionado — só a coordenada falta.
|
|
25
|
+
*/
|
|
26
|
+
interface UnpositionedDiagnostic {
|
|
27
|
+
readonly code: string;
|
|
28
|
+
readonly message: string;
|
|
29
|
+
readonly severity: "error" | "warning";
|
|
30
|
+
readonly help?: DiagnosticHelp;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Marcas de diagnóstico — os mesmos valores no Monaco (`MarkerTag`) e no LSP
|
|
34
|
+
* (`DiagnosticTag`). Mudam como o trecho é RENDERIZADO, não a severidade.
|
|
35
|
+
*/
|
|
36
|
+
declare const DIAGNOSTIC_TAG: {
|
|
37
|
+
/** Código desnecessário → o editor o mostra **apagado** (opaco). */
|
|
38
|
+
readonly Unnecessary: 1;
|
|
39
|
+
/** Depreciado → riscado. */
|
|
40
|
+
readonly Deprecated: 2;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Os códigos cujo diagnóstico é "isto está sobrando", não "isto está errado".
|
|
44
|
+
* Fonte única do `tags` — os dois emissores só repassam.
|
|
45
|
+
*/
|
|
46
|
+
declare const UNNECESSARY_CODES: ReadonlySet<string>;
|
|
47
|
+
/** Um diagnóstico já POSICIONADO, pronto pra virar marker/diagnostic. */
|
|
48
|
+
interface EditorDiagnostic {
|
|
49
|
+
readonly range: EditorRange;
|
|
50
|
+
readonly message: string;
|
|
51
|
+
readonly severity: "error" | "warning";
|
|
52
|
+
readonly code: string;
|
|
53
|
+
/** Ajuda pedagógica (JS-isms) — vira o hover rico. */
|
|
54
|
+
readonly help?: DiagnosticHelp;
|
|
55
|
+
/** Correção mecânica aplicável — vira o code action. */
|
|
56
|
+
readonly edit?: EditorEdit;
|
|
57
|
+
/**
|
|
58
|
+
* Marcas de renderização (ver {@link DIAGNOSTIC_TAG}). O binding não-usado sai
|
|
59
|
+
* com `[1]` — é o que faz o editor APAGAR o trecho em vez de sublinhá-lo. Sem
|
|
60
|
+
* isto, "variável em desuso" viraria mais um squiggle amarelo no meio do código.
|
|
61
|
+
*/
|
|
62
|
+
readonly tags?: readonly number[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* O resultado do `analyze`. `unpositioned` existe para que **nada seja perdido em
|
|
66
|
+
* silêncio**: um diagnóstico cujo nó não tem `loc` (AST vindo de builders, não de
|
|
67
|
+
* texto) não pode virar marker, mas continua sendo um erro real — mostre-o num
|
|
68
|
+
* painel. Se a fonte é texto, esta lista é sempre vazia.
|
|
69
|
+
*/
|
|
70
|
+
interface AnalyzeResult {
|
|
71
|
+
readonly diagnostics: readonly EditorDiagnostic[];
|
|
72
|
+
readonly unpositioned: readonly UnpositionedDiagnostic[];
|
|
73
|
+
/** `true` se o código nem parseou (só há um diagnóstico, o de sintaxe). */
|
|
74
|
+
readonly parseFailed: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* AST + overlay do arquivo — habilita consultas por POSIÇÃO (`typeAtPosition`).
|
|
77
|
+
* Ausente quando não parseou.
|
|
78
|
+
*
|
|
79
|
+
* É objeto vivo e pesado (o `overlay` é um `WeakMap`): guarde-o, mas **leia de
|
|
80
|
+
* forma não-reativa**. Um componente que o selecione re-renderiza a cada análise
|
|
81
|
+
* sem precisar.
|
|
82
|
+
*/
|
|
83
|
+
readonly program?: ProgramInfo;
|
|
84
|
+
}
|
|
85
|
+
/** O AST tipado de um arquivo — a entrada das consultas por posição. */
|
|
86
|
+
interface ProgramInfo {
|
|
87
|
+
readonly ast: BaseNode;
|
|
88
|
+
readonly overlay: TypeOverlay;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Casa com `monaco.editor.IMarkerData`. Severidade: 8=Error, 4=Warning.
|
|
92
|
+
*
|
|
93
|
+
* `tags: [1]` (`MarkerTag.Unnecessary`) é o que faz o editor renderizar o trecho
|
|
94
|
+
* **APAGADO** em vez de sublinhado — é assim que "variável não usada" fica opaca
|
|
95
|
+
* no VSCode. Não é colorização: é o diagnóstico que carrega a marca.
|
|
96
|
+
*/
|
|
97
|
+
interface MonacoMarker {
|
|
98
|
+
readonly startLineNumber: number;
|
|
99
|
+
readonly startColumn: number;
|
|
100
|
+
readonly endLineNumber: number;
|
|
101
|
+
readonly endColumn: number;
|
|
102
|
+
readonly message: string;
|
|
103
|
+
readonly severity: number;
|
|
104
|
+
readonly code?: string;
|
|
105
|
+
readonly source?: string;
|
|
106
|
+
/** `1` = Unnecessary (apagado) · `2` = Deprecated (riscado). */
|
|
107
|
+
readonly tags?: readonly number[];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Casa com `vscode.Diagnostic` / LSP. Severidade: 1=Error, 2=Warning.
|
|
111
|
+
*
|
|
112
|
+
* `tags` usa os MESMOS valores do Monaco (`DiagnosticTag` do LSP: 1=Unnecessary,
|
|
113
|
+
* 2=Deprecated) — uma das raras coisas que não mudam de base entre os dois.
|
|
114
|
+
*/
|
|
115
|
+
interface LspDiagnostic {
|
|
116
|
+
readonly range: {
|
|
117
|
+
readonly start: {
|
|
118
|
+
readonly line: number;
|
|
119
|
+
readonly character: number;
|
|
120
|
+
};
|
|
121
|
+
readonly end: {
|
|
122
|
+
readonly line: number;
|
|
123
|
+
readonly character: number;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
readonly message: string;
|
|
127
|
+
readonly severity: number;
|
|
128
|
+
readonly code?: string;
|
|
129
|
+
readonly source?: string;
|
|
130
|
+
/** `1` = Unnecessary (apagado) · `2` = Deprecated (riscado). */
|
|
131
|
+
readonly tags?: readonly number[];
|
|
132
|
+
}
|
|
133
|
+
/** Um quick-fix, na forma comum a Monaco (`CodeAction`) e LSP. */
|
|
134
|
+
interface EditorCodeAction {
|
|
135
|
+
readonly title: string;
|
|
136
|
+
readonly kind: "quickfix";
|
|
137
|
+
readonly isPreferred: boolean;
|
|
138
|
+
/** O diagnóstico que esta ação corrige (mesmo range/código). */
|
|
139
|
+
readonly diagnostic: {
|
|
140
|
+
readonly code: string;
|
|
141
|
+
readonly message: string;
|
|
142
|
+
};
|
|
143
|
+
/** A edição — já na base do alvo (Monaco 1-based col; LSP 0-based line). */
|
|
144
|
+
readonly edit: {
|
|
145
|
+
readonly range: {
|
|
146
|
+
readonly startLineNumber: number;
|
|
147
|
+
readonly startColumn: number;
|
|
148
|
+
readonly endLineNumber: number;
|
|
149
|
+
readonly endColumn: number;
|
|
150
|
+
};
|
|
151
|
+
readonly text: string;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface AnalyzeOptions {
|
|
156
|
+
/** `program` (default) ou `expression` (uma expressão solta, ex.: um mapper). */
|
|
157
|
+
readonly mode?: "program" | "expression";
|
|
158
|
+
/**
|
|
159
|
+
* Bindings declarados e nunca lidos (`unused-name`) — **ligado por default aqui**,
|
|
160
|
+
* ao contrário do `check`.
|
|
161
|
+
*
|
|
162
|
+
* Não é incoerência, é fidelidade: no tsc o `noUnusedLocals` vem desligado (o
|
|
163
|
+
* *compilador* não deve falhar por higiene), mas o **tsserver** reporta o não-usado
|
|
164
|
+
* como sugestão de qualquer forma — é por isso que o VSCode apaga a variável em
|
|
165
|
+
* desuso num `.ts` sem nenhum `tsconfig`. `analyze` é a API de EDITOR, então segue
|
|
166
|
+
* o editor; `check` é a do compilador, e segue o compilador.
|
|
167
|
+
*
|
|
168
|
+
* Passe `false` para desligar.
|
|
169
|
+
*/
|
|
170
|
+
readonly unused?: boolean | {
|
|
171
|
+
readonly locals?: boolean;
|
|
172
|
+
readonly parameters?: boolean;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Analisa um trecho de código e devolve tudo que um editor precisa.
|
|
177
|
+
* **Nunca lança** — erro de sintaxe vira diagnóstico.
|
|
178
|
+
*/
|
|
179
|
+
declare function analyze(source: string, env: Env, opts?: AnalyzeOptions): AnalyzeResult;
|
|
180
|
+
|
|
181
|
+
/** Markdown do hover: mensagem + o "por que NÃO é bug" + a sugestão + o fix. */
|
|
182
|
+
declare function hoverMarkdown(d: EditorDiagnostic): string;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Converte diagnósticos em markers do Monaco (o sublinhado vermelho).
|
|
186
|
+
*
|
|
187
|
+
* ```ts
|
|
188
|
+
* monaco.editor.setModelMarkers(model, "tslite", toMonacoMarkers(diags));
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
declare function toMonacoMarkers(diagnostics: readonly EditorDiagnostic[], source?: string): MonacoMarker[];
|
|
192
|
+
/**
|
|
193
|
+
* Os quick-fixes, na base do Monaco. Só existem para diagnósticos com `edit`
|
|
194
|
+
* (hoje: os JS-isms com operador equivalente — `arr.length` → `length(arr)`).
|
|
195
|
+
*
|
|
196
|
+
* ```ts
|
|
197
|
+
* monaco.languages.registerCodeActionProvider("tslite", {
|
|
198
|
+
* provideCodeActions: (model) => ({
|
|
199
|
+
* actions: toMonacoCodeActions(diags).map((a) => ({
|
|
200
|
+
* title: a.title, kind: a.kind, isPreferred: a.isPreferred,
|
|
201
|
+
* edit: { edits: [{ resource: model.uri, textEdit: { range: a.edit.range, text: a.edit.text }, versionId: undefined }] },
|
|
202
|
+
* })),
|
|
203
|
+
* dispose() {},
|
|
204
|
+
* }),
|
|
205
|
+
* });
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
declare function toMonacoCodeActions(diagnostics: readonly EditorDiagnostic[]): EditorCodeAction[];
|
|
209
|
+
/**
|
|
210
|
+
* O conteúdo do hover (markdown) para uma posição do Monaco — recebe linha/coluna
|
|
211
|
+
* **na base do Monaco** e devolve o diagnóstico que cobre aquele ponto.
|
|
212
|
+
*
|
|
213
|
+
* ```ts
|
|
214
|
+
* monaco.languages.registerHoverProvider("tslite", {
|
|
215
|
+
* provideHover: (_m, pos) => {
|
|
216
|
+
* const h = monacoHoverAt(diags, pos.lineNumber, pos.column);
|
|
217
|
+
* return h ? { contents: [{ value: h }] } : null;
|
|
218
|
+
* },
|
|
219
|
+
* });
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
declare function monacoHoverAt(diagnostics: readonly EditorDiagnostic[], lineNumber: number, column: number): string | undefined;
|
|
223
|
+
|
|
224
|
+
/** Converte diagnósticos para a forma do LSP / `vscode.Diagnostic`. */
|
|
225
|
+
declare function toLspDiagnostics(diagnostics: readonly EditorDiagnostic[], source?: string): LspDiagnostic[];
|
|
226
|
+
/** Os quick-fixes na base do LSP (linha 0-based). */
|
|
227
|
+
declare function toLspCodeActions(diagnostics: readonly EditorDiagnostic[]): EditorCodeAction[];
|
|
228
|
+
/** O hover markdown na base do LSP (linha/char 0-based). */
|
|
229
|
+
declare function lspHoverAt(diagnostics: readonly EditorDiagnostic[], line: number, character: number): string | undefined;
|
|
230
|
+
|
|
231
|
+
/** O id da linguagem. Registre o modelo e os provedores neste id. */
|
|
232
|
+
declare const TSLITE_LANGUAGE_ID = "tslite";
|
|
233
|
+
/** Extensões que o editor deve associar à linguagem. */
|
|
234
|
+
declare const TSLITE_EXTENSIONS: readonly [".ts", ".d.ts", ".tsl"];
|
|
235
|
+
/**
|
|
236
|
+
* A gramática Monarch. Estrutura compatível com `monaco.languages.IMonarchLanguage`
|
|
237
|
+
* (tipada estruturalmente para não importar o monaco).
|
|
238
|
+
*/
|
|
239
|
+
declare const tsliteMonarchLanguage: {
|
|
240
|
+
defaultToken: string;
|
|
241
|
+
tokenPostfix: string;
|
|
242
|
+
keywords: ("undefined" | "type" | "in" | "typeof" | "void" | "delete" | "var" | "let" | "const" | "null" | "false" | "break" | "if" | "else" | "return" | "async" | "await" | "true" | "for" | "while" | "do" | "throw" | "try" | "catch" | "finally" | "switch" | "case" | "continue" | "default" | "import" | "export" | "extends" | "infer" | "of" | "keyof" | "as" | "from")[];
|
|
243
|
+
controlKeywords: ("break" | "if" | "else" | "return" | "await" | "for" | "while" | "do" | "throw" | "try" | "catch" | "finally" | "switch" | "case" | "continue" | "import" | "export" | "from")[];
|
|
244
|
+
literalKeywords: ("undefined" | "null" | "false" | "true")[];
|
|
245
|
+
forbidden: ("function" | "instanceof" | "class" | "new" | "this" | "yield" | "super" | "debugger" | "with")[];
|
|
246
|
+
typeKeywords: ("string" | "number" | "bigint" | "boolean" | "symbol" | "object" | "any" | "unknown" | "never")[];
|
|
247
|
+
operators: string[];
|
|
248
|
+
symbols: RegExp;
|
|
249
|
+
escapes: RegExp;
|
|
250
|
+
digits: RegExp;
|
|
251
|
+
tokenizer: {
|
|
252
|
+
root: ((string | RegExp)[] | {
|
|
253
|
+
include: string;
|
|
254
|
+
} | (RegExp | string[])[] | (RegExp | {
|
|
255
|
+
cases: {
|
|
256
|
+
"@controlKeywords": string;
|
|
257
|
+
"@keywords": string;
|
|
258
|
+
"@typeKeywords": string;
|
|
259
|
+
"@default": string;
|
|
260
|
+
};
|
|
261
|
+
})[] | (RegExp | {
|
|
262
|
+
cases: {
|
|
263
|
+
"@typeKeywords": string;
|
|
264
|
+
"@default": string;
|
|
265
|
+
};
|
|
266
|
+
})[] | (RegExp | {
|
|
267
|
+
cases: {
|
|
268
|
+
"@controlKeywords": string;
|
|
269
|
+
"@literalKeywords": string;
|
|
270
|
+
"@keywords": string;
|
|
271
|
+
"@typeKeywords": string;
|
|
272
|
+
"@default": string;
|
|
273
|
+
};
|
|
274
|
+
})[] | (RegExp | {
|
|
275
|
+
cases: {
|
|
276
|
+
"@operators": string;
|
|
277
|
+
"@default": string;
|
|
278
|
+
};
|
|
279
|
+
})[])[];
|
|
280
|
+
whitespace: (string | RegExp)[][];
|
|
281
|
+
comment: (string | RegExp)[][];
|
|
282
|
+
string_double: (string | RegExp)[][];
|
|
283
|
+
string_single: (string | RegExp)[][];
|
|
284
|
+
string_backtick: ((string | RegExp)[] | (RegExp | {
|
|
285
|
+
token: string;
|
|
286
|
+
next: string;
|
|
287
|
+
})[])[];
|
|
288
|
+
bracketCounting: ((string | RegExp)[] | {
|
|
289
|
+
include: string;
|
|
290
|
+
})[];
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* Configuração da linguagem: comentários, pares de brackets, auto-fechamento.
|
|
295
|
+
* Compatível com `monaco.languages.LanguageConfiguration`.
|
|
296
|
+
*/
|
|
297
|
+
declare const tsliteLanguageConfiguration: {
|
|
298
|
+
comments: {
|
|
299
|
+
lineComment: string;
|
|
300
|
+
blockComment: [string, string];
|
|
301
|
+
};
|
|
302
|
+
brackets: [string, string][];
|
|
303
|
+
autoClosingPairs: ({
|
|
304
|
+
open: string;
|
|
305
|
+
close: string;
|
|
306
|
+
notIn?: undefined;
|
|
307
|
+
} | {
|
|
308
|
+
open: string;
|
|
309
|
+
close: string;
|
|
310
|
+
notIn: string[];
|
|
311
|
+
})[];
|
|
312
|
+
surroundingPairs: {
|
|
313
|
+
open: string;
|
|
314
|
+
close: string;
|
|
315
|
+
}[];
|
|
316
|
+
folding: {
|
|
317
|
+
markers: {
|
|
318
|
+
start: RegExp;
|
|
319
|
+
end: RegExp;
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
};
|
|
323
|
+
/** Fiel ao VSCode Dark+ — a referência de "parece TypeScript". */
|
|
324
|
+
declare const tsliteDarkPlusThemeRules: readonly [{
|
|
325
|
+
readonly token: "invalid";
|
|
326
|
+
readonly foreground: "f14c4c";
|
|
327
|
+
readonly fontStyle: "underline";
|
|
328
|
+
}, {
|
|
329
|
+
readonly token: "string.invalid";
|
|
330
|
+
readonly foreground: "f14c4c";
|
|
331
|
+
}, {
|
|
332
|
+
readonly token: "keyword";
|
|
333
|
+
readonly foreground: "569cd6";
|
|
334
|
+
}, {
|
|
335
|
+
readonly token: "keyword.control";
|
|
336
|
+
readonly foreground: "c586c0";
|
|
337
|
+
}, {
|
|
338
|
+
readonly token: "keyword.literal";
|
|
339
|
+
readonly foreground: "569cd6";
|
|
340
|
+
}, {
|
|
341
|
+
readonly token: "type";
|
|
342
|
+
readonly foreground: "4ec9b0";
|
|
343
|
+
}, {
|
|
344
|
+
readonly token: "type.identifier";
|
|
345
|
+
readonly foreground: "4ec9b0";
|
|
346
|
+
}, {
|
|
347
|
+
readonly token: "function";
|
|
348
|
+
readonly foreground: "dcdcaa";
|
|
349
|
+
}, {
|
|
350
|
+
readonly token: "function.member";
|
|
351
|
+
readonly foreground: "dcdcaa";
|
|
352
|
+
}, {
|
|
353
|
+
readonly token: "property";
|
|
354
|
+
readonly foreground: "9cdcfe";
|
|
355
|
+
}, {
|
|
356
|
+
readonly token: "property.declaration";
|
|
357
|
+
readonly foreground: "9cdcfe";
|
|
358
|
+
}, {
|
|
359
|
+
readonly token: "identifier";
|
|
360
|
+
readonly foreground: "9cdcfe";
|
|
361
|
+
}, {
|
|
362
|
+
readonly token: "variable";
|
|
363
|
+
readonly foreground: "9cdcfe";
|
|
364
|
+
}, {
|
|
365
|
+
readonly token: "parameter";
|
|
366
|
+
readonly foreground: "9cdcfe";
|
|
367
|
+
}, {
|
|
368
|
+
readonly token: "string";
|
|
369
|
+
readonly foreground: "ce9178";
|
|
370
|
+
}, {
|
|
371
|
+
readonly token: "string.escape";
|
|
372
|
+
readonly foreground: "d7ba7d";
|
|
373
|
+
}, {
|
|
374
|
+
readonly token: "number";
|
|
375
|
+
readonly foreground: "b5cea8";
|
|
376
|
+
}, {
|
|
377
|
+
readonly token: "comment";
|
|
378
|
+
readonly foreground: "6a9955";
|
|
379
|
+
readonly fontStyle: "italic";
|
|
380
|
+
}, {
|
|
381
|
+
readonly token: "operator";
|
|
382
|
+
readonly foreground: "d4d4d4";
|
|
383
|
+
}, {
|
|
384
|
+
readonly token: "operator.arrow";
|
|
385
|
+
readonly foreground: "569cd6";
|
|
386
|
+
}, {
|
|
387
|
+
readonly token: "delimiter";
|
|
388
|
+
readonly foreground: "d4d4d4";
|
|
389
|
+
}];
|
|
390
|
+
/**
|
|
391
|
+
* O DEFAULT: separação alta de papéis.
|
|
392
|
+
*
|
|
393
|
+
* O que muda em relação ao Dark+, e por quê — cada linha resolve um caso em que
|
|
394
|
+
* a tela escondia informação que o checker já tinha:
|
|
395
|
+
*
|
|
396
|
+
* | papel | aqui | no Dark+ |
|
|
397
|
+
* | --- | --- | --- |
|
|
398
|
+
* | parâmetro | laranja **itálico** | #9CDCFE (igual a tudo) |
|
|
399
|
+
* | chave de objeto (`cep:`) | ciano | #9CDCFE (igual ao valor) |
|
|
400
|
+
* | propriedade lida (`r.cep`) | cor de texto | #9CDCFE |
|
|
401
|
+
* | função | verde | amarelo |
|
|
402
|
+
* | tipo | ciano **itálico** | teal |
|
|
403
|
+
*
|
|
404
|
+
* Resultado prático: em `cep: r.cep`, a chave, o parâmetro e a propriedade
|
|
405
|
+
* ficam em três tons distintos — que era o ponto.
|
|
406
|
+
*/
|
|
407
|
+
declare const tsliteThemeRules: readonly [{
|
|
408
|
+
readonly token: "invalid";
|
|
409
|
+
readonly foreground: "ff5555";
|
|
410
|
+
readonly fontStyle: "underline";
|
|
411
|
+
}, {
|
|
412
|
+
readonly token: "string.invalid";
|
|
413
|
+
readonly foreground: "ff5555";
|
|
414
|
+
}, {
|
|
415
|
+
readonly token: "keyword";
|
|
416
|
+
readonly foreground: "ff79c6";
|
|
417
|
+
}, {
|
|
418
|
+
readonly token: "keyword.control";
|
|
419
|
+
readonly foreground: "ff79c6";
|
|
420
|
+
}, {
|
|
421
|
+
readonly token: "keyword.literal";
|
|
422
|
+
readonly foreground: "bd93f9";
|
|
423
|
+
}, {
|
|
424
|
+
readonly token: "type";
|
|
425
|
+
readonly foreground: "8be9fd";
|
|
426
|
+
readonly fontStyle: "italic";
|
|
427
|
+
}, {
|
|
428
|
+
readonly token: "type.identifier";
|
|
429
|
+
readonly foreground: "8be9fd";
|
|
430
|
+
readonly fontStyle: "italic";
|
|
431
|
+
}, {
|
|
432
|
+
readonly token: "function";
|
|
433
|
+
readonly foreground: "50fa7b";
|
|
434
|
+
}, {
|
|
435
|
+
readonly token: "function.member";
|
|
436
|
+
readonly foreground: "50fa7b";
|
|
437
|
+
}, {
|
|
438
|
+
readonly token: "parameter";
|
|
439
|
+
readonly foreground: "ffb86c";
|
|
440
|
+
readonly fontStyle: "italic";
|
|
441
|
+
}, {
|
|
442
|
+
readonly token: "property.declaration";
|
|
443
|
+
readonly foreground: "8be9fd";
|
|
444
|
+
}, {
|
|
445
|
+
readonly token: "property";
|
|
446
|
+
readonly foreground: "f8f8f2";
|
|
447
|
+
}, {
|
|
448
|
+
readonly token: "variable";
|
|
449
|
+
readonly foreground: "f8f8f2";
|
|
450
|
+
}, {
|
|
451
|
+
readonly token: "identifier";
|
|
452
|
+
readonly foreground: "f8f8f2";
|
|
453
|
+
}, {
|
|
454
|
+
readonly token: "string";
|
|
455
|
+
readonly foreground: "f1fa8c";
|
|
456
|
+
}, {
|
|
457
|
+
readonly token: "string.escape";
|
|
458
|
+
readonly foreground: "ffb86c";
|
|
459
|
+
}, {
|
|
460
|
+
readonly token: "number";
|
|
461
|
+
readonly foreground: "bd93f9";
|
|
462
|
+
}, {
|
|
463
|
+
readonly token: "comment";
|
|
464
|
+
readonly foreground: "6272a4";
|
|
465
|
+
readonly fontStyle: "italic";
|
|
466
|
+
}, {
|
|
467
|
+
readonly token: "operator";
|
|
468
|
+
readonly foreground: "ff79c6";
|
|
469
|
+
}, {
|
|
470
|
+
readonly token: "operator.arrow";
|
|
471
|
+
readonly foreground: "ff79c6";
|
|
472
|
+
}, {
|
|
473
|
+
readonly token: "delimiter";
|
|
474
|
+
readonly foreground: "f8f8f2";
|
|
475
|
+
}];
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* A legenda — a ORDEM define os índices usados na codificação. Um consumidor
|
|
479
|
+
* precisa registrar exatamente esta legenda, senão as cores saem trocadas.
|
|
480
|
+
*
|
|
481
|
+
* Subconjunto dos tipos padrão do protocolo (os que a Linguagem realmente tem:
|
|
482
|
+
* sem classe, sem enum, sem método).
|
|
483
|
+
*/
|
|
484
|
+
declare const TSLITE_SEMANTIC_LEGEND: {
|
|
485
|
+
readonly tokenTypes: readonly ["variable", "parameter", "property", "function", "type"];
|
|
486
|
+
readonly tokenModifiers: readonly ["declaration", "readonly", "defaultLibrary"];
|
|
487
|
+
};
|
|
488
|
+
type SemanticTokenType = (typeof TSLITE_SEMANTIC_LEGEND.tokenTypes)[number];
|
|
489
|
+
type SemanticTokenModifier = (typeof TSLITE_SEMANTIC_LEGEND.tokenModifiers)[number];
|
|
490
|
+
/** Um token semântico na convenção TSLite (linha 1-based, coluna 0-based). */
|
|
491
|
+
interface SemanticToken {
|
|
492
|
+
readonly range: EditorRange;
|
|
493
|
+
readonly type: SemanticTokenType;
|
|
494
|
+
readonly modifiers: readonly SemanticTokenModifier[];
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Os tokens semânticos do arquivo, na convenção TSLite (linha 1-based, coluna
|
|
498
|
+
* 0-based), ordenados por posição.
|
|
499
|
+
*
|
|
500
|
+
* **Limite conhecido** (o mesmo do hover de tipo, E6): uma **anotação de tipo**
|
|
501
|
+
* (`r: RawViaCep`) não é nó com `loc` — é `Schema` apagável no nó —, então o nome
|
|
502
|
+
* do tipo ali não recebe token semântico. Quem pinta esse caso é a heurística de
|
|
503
|
+
* capitalização da gramática Monarch. O nome de um `type X = …` (que É nó) recebe.
|
|
504
|
+
*/
|
|
505
|
+
declare function semanticTokensOf(program: ProgramInfo): SemanticToken[];
|
|
506
|
+
/**
|
|
507
|
+
* Os tokens no formato de fio do protocolo: `Uint32Array` de quíntuplas
|
|
508
|
+
* `[deltaLine, deltaStart, length, tokenType, tokenModifiers]`, delta-encodadas.
|
|
509
|
+
*
|
|
510
|
+
* **Serve Monaco E LSP com o MESMO array** — o Monaco copiou o protocolo do LSP
|
|
511
|
+
* inteiro. É a exceção à regra dos dois emissores (E2), e a razão é justamente a
|
|
512
|
+
* que dita a regra: aqui as bases coincidem (**linha 0-based** nos dois), então
|
|
513
|
+
* um emissor só não esconde divergência nenhuma.
|
|
514
|
+
*
|
|
515
|
+
* Cuidado: `linha - 1` porque o TSLite é 1-based e este protocolo é 0-based —
|
|
516
|
+
* ao contrário dos markers do próprio Monaco, que são 1-based.
|
|
517
|
+
*/
|
|
518
|
+
declare function encodeSemanticTokens(tokens: readonly SemanticToken[]): Uint32Array;
|
|
519
|
+
/**
|
|
520
|
+
* Atalho: do `program` direto ao que o provider do editor devolve.
|
|
521
|
+
*
|
|
522
|
+
* ```ts
|
|
523
|
+
* monaco.languages.registerDocumentSemanticTokensProvider(TSLITE_LANGUAGE_ID, {
|
|
524
|
+
* getLegend: () => TSLITE_SEMANTIC_LEGEND,
|
|
525
|
+
* provideDocumentSemanticTokens: () => semanticTokens(program),
|
|
526
|
+
* releaseDocumentSemanticTokens: () => {},
|
|
527
|
+
* });
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
declare function semanticTokens(program: ProgramInfo): {
|
|
531
|
+
data: Uint32Array;
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
/** Uma propriedade de um tipo objeto. */
|
|
535
|
+
interface Prop {
|
|
536
|
+
readonly type: Schema;
|
|
537
|
+
/** `true` quando a propriedade pode estar ausente (`{ x?: T }`). */
|
|
538
|
+
readonly optional?: boolean;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Assinatura de índice de um objeto — `{ [k: string]: V }` (a forma de `Record<K, V>`).
|
|
542
|
+
* Coexiste com props nomeadas (`{ a: number; [k: string]: unknown }`), como no TS.
|
|
543
|
+
* O domínio da chave é só `string`/`number` (o que o TS permite).
|
|
544
|
+
*/
|
|
545
|
+
interface IndexSig {
|
|
546
|
+
readonly key: "string" | "number";
|
|
547
|
+
readonly value: Schema;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Flag de um elemento de tupla (espelha o `ElementFlags` do tsc):
|
|
551
|
+
* - `req` — elemento posicional normal (`A` em `[A, B]`);
|
|
552
|
+
* - `optional` — `A?` (pode estar ausente; `[A, B?]`); só TRAILING, posicional;
|
|
553
|
+
* - `rest` — `...T[]` (cauda de array); o tipo do elemento é o do array;
|
|
554
|
+
* - `variadic` — `...T` (spread de uma tupla/var); após `normalizeTuple` só var
|
|
555
|
+
* genérica fica `variadic` (tupla concreta é espalhada; array vira `rest`).
|
|
556
|
+
*/
|
|
557
|
+
type ElementFlag = "req" | "optional" | "rest" | "variadic";
|
|
558
|
+
/** Um parâmetro de um tipo função. */
|
|
559
|
+
interface Param {
|
|
560
|
+
readonly name: string;
|
|
561
|
+
readonly type: Schema;
|
|
562
|
+
/** `true` quando o argumento pode ser omitido. */
|
|
563
|
+
readonly optional?: boolean;
|
|
564
|
+
/** `true` para o parâmetro rest (`...args: T[]`). */
|
|
565
|
+
readonly variadic?: boolean;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Type predicate `(v) => v is S` — quando a fn devolve `true`, o argumento na
|
|
569
|
+
* posição `param` é estreitado para `type` (S). `returns` da fn continua `boolean`
|
|
570
|
+
* (é o que roda); o `guard` é a info de narrowing. `filter`/`find` inferem S dele;
|
|
571
|
+
* `if (g(x))` estreita `x` (D13). Covariante em `type`.
|
|
572
|
+
*/
|
|
573
|
+
interface GuardSig {
|
|
574
|
+
readonly param: number;
|
|
575
|
+
readonly type: Schema;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* O tipo de um valor na linguagem TSLite.
|
|
579
|
+
*
|
|
580
|
+
* O discriminador é `t`. Estruturas (object/array/union/fn) referenciam outros
|
|
581
|
+
* `Schema` recursivamente — inclusive de forma cíclica (ex.: `Node` que contém
|
|
582
|
+
* `Node[]`); as operações que percorrem `Schema` são cycle-safe.
|
|
583
|
+
*/
|
|
584
|
+
type Schema = {
|
|
585
|
+
readonly t: "any";
|
|
586
|
+
} | {
|
|
587
|
+
readonly t: "unknown";
|
|
588
|
+
} | {
|
|
589
|
+
readonly t: "string";
|
|
590
|
+
} | {
|
|
591
|
+
readonly t: "number";
|
|
592
|
+
} | {
|
|
593
|
+
readonly t: "boolean";
|
|
594
|
+
} | {
|
|
595
|
+
readonly t: "null";
|
|
596
|
+
} | {
|
|
597
|
+
readonly t: "undefined";
|
|
598
|
+
} | {
|
|
599
|
+
readonly t: "void";
|
|
600
|
+
} | {
|
|
601
|
+
readonly t: "literal";
|
|
602
|
+
readonly value: string | number | boolean;
|
|
603
|
+
/**
|
|
604
|
+
* `fresh` = literal "fresco" de uma EXPRESSÃO de valor (`1`, `"x"`) — alarga
|
|
605
|
+
* pra base em posição de membro (array/object/tupla) ou inferido num `T[]`,
|
|
606
|
+
* mas preserva no topo (`const x = 1` → `1`; `id(1)` → `1`). Literal de
|
|
607
|
+
* `keyof`/declarado é NÃO-fresh → nunca alarga. Transparente p/ subtype/equals.
|
|
608
|
+
*/
|
|
609
|
+
readonly fresh?: boolean;
|
|
610
|
+
} | {
|
|
611
|
+
readonly t: "object";
|
|
612
|
+
readonly props: Readonly<Record<string, Prop>>;
|
|
613
|
+
/** Assinatura de índice (`Record<K, V>`); coexiste com `props`. Ausente = objeto fechado. */
|
|
614
|
+
readonly index?: IndexSig;
|
|
615
|
+
} | {
|
|
616
|
+
readonly t: "array";
|
|
617
|
+
readonly items: Schema;
|
|
618
|
+
/**
|
|
619
|
+
* `readonly T[]` (o `ReadonlyArray<T>` do TS). Só afeta a RELAÇÃO, e num
|
|
620
|
+
* sentido: `T[] ≤ readonly T[]`, mas **não** o contrário — dar um readonly
|
|
621
|
+
* onde se espera mutável perderia a garantia. TC28.
|
|
622
|
+
*/
|
|
623
|
+
readonly readonly?: boolean;
|
|
624
|
+
} | {
|
|
625
|
+
readonly t: "tuple";
|
|
626
|
+
readonly elements: readonly Schema[];
|
|
627
|
+
readonly flags?: readonly ElementFlag[];
|
|
628
|
+
/** `readonly [A, B]` — mesma regra do array readonly (TC28). */
|
|
629
|
+
readonly readonly?: boolean;
|
|
630
|
+
} | {
|
|
631
|
+
readonly t: "union";
|
|
632
|
+
readonly of: readonly Schema[];
|
|
633
|
+
} | {
|
|
634
|
+
readonly t: "fn";
|
|
635
|
+
readonly params: readonly Param[];
|
|
636
|
+
readonly returns: Schema;
|
|
637
|
+
/** Type predicate `(v) => v is S` — narrowing (ver `GuardSig`). */
|
|
638
|
+
readonly guard?: GuardSig;
|
|
639
|
+
/**
|
|
640
|
+
* Os type params **DECLARADOS**, em ordem (`<T, U>`). Ausente = a assinatura
|
|
641
|
+
* **não é genérica** — que é o que o tsc diz quando `Signature.typeParameters`
|
|
642
|
+
* é `undefined`.
|
|
643
|
+
*
|
|
644
|
+
* Existe para o **argumento de tipo explícito** (`f<T>(x)`): sem ordem
|
|
645
|
+
* declarada não dá para saber a que `var` o 1º argumento se liga, nem checar
|
|
646
|
+
* aridade. O tsc carrega exatamente isto (`types.ts#Signature.typeParameters`)
|
|
647
|
+
* e **nunca** deriva a ordem por aparição — sem a lista, ele trata a chamada
|
|
648
|
+
* como não-genérica e reporta TS2558. Fazemos igual (TC27).
|
|
649
|
+
*
|
|
650
|
+
* Só os NOMES: a constraint continua no próprio `var` (`var.bound`, TC10), que
|
|
651
|
+
* é onde o `sigBounds` já a procura. Defaults (`<T = string>`) estão fora do
|
|
652
|
+
* vocabulário, então "mínimo" ≡ "total" na checagem de aridade.
|
|
653
|
+
*/
|
|
654
|
+
readonly typeParams?: readonly string[];
|
|
655
|
+
} | {
|
|
656
|
+
readonly t: "overload";
|
|
657
|
+
readonly signatures: readonly {
|
|
658
|
+
readonly t: "fn";
|
|
659
|
+
readonly params: readonly Param[];
|
|
660
|
+
readonly returns: Schema;
|
|
661
|
+
readonly guard?: GuardSig;
|
|
662
|
+
/** Type params DECLARADOS desta assinatura (ver o `fn` acima). */
|
|
663
|
+
readonly typeParams?: readonly string[];
|
|
664
|
+
}[];
|
|
665
|
+
} | {
|
|
666
|
+
readonly t: "keyof";
|
|
667
|
+
readonly of: Schema;
|
|
668
|
+
} | {
|
|
669
|
+
readonly t: "index";
|
|
670
|
+
readonly obj: Schema;
|
|
671
|
+
readonly key: Schema;
|
|
672
|
+
} | {
|
|
673
|
+
readonly t: "mapped";
|
|
674
|
+
readonly key: string;
|
|
675
|
+
readonly over: Schema;
|
|
676
|
+
readonly body: Schema;
|
|
677
|
+
readonly optional?: boolean;
|
|
678
|
+
} | {
|
|
679
|
+
readonly t: "conditional";
|
|
680
|
+
readonly check: Schema;
|
|
681
|
+
readonly extends: Schema;
|
|
682
|
+
readonly then: Schema;
|
|
683
|
+
readonly else: Schema;
|
|
684
|
+
readonly infer?: readonly string[];
|
|
685
|
+
} | {
|
|
686
|
+
readonly t: "intersection";
|
|
687
|
+
readonly of: readonly Schema[];
|
|
688
|
+
} | {
|
|
689
|
+
readonly t: "returnType";
|
|
690
|
+
readonly fn: Schema;
|
|
691
|
+
} | {
|
|
692
|
+
readonly t: "parameters";
|
|
693
|
+
readonly fn: Schema;
|
|
694
|
+
} | {
|
|
695
|
+
readonly t: "var";
|
|
696
|
+
readonly name: string;
|
|
697
|
+
readonly bound?: Schema;
|
|
698
|
+
readonly isConst?: boolean;
|
|
699
|
+
} | {
|
|
700
|
+
/**
|
|
701
|
+
* `typeof x` em posição de TIPO — o *type query* do TS.
|
|
702
|
+
*
|
|
703
|
+
* É o único nó do vocabulário que **não** se resolve pela álgebra: ele
|
|
704
|
+
* pergunta o tipo de um **VALOR**, e valor é assunto do escopo, que este
|
|
705
|
+
* package não conhece (zero-dep, por desenho). Quem resolve é o checker,
|
|
706
|
+
* no ponto de USO — espelhando o `getTypeFromTypeQueryNode` do tsc, que é
|
|
707
|
+
* lazy (`links.resolvedType`) pelo mesmo motivo.
|
|
708
|
+
*
|
|
709
|
+
* Um `typeQuery` que chegue à álgebra é sinal de que a resolução não
|
|
710
|
+
* aconteceu (nome inexistente — já reportado); os algoritmos o tratam como
|
|
711
|
+
* folha opaca, sem estourar.
|
|
712
|
+
*/
|
|
713
|
+
readonly t: "typeQuery";
|
|
714
|
+
/** O entity name, em partes: `typeof obj.m` → `["obj", "m"]`. */
|
|
715
|
+
readonly path: readonly string[];
|
|
716
|
+
} | {
|
|
717
|
+
readonly t: "apply";
|
|
718
|
+
readonly name: string;
|
|
719
|
+
readonly args: readonly Schema[];
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
/** O que o hover de tipo devolve. */
|
|
723
|
+
interface TypeInfo {
|
|
724
|
+
/** O tipo formatado, estilo TS (`{ cep: string; uf: string }`). */
|
|
725
|
+
readonly text: string;
|
|
726
|
+
/**
|
|
727
|
+
* O que MOSTRAR no hover — o tipo em estilo **declaração** quando o nó é uma,
|
|
728
|
+
* como o VSCode faz (`const fn: () => number`, `type Res = number`,
|
|
729
|
+
* `(parameter) x: number`); igual a `text` no resto.
|
|
730
|
+
*
|
|
731
|
+
* Existe separado porque `text` é o TIPO (dado, comparável), e isto é
|
|
732
|
+
* APRESENTAÇÃO. Um consumidor que só quer o tipo continua lendo `text`.
|
|
733
|
+
*/
|
|
734
|
+
readonly display: string;
|
|
735
|
+
/** O `Schema` cru — para quem quiser renderizar de outro jeito. */
|
|
736
|
+
readonly schema: Schema;
|
|
737
|
+
/** O tipo do nó ESTree que respondeu (`Identifier`, `CallExpression`, …). */
|
|
738
|
+
readonly nodeType: string;
|
|
739
|
+
/** O trecho coberto — para o editor destacar o que foi consultado. */
|
|
740
|
+
readonly range: EditorRange;
|
|
741
|
+
}
|
|
742
|
+
/** O nó mais interno que cobre a posição (convenção TSLite: coluna 0-based). */
|
|
743
|
+
declare function nodeAt(ast: BaseNode, position: EditorPosition): BaseNode | undefined;
|
|
744
|
+
/**
|
|
745
|
+
* O tipo sob a posição. `undefined` quando não há nó ali ou nenhum nó que a cobre
|
|
746
|
+
* foi tipado — o que é normal: pontuação e nós puramente estruturais não têm tipo.
|
|
747
|
+
*
|
|
748
|
+
* Sobe pelos ancestrais quando o nó mais interno não tem tipo (o cursor no `.` de
|
|
749
|
+
* `a.b`, por exemplo), para responder algo útil em vez de nada.
|
|
750
|
+
*/
|
|
751
|
+
declare function typeAtPosition(program: ProgramInfo, position: EditorPosition): TypeInfo | undefined;
|
|
752
|
+
/** Onde um nome foi declarado — o que o Alt+clique do editor precisa. */
|
|
753
|
+
interface DefinitionInfo {
|
|
754
|
+
/** O trecho da DECLARAÇÃO (convenção TSLite: linha 1-based, coluna 0-based). */
|
|
755
|
+
readonly range: EditorRange;
|
|
756
|
+
/** O nome resolvido — útil pra UI e pra teste. */
|
|
757
|
+
readonly name: string;
|
|
758
|
+
/**
|
|
759
|
+
* O que foi resolvido. `value` sai do binder (mesmo arquivo, sempre com
|
|
760
|
+
* `range`); `type` sai da tabela lateral de referências e pode estar em OUTRO
|
|
761
|
+
* arquivo — nesse caso o `range` é um placeholder e quem resolve é o consumidor,
|
|
762
|
+
* que é quem conhece o conjunto de arquivos. Ver `typeRefAt`.
|
|
763
|
+
*/
|
|
764
|
+
readonly kind: "value" | "type";
|
|
765
|
+
}
|
|
766
|
+
/** O nome de TIPO sob a posição, se houver — a metade que o binder não vê. */
|
|
767
|
+
declare function typeRefAt(program: ProgramInfo, position: EditorPosition): {
|
|
768
|
+
readonly name: string;
|
|
769
|
+
readonly range: EditorRange;
|
|
770
|
+
} | undefined;
|
|
771
|
+
declare function definitionAt(program: ProgramInfo, position: EditorPosition): DefinitionInfo | undefined;
|
|
772
|
+
|
|
773
|
+
export { type AnalyzeOptions, type AnalyzeResult, DIAGNOSTIC_TAG, type DefinitionInfo, type EditorCodeAction, type EditorDiagnostic, type EditorEdit, type EditorPosition, type EditorRange, type LspDiagnostic, type MonacoMarker, type ProgramInfo, type SemanticToken, type SemanticTokenModifier, type SemanticTokenType, TSLITE_EXTENSIONS, TSLITE_LANGUAGE_ID, TSLITE_SEMANTIC_LEGEND, type TypeInfo, UNNECESSARY_CODES, type UnpositionedDiagnostic, analyze, definitionAt, encodeSemanticTokens, hoverMarkdown, lspHoverAt, monacoHoverAt, nodeAt, semanticTokens, semanticTokensOf, toLspCodeActions, toLspDiagnostics, toMonacoCodeActions, toMonacoMarkers, tsliteDarkPlusThemeRules, tsliteLanguageConfiguration, tsliteMonarchLanguage, tsliteThemeRules, typeAtPosition, typeRefAt };
|