@cedarjs/structure 0.0.4
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 +145 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +19 -0
- package/dist/hosts.d.ts +23 -0
- package/dist/hosts.d.ts.map +1 -0
- package/dist/hosts.js +45 -0
- package/dist/ide.d.ts +122 -0
- package/dist/ide.d.ts.map +1 -0
- package/dist/ide.js +240 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/interactive_cli/RedwoodCommandString.d.ts +20 -0
- package/dist/interactive_cli/RedwoodCommandString.d.ts.map +1 -0
- package/dist/interactive_cli/RedwoodCommandString.js +72 -0
- package/dist/interactive_cli/command_builder.d.ts +10 -0
- package/dist/interactive_cli/command_builder.d.ts.map +1 -0
- package/dist/interactive_cli/command_builder.js +196 -0
- package/dist/interactive_cli/dry_run.d.ts +28 -0
- package/dist/interactive_cli/dry_run.d.ts.map +1 -0
- package/dist/interactive_cli/dry_run.js +101 -0
- package/dist/interactive_cli/ui.d.ts +32 -0
- package/dist/interactive_cli/ui.d.ts.map +1 -0
- package/dist/interactive_cli/ui.js +84 -0
- package/dist/language_server/RWLanguageServer.d.ts +30 -0
- package/dist/language_server/RWLanguageServer.d.ts.map +1 -0
- package/dist/language_server/RWLanguageServer.js +201 -0
- package/dist/language_server/commands.d.ts +14 -0
- package/dist/language_server/commands.d.ts.map +1 -0
- package/dist/language_server/commands.js +122 -0
- package/dist/language_server/diagnostics.d.ts +10 -0
- package/dist/language_server/diagnostics.d.ts.map +1 -0
- package/dist/language_server/diagnostics.js +61 -0
- package/dist/language_server/outline.d.ts +7 -0
- package/dist/language_server/outline.d.ts.map +1 -0
- package/dist/language_server/outline.js +37 -0
- package/dist/language_server/start.d.ts +2 -0
- package/dist/language_server/start.d.ts.map +1 -0
- package/dist/language_server/start.js +4 -0
- package/dist/language_server/xmethods.d.ts +11 -0
- package/dist/language_server/xmethods.d.ts.map +1 -0
- package/dist/language_server/xmethods.js +42 -0
- package/dist/model/RWCell.d.ts +22 -0
- package/dist/model/RWCell.d.ts.map +1 -0
- package/dist/model/RWCell.js +111 -0
- package/dist/model/RWComponent.d.ts +11 -0
- package/dist/model/RWComponent.d.ts.map +1 -0
- package/dist/model/RWComponent.js +42 -0
- package/dist/model/RWEnvHelper.d.ts +64 -0
- package/dist/model/RWEnvHelper.d.ts.map +1 -0
- package/dist/model/RWEnvHelper.js +295 -0
- package/dist/model/RWFunction.d.ts +11 -0
- package/dist/model/RWFunction.d.ts.map +1 -0
- package/dist/model/RWFunction.js +19 -0
- package/dist/model/RWLayout.d.ts +11 -0
- package/dist/model/RWLayout.d.ts.map +1 -0
- package/dist/model/RWLayout.js +19 -0
- package/dist/model/RWPage.d.ts +13 -0
- package/dist/model/RWPage.d.ts.map +1 -0
- package/dist/model/RWPage.js +60 -0
- package/dist/model/RWProject.d.ts +61 -0
- package/dist/model/RWProject.d.ts.map +1 -0
- package/dist/model/RWProject.js +170 -0
- package/dist/model/RWRoute.d.ts +58 -0
- package/dist/model/RWRoute.d.ts.map +1 -0
- package/dist/model/RWRoute.js +416 -0
- package/dist/model/RWRouter.d.ts +30 -0
- package/dist/model/RWRouter.d.ts.map +1 -0
- package/dist/model/RWRouter.js +186 -0
- package/dist/model/RWSDL.d.ts +21 -0
- package/dist/model/RWSDL.d.ts.map +1 -0
- package/dist/model/RWSDL.js +89 -0
- package/dist/model/RWSDLField.d.ts +31 -0
- package/dist/model/RWSDLField.d.ts.map +1 -0
- package/dist/model/RWSDLField.js +132 -0
- package/dist/model/RWService.d.ts +26 -0
- package/dist/model/RWService.d.ts.map +1 -0
- package/dist/model/RWService.js +76 -0
- package/dist/model/RWServiceFunction.d.ts +20 -0
- package/dist/model/RWServiceFunction.d.ts.map +1 -0
- package/dist/model/RWServiceFunction.js +100 -0
- package/dist/model/RWTOML.d.ts +12 -0
- package/dist/model/RWTOML.d.ts.map +1 -0
- package/dist/model/RWTOML.js +56 -0
- package/dist/model/index.d.ts +2 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +13 -0
- package/dist/model/util/advanced_path_parser.d.ts +12 -0
- package/dist/model/util/advanced_path_parser.d.ts.map +1 -0
- package/dist/model/util/advanced_path_parser.js +38 -0
- package/dist/model/util/process_env.d.ts +23 -0
- package/dist/model/util/process_env.d.ts.map +1 -0
- package/dist/model/util/process_env.js +76 -0
- package/dist/outline/index.d.ts +3 -0
- package/dist/outline/index.d.ts.map +1 -0
- package/dist/outline/index.js +31 -0
- package/dist/outline/outline.d.ts +4 -0
- package/dist/outline/outline.d.ts.map +1 -0
- package/dist/outline/outline.js +260 -0
- package/dist/outline/types.d.ts +88 -0
- package/dist/outline/types.d.ts.map +1 -0
- package/dist/outline/types.js +73 -0
- package/dist/util.d.ts +2 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +34 -0
- package/dist/x/Array.d.ts +4 -0
- package/dist/x/Array.d.ts.map +1 -0
- package/dist/x/Array.js +26 -0
- package/dist/x/URL.d.ts +15 -0
- package/dist/x/URL.d.ts.map +1 -0
- package/dist/x/URL.js +99 -0
- package/dist/x/child_process.d.ts +15 -0
- package/dist/x/child_process.d.ts.map +1 -0
- package/dist/x/child_process.js +51 -0
- package/dist/x/decorators.d.ts +3 -0
- package/dist/x/decorators.d.ts.map +1 -0
- package/dist/x/decorators.js +26 -0
- package/dist/x/path.d.ts +6 -0
- package/dist/x/path.d.ts.map +1 -0
- package/dist/x/path.js +53 -0
- package/dist/x/prisma.d.ts +19 -0
- package/dist/x/prisma.d.ts.map +1 -0
- package/dist/x/prisma.js +65 -0
- package/dist/x/ts-morph.d.ts +10 -0
- package/dist/x/ts-morph.d.ts.map +1 -0
- package/dist/x/ts-morph.js +56 -0
- package/dist/x/vscode-languageserver-types.d.ts +93 -0
- package/dist/x/vscode-languageserver-types.d.ts.map +1 -0
- package/dist/x/vscode-languageserver-types.js +421 -0
- package/dist/x/vscode-languageserver.d.ts +12 -0
- package/dist/x/vscode-languageserver.d.ts.map +1 -0
- package/dist/x/vscode-languageserver.js +61 -0
- package/dist/x/vscode.d.ts +126 -0
- package/dist/x/vscode.d.ts.map +1 -0
- package/dist/x/vscode.js +294 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Cedar
|
|
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
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
**IMPORTANT:** This is an **internal** and **development-time only** package :exclamation:
|
|
2
|
+
|
|
3
|
+
# Overview
|
|
4
|
+
|
|
5
|
+
- The @redwoodjs/structure package lets you build, validate and inspect an object graph that represents a complete Redwood project
|
|
6
|
+
- It is used by the CLI and by VSCode extensions to provide IDE features such as diagnostics, code-fixes, etc.
|
|
7
|
+
- **IMPORTANT:** This is an **internal** and **development-time only** package
|
|
8
|
+
- You **cannot** "import it" into a normal redwood app
|
|
9
|
+
|
|
10
|
+
## Code
|
|
11
|
+
|
|
12
|
+
- `/model/*`: The main API and classes (such as RWProject, RWPage, RWService, etc)
|
|
13
|
+
- `/language_server/*`: A [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) implementation that wraps the `model` classes. More info [here](./src/language_server/README.md)
|
|
14
|
+
- We use [vscode-languageserver-types](https://www.npmjs.com/package/vscode-languageserver-types) where possible (to represent Document URIs, Positions, Ranges, Diagnostics, etc)
|
|
15
|
+
|
|
16
|
+
# Usage
|
|
17
|
+
|
|
18
|
+
## Diagnostics
|
|
19
|
+
|
|
20
|
+
The most common use-case is getting the diagnostics of a complete Redwood project:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { getProject } from '@cedarjs/structure'
|
|
24
|
+
async function test() {
|
|
25
|
+
const project = getProject('/path/to/app') // or "file:///path/to/app"
|
|
26
|
+
for (const d of await project.collectDiagnostics()) {
|
|
27
|
+
console.log(d.diagnostic.severity + ': ' + d.diagnostic.message)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// ...
|
|
31
|
+
// error: Router must have only one "notfound" page
|
|
32
|
+
// error: Duplicate path in router: '/about-us'
|
|
33
|
+
// error: Parameter "id" in route '/product/{id}' does not exist on ProductPage
|
|
34
|
+
// error: PostsCell is missing the "Success" exported const
|
|
35
|
+
// error: Property "email" does not exist on "User" model
|
|
36
|
+
// warning: Unused page AboutUs.js
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Note: Gathering _all_ diagnostics is expensive. It will trigger the creation of the complete project graph.
|
|
40
|
+
|
|
41
|
+
## Exploration
|
|
42
|
+
|
|
43
|
+
You can also traverse the graph to get more detailed information on multiple aspects of your app.
|
|
44
|
+
|
|
45
|
+
For example, iterating over the routes of a Redwood project:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { getProject } from '@cedarjs/structure'
|
|
49
|
+
async function test() {
|
|
50
|
+
const project = getProject('/path/to/app')
|
|
51
|
+
for (const route of project.router.routes) {
|
|
52
|
+
console.log(route.path + (route.isPrivate ? ' (private)' : ''))
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// /
|
|
56
|
+
// /about
|
|
57
|
+
// /product/{id}
|
|
58
|
+
// /admin (private)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
# Design Notes
|
|
62
|
+
|
|
63
|
+
- The project is represented by an AST of sorts (via the RWProject, RWRoute, etc classes)
|
|
64
|
+
- While it can be explored as a graph, it is effectively a **tree** (via the children/parent properties) with stable IDs for each node
|
|
65
|
+
- Nodes are created lazily as the user traverses properties.
|
|
66
|
+
- There is extensive caching going on under the hood. **If the underlying project changes, you need to create a new project**
|
|
67
|
+
|
|
68
|
+
## ids
|
|
69
|
+
|
|
70
|
+
- Each node in the graph has an `id` property.
|
|
71
|
+
- ids are unique and stable
|
|
72
|
+
- They are organized in a hierarchical fashion (so that `child.id.startsWith(parent.id) === true`)
|
|
73
|
+
- Requesting a node using its id will not require the complete project to be processed. Only the subset that is needed (usually only the node's ancestors). This is important to enable efficient IDE-like tooling to interact with the project graph and get diagnostics for quickly changing files.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { getProject } from '@cedarjs/structure'
|
|
77
|
+
async function test() {
|
|
78
|
+
const project = getProject('/path/to/app')
|
|
79
|
+
const router = await project.findNode('file:///path/to/app/web/src/Routes.js')
|
|
80
|
+
console.log(router.routes.length)
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Here are some examples of ids:
|
|
85
|
+
|
|
86
|
+
- (Project)
|
|
87
|
+
- id: `"file:///project/root"`
|
|
88
|
+
- router: (Router)
|
|
89
|
+
- id: `"file:///project/root/web/src/Routes.js"`
|
|
90
|
+
- routes[0]: (Route)
|
|
91
|
+
- id: `"file:///project/root/web/src/Routes.js /home"` (notice that this id has two elements - it is an "internal" node)
|
|
92
|
+
|
|
93
|
+
An id is "usually" a file or folder.
|
|
94
|
+
|
|
95
|
+
Anatomy of an id:
|
|
96
|
+
|
|
97
|
+
- An id is a string.
|
|
98
|
+
- It has components separated by spaces.
|
|
99
|
+
- The first component is always a file URI (or folder URI).
|
|
100
|
+
- The rest are optional, and only exist when the node is internal to a file.
|
|
101
|
+
|
|
102
|
+
## Abstracting File System Access
|
|
103
|
+
|
|
104
|
+
To allow use cases like dealing with unsaved files in IDEs, some filesystem methods can be overridden via the Host interface.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
import { Host, getProject } from '@cedarjs/structure'
|
|
108
|
+
const myHost: Host {
|
|
109
|
+
readFileSync(path:string){
|
|
110
|
+
// ...
|
|
111
|
+
}
|
|
112
|
+
// ...
|
|
113
|
+
}
|
|
114
|
+
const project = getProject('/path/to/project', myHost)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Sync VS Async
|
|
118
|
+
|
|
119
|
+
When possible, the project graph is constructed synchronously. There are only a few exceptions. This simplifies the domain logic and validations, which is the main driver behind the project model itself.
|
|
120
|
+
|
|
121
|
+
## Parsing Invalid Projects
|
|
122
|
+
|
|
123
|
+
- It is possible to obtain a graph for an invalid/malformed Redwood project. This is by design since one of the main goals of this package is to provide a foundation for IDEs, which must support projects in invalid states
|
|
124
|
+
- If you want to check for structural validity, gather all diagnostics and look for errors.
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import { getProject, DiagnosticSeverity } from '@cedarjs/structure'
|
|
128
|
+
async function test() {
|
|
129
|
+
try {
|
|
130
|
+
const project = getProject('/path/to/app')
|
|
131
|
+
const diagnostics = await project.collectDiagnostics()
|
|
132
|
+
const hasErrors = diagnostics.some(
|
|
133
|
+
(d) => d.diagnostic.severity === DiagnosticSeverity.Error,
|
|
134
|
+
)
|
|
135
|
+
} catch (e) {
|
|
136
|
+
// we caught a runtime error
|
|
137
|
+
// in some cases this is the desired behavior
|
|
138
|
+
// but in MOST cases we SHOULD turn this into a diagnostic error
|
|
139
|
+
// please file an issue if you believe this should be the case
|
|
140
|
+
throw e
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
NOTE: It is possible (and very likely at this point) that this package will sometimes fail with a runtime error (for example, it will try to read a file that doesn't exist).
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable error codes
|
|
3
|
+
* TODO: use numbers? they tend to be more resilient to changes.
|
|
4
|
+
*/
|
|
5
|
+
export declare enum RWError {
|
|
6
|
+
SERVICE_NOT_IMPLEMENTED = "SERVICE_NOT_IMPLEMENTED",
|
|
7
|
+
NOTFOUND_PAGE_NOT_DEFINED = "NOTFOUND_PAGE_NOT_DEFINED",
|
|
8
|
+
INVALID_ROUTE_PATH_SYNTAX = "INVALID_ROUTE_PATH_SYNTAX",
|
|
9
|
+
SCHEMA_NOT_DEFINED = "SCHEMA_NOT_DEFINED"
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,OAAO;IACjB,uBAAuB,4BAA4B;IACnD,yBAAyB,8BAA8B;IAEvD,yBAAyB,8BAA8B;IACvD,kBAAkB,uBAAuB;CAC1C"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
|
|
4
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.RWError = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Stable error codes
|
|
10
|
+
* TODO: use numbers? they tend to be more resilient to changes.
|
|
11
|
+
*/
|
|
12
|
+
let RWError = exports.RWError = /*#__PURE__*/function (RWError) {
|
|
13
|
+
RWError["SERVICE_NOT_IMPLEMENTED"] = "SERVICE_NOT_IMPLEMENTED";
|
|
14
|
+
RWError["NOTFOUND_PAGE_NOT_DEFINED"] = "NOTFOUND_PAGE_NOT_DEFINED";
|
|
15
|
+
// this error should be broken down into more specialized errors: syntax error, duplicate parameters
|
|
16
|
+
RWError["INVALID_ROUTE_PATH_SYNTAX"] = "INVALID_ROUTE_PATH_SYNTAX";
|
|
17
|
+
RWError["SCHEMA_NOT_DEFINED"] = "SCHEMA_NOT_DEFINED";
|
|
18
|
+
return RWError;
|
|
19
|
+
}({});
|
package/dist/hosts.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Paths } from '@cedarjs/project-config';
|
|
2
|
+
/**
|
|
3
|
+
* The host interface allows us to decouple the "model/*"
|
|
4
|
+
* classes from access to the file system.
|
|
5
|
+
* This is critical for editor support (ex: showing diagnostics on unsaved files)
|
|
6
|
+
*/
|
|
7
|
+
export interface Host {
|
|
8
|
+
existsSync(path: string): boolean;
|
|
9
|
+
readFileSync(path: string): string;
|
|
10
|
+
readdirSync(path: string): string[];
|
|
11
|
+
globSync(pattern: string): string[];
|
|
12
|
+
writeFileSync(path: string, contents: string): void;
|
|
13
|
+
paths: Paths;
|
|
14
|
+
}
|
|
15
|
+
export declare class DefaultHost implements Host {
|
|
16
|
+
existsSync(path: string): boolean;
|
|
17
|
+
readFileSync(path: string): string;
|
|
18
|
+
readdirSync(path: string): string[];
|
|
19
|
+
globSync(pattern: string): string[];
|
|
20
|
+
writeFileSync(path: string, contents: string): void;
|
|
21
|
+
get paths(): Paths;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=hosts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hosts.d.ts","sourceRoot":"","sources":["../src/hosts.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAKpD;;;;GAIG;AACH,MAAM,WAAW,IAAI;IACnB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IACjC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IAClC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACnC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACnD,KAAK,EAAE,KAAK,CAAA;CACb;AAED,qBAAa,WAAY,YAAW,IAAI;IACtC,UAAU,CAAC,IAAI,EAAE,MAAM;IAGvB,YAAY,CAAC,IAAI,EAAE,MAAM;IAGzB,WAAW,CAAC,IAAI,EAAE,MAAM;IAGxB,QAAQ,CAAC,OAAO,EAAE,MAAM;IAIxB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAG5C,IACI,KAAK,UAER;CACF"}
|
package/dist/hosts.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
5
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
6
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.DefaultHost = void 0;
|
|
10
|
+
var _replaceAll = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/replace-all"));
|
|
11
|
+
var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/object/get-own-property-descriptor"));
|
|
12
|
+
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/applyDecoratedDescriptor"));
|
|
13
|
+
var _fastGlob = _interopRequireDefault(require("fast-glob"));
|
|
14
|
+
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
15
|
+
var _projectConfig = require("@cedarjs/project-config");
|
|
16
|
+
var _decorators = require("./x/decorators");
|
|
17
|
+
var _dec, _class;
|
|
18
|
+
/**
|
|
19
|
+
* The host interface allows us to decouple the "model/*"
|
|
20
|
+
* classes from access to the file system.
|
|
21
|
+
* This is critical for editor support (ex: showing diagnostics on unsaved files)
|
|
22
|
+
*/
|
|
23
|
+
let DefaultHost = exports.DefaultHost = (_dec = (0, _decorators.lazy)(), _class = class DefaultHost {
|
|
24
|
+
existsSync(path) {
|
|
25
|
+
return fs.existsSync(path);
|
|
26
|
+
}
|
|
27
|
+
readFileSync(path) {
|
|
28
|
+
return fs.readFileSync(path, {
|
|
29
|
+
encoding: 'utf8'
|
|
30
|
+
}).toString();
|
|
31
|
+
}
|
|
32
|
+
readdirSync(path) {
|
|
33
|
+
return fs.readdirSync(path);
|
|
34
|
+
}
|
|
35
|
+
globSync(pattern) {
|
|
36
|
+
// globSync only works with / as the path separator, even on Windows
|
|
37
|
+
return _fastGlob.default.sync((0, _replaceAll.default)(pattern).call(pattern, '\\', '/'));
|
|
38
|
+
}
|
|
39
|
+
writeFileSync(path, contents) {
|
|
40
|
+
return fs.writeFileSync(path, contents);
|
|
41
|
+
}
|
|
42
|
+
get paths() {
|
|
43
|
+
return (0, _projectConfig.getPaths)();
|
|
44
|
+
}
|
|
45
|
+
}, (0, _applyDecoratedDescriptor2.default)(_class.prototype, "paths", [_dec], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "paths"), _class.prototype), _class);
|
package/dist/ide.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type * as tsm from 'ts-morph';
|
|
2
|
+
import type { TextDocuments } from 'vscode-languageserver';
|
|
3
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
|
+
import type { CodeLens, DocumentLink, Hover, Location } from 'vscode-languageserver-types';
|
|
5
|
+
import type { Host } from './hosts';
|
|
6
|
+
import { DefaultHost } from './hosts';
|
|
7
|
+
import type { ArrayLike } from './x/Array';
|
|
8
|
+
import type { ExtendedDiagnostic } from './x/vscode-languageserver-types';
|
|
9
|
+
export type NodeID = string;
|
|
10
|
+
export type IDEInfo = Definition | Implementation | Reference | CodeLensX | HoverX | Decoration | DocumentLinkX;
|
|
11
|
+
export interface Definition {
|
|
12
|
+
kind: 'Definition';
|
|
13
|
+
location: Location;
|
|
14
|
+
target: Location;
|
|
15
|
+
}
|
|
16
|
+
export interface Implementation {
|
|
17
|
+
kind: 'Implementation';
|
|
18
|
+
location: Location;
|
|
19
|
+
target: Location;
|
|
20
|
+
}
|
|
21
|
+
export interface Reference {
|
|
22
|
+
kind: 'Reference';
|
|
23
|
+
location: Location;
|
|
24
|
+
target: Location;
|
|
25
|
+
}
|
|
26
|
+
export interface CodeLensX {
|
|
27
|
+
kind: 'CodeLens';
|
|
28
|
+
location: Location;
|
|
29
|
+
codeLens: CodeLens;
|
|
30
|
+
}
|
|
31
|
+
export interface HoverX {
|
|
32
|
+
kind: 'Hover';
|
|
33
|
+
location: Location;
|
|
34
|
+
hover: Hover;
|
|
35
|
+
}
|
|
36
|
+
export interface Decoration {
|
|
37
|
+
kind: 'Decoration';
|
|
38
|
+
location: Location;
|
|
39
|
+
style: 'path_punctuation' | 'path_parameter' | 'path_slash' | 'path_parameter_type';
|
|
40
|
+
}
|
|
41
|
+
export interface DocumentLinkX {
|
|
42
|
+
kind: 'DocumentLink';
|
|
43
|
+
location: Location;
|
|
44
|
+
link: DocumentLink;
|
|
45
|
+
}
|
|
46
|
+
export declare abstract class BaseNode {
|
|
47
|
+
/**
|
|
48
|
+
* Each node MUST have a unique ID.
|
|
49
|
+
* IDs have meaningful information.
|
|
50
|
+
*
|
|
51
|
+
* examples:
|
|
52
|
+
* - /path/to/project
|
|
53
|
+
* - /path/to/project/web/src/Routes.js
|
|
54
|
+
* - /path/to/project/web/src/Routes.js /route1
|
|
55
|
+
*/
|
|
56
|
+
abstract get id(): NodeID;
|
|
57
|
+
abstract get parent(): BaseNode | undefined;
|
|
58
|
+
get host(): Host;
|
|
59
|
+
exists: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Returns the children of this node.
|
|
62
|
+
* Override this.
|
|
63
|
+
*/
|
|
64
|
+
children(): ArrayLike<BaseNode>;
|
|
65
|
+
private _children;
|
|
66
|
+
/**
|
|
67
|
+
* Diagnostics for this node (must not include children's diagnostics).
|
|
68
|
+
* Override this.
|
|
69
|
+
*/
|
|
70
|
+
diagnostics(): ArrayLike<ExtendedDiagnostic>;
|
|
71
|
+
private _diagnostics;
|
|
72
|
+
/**
|
|
73
|
+
* IDE info for this node.
|
|
74
|
+
* Override this.
|
|
75
|
+
*/
|
|
76
|
+
ideInfo(): ArrayLike<IDEInfo>;
|
|
77
|
+
private _ideInfo;
|
|
78
|
+
collectIDEInfo(uri?: string): Promise<IDEInfo[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Collects diagnostics for this node and all descendants.
|
|
81
|
+
* This is what you'll use to gather all the project diagnostics.
|
|
82
|
+
*/
|
|
83
|
+
collectDiagnostics(uri?: string): Promise<ExtendedDiagnostic[]>;
|
|
84
|
+
bailOutOnCollection(uri: string): boolean;
|
|
85
|
+
get closestContainingUri(): string | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Finds a node by ID.
|
|
88
|
+
* The default algorithm tries to be economic and only create the necessary
|
|
89
|
+
* intermediate nodes.
|
|
90
|
+
* Subclasses can override this to add further optimizations.
|
|
91
|
+
* @param id
|
|
92
|
+
*/
|
|
93
|
+
findNode(id: NodeID): Promise<BaseNode | undefined>;
|
|
94
|
+
}
|
|
95
|
+
export declare abstract class FileNode extends BaseNode {
|
|
96
|
+
abstract get filePath(): string;
|
|
97
|
+
get uri(): string;
|
|
98
|
+
/**
|
|
99
|
+
* the ID of a FileNode is its file:// uri.
|
|
100
|
+
*/
|
|
101
|
+
get id(): string;
|
|
102
|
+
get text(): string;
|
|
103
|
+
get fileExists(): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* parsed ts-morph source file
|
|
106
|
+
*/
|
|
107
|
+
get sf(): tsm.SourceFile;
|
|
108
|
+
get basenameNoExt(): string;
|
|
109
|
+
get basename(): string;
|
|
110
|
+
}
|
|
111
|
+
export declare class HostWithDocumentsStore implements Host {
|
|
112
|
+
documents: TextDocuments<TextDocument>;
|
|
113
|
+
defaultHost: DefaultHost;
|
|
114
|
+
constructor(documents: TextDocuments<TextDocument>);
|
|
115
|
+
readFileSync(path: string): string;
|
|
116
|
+
existsSync(path: string): boolean;
|
|
117
|
+
readdirSync(path: string): string[];
|
|
118
|
+
globSync(pattern: string): string[];
|
|
119
|
+
writeFileSync(path: string, contents: string): void;
|
|
120
|
+
get paths(): import("@cedarjs/project-config").Paths;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=ide.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ide.d.ts","sourceRoot":"","sources":["../src/ide.ts"],"names":[],"mappings":"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"}
|
package/dist/ide.js
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
5
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.HostWithDocumentsStore = exports.FileNode = exports.BaseNode = void 0;
|
|
9
|
+
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/json/stringify"));
|
|
10
|
+
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/promise"));
|
|
11
|
+
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/map"));
|
|
12
|
+
var _flat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/flat"));
|
|
13
|
+
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/filter"));
|
|
14
|
+
var _startsWith = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/starts-with"));
|
|
15
|
+
var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/object/get-own-property-descriptor"));
|
|
16
|
+
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/applyDecoratedDescriptor"));
|
|
17
|
+
var _path = require("path");
|
|
18
|
+
var _vscodeLanguageserverTypes = require("vscode-languageserver-types");
|
|
19
|
+
var _hosts = require("./hosts");
|
|
20
|
+
var _Array = require("./x/Array");
|
|
21
|
+
var _decorators = require("./x/decorators");
|
|
22
|
+
var _path2 = require("./x/path");
|
|
23
|
+
var _tsMorph = require("./x/ts-morph");
|
|
24
|
+
var _URL = require("./x/URL");
|
|
25
|
+
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _class2;
|
|
26
|
+
let BaseNode = exports.BaseNode = (_dec = (0, _decorators.lazy)(), _dec2 = (0, _decorators.memo)(), _dec3 = (0, _decorators.memo)(), _dec4 = (0, _decorators.memo)(), _dec5 = (0, _decorators.memo)(_stringify.default), _dec6 = (0, _decorators.memo)(_stringify.default), _dec7 = (0, _decorators.lazy)(), _dec8 = (0, _decorators.memo)(), _class = class BaseNode {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.exists = true;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Each node MUST have a unique ID.
|
|
32
|
+
* IDs have meaningful information.
|
|
33
|
+
*
|
|
34
|
+
* examples:
|
|
35
|
+
* - /path/to/project
|
|
36
|
+
* - /path/to/project/web/src/Routes.js
|
|
37
|
+
* - /path/to/project/web/src/Routes.js /route1
|
|
38
|
+
*/
|
|
39
|
+
get host() {
|
|
40
|
+
if (this.parent) {
|
|
41
|
+
return this.parent.host;
|
|
42
|
+
}
|
|
43
|
+
throw new Error("Could not find host implementation on root node (you must override the 'host' getter)");
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns the children of this node.
|
|
47
|
+
* Override this.
|
|
48
|
+
*/
|
|
49
|
+
children() {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
_children() {
|
|
53
|
+
return (0, _Array.ArrayLike_normalize)(this.children());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Diagnostics for this node (must not include children's diagnostics).
|
|
58
|
+
* Override this.
|
|
59
|
+
*/
|
|
60
|
+
diagnostics() {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
_diagnostics() {
|
|
64
|
+
return (0, _Array.ArrayLike_normalize)(this.diagnostics());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* IDE info for this node.
|
|
69
|
+
* Override this.
|
|
70
|
+
*/
|
|
71
|
+
ideInfo() {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
_ideInfo() {
|
|
75
|
+
return (0, _Array.ArrayLike_normalize)(this.ideInfo());
|
|
76
|
+
}
|
|
77
|
+
async collectIDEInfo(uri) {
|
|
78
|
+
if (uri && this.bailOutOnCollection(uri)) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
var _context;
|
|
83
|
+
const d1 = await this._ideInfo();
|
|
84
|
+
const dd = await _promise.default.all((0, _map.default)(_context = await this._children()).call(_context, c => c.collectIDEInfo(uri)));
|
|
85
|
+
const d2 = (0, _flat.default)(dd).call(dd);
|
|
86
|
+
let all = [...d1, ...d2];
|
|
87
|
+
if (uri) {
|
|
88
|
+
all = (0, _filter.default)(all).call(all, x => x.location.uri === uri);
|
|
89
|
+
}
|
|
90
|
+
return all;
|
|
91
|
+
} catch (e) {
|
|
92
|
+
// TODO: this diagnostic is also interesting
|
|
93
|
+
console.log(e);
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Collects diagnostics for this node and all descendants.
|
|
100
|
+
* This is what you'll use to gather all the project diagnostics.
|
|
101
|
+
*/
|
|
102
|
+
async collectDiagnostics(uri) {
|
|
103
|
+
// TODO: catch runtime errors and add them as diagnostics
|
|
104
|
+
// TODO: we can parallelize this further
|
|
105
|
+
if (uri && this.bailOutOnCollection(uri)) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
var _context2;
|
|
110
|
+
const d1 = await this._diagnostics();
|
|
111
|
+
const dd = await _promise.default.all((0, _map.default)(_context2 = await this._children()).call(_context2, c => c.collectDiagnostics(uri)));
|
|
112
|
+
const d2 = (0, _flat.default)(dd).call(dd);
|
|
113
|
+
let all = [...d1, ...d2];
|
|
114
|
+
if (uri) {
|
|
115
|
+
all = (0, _filter.default)(all).call(all, x => x.uri === uri);
|
|
116
|
+
}
|
|
117
|
+
return all;
|
|
118
|
+
} catch (e) {
|
|
119
|
+
const uri = this.closestContainingUri;
|
|
120
|
+
if (!uri) {
|
|
121
|
+
throw e;
|
|
122
|
+
}
|
|
123
|
+
const range = _vscodeLanguageserverTypes.Range.create(0, 0, 0, 0);
|
|
124
|
+
return [{
|
|
125
|
+
uri,
|
|
126
|
+
diagnostic: {
|
|
127
|
+
message: e + '',
|
|
128
|
+
range
|
|
129
|
+
}
|
|
130
|
+
}];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
bailOutOnCollection(uri) {
|
|
134
|
+
if (this.id === uri) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
if ((0, _startsWith.default)(uri).call(uri, this.id)) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
get closestContainingUri() {
|
|
143
|
+
const {
|
|
144
|
+
uri
|
|
145
|
+
} = this;
|
|
146
|
+
if (uri) {
|
|
147
|
+
return uri;
|
|
148
|
+
}
|
|
149
|
+
if (this.parent) {
|
|
150
|
+
return this.parent.closestContainingUri;
|
|
151
|
+
}
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Finds a node by ID.
|
|
157
|
+
* The default algorithm tries to be economic and only create the necessary
|
|
158
|
+
* intermediate nodes.
|
|
159
|
+
* Subclasses can override this to add further optimizations.
|
|
160
|
+
* @param id
|
|
161
|
+
*/
|
|
162
|
+
async findNode(id) {
|
|
163
|
+
id = (0, _URL.URL_file)(id);
|
|
164
|
+
if (this.id === id) {
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
if ((0, _startsWith.default)(id).call(id, this.id)) {
|
|
168
|
+
for (const c of await this._children()) {
|
|
169
|
+
// depth first search by default
|
|
170
|
+
const cc = await c.findNode(id);
|
|
171
|
+
if (cc) {
|
|
172
|
+
return cc;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
}, (0, _applyDecoratedDescriptor2.default)(_class.prototype, "host", [_dec], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "host"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "_children", [_dec2], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "_children"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "_diagnostics", [_dec3], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "_diagnostics"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "_ideInfo", [_dec4], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "_ideInfo"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "collectIDEInfo", [_dec5], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "collectIDEInfo"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "collectDiagnostics", [_dec6], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "collectDiagnostics"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "closestContainingUri", [_dec7], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "closestContainingUri"), _class.prototype), (0, _applyDecoratedDescriptor2.default)(_class.prototype, "findNode", [_dec8], (0, _getOwnPropertyDescriptor.default)(_class.prototype, "findNode"), _class.prototype), _class);
|
|
179
|
+
let FileNode = exports.FileNode = (_dec9 = (0, _decorators.lazy)(), _dec10 = (0, _decorators.lazy)(), _dec11 = (0, _decorators.lazy)(), _dec12 = (0, _decorators.lazy)(), _dec13 = (0, _decorators.lazy)(), _dec14 = (0, _decorators.lazy)(), _dec15 = (0, _decorators.lazy)(), _class2 = class FileNode extends BaseNode {
|
|
180
|
+
get uri() {
|
|
181
|
+
return (0, _URL.URL_file)(this.filePath);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* the ID of a FileNode is its file:// uri.
|
|
185
|
+
*/
|
|
186
|
+
get id() {
|
|
187
|
+
return this.uri;
|
|
188
|
+
}
|
|
189
|
+
get text() {
|
|
190
|
+
return this.host.readFileSync(this.filePath);
|
|
191
|
+
}
|
|
192
|
+
get fileExists() {
|
|
193
|
+
return this.host.existsSync(this.filePath);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* parsed ts-morph source file
|
|
197
|
+
*/
|
|
198
|
+
get sf() {
|
|
199
|
+
if (typeof this.text === 'undefined') {
|
|
200
|
+
throw new Error('undefined file ' + this.filePath);
|
|
201
|
+
}
|
|
202
|
+
return (0, _tsMorph.createTSMSourceFile_cached)(this.filePath, this.text);
|
|
203
|
+
}
|
|
204
|
+
get basenameNoExt() {
|
|
205
|
+
return (0, _path2.basenameNoExt)(this.filePath);
|
|
206
|
+
}
|
|
207
|
+
get basename() {
|
|
208
|
+
return (0, _path.basename)(this.filePath);
|
|
209
|
+
}
|
|
210
|
+
}, (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "uri", [_dec9], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "uri"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "id", [_dec10], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "id"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "text", [_dec11], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "text"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "fileExists", [_dec12], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "fileExists"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "sf", [_dec13], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "sf"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "basenameNoExt", [_dec14], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "basenameNoExt"), _class2.prototype), (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "basename", [_dec15], (0, _getOwnPropertyDescriptor.default)(_class2.prototype, "basename"), _class2.prototype), _class2);
|
|
211
|
+
class HostWithDocumentsStore {
|
|
212
|
+
constructor(documents) {
|
|
213
|
+
this.defaultHost = new _hosts.DefaultHost();
|
|
214
|
+
this.documents = documents;
|
|
215
|
+
}
|
|
216
|
+
readFileSync(path) {
|
|
217
|
+
const uri = (0, _URL.URL_file)(path);
|
|
218
|
+
const doc = this.documents.get(uri);
|
|
219
|
+
if (doc) {
|
|
220
|
+
return doc.getText();
|
|
221
|
+
}
|
|
222
|
+
return this.defaultHost.readFileSync(path);
|
|
223
|
+
}
|
|
224
|
+
existsSync(path) {
|
|
225
|
+
return this.defaultHost.existsSync(path);
|
|
226
|
+
}
|
|
227
|
+
readdirSync(path) {
|
|
228
|
+
return this.defaultHost.readdirSync(path);
|
|
229
|
+
}
|
|
230
|
+
globSync(pattern) {
|
|
231
|
+
return this.defaultHost.globSync(pattern);
|
|
232
|
+
}
|
|
233
|
+
writeFileSync(path, contents) {
|
|
234
|
+
return this.defaultHost.writeFileSync(path, contents);
|
|
235
|
+
}
|
|
236
|
+
get paths() {
|
|
237
|
+
return this.defaultHost.paths;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
exports.HostWithDocumentsStore = HostWithDocumentsStore;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { DiagnosticSeverity } from 'vscode-languageserver-types';
|
|
2
|
+
export { DefaultHost, Host } from './hosts';
|
|
3
|
+
export { RWProject } from './model';
|
|
4
|
+
export { URL_file } from './x/URL';
|
|
5
|
+
import { DefaultHost } from './hosts';
|
|
6
|
+
import { RWProject } from './model';
|
|
7
|
+
import type { GetSeverityLabelFunction } from './x/vscode-languageserver-types';
|
|
8
|
+
export declare function getProject(projectRoot: string, host?: DefaultHost): RWProject;
|
|
9
|
+
export declare function printDiagnostics(projectRoot: string, opts?: {
|
|
10
|
+
getSeverityLabel?: GetSeverityLabelFunction;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAChE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAA;AAG/E,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,cAAoB,aAKvE;AAED,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE;IAAE,gBAAgB,CAAC,EAAE,wBAAwB,CAAA;CAAE,iBA8BvD"}
|