-
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: warn if deprecated/experimental declarations are used (#608)
Closes partially #543 Closes partially #540 ### Summary of Changes Show a warning if deprecated or experimental declarations are used. To implement this, I've also added scoping for member accesses to results. --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
- Loading branch information
1 parent
d53bda3
commit 9b5287c
Showing
38 changed files
with
1,148 additions
and
408 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { resolveRelativePathToBuiltinFile } from './fileFinder.js'; | ||
import { isSdsAnnotation, SdsAnnotatedObject, SdsAnnotation } from '../generated/ast.js'; | ||
import { annotationCallsOrEmpty } from '../helpers/nodeProperties.js'; | ||
import { SafeDsModuleMembers } from './safe-ds-module-members.js'; | ||
|
||
const CORE_ANNOTATIONS_URI = resolveRelativePathToBuiltinFile('safeds/lang/coreAnnotations.sdsstub'); | ||
|
||
export class SafeDsAnnotations extends SafeDsModuleMembers<SdsAnnotation> { | ||
isDeprecated(node: SdsAnnotatedObject | undefined): boolean { | ||
return annotationCallsOrEmpty(node).some((it) => { | ||
const annotation = it.annotation?.ref; | ||
return annotation === this.Deprecated; | ||
}); | ||
} | ||
|
||
isExperimental(node: SdsAnnotatedObject | undefined): boolean { | ||
return annotationCallsOrEmpty(node).some((it) => { | ||
const annotation = it.annotation?.ref; | ||
return annotation === this.Experimental; | ||
}); | ||
} | ||
|
||
private get Deprecated(): SdsAnnotation | undefined { | ||
return this.getAnnotation('Deprecated'); | ||
} | ||
|
||
private get Experimental(): SdsAnnotation | undefined { | ||
return this.getAnnotation('Experimental'); | ||
} | ||
|
||
private getAnnotation(name: string): SdsAnnotation | undefined { | ||
return this.getModuleMember(CORE_ANNOTATIONS_URI, name, isSdsAnnotation); | ||
} | ||
} |
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,38 @@ | ||
import { resolveRelativePathToBuiltinFile } from './fileFinder.js'; | ||
import { isSdsClass, SdsClass } from '../generated/ast.js'; | ||
import { SafeDsModuleMembers } from './safe-ds-module-members.js'; | ||
|
||
const CORE_CLASSES_URI = resolveRelativePathToBuiltinFile('safeds/lang/coreClasses.sdsstub'); | ||
|
||
export class SafeDsClasses extends SafeDsModuleMembers<SdsClass> { | ||
/* c8 ignore start */ | ||
get Any(): SdsClass | undefined { | ||
return this.getClass('Any'); | ||
} | ||
|
||
/* c8 ignore stop */ | ||
|
||
get Boolean(): SdsClass | undefined { | ||
return this.getClass('Boolean'); | ||
} | ||
|
||
get Float(): SdsClass | undefined { | ||
return this.getClass('Float'); | ||
} | ||
|
||
get Int(): SdsClass | undefined { | ||
return this.getClass('Int'); | ||
} | ||
|
||
get Nothing(): SdsClass | undefined { | ||
return this.getClass('Nothing'); | ||
} | ||
|
||
get String(): SdsClass | undefined { | ||
return this.getClass('String'); | ||
} | ||
|
||
private getClass(name: string): SdsClass | undefined { | ||
return this.getModuleMember(CORE_CLASSES_URI, name, isSdsClass); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
import { SafeDsServices } from '../safe-ds-module.js'; | ||
import { isSdsModule, SdsModuleMember } from '../generated/ast.js'; | ||
import { LangiumDocuments, URI, WorkspaceCache } from 'langium'; | ||
import { moduleMembersOrEmpty } from '../helpers/nodeProperties.js'; | ||
|
||
export abstract class SafeDsModuleMembers<T extends SdsModuleMember> { | ||
private readonly langiumDocuments: LangiumDocuments; | ||
private readonly cache: WorkspaceCache<string, T>; | ||
|
||
constructor(services: SafeDsServices) { | ||
this.langiumDocuments = services.shared.workspace.LangiumDocuments; | ||
this.cache = new WorkspaceCache(services.shared); | ||
} | ||
|
||
protected getModuleMember(uri: URI, name: string, predicate: (node: unknown) => node is T): T | undefined { | ||
const key = `${uri.toString()}#${name}`; | ||
|
||
if (this.cache.has(key)) { | ||
return this.cache.get(key); | ||
} | ||
|
||
if (!this.langiumDocuments.hasDocument(uri)) { | ||
/* c8 ignore next 2 */ | ||
return undefined; | ||
} | ||
|
||
const document = this.langiumDocuments.getOrCreateDocument(uri); | ||
const root = document.parseResult.value; | ||
if (!isSdsModule(root)) { | ||
/* c8 ignore next 2 */ | ||
return undefined; | ||
} | ||
|
||
const firstMatchingModuleMember = moduleMembersOrEmpty(root).find((m) => m.name === name); | ||
if (!predicate(firstMatchingModuleMember)) { | ||
/* c8 ignore next 2 */ | ||
return undefined; | ||
} | ||
|
||
this.cache.set(key, firstMatchingModuleMember); | ||
return firstMatchingModuleMember; | ||
} | ||
} |
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
Oops, something went wrong.