Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Fix auto import for enums #131

Merged
merged 1 commit into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/providers/autoImportActionProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
19 changes: 19 additions & 0 deletions test/autoImportActionProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down