Closed unlocomqx closed 3 years ago
I have somewhat working solution on local branch but JB refactored this inspection in 2020.2 and I'm unsure how to proceed for now
native importing code:
Old:
com.intellij.lang.javascript.modules.ES6ModulesDependenciesInspection
(id ES6ModulesDependencies
)
New:
com.intellij.lang.javascript.inspections.JSUnresolvedVariableInspection
(id JSUnresolvedVariable
)
com.intellij.lang.javascript.inspections.JSUnresolvedFunctionInspection
(id JSUnresolvedFunction
)
Relevant, also new:
com.intellij.lang.javascript.validation.JSUnresolvedReferenceErrorUpdater
Both old and new inspections use different classes and it's impossible to support 2020.1 and 2020.2 with one binary
I don't even know if inspections are relevant to this issue, it's an auto-import so it's probably relevant to completion rather than inspection. Maybe I don't understand but here's a gif to alleviate any potential ambiguity
The shortest way I think is to change the behaviour of ES6ImportPsiUtil::findAnchorToInsert
findAnchorToInsert:236, ES6ImportPsiUtil (com.intellij.lang.ecmascript6.psi.impl)
findPlaceForImport:204, ES6ImportPsiUtil (com.intellij.lang.ecmascript6.psi.impl)
findPlaceByModuleName:174, ES6ImportPsiUtil (com.intellij.lang.ecmascript6.psi.impl)
findPlaceAndInsertES6Import:460, ES6CreateImportUtil (com.intellij.lang.ecmascript6.psi.impl)
createImportOrUseExisting:302, ES6AddImportExecutor (com.intellij.lang.ecmascript6.actions)
executeImpl:46, ImportES6ModuleFix (com.intellij.lang.javascript.modules)
invokeAction:104, ImportCommonJSModuleFix (com.intellij.lang.javascript.modules)
insertJSImport:730, ES6ImportPsiUtil (com.intellij.lang.ecmascript6.psi.impl)
insertJSImport:717, ES6ImportPsiUtil (com.intellij.lang.ecmascript6.psi.impl)
insertJSImport:680, ES6ImportPsiUtil (com.intellij.lang.ecmascript6.psi.impl)
insertJSImport:672, ES6ImportPsiUtil (com.intellij.lang.ecmascript6.psi.impl)
......
insertLookupItem:519, JSImportCompletionUtil (com.intellij.lang.javascript.completion)
importForElement:451, JSImportCompletionUtil (com.intellij.lang.javascript.completion)
access$100:63, JSImportCompletionUtil (com.intellij.lang.javascript.completion)
handleInsert:543, JSImportCompletionUtil$ImportInsertHandler (com.intellij.lang.javascript.completion)
....
lambda$insertItem$15:688, CodeCompletionHandlerBase (com.intellij.codeInsight.completion)
...
doInsertItem:587, CodeCompletionHandlerBase (com.intellij.codeInsight.completion)
insertItemHonorBlockSelection:547, CodeCompletionHandlerBase (com.intellij.codeInsight.completion)
lookupItemSelected:493, CodeCompletionHandlerBase (com.intellij.codeInsight.completion)
...
It's the same for the quick action "insert import":
This works for me (now) unless I missed something obvious
@Treverix it does not work outside of the script tag.
@bbuhler ok, I see - I just noticed that it works inside the script tag and also on a blank file now - it does not put the import
inside the curly brackets (anymore) but yes, if there is script element, it does not add it to it, the import is put outside.
Thank you @tomblachut for your work on the plugin and the platform!
It's a pleasure 😊
This is a tricky one An auto-import is inserted in the template, it should be inserted in the script section