-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: visibility modifiers for any module member (#1104)
Closes #1083 ### Summary of Changes All module members can now have a visibility. This is useful if, say, a class is only used internally for typing. Pipelines must always be private, which is also the default if no visibility modifier is provided. They can never be referenced anyway, not even in the same file. --------- Co-authored-by: megalinter-bot <[email protected]>
- Loading branch information
1 parent
3f1ab6f
commit 3d43d38
Showing
191 changed files
with
2,469 additions
and
583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/safe-ds-lang/src/language/validation/other/declarations/moduleMembers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { SafeDsServices } from '../../../safe-ds-module.js'; | ||
import { isSdsPipeline, SdsModuleMember } from '../../../generated/ast.js'; | ||
import { ValidationAcceptor } from 'langium'; | ||
import { DiagnosticTag } from 'vscode-languageserver'; | ||
|
||
export const CODE_MODULE_MEMBER_UNUSED = 'module-member/unused'; | ||
|
||
export const moduleMemberShouldBeUsed = (services: SafeDsServices) => { | ||
const referenceProvider = services.references.References; | ||
|
||
return (node: SdsModuleMember, accept: ValidationAcceptor) => { | ||
// Don't show this warning for pipelines or public declarations | ||
if (isSdsPipeline(node) || node.visibility === undefined) { | ||
return; | ||
} | ||
|
||
const references = referenceProvider.findReferences(node, {}); | ||
if (references.isEmpty()) { | ||
accept('warning', 'This declaration is unused and can be removed.', { | ||
node, | ||
property: 'name', | ||
code: CODE_MODULE_MEMBER_UNUSED, | ||
tags: [DiagnosticTag.Unnecessary], | ||
}); | ||
} | ||
}; | ||
}; |
21 changes: 21 additions & 0 deletions
21
packages/safe-ds-lang/src/language/validation/other/declarations/pipelines.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ValidationAcceptor } from 'langium'; | ||
import { SdsPipeline } from '../../../generated/ast.js'; | ||
import { isInternal, isPrivate } from '../../../helpers/nodeProperties.js'; | ||
|
||
export const CODE_PIPELINE_VISIBILITY = 'pipeline/visibility'; | ||
|
||
export const pipelinesMustBePrivate = (node: SdsPipeline, accept: ValidationAcceptor) => { | ||
if (isInternal(node)) { | ||
accept('error', 'Pipelines are always private and cannot be declared as internal.', { | ||
node, | ||
property: 'visibility', | ||
code: CODE_PIPELINE_VISIBILITY, | ||
}); | ||
} else if (isPrivate(node)) { | ||
accept('info', 'Pipelines are always private and need no explicit visibility modifier.', { | ||
node, | ||
property: 'visibility', | ||
code: CODE_PIPELINE_VISIBILITY, | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.