@mermaid-js/language-service 0.0.0-stage → 13.0.0-alpha.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 +43 -2
- package/package.json +67 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014 - 2022 Knut Sveidqvist
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mermaid-js/language-service
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An editor-agnostic language service for Mermaid: diagnostics, go to definition, references, rename, hover, completion (front-matter `config:` included), folding, semantic tokens, and a cursor ↔ AST map for live previews. It has no runtime dependencies. `@mermaid-js/core` is a peer, and each diagram's language support (its _facet_) is an optional peer that loads on `preload()`.
|
|
4
|
+
|
|
5
|
+
Use it directly, or through an adapter: `@mermaid-js/language-server` for any LSP editor, `@mermaid-js/language-service-codemirror` for CodeMirror 6, `@mermaid-js/language-service-monaco` for Monaco.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @mermaid-js/language-service @mermaid-js/core @mermaid-js/diagram-flowchart
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createLanguageService } from '@mermaid-js/language-service';
|
|
15
|
+
|
|
16
|
+
const service = createLanguageService();
|
|
17
|
+
await service.preload(); // load the facets before the first update
|
|
18
|
+
|
|
19
|
+
const doc = service.update('file:///a.mmd', text); // synchronous, complete, immutable
|
|
20
|
+
doc.diagnostics();
|
|
21
|
+
doc.completions(offset);
|
|
22
|
+
doc.rename(offset, 'NewName'); // { edits } or { refused: reason }
|
|
23
|
+
doc.lineFoldingRanges(); // folds by line, as editors show them
|
|
24
|
+
doc.lineSemanticTokens(); // tokens cut per line
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Call `preload()` (or `preload({ types: ['flowchart'] })`) once, before the first `update`. A type whose facet is not loaded gets a `LANGUAGE_NOT_LOADED` diagnostic and generic features only; a facet that fails to load gets `LANGUAGE_LOAD_FAILED`, and one whose parser throws gets `LANGUAGE_FACET_FAILED`. `preload` never rejects.
|
|
28
|
+
|
|
29
|
+
Positions are UTF-16 offsets into the whole text (front matter included). `doc.lines()` converts to 0-based line and column.
|
|
30
|
+
|
|
31
|
+
## Third-party diagram types
|
|
32
|
+
|
|
33
|
+
Pass their rows to `createLanguageService({ facets: [{ type, id, detector, load }] })`. A facet is written against the types this package re-exports (`LanguageFacet`, `ParseResult`, `ProbeResult`, `DocumentView`, `HoverTarget`, …). The shared golden suite runs from `@mermaid-js/language-service/testing` (Node only).
|
|
34
|
+
|
|
35
|
+
The language server does not load third-party facets by default: a client opts in with `initializationOptions: { mermaid: { plugins: true } }` (D157), so opening an untrusted folder runs none of its code.
|
|
36
|
+
|
|
37
|
+
## Bundlers
|
|
38
|
+
|
|
39
|
+
- **Optional peers.** The first-party facets are dynamic imports of optional peers, such as `@mermaid-js/diagram-flowchart/language`. Bundlers resolve them at build time: install the diagram packages you want, or mark the missing ones external. Otherwise the build can fail instead of the service reporting `LANGUAGE_LOAD_FAILED`.
|
|
40
|
+
- **No top-level `await` of `preload()` in a Vite entry.** The facet and config-schema chunks import shared code from the entry chunk. An entry that awaits them at top level never finishes loading, with no error. Wrap the setup in a function: `async function start() { await service.preload(); … } void start();`.
|
|
41
|
+
|
|
42
|
+
## Limitations
|
|
43
|
+
|
|
44
|
+
- Language support exists for flowchart, sequence, class, state and ER diagrams. Other types get generic features: comments, directives, and front-matter config.
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mermaid-js/language-service",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "13.0.0-alpha.0",
|
|
4
|
+
"description": "Editor-agnostic Mermaid language service: diagnostics, navigation, rename, folding, semantic tokens.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./testing": {
|
|
14
|
+
"types": "./dist/testing/index.d.ts",
|
|
15
|
+
"default": "./dist/testing/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=20"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@mermaid-js/diagram-class": "13.0.0-alpha.0",
|
|
26
|
+
"@mermaid-js/core": "13.0.0-alpha.0",
|
|
27
|
+
"@mermaid-js/diagram-flowchart": "13.0.0-alpha.0",
|
|
28
|
+
"@mermaid-js/diagram-pie": "13.0.0-alpha.0",
|
|
29
|
+
"@mermaid-js/diagram-er": "13.0.0-alpha.0",
|
|
30
|
+
"@mermaid-js/diagram-journey": "13.0.0-alpha.0",
|
|
31
|
+
"@mermaid-js/diagram-quadrant": "13.0.0-alpha.0",
|
|
32
|
+
"@mermaid-js/diagram-sequence": "13.0.0-alpha.0",
|
|
33
|
+
"@mermaid-js/diagram-state": "13.0.0-alpha.0",
|
|
34
|
+
"@mermaid-js/diagram-timeline": "13.0.0-alpha.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"@mermaid-js/diagram-class": {
|
|
38
|
+
"optional": true
|
|
39
|
+
},
|
|
40
|
+
"@mermaid-js/diagram-er": {
|
|
41
|
+
"optional": true
|
|
42
|
+
},
|
|
43
|
+
"@mermaid-js/diagram-flowchart": {
|
|
44
|
+
"optional": true
|
|
45
|
+
},
|
|
46
|
+
"@mermaid-js/diagram-journey": {
|
|
47
|
+
"optional": true
|
|
48
|
+
},
|
|
49
|
+
"@mermaid-js/diagram-pie": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"@mermaid-js/diagram-quadrant": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"@mermaid-js/diagram-sequence": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"@mermaid-js/diagram-state": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"@mermaid-js/diagram-timeline": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "tsc -p tsconfig.build.json && tsc -p tsconfig.testing.json",
|
|
67
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
68
|
+
}
|
|
69
|
+
}
|