@domainlang/language 0.1.20 → 0.1.82
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/out/domain-lang-module.d.ts +0 -2
- package/out/domain-lang-module.js +3 -11
- package/out/domain-lang-module.js.map +1 -1
- package/out/generated/ast.d.ts +19 -8
- package/out/generated/ast.js +10 -1
- package/out/generated/ast.js.map +1 -1
- package/out/generated/grammar.d.ts +1 -1
- package/out/generated/grammar.js +123 -28
- package/out/generated/grammar.js.map +1 -1
- package/out/generated/module.d.ts +1 -1
- package/out/generated/module.js +1 -1
- package/out/index.d.ts +0 -3
- package/out/index.js +0 -5
- package/out/index.js.map +1 -1
- package/out/lsp/hover/domain-lang-hover.js +4 -0
- package/out/lsp/hover/domain-lang-hover.js.map +1 -1
- package/out/sdk/index.d.ts +1 -1
- package/out/sdk/loader-node.d.ts +3 -7
- package/out/sdk/loader-node.js +9 -24
- package/out/sdk/loader-node.js.map +1 -1
- package/out/sdk/types.d.ts +21 -0
- package/out/services/dependency-analyzer.d.ts +39 -3
- package/out/services/dependency-analyzer.js +47 -22
- package/out/services/dependency-analyzer.js.map +1 -1
- package/out/services/dependency-resolver.d.ts +45 -68
- package/out/services/dependency-resolver.js +43 -243
- package/out/services/dependency-resolver.js.map +1 -1
- package/out/services/git-url-resolver.browser.d.ts +12 -4
- package/out/services/git-url-resolver.browser.js +1 -5
- package/out/services/git-url-resolver.browser.js.map +1 -1
- package/out/services/git-url-resolver.d.ts +56 -22
- package/out/services/git-url-resolver.js +36 -70
- package/out/services/git-url-resolver.js.map +1 -1
- package/out/services/governance-validator.d.ts +37 -1
- package/out/services/governance-validator.js +10 -4
- package/out/services/governance-validator.js.map +1 -1
- package/out/services/import-resolver.d.ts +6 -65
- package/out/services/import-resolver.js +5 -223
- package/out/services/import-resolver.js.map +1 -1
- package/out/services/performance-optimizer.d.ts +1 -1
- package/out/services/workspace-manager.d.ts +10 -57
- package/out/services/workspace-manager.js +21 -187
- package/out/services/workspace-manager.js.map +1 -1
- package/out/syntaxes/domain-lang.monarch.js +1 -1
- package/out/syntaxes/domain-lang.monarch.js.map +1 -1
- package/out/utils/import-utils.d.ts +12 -4
- package/out/utils/import-utils.js +135 -35
- package/out/utils/import-utils.js.map +1 -1
- package/out/validation/constants.d.ts +0 -103
- package/out/validation/constants.js +1 -140
- package/out/validation/constants.js.map +1 -1
- package/out/validation/domain.js +1 -46
- package/out/validation/domain.js.map +1 -1
- package/out/validation/import.d.ts +22 -46
- package/out/validation/import.js +85 -187
- package/out/validation/import.js.map +1 -1
- package/out/validation/maps.js +6 -10
- package/out/validation/maps.js.map +1 -1
- package/out/validation/metadata.js +1 -5
- package/out/validation/metadata.js.map +1 -1
- package/package.json +6 -8
- package/src/domain-lang-module.ts +6 -18
- package/src/domain-lang.langium +12 -7
- package/src/generated/ast.ts +20 -7
- package/src/generated/grammar.ts +123 -28
- package/src/generated/module.ts +1 -1
- package/src/index.ts +0 -7
- package/src/lsp/hover/domain-lang-hover.ts +2 -0
- package/src/sdk/index.ts +2 -0
- package/src/sdk/loader-node.ts +9 -29
- package/src/sdk/types.ts +23 -0
- package/src/services/dependency-analyzer.ts +84 -24
- package/src/services/dependency-resolver.ts +84 -301
- package/src/services/git-url-resolver.browser.ts +14 -9
- package/src/services/git-url-resolver.ts +93 -86
- package/src/services/governance-validator.ts +47 -5
- package/src/services/import-resolver.ts +8 -270
- package/src/services/performance-optimizer.ts +1 -1
- package/src/services/workspace-manager.ts +46 -237
- package/src/syntaxes/domain-lang.monarch.ts +1 -1
- package/src/utils/import-utils.ts +160 -38
- package/src/validation/constants.ts +1 -181
- package/src/validation/domain.ts +1 -54
- package/src/validation/import.ts +104 -228
- package/src/validation/maps.ts +6 -10
- package/src/validation/metadata.ts +1 -5
- package/out/lsp/domain-lang-code-actions.d.ts +0 -55
- package/out/lsp/domain-lang-code-actions.js +0 -143
- package/out/lsp/domain-lang-code-actions.js.map +0 -1
- package/out/lsp/domain-lang-workspace-manager.d.ts +0 -21
- package/out/lsp/domain-lang-workspace-manager.js +0 -93
- package/out/lsp/domain-lang-workspace-manager.js.map +0 -1
- package/out/lsp/manifest-diagnostics.d.ts +0 -82
- package/out/lsp/manifest-diagnostics.js +0 -230
- package/out/lsp/manifest-diagnostics.js.map +0 -1
- package/out/services/semver.d.ts +0 -98
- package/out/services/semver.js +0 -195
- package/out/services/semver.js.map +0 -1
- package/out/services/types.d.ts +0 -340
- package/out/services/types.js +0 -46
- package/out/services/types.js.map +0 -1
- package/out/validation/manifest.d.ts +0 -144
- package/out/validation/manifest.js +0 -327
- package/out/validation/manifest.js.map +0 -1
- package/src/lsp/domain-lang-code-actions.ts +0 -189
- package/src/lsp/domain-lang-workspace-manager.ts +0 -104
- package/src/lsp/manifest-diagnostics.ts +0 -290
- package/src/services/semver.ts +0 -213
- package/src/services/types.ts +0 -415
- package/src/validation/manifest.ts +0 -439
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manifest Validation for DomainLang.
|
|
3
|
-
*
|
|
4
|
-
* Provides schema validation and issue detection for model.yaml files.
|
|
5
|
-
* This validation is triggered by the workspace manager when manifests are loaded.
|
|
6
|
-
*
|
|
7
|
-
* Validation includes:
|
|
8
|
-
* - Required fields for publishable packages
|
|
9
|
-
* - Dependency configuration correctness
|
|
10
|
-
* - Path alias validation
|
|
11
|
-
* - Version format validation
|
|
12
|
-
*
|
|
13
|
-
* @module
|
|
14
|
-
*/
|
|
15
|
-
import type { ModelManifest } from '../services/types.js';
|
|
16
|
-
/**
|
|
17
|
-
* Severity levels for manifest diagnostics.
|
|
18
|
-
*/
|
|
19
|
-
export type ManifestSeverity = 'error' | 'warning' | 'info';
|
|
20
|
-
/**
|
|
21
|
-
* A diagnostic issue found in model.yaml.
|
|
22
|
-
*/
|
|
23
|
-
export interface ManifestDiagnostic {
|
|
24
|
-
/** Issue code for code action mapping */
|
|
25
|
-
readonly code: string;
|
|
26
|
-
/** Error severity */
|
|
27
|
-
readonly severity: ManifestSeverity;
|
|
28
|
-
/** Human-readable message */
|
|
29
|
-
readonly message: string;
|
|
30
|
-
/** YAML path to the issue (e.g., "dependencies.core.version") */
|
|
31
|
-
readonly path: string;
|
|
32
|
-
/** Optional hint for resolution */
|
|
33
|
-
readonly hint?: string;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Result of manifest validation.
|
|
37
|
-
*/
|
|
38
|
-
export interface ManifestValidationResult {
|
|
39
|
-
/** Whether the manifest is valid (no errors) */
|
|
40
|
-
readonly valid: boolean;
|
|
41
|
-
/** All diagnostics found */
|
|
42
|
-
readonly diagnostics: ManifestDiagnostic[];
|
|
43
|
-
/** Count of errors only */
|
|
44
|
-
readonly errorCount: number;
|
|
45
|
-
/** Count of warnings only */
|
|
46
|
-
readonly warningCount: number;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Issue codes specific to manifest validation.
|
|
50
|
-
* These extend the general IssueCodes for manifest-specific issues.
|
|
51
|
-
*/
|
|
52
|
-
export declare const ManifestIssueCodes: {
|
|
53
|
-
readonly ModelMissingName: "manifest-model-missing-name";
|
|
54
|
-
readonly ModelMissingVersion: "manifest-model-missing-version";
|
|
55
|
-
readonly ModelInvalidVersion: "manifest-model-invalid-version";
|
|
56
|
-
readonly DependencyMissingRef: "manifest-dependency-missing-ref";
|
|
57
|
-
readonly DependencyInvalidRef: "manifest-dependency-invalid-ref";
|
|
58
|
-
readonly DependencyConflictingSourcePath: "manifest-dependency-conflicting-source-path";
|
|
59
|
-
readonly DependencyMissingSourceOrPath: "manifest-dependency-missing-source-or-path";
|
|
60
|
-
readonly DependencyInvalidSource: "manifest-dependency-invalid-source";
|
|
61
|
-
readonly DependencyAbsolutePath: "manifest-dependency-absolute-path";
|
|
62
|
-
readonly PathAliasMissingAtPrefix: "manifest-path-alias-missing-at-prefix";
|
|
63
|
-
readonly PathAliasAbsolutePath: "manifest-path-alias-absolute-path";
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Validates model.yaml manifests and reports issues.
|
|
67
|
-
*
|
|
68
|
-
* Usage:
|
|
69
|
-
* ```typescript
|
|
70
|
-
* const validator = new ManifestValidator();
|
|
71
|
-
* const result = validator.validate(manifest);
|
|
72
|
-
* if (!result.valid) {
|
|
73
|
-
* console.log(result.diagnostics);
|
|
74
|
-
* }
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
export declare class ManifestValidator {
|
|
78
|
-
/**
|
|
79
|
-
* Validates a parsed model.yaml manifest.
|
|
80
|
-
*
|
|
81
|
-
* @param manifest - The parsed manifest object
|
|
82
|
-
* @param options - Optional validation options
|
|
83
|
-
* @returns Validation result with diagnostics
|
|
84
|
-
*/
|
|
85
|
-
validate(manifest: ModelManifest, options?: {
|
|
86
|
-
requirePublishable?: boolean;
|
|
87
|
-
}): ManifestValidationResult;
|
|
88
|
-
/**
|
|
89
|
-
* Validates the model section of the manifest.
|
|
90
|
-
*/
|
|
91
|
-
private validateModelSection;
|
|
92
|
-
/**
|
|
93
|
-
* Validates the dependencies section of the manifest.
|
|
94
|
-
*/
|
|
95
|
-
private validateDependenciesSection;
|
|
96
|
-
/**
|
|
97
|
-
* Validates a single dependency entry.
|
|
98
|
-
*/
|
|
99
|
-
private validateDependency;
|
|
100
|
-
/**
|
|
101
|
-
* Validates a git-source based dependency.
|
|
102
|
-
*/
|
|
103
|
-
private validateSourceDependency;
|
|
104
|
-
/**
|
|
105
|
-
* Validates a path-based local dependency.
|
|
106
|
-
*/
|
|
107
|
-
private validatePathDependency;
|
|
108
|
-
/**
|
|
109
|
-
* Validates the paths section of the manifest.
|
|
110
|
-
*/
|
|
111
|
-
private validatePathsSection;
|
|
112
|
-
/**
|
|
113
|
-
* Normalizes a dependency to extended form.
|
|
114
|
-
*/
|
|
115
|
-
private normalizeDependency;
|
|
116
|
-
/**
|
|
117
|
-
* Checks if a version string is valid SemVer.
|
|
118
|
-
*/
|
|
119
|
-
private isValidSemVer;
|
|
120
|
-
/**
|
|
121
|
-
* Checks if a ref spec is valid (tag, branch, or commit SHA).
|
|
122
|
-
*/
|
|
123
|
-
private isValidRefSpec;
|
|
124
|
-
/**
|
|
125
|
-
* Checks if source is valid owner/repo format.
|
|
126
|
-
*/
|
|
127
|
-
private isValidSourceFormat;
|
|
128
|
-
/**
|
|
129
|
-
* Checks if a path is absolute.
|
|
130
|
-
*/
|
|
131
|
-
private isAbsolutePath;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Validates a manifest and returns true if valid, false otherwise.
|
|
135
|
-
* Use this for simple pass/fail checks.
|
|
136
|
-
*/
|
|
137
|
-
export declare function isManifestValid(manifest: ModelManifest): boolean;
|
|
138
|
-
/**
|
|
139
|
-
* Validates a manifest and returns all diagnostics.
|
|
140
|
-
* Use this to display validation errors to users.
|
|
141
|
-
*/
|
|
142
|
-
export declare function validateManifest(manifest: ModelManifest, options?: {
|
|
143
|
-
requirePublishable?: boolean;
|
|
144
|
-
}): ManifestDiagnostic[];
|
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manifest Validation for DomainLang.
|
|
3
|
-
*
|
|
4
|
-
* Provides schema validation and issue detection for model.yaml files.
|
|
5
|
-
* This validation is triggered by the workspace manager when manifests are loaded.
|
|
6
|
-
*
|
|
7
|
-
* Validation includes:
|
|
8
|
-
* - Required fields for publishable packages
|
|
9
|
-
* - Dependency configuration correctness
|
|
10
|
-
* - Path alias validation
|
|
11
|
-
* - Version format validation
|
|
12
|
-
*
|
|
13
|
-
* @module
|
|
14
|
-
*/
|
|
15
|
-
import { IssueCodes } from './constants.js';
|
|
16
|
-
// ============================================================================
|
|
17
|
-
// Issue Code Mapping for Manifest Validation
|
|
18
|
-
// ============================================================================
|
|
19
|
-
/**
|
|
20
|
-
* Issue codes specific to manifest validation.
|
|
21
|
-
* These extend the general IssueCodes for manifest-specific issues.
|
|
22
|
-
*/
|
|
23
|
-
export const ManifestIssueCodes = {
|
|
24
|
-
// Model section issues
|
|
25
|
-
ModelMissingName: 'manifest-model-missing-name',
|
|
26
|
-
ModelMissingVersion: 'manifest-model-missing-version',
|
|
27
|
-
ModelInvalidVersion: 'manifest-model-invalid-version',
|
|
28
|
-
// Dependency section issues
|
|
29
|
-
DependencyMissingRef: 'manifest-dependency-missing-ref',
|
|
30
|
-
DependencyInvalidRef: 'manifest-dependency-invalid-ref',
|
|
31
|
-
DependencyConflictingSourcePath: 'manifest-dependency-conflicting-source-path',
|
|
32
|
-
DependencyMissingSourceOrPath: 'manifest-dependency-missing-source-or-path',
|
|
33
|
-
DependencyInvalidSource: 'manifest-dependency-invalid-source',
|
|
34
|
-
DependencyAbsolutePath: 'manifest-dependency-absolute-path',
|
|
35
|
-
// Path alias issues
|
|
36
|
-
PathAliasMissingAtPrefix: 'manifest-path-alias-missing-at-prefix',
|
|
37
|
-
PathAliasAbsolutePath: 'manifest-path-alias-absolute-path'
|
|
38
|
-
};
|
|
39
|
-
// ============================================================================
|
|
40
|
-
// Manifest Validator
|
|
41
|
-
// ============================================================================
|
|
42
|
-
/**
|
|
43
|
-
* Validates model.yaml manifests and reports issues.
|
|
44
|
-
*
|
|
45
|
-
* Usage:
|
|
46
|
-
* ```typescript
|
|
47
|
-
* const validator = new ManifestValidator();
|
|
48
|
-
* const result = validator.validate(manifest);
|
|
49
|
-
* if (!result.valid) {
|
|
50
|
-
* console.log(result.diagnostics);
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export class ManifestValidator {
|
|
55
|
-
/**
|
|
56
|
-
* Validates a parsed model.yaml manifest.
|
|
57
|
-
*
|
|
58
|
-
* @param manifest - The parsed manifest object
|
|
59
|
-
* @param options - Optional validation options
|
|
60
|
-
* @returns Validation result with diagnostics
|
|
61
|
-
*/
|
|
62
|
-
validate(manifest, options = {}) {
|
|
63
|
-
const diagnostics = [];
|
|
64
|
-
// Validate model section
|
|
65
|
-
this.validateModelSection(manifest, diagnostics, options.requirePublishable ?? false);
|
|
66
|
-
// Validate dependencies section
|
|
67
|
-
this.validateDependenciesSection(manifest, diagnostics);
|
|
68
|
-
// Validate paths section
|
|
69
|
-
this.validatePathsSection(manifest, diagnostics);
|
|
70
|
-
// Calculate counts
|
|
71
|
-
const errorCount = diagnostics.filter(d => d.severity === 'error').length;
|
|
72
|
-
const warningCount = diagnostics.filter(d => d.severity === 'warning').length;
|
|
73
|
-
return {
|
|
74
|
-
valid: errorCount === 0,
|
|
75
|
-
diagnostics,
|
|
76
|
-
errorCount,
|
|
77
|
-
warningCount
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Validates the model section of the manifest.
|
|
82
|
-
*/
|
|
83
|
-
validateModelSection(manifest, diagnostics, requirePublishable) {
|
|
84
|
-
const model = manifest.model;
|
|
85
|
-
// If no model section and not requiring publishable, that's OK
|
|
86
|
-
if (!model && !requirePublishable) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
// If requiring publishable package, name and version are required
|
|
90
|
-
if (requirePublishable) {
|
|
91
|
-
if (!model?.name) {
|
|
92
|
-
diagnostics.push({
|
|
93
|
-
code: ManifestIssueCodes.ModelMissingName,
|
|
94
|
-
severity: 'error',
|
|
95
|
-
message: 'Publishable packages require a model.name field.',
|
|
96
|
-
path: 'model.name',
|
|
97
|
-
hint: 'Add "name: my-package" under the model section.'
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
if (!model?.version) {
|
|
101
|
-
diagnostics.push({
|
|
102
|
-
code: ManifestIssueCodes.ModelMissingVersion,
|
|
103
|
-
severity: 'error',
|
|
104
|
-
message: 'Publishable packages require a model.version field.',
|
|
105
|
-
path: 'model.version',
|
|
106
|
-
hint: 'Add "version: 1.0.0" under the model section.'
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// Validate version format if present
|
|
111
|
-
if (model?.version && !this.isValidSemVer(model.version)) {
|
|
112
|
-
diagnostics.push({
|
|
113
|
-
code: ManifestIssueCodes.ModelInvalidVersion,
|
|
114
|
-
severity: 'warning',
|
|
115
|
-
message: `Version '${model.version}' is not valid SemVer format.`,
|
|
116
|
-
path: 'model.version',
|
|
117
|
-
hint: 'Use SemVer format like "1.0.0" or "1.2.3-beta".'
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Validates the dependencies section of the manifest.
|
|
123
|
-
*/
|
|
124
|
-
validateDependenciesSection(manifest, diagnostics) {
|
|
125
|
-
const dependencies = manifest.dependencies;
|
|
126
|
-
if (!dependencies) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
for (const [key, dep] of Object.entries(dependencies)) {
|
|
130
|
-
this.validateDependency(key, dep, diagnostics);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Validates a single dependency entry.
|
|
135
|
-
*/
|
|
136
|
-
validateDependency(key, dep, diagnostics) {
|
|
137
|
-
const normalized = this.normalizeDependency(key, dep);
|
|
138
|
-
const basePath = `dependencies.${key}`;
|
|
139
|
-
// Check for conflicting source and path
|
|
140
|
-
if (normalized.source && normalized.path) {
|
|
141
|
-
diagnostics.push({
|
|
142
|
-
code: IssueCodes.ImportConflictingSourcePath,
|
|
143
|
-
severity: 'error',
|
|
144
|
-
message: `Dependency '${key}' cannot have both 'source' and 'path'.`,
|
|
145
|
-
path: basePath,
|
|
146
|
-
hint: `Use 'source' for git packages or 'path' for local workspace packages.`
|
|
147
|
-
});
|
|
148
|
-
return; // Don't validate further if this fundamental issue exists
|
|
149
|
-
}
|
|
150
|
-
// Check that at least one of source or path is present
|
|
151
|
-
if (!normalized.source && !normalized.path) {
|
|
152
|
-
diagnostics.push({
|
|
153
|
-
code: IssueCodes.ImportMissingSourceOrPath,
|
|
154
|
-
severity: 'error',
|
|
155
|
-
message: `Dependency '${key}' must have either 'source' or 'path'.`,
|
|
156
|
-
path: basePath,
|
|
157
|
-
hint: `Add 'source: owner/repo' for git packages or 'path: ./local' for local packages.`
|
|
158
|
-
});
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
// Validate source-based dependencies
|
|
162
|
-
if (normalized.source) {
|
|
163
|
-
this.validateSourceDependency(key, normalized, basePath, diagnostics);
|
|
164
|
-
}
|
|
165
|
-
// Validate path-based dependencies
|
|
166
|
-
if (normalized.path) {
|
|
167
|
-
this.validatePathDependency(key, normalized, basePath, diagnostics);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Validates a git-source based dependency.
|
|
172
|
-
*/
|
|
173
|
-
validateSourceDependency(key, dep, basePath, diagnostics) {
|
|
174
|
-
// Source dependencies require a ref (tag, branch, or commit)
|
|
175
|
-
if (!dep.ref) {
|
|
176
|
-
diagnostics.push({
|
|
177
|
-
code: IssueCodes.ImportMissingRef,
|
|
178
|
-
severity: 'error',
|
|
179
|
-
message: `Git dependency '${key}' requires a ref.`,
|
|
180
|
-
path: `${basePath}.ref`,
|
|
181
|
-
hint: `Add a git ref: 'ref: v1.0.0' (tag), 'ref: main' (branch), or a commit SHA.`
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
// Validate ref format
|
|
185
|
-
if (dep.ref && !this.isValidRefSpec(dep.ref)) {
|
|
186
|
-
diagnostics.push({
|
|
187
|
-
code: ManifestIssueCodes.DependencyInvalidRef,
|
|
188
|
-
severity: 'warning',
|
|
189
|
-
message: `Ref '${dep.ref}' for '${key}' may be invalid.`,
|
|
190
|
-
path: `${basePath}.ref`,
|
|
191
|
-
hint: `Use a tag (v1.0.0), branch name (main), or commit SHA.`
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
// Validate source format (should be owner/repo)
|
|
195
|
-
if (dep.source && !this.isValidSourceFormat(dep.source)) {
|
|
196
|
-
diagnostics.push({
|
|
197
|
-
code: ManifestIssueCodes.DependencyInvalidSource,
|
|
198
|
-
severity: 'error',
|
|
199
|
-
message: `Source '${dep.source}' is not valid owner/repo format.`,
|
|
200
|
-
path: `${basePath}.source`,
|
|
201
|
-
hint: `Use format 'owner/repo' like 'domainlang/core'.`
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Validates a path-based local dependency.
|
|
207
|
-
*/
|
|
208
|
-
validatePathDependency(key, dep, basePath, diagnostics) {
|
|
209
|
-
// Path dependencies should use relative paths
|
|
210
|
-
if (dep.path && this.isAbsolutePath(dep.path)) {
|
|
211
|
-
diagnostics.push({
|
|
212
|
-
code: IssueCodes.ImportAbsolutePath,
|
|
213
|
-
severity: 'error',
|
|
214
|
-
message: `Local path '${dep.path}' for '${key}' must be relative.`,
|
|
215
|
-
path: `${basePath}.path`,
|
|
216
|
-
hint: `Use a relative path like './packages/shared'.`
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Validates the paths section of the manifest.
|
|
222
|
-
*/
|
|
223
|
-
validatePathsSection(manifest, diagnostics) {
|
|
224
|
-
const paths = manifest.paths;
|
|
225
|
-
if (!paths) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
for (const [alias, targetPath] of Object.entries(paths)) {
|
|
229
|
-
// Path aliases should start with @
|
|
230
|
-
if (!alias.startsWith('@')) {
|
|
231
|
-
diagnostics.push({
|
|
232
|
-
code: ManifestIssueCodes.PathAliasMissingAtPrefix,
|
|
233
|
-
severity: 'warning',
|
|
234
|
-
message: `Path alias '${alias}' should start with '@'.`,
|
|
235
|
-
path: `paths.${alias}`,
|
|
236
|
-
hint: `Rename to '@${alias}' for consistency.`
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
// Target paths should be relative
|
|
240
|
-
if (this.isAbsolutePath(targetPath)) {
|
|
241
|
-
diagnostics.push({
|
|
242
|
-
code: ManifestIssueCodes.PathAliasAbsolutePath,
|
|
243
|
-
severity: 'error',
|
|
244
|
-
message: `Path alias '${alias}' cannot map to absolute path '${targetPath}'.`,
|
|
245
|
-
path: `paths.${alias}`,
|
|
246
|
-
hint: `Use a relative path like './src' or '.'`
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
// ========================================================================
|
|
252
|
-
// Helpers
|
|
253
|
-
// ========================================================================
|
|
254
|
-
/**
|
|
255
|
-
* Normalizes a dependency to extended form.
|
|
256
|
-
*/
|
|
257
|
-
normalizeDependency(key, dep) {
|
|
258
|
-
if (typeof dep === 'string') {
|
|
259
|
-
return { source: key, ref: dep };
|
|
260
|
-
}
|
|
261
|
-
if (dep.source || dep.path) {
|
|
262
|
-
return dep;
|
|
263
|
-
}
|
|
264
|
-
return { ...dep, source: key };
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Checks if a version string is valid SemVer.
|
|
268
|
-
*/
|
|
269
|
-
isValidSemVer(version) {
|
|
270
|
-
const semverRegex = /^\d+\.\d+\.\d+(-[\w.]+)?(\+[\w.]+)?$/;
|
|
271
|
-
return semverRegex.test(version);
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Checks if a ref spec is valid (tag, branch, or commit SHA).
|
|
275
|
-
*/
|
|
276
|
-
isValidRefSpec(ref) {
|
|
277
|
-
// SemVer with optional v prefix (tags)
|
|
278
|
-
if (/^v?\d+\.\d+\.\d+/.test(ref)) {
|
|
279
|
-
return true;
|
|
280
|
-
}
|
|
281
|
-
// Branch names (simple word chars)
|
|
282
|
-
if (/^[\w][\w.-]*$/.test(ref)) {
|
|
283
|
-
return true;
|
|
284
|
-
}
|
|
285
|
-
// Commit SHAs (40 hex chars)
|
|
286
|
-
if (/^[0-9a-f]{40}$/i.test(ref)) {
|
|
287
|
-
return true;
|
|
288
|
-
}
|
|
289
|
-
// Short commit SHAs (7+ hex chars)
|
|
290
|
-
if (/^[0-9a-f]{7,}$/i.test(ref)) {
|
|
291
|
-
return true;
|
|
292
|
-
}
|
|
293
|
-
return false;
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Checks if source is valid owner/repo format.
|
|
297
|
-
*/
|
|
298
|
-
isValidSourceFormat(source) {
|
|
299
|
-
return /^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(source);
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Checks if a path is absolute.
|
|
303
|
-
*/
|
|
304
|
-
isAbsolutePath(p) {
|
|
305
|
-
return p.startsWith('/') || /^[A-Za-z]:/.test(p);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
// ============================================================================
|
|
309
|
-
// Convenience Functions
|
|
310
|
-
// ============================================================================
|
|
311
|
-
/**
|
|
312
|
-
* Validates a manifest and returns true if valid, false otherwise.
|
|
313
|
-
* Use this for simple pass/fail checks.
|
|
314
|
-
*/
|
|
315
|
-
export function isManifestValid(manifest) {
|
|
316
|
-
const validator = new ManifestValidator();
|
|
317
|
-
return validator.validate(manifest).valid;
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Validates a manifest and returns all diagnostics.
|
|
321
|
-
* Use this to display validation errors to users.
|
|
322
|
-
*/
|
|
323
|
-
export function validateManifest(manifest, options) {
|
|
324
|
-
const validator = new ManifestValidator();
|
|
325
|
-
return validator.validate(manifest, options).diagnostics;
|
|
326
|
-
}
|
|
327
|
-
//# sourceMappingURL=manifest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/validation/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAyC5C,+EAA+E;AAC/E,6CAA6C;AAC7C,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAC9B,uBAAuB;IACvB,gBAAgB,EAAE,6BAA6B;IAC/C,mBAAmB,EAAE,gCAAgC;IACrD,mBAAmB,EAAE,gCAAgC;I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K,mBAAmB,CAAC,MAAc;QACtC,OAAO,oCAAoC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7D,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,CAAS;QAC5B,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC;CACJ;AAED,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,QAAuB;IACnD,MAAM,SAAS,GAAG,IAAI,iBAAiB,EAAE,CAAC;IAC1C,OAAO,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;AAC9C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC5B,QAAuB,EACvB,OAA0C;IAE1C,MAAM,SAAS,GAAG,IAAI,iBAAiB,EAAE,CAAC;IAC1C,OAAO,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,WAAW,CAAC;AAC7D,CAAC"}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Code Action Provider for DomainLang.
|
|
3
|
-
*
|
|
4
|
-
* Provides quick-fix code actions for validation diagnostics.
|
|
5
|
-
*
|
|
6
|
-
* Key Features:
|
|
7
|
-
* - "Add dependency to model.yaml" for unknown import aliases
|
|
8
|
-
* - "Run dlang install" for uninstalled dependencies
|
|
9
|
-
*
|
|
10
|
-
* @module
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import type { CodeAction, CodeActionParams, Command, Diagnostic } from 'vscode-languageserver';
|
|
14
|
-
import { CodeActionKind } from 'vscode-languageserver';
|
|
15
|
-
import type { MaybePromise, LangiumDocument } from 'langium';
|
|
16
|
-
import type { CodeActionProvider } from 'langium/lsp';
|
|
17
|
-
import { IssueCodes } from '../validation/constants.js';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Shape of diagnostic data used for code action matching.
|
|
21
|
-
* Must match the data structure used in validators.
|
|
22
|
-
*/
|
|
23
|
-
interface ImportDiagnosticData {
|
|
24
|
-
code: string;
|
|
25
|
-
alias?: string;
|
|
26
|
-
specifier?: string;
|
|
27
|
-
path?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Code action provider for DomainLang LSP features.
|
|
32
|
-
*
|
|
33
|
-
* Implements quick fixes for:
|
|
34
|
-
* - Import validation errors (add to model.yaml, run install)
|
|
35
|
-
*/
|
|
36
|
-
export class DomainLangCodeActionProvider implements CodeActionProvider {
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Generates code actions for the given diagnostics.
|
|
40
|
-
*
|
|
41
|
-
* @param document - The document containing the diagnostics
|
|
42
|
-
* @param params - Code action request parameters including diagnostics
|
|
43
|
-
* @returns Array of code actions, or undefined if none applicable
|
|
44
|
-
*/
|
|
45
|
-
getCodeActions(
|
|
46
|
-
document: LangiumDocument,
|
|
47
|
-
params: CodeActionParams
|
|
48
|
-
): MaybePromise<Array<Command | CodeAction> | undefined> {
|
|
49
|
-
const result: CodeAction[] = [];
|
|
50
|
-
const acceptor = (ca: CodeAction | undefined): void => {
|
|
51
|
-
if (ca) result.push(ca);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
for (const diagnostic of params.context.diagnostics) {
|
|
55
|
-
this.createCodeActions(diagnostic, document, acceptor);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return result.length > 0 ? result : undefined;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Creates code actions for a specific diagnostic.
|
|
63
|
-
*
|
|
64
|
-
* Matches on diagnostic.data.code to determine which quick fix to offer.
|
|
65
|
-
*/
|
|
66
|
-
private createCodeActions(
|
|
67
|
-
diagnostic: Diagnostic,
|
|
68
|
-
document: LangiumDocument,
|
|
69
|
-
accept: (ca: CodeAction | undefined) => void
|
|
70
|
-
): void {
|
|
71
|
-
const data = diagnostic.data as ImportDiagnosticData | undefined;
|
|
72
|
-
if (!data?.code) return;
|
|
73
|
-
|
|
74
|
-
switch (data.code) {
|
|
75
|
-
case IssueCodes.ImportNotInManifest:
|
|
76
|
-
if (data.alias) {
|
|
77
|
-
accept(this.createAddToManifestAction(diagnostic, document, data.alias));
|
|
78
|
-
}
|
|
79
|
-
break;
|
|
80
|
-
|
|
81
|
-
case IssueCodes.ImportRequiresManifest:
|
|
82
|
-
if (data.specifier) {
|
|
83
|
-
accept(this.createCreateManifestAction(diagnostic, document, data.specifier));
|
|
84
|
-
}
|
|
85
|
-
break;
|
|
86
|
-
|
|
87
|
-
case IssueCodes.ImportNotInstalled:
|
|
88
|
-
if (data.alias) {
|
|
89
|
-
accept(this.createRunInstallAction(diagnostic, data.alias));
|
|
90
|
-
}
|
|
91
|
-
break;
|
|
92
|
-
|
|
93
|
-
case IssueCodes.ImportMissingRef:
|
|
94
|
-
if (data.alias) {
|
|
95
|
-
accept(this.createAddRefAction(diagnostic, data.alias));
|
|
96
|
-
}
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Creates a code action to add a dependency to model.yaml.
|
|
103
|
-
*
|
|
104
|
-
* This generates a WorkspaceEdit that modifies model.yaml to add
|
|
105
|
-
* the missing dependency with a placeholder version.
|
|
106
|
-
*/
|
|
107
|
-
private createAddToManifestAction(
|
|
108
|
-
diagnostic: Diagnostic,
|
|
109
|
-
_document: LangiumDocument,
|
|
110
|
-
alias: string
|
|
111
|
-
): CodeAction {
|
|
112
|
-
// Create a command that will be executed to add the dependency
|
|
113
|
-
// Since we can't directly edit model.yaml from here (it's not the current document),
|
|
114
|
-
// we provide a command that the extension can handle
|
|
115
|
-
return {
|
|
116
|
-
title: `Add '${alias}' to model.yaml`,
|
|
117
|
-
kind: CodeActionKind.QuickFix,
|
|
118
|
-
diagnostics: [diagnostic],
|
|
119
|
-
isPreferred: true,
|
|
120
|
-
command: {
|
|
121
|
-
title: `Add '${alias}' to model.yaml`,
|
|
122
|
-
command: 'domainlang.addDependency',
|
|
123
|
-
arguments: [alias]
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Creates a code action to create model.yaml with the dependency.
|
|
130
|
-
*/
|
|
131
|
-
private createCreateManifestAction(
|
|
132
|
-
diagnostic: Diagnostic,
|
|
133
|
-
_document: LangiumDocument,
|
|
134
|
-
specifier: string
|
|
135
|
-
): CodeAction {
|
|
136
|
-
const alias = specifier.split('/')[0];
|
|
137
|
-
return {
|
|
138
|
-
title: `Create model.yaml with '${alias}' dependency`,
|
|
139
|
-
kind: CodeActionKind.QuickFix,
|
|
140
|
-
diagnostics: [diagnostic],
|
|
141
|
-
isPreferred: true,
|
|
142
|
-
command: {
|
|
143
|
-
title: `Create model.yaml`,
|
|
144
|
-
command: 'domainlang.createManifest',
|
|
145
|
-
arguments: [alias, specifier]
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Creates a code action to run dlang install.
|
|
152
|
-
*/
|
|
153
|
-
private createRunInstallAction(
|
|
154
|
-
diagnostic: Diagnostic,
|
|
155
|
-
alias: string
|
|
156
|
-
): CodeAction {
|
|
157
|
-
return {
|
|
158
|
-
title: `Run 'dlang install' to fetch '${alias}'`,
|
|
159
|
-
kind: CodeActionKind.QuickFix,
|
|
160
|
-
diagnostics: [diagnostic],
|
|
161
|
-
isPreferred: true,
|
|
162
|
-
command: {
|
|
163
|
-
title: 'Install dependencies',
|
|
164
|
-
command: 'domainlang.install',
|
|
165
|
-
arguments: []
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Creates a code action to add ref to dependency.
|
|
172
|
-
*/
|
|
173
|
-
private createAddRefAction(
|
|
174
|
-
diagnostic: Diagnostic,
|
|
175
|
-
alias: string
|
|
176
|
-
): CodeAction {
|
|
177
|
-
return {
|
|
178
|
-
title: `Add git ref to '${alias}' in model.yaml`,
|
|
179
|
-
kind: CodeActionKind.QuickFix,
|
|
180
|
-
diagnostics: [diagnostic],
|
|
181
|
-
isPreferred: false,
|
|
182
|
-
command: {
|
|
183
|
-
title: 'Add ref',
|
|
184
|
-
command: 'domainlang.addRef',
|
|
185
|
-
arguments: [alias]
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
}
|