@exercism/codemirror-lang-lean 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +235 -2
- package/dist/index.cjs +873 -0
- package/dist/index.d.cts +79 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.js +867 -0
- package/package.json +52 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { LRLanguage, LanguageSupport } from "@codemirror/language";
|
|
2
|
+
import { EditorState, Extension } from "@codemirror/state";
|
|
3
|
+
import { Command } from "@codemirror/view";
|
|
4
|
+
import { AbbreviationProvider } from "@leanprover/unicode-input";
|
|
5
|
+
// Lean's `\`-abbreviations (`\to` → `→`, `\<>` → `⟨⟩`, `\alpha` → `α`, ...),
|
|
6
|
+
// behaving the way they do in the Lean 4 VS Code extension.
|
|
7
|
+
//
|
|
8
|
+
// Both the abbreviation table and the rules for when an abbreviation is
|
|
9
|
+
// replaced come from `@leanprover/unicode-input`, the package the VS Code
|
|
10
|
+
// extension itself is built on, so the two cannot drift apart: this file
|
|
11
|
+
// holds no table and no matching logic of its own. All it does is connect
|
|
12
|
+
// that engine to a CodeMirror editor, the way `VSCodeAbbreviationRewriter`
|
|
13
|
+
// connects it to a VS Code one:
|
|
14
|
+
//
|
|
15
|
+
// - every document change is reported to the engine, which tracks the
|
|
16
|
+
// abbreviation being typed;
|
|
17
|
+
// - after each change the engine replaces whatever is finished (the next
|
|
18
|
+
// character can't continue any abbreviation) or, with eager replacement,
|
|
19
|
+
// complete and unambiguous;
|
|
20
|
+
// - moving the cursor out of an abbreviation, pressing Tab, or leaving the
|
|
21
|
+
// editor replaces it too;
|
|
22
|
+
// - the abbreviation being typed is underlined.
|
|
23
|
+
interface LeanUnicodeInputConfig {
|
|
24
|
+
/// The character that starts an abbreviation. Defaults to `\`, like VS
|
|
25
|
+
/// Code's `lean4.input.leader`.
|
|
26
|
+
leader?: string;
|
|
27
|
+
/// Extra abbreviations, without the leader (`{ foo: "☺" }` adds `\foo`).
|
|
28
|
+
/// They take precedence over the built-in ones. This is VS Code's
|
|
29
|
+
/// `lean4.input.customTranslations`.
|
|
30
|
+
customTranslations?: {
|
|
31
|
+
[abbreviation: string]: string;
|
|
32
|
+
};
|
|
33
|
+
/// Replace an abbreviation as soon as it is complete and no other
|
|
34
|
+
/// abbreviation starts with it, without waiting for the next character.
|
|
35
|
+
/// Defaults to true, like VS Code's `lean4.input.eagerReplacementEnabled`.
|
|
36
|
+
eagerReplacement?: boolean;
|
|
37
|
+
/// Whether a leader typed inside a string or character literal starts an
|
|
38
|
+
/// abbreviation. VS Code does this, which turns the escapes `\t`, `\r`,
|
|
39
|
+
/// `\"` and `\x41` into `▸`, `→`, `Ä` and `×41` as they are typed. The
|
|
40
|
+
/// default here is false, so that escapes can be typed normally; the code
|
|
41
|
+
/// inside an `s!"…{…}…"` interpolation is not affected either way.
|
|
42
|
+
inStringLiterals?: boolean;
|
|
43
|
+
/// Show how a symbol is typed when the pointer rests on it ("Type ⊓ using
|
|
44
|
+
/// `\glb` or `\sqcap`"), as VS Code does. Defaults to true.
|
|
45
|
+
hover?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/// How the symbol at a position is typed.
|
|
48
|
+
interface AbbreviationHint {
|
|
49
|
+
from: number;
|
|
50
|
+
to: number;
|
|
51
|
+
symbol: string;
|
|
52
|
+
/// Every abbreviation that gives the symbol, with the leader.
|
|
53
|
+
abbreviations: string[];
|
|
54
|
+
/// Abbreviations that give the symbol together with its closing partner,
|
|
55
|
+
/// such as `\<>` for `⟨⟩`.
|
|
56
|
+
pairs: {
|
|
57
|
+
abbreviation: string;
|
|
58
|
+
closing: string;
|
|
59
|
+
}[];
|
|
60
|
+
}
|
|
61
|
+
/// The hint for the symbol that starts at `pos`, if the table has one. This
|
|
62
|
+
/// is what the VS Code extension shows on hover, from the same table.
|
|
63
|
+
///
|
|
64
|
+
/// Characters every keyboard has give no hint (the table has `\\` for `\`),
|
|
65
|
+
/// and neither does a symbol in a string or character literal, unless
|
|
66
|
+
/// abbreviations work there.
|
|
67
|
+
declare function abbreviationHintAt(state: EditorState, pos: number, config?: LeanUnicodeInputConfig, provider?: AbbreviationProvider): AbbreviationHint | null;
|
|
68
|
+
/// Replace the abbreviations being typed with their symbols right away.
|
|
69
|
+
/// Returns false, leaving the key to other bindings, when there are none.
|
|
70
|
+
declare const convertLeanAbbreviations: Command;
|
|
71
|
+
/// Lean's `\`-abbreviations, as an extension. `lean()` includes it.
|
|
72
|
+
declare function leanUnicodeInput(config?: LeanUnicodeInputConfig): Extension;
|
|
73
|
+
declare const leanLanguage: LRLanguage;
|
|
74
|
+
interface LeanConfig {
|
|
75
|
+
unicodeInput?: boolean | LeanUnicodeInputConfig;
|
|
76
|
+
}
|
|
77
|
+
declare function lean(config?: LeanConfig): LanguageSupport;
|
|
78
|
+
export { leanUnicodeInput, convertLeanAbbreviations, abbreviationHintAt, leanLanguage, LeanConfig, lean };
|
|
79
|
+
export type { LeanUnicodeInputConfig, AbbreviationHint };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { LRLanguage, LanguageSupport } from "@codemirror/language";
|
|
2
|
+
import { EditorState, Extension } from "@codemirror/state";
|
|
3
|
+
import { Command } from "@codemirror/view";
|
|
4
|
+
import { AbbreviationProvider } from "@leanprover/unicode-input";
|
|
5
|
+
// Lean's `\`-abbreviations (`\to` → `→`, `\<>` → `⟨⟩`, `\alpha` → `α`, ...),
|
|
6
|
+
// behaving the way they do in the Lean 4 VS Code extension.
|
|
7
|
+
//
|
|
8
|
+
// Both the abbreviation table and the rules for when an abbreviation is
|
|
9
|
+
// replaced come from `@leanprover/unicode-input`, the package the VS Code
|
|
10
|
+
// extension itself is built on, so the two cannot drift apart: this file
|
|
11
|
+
// holds no table and no matching logic of its own. All it does is connect
|
|
12
|
+
// that engine to a CodeMirror editor, the way `VSCodeAbbreviationRewriter`
|
|
13
|
+
// connects it to a VS Code one:
|
|
14
|
+
//
|
|
15
|
+
// - every document change is reported to the engine, which tracks the
|
|
16
|
+
// abbreviation being typed;
|
|
17
|
+
// - after each change the engine replaces whatever is finished (the next
|
|
18
|
+
// character can't continue any abbreviation) or, with eager replacement,
|
|
19
|
+
// complete and unambiguous;
|
|
20
|
+
// - moving the cursor out of an abbreviation, pressing Tab, or leaving the
|
|
21
|
+
// editor replaces it too;
|
|
22
|
+
// - the abbreviation being typed is underlined.
|
|
23
|
+
interface LeanUnicodeInputConfig {
|
|
24
|
+
/// The character that starts an abbreviation. Defaults to `\`, like VS
|
|
25
|
+
/// Code's `lean4.input.leader`.
|
|
26
|
+
leader?: string;
|
|
27
|
+
/// Extra abbreviations, without the leader (`{ foo: "☺" }` adds `\foo`).
|
|
28
|
+
/// They take precedence over the built-in ones. This is VS Code's
|
|
29
|
+
/// `lean4.input.customTranslations`.
|
|
30
|
+
customTranslations?: {
|
|
31
|
+
[abbreviation: string]: string;
|
|
32
|
+
};
|
|
33
|
+
/// Replace an abbreviation as soon as it is complete and no other
|
|
34
|
+
/// abbreviation starts with it, without waiting for the next character.
|
|
35
|
+
/// Defaults to true, like VS Code's `lean4.input.eagerReplacementEnabled`.
|
|
36
|
+
eagerReplacement?: boolean;
|
|
37
|
+
/// Whether a leader typed inside a string or character literal starts an
|
|
38
|
+
/// abbreviation. VS Code does this, which turns the escapes `\t`, `\r`,
|
|
39
|
+
/// `\"` and `\x41` into `▸`, `→`, `Ä` and `×41` as they are typed. The
|
|
40
|
+
/// default here is false, so that escapes can be typed normally; the code
|
|
41
|
+
/// inside an `s!"…{…}…"` interpolation is not affected either way.
|
|
42
|
+
inStringLiterals?: boolean;
|
|
43
|
+
/// Show how a symbol is typed when the pointer rests on it ("Type ⊓ using
|
|
44
|
+
/// `\glb` or `\sqcap`"), as VS Code does. Defaults to true.
|
|
45
|
+
hover?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/// How the symbol at a position is typed.
|
|
48
|
+
interface AbbreviationHint {
|
|
49
|
+
from: number;
|
|
50
|
+
to: number;
|
|
51
|
+
symbol: string;
|
|
52
|
+
/// Every abbreviation that gives the symbol, with the leader.
|
|
53
|
+
abbreviations: string[];
|
|
54
|
+
/// Abbreviations that give the symbol together with its closing partner,
|
|
55
|
+
/// such as `\<>` for `⟨⟩`.
|
|
56
|
+
pairs: {
|
|
57
|
+
abbreviation: string;
|
|
58
|
+
closing: string;
|
|
59
|
+
}[];
|
|
60
|
+
}
|
|
61
|
+
/// The hint for the symbol that starts at `pos`, if the table has one. This
|
|
62
|
+
/// is what the VS Code extension shows on hover, from the same table.
|
|
63
|
+
///
|
|
64
|
+
/// Characters every keyboard has give no hint (the table has `\\` for `\`),
|
|
65
|
+
/// and neither does a symbol in a string or character literal, unless
|
|
66
|
+
/// abbreviations work there.
|
|
67
|
+
declare function abbreviationHintAt(state: EditorState, pos: number, config?: LeanUnicodeInputConfig, provider?: AbbreviationProvider): AbbreviationHint | null;
|
|
68
|
+
/// Replace the abbreviations being typed with their symbols right away.
|
|
69
|
+
/// Returns false, leaving the key to other bindings, when there are none.
|
|
70
|
+
declare const convertLeanAbbreviations: Command;
|
|
71
|
+
/// Lean's `\`-abbreviations, as an extension. `lean()` includes it.
|
|
72
|
+
declare function leanUnicodeInput(config?: LeanUnicodeInputConfig): Extension;
|
|
73
|
+
declare const leanLanguage: LRLanguage;
|
|
74
|
+
interface LeanConfig {
|
|
75
|
+
unicodeInput?: boolean | LeanUnicodeInputConfig;
|
|
76
|
+
}
|
|
77
|
+
declare function lean(config?: LeanConfig): LanguageSupport;
|
|
78
|
+
export { leanUnicodeInput, convertLeanAbbreviations, abbreviationHintAt, leanLanguage, LeanConfig, lean };
|
|
79
|
+
export type { LeanUnicodeInputConfig, AbbreviationHint };
|