1
1
import { AstNodeDescription , getDocument , ValidationAcceptor } from 'langium' ;
2
2
import { duplicatesBy } from '../../helpers/collectionUtils.js' ;
3
3
import { listBuiltinFiles } from '../builtins/fileFinder.js' ;
4
- import { BUILTINS_ROOT_PACKAGE } from '../builtins/packageNames.js' ;
4
+ import { BUILTINS_LANG_PACKAGE , BUILTINS_ROOT_PACKAGE } from '../builtins/packageNames.js' ;
5
5
import {
6
6
isSdsQualifiedImport ,
7
7
SdsAnnotation ,
@@ -46,6 +46,7 @@ import { SafeDsServices } from '../safe-ds-module.js';
46
46
import { declarationIsAllowedInPipelineFile , declarationIsAllowedInStubFile } from './other/modules.js' ;
47
47
48
48
export const CODE_NAME_CODEGEN_PREFIX = 'name/codegen-prefix' ;
49
+ export const CODE_NAME_CORE_DECLARATION = 'name/core-declaration' ;
49
50
export const CODE_NAME_CASING = 'name/casing' ;
50
51
export const CODE_NAME_DUPLICATE = 'name/duplicate' ;
51
52
@@ -68,6 +69,36 @@ export const nameMustNotStartWithCodegenPrefix = (node: SdsDeclaration, accept:
68
69
}
69
70
} ;
70
71
72
+ // -----------------------------------------------------------------------------
73
+ // Core declaration
74
+ // -----------------------------------------------------------------------------
75
+
76
+ export const nameMustNotOccurOnCoreDeclaration = ( services : SafeDsServices ) => {
77
+ const packageManager = services . workspace . PackageManager ;
78
+
79
+ return ( node : SdsDeclaration , accept : ValidationAcceptor ) => {
80
+ if ( ! node . name ) {
81
+ /* c8 ignore next 2 */
82
+ return ;
83
+ }
84
+
85
+ // Prevents the error from showing when editing the builtin files
86
+ const packageName = getPackageName ( node ) ;
87
+ if ( packageName === BUILTINS_LANG_PACKAGE ) {
88
+ return ;
89
+ }
90
+
91
+ const coreDeclarations = packageManager . getDeclarationsInPackage ( BUILTINS_LANG_PACKAGE ) ;
92
+ if ( coreDeclarations . some ( ( it ) => it . name === node . name ) ) {
93
+ accept ( 'error' , 'Names of core declarations must not be used for own declarations.' , {
94
+ node,
95
+ property : 'name' ,
96
+ code : CODE_NAME_CORE_DECLARATION ,
97
+ } ) ;
98
+ }
99
+ } ;
100
+ } ;
101
+
71
102
// -----------------------------------------------------------------------------
72
103
// Casing
73
104
// -----------------------------------------------------------------------------
0 commit comments