From 8167ff7b1cffc9d82acd581e0fac7669c58a96ba Mon Sep 17 00:00:00 2001 From: m-lib Date: Fri, 4 Sep 2020 00:07:53 -0300 Subject: [PATCH] Fix auto import for enums --- lib/providers/autoImportActionProvider.js | 1 + test/autoImportActionProvider.test.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/providers/autoImportActionProvider.js b/lib/providers/autoImportActionProvider.js index a493d05..604cae3 100644 --- a/lib/providers/autoImportActionProvider.js +++ b/lib/providers/autoImportActionProvider.js @@ -118,6 +118,7 @@ function getImportChoice(missingType, editor, typeRange, languageClient) { function buildImportSuggestion(autocompleteSuggestion) { switch (autocompleteSuggestion.type) { case 'class': + case 'enum': const { displayText } = autocompleteSuggestion const [ typeName, pkgName ] = displayText.split('-').map(s => s.trim()) diff --git a/test/autoImportActionProvider.test.js b/test/autoImportActionProvider.test.js index 6f8576a..a9f6c0f 100644 --- a/test/autoImportActionProvider.test.js +++ b/test/autoImportActionProvider.test.js @@ -78,6 +78,25 @@ describe.only('autoImportActionProvider', () => { }) }) + describe('Suggestion Type: `enum`', () => { + it('should build the correct import package path', () => { + const suggestion = { + type: 'enum', + displayText: 'Month - java.time' + } + + expect(buildImportSuggestion(suggestion)).to.equal('java.time.Month') + }) + + it('should throw error if type or package name is missing', () => { + try { + expect.fail('Should have thrown error') + } catch (error) { + expect(error).not.to.be.null + } + }) + }) + it('should throw error for unknown suggestion type', () => { try { buildImportSuggestion({ type: 'unknown type' })