mirror of
https://github.com/eMoflon/model-modeling-language.git
synced 2024-05-20 20:00:39 +00:00
implemented code action to propose additional imports that would fix missing reference resolutions
This commit is contained in:
parent
1ee4b47c3d
commit
7126b2aef3
|
@ -50,6 +50,9 @@ export class ModelModelingLanguageCodeActionProvider implements CodeActionProvid
|
|||
case IssueCodes.ImportAlreadyExists:
|
||||
accept(this.fixDuplicateImport(diagnostic, document));
|
||||
break;
|
||||
case IssueCodes.ImportIsMissing:
|
||||
accept(this.fixMissingImport(diagnostic, document));
|
||||
break;
|
||||
case IssueCodes.OppositeAnnotationMissing:
|
||||
accept(this.fixMissingOppositeAnnotation(diagnostic, document));
|
||||
break;
|
||||
|
@ -247,6 +250,27 @@ export class ModelModelingLanguageCodeActionProvider implements CodeActionProvid
|
|||
return undefined;
|
||||
}
|
||||
|
||||
private fixMissingImport(diagnostic: Diagnostic, document: LangiumDocument): CodeAction[] | undefined {
|
||||
const possibleImports: string[] = diagnostic.data as string[];
|
||||
if (possibleImports.length == 0) {
|
||||
return undefined;
|
||||
}
|
||||
return possibleImports.map(pimport => {
|
||||
return ({
|
||||
title: `Import ${pimport}`,
|
||||
kind: CodeActionKind.QuickFix,
|
||||
diagnostics: [diagnostic],
|
||||
edit: {
|
||||
changes: {
|
||||
[document.textDocument.uri]: [{
|
||||
range: {start: {character: 0, line: 0}, end: {character: 0, line: 0}},
|
||||
newText: `import "${pimport}";\n`
|
||||
}]
|
||||
}
|
||||
}
|
||||
} as CodeAction)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue