@@ -180,7 +180,7 @@ class WorkspaceInformation {
180
180
181
181
export class ImportDiagnosticCompletionProvider implements IDiagnosticCompletionProvider < ImportDiagnosticCompletionItem > {
182
182
183
- public static SupportedLanguages = new Set < string > ( [ 'typescript' , 'javascript' , 'typescriptreact' , 'javascriptreact' , 'python' ] ) ;
183
+ public static SupportedLanguages = new Set < string > ( [ 'typescript' , 'javascript' , 'typescriptreact' , 'javascriptreact' , 'python' , 'java' ] ) ;
184
184
185
185
public readonly providerName = 'import' ;
186
186
@@ -198,12 +198,14 @@ export class ImportDiagnosticCompletionProvider implements IDiagnosticCompletion
198
198
199
199
const javascriptImportHandler = new JavascriptImportHandler ( ) ;
200
200
const pythonImportHandler = new PythonImportHandler ( ) ;
201
+ const javaImportHandler = new JavaImportHandler ( ) ;
201
202
this . _importHandlers = new Map < string , ILanguageImportHandler > ( [
202
203
[ 'javascript' , javascriptImportHandler ] ,
203
204
[ 'typescript' , javascriptImportHandler ] ,
204
205
[ 'typescriptreact' , javascriptImportHandler ] ,
205
206
[ 'javascriptreact' , javascriptImportHandler ] ,
206
207
[ 'python' , pythonImportHandler ] ,
208
+ [ 'java' , javaImportHandler ] ,
207
209
] ) ;
208
210
}
209
211
@@ -316,7 +318,7 @@ export class ImportDiagnosticCompletionProvider implements IDiagnosticCompletion
316
318
// The diagnostic might have changed in the meantime to a different range
317
319
// So we need to get the import name from the referenced diagnostic
318
320
let codeActionImportName = importName ;
319
- if ( codeAction . diagnostics ) {
321
+ if ( codeAction . diagnostics && codeAction . diagnostics . length > 0 ) {
320
322
codeActionImportName = codeAction . diagnostics [ 0 ] . range . substring ( documentContent . value ) ;
321
323
}
322
324
@@ -489,3 +491,28 @@ class PythonImportHandler implements ILanguageImportHandler {
489
491
return ImportSource . unknown ;
490
492
}
491
493
}
494
+
495
+ class JavaImportHandler implements ILanguageImportHandler {
496
+
497
+ isImportDiagnostic ( diagnostic : Diagnostic ) : boolean {
498
+ return String ( diagnostic . data . code ) === '16777218' || diagnostic . message . endsWith ( 'cannot be resolved to a type' ) ;
499
+ }
500
+
501
+ isImportCodeAction ( codeAction : CodeActionData ) : boolean {
502
+ return codeAction . title . startsWith ( 'Import' ) ;
503
+ }
504
+
505
+ isImportInIgnoreList ( importCodeAction : ImportCodeAction ) : boolean {
506
+ return false ;
507
+ }
508
+
509
+ getImportDetails ( codeAction : CodeActionData , importName : string , workspaceInfo : WorkspaceInformation ) : ImportDetails | null {
510
+ return {
511
+ importName,
512
+ importPath : codeAction . title . split ( `\'` ) [ 2 ] . trim ( ) ,
513
+ labelShort : 'import ' + importName ,
514
+ labelDeduped : codeAction . title ,
515
+ importSource : ImportSource . unknown
516
+ } ;
517
+ }
518
+ }
0 commit comments