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

Commit

Permalink
Merge pull request #131 from m-lnrs/suggestion-type-enum-issue-130
Browse files Browse the repository at this point in the history
Fix auto import for enums
  • Loading branch information
darangi authored Mar 4, 2021
2 parents c0379ef + 8167ff7 commit dede888
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit dede888

Please sign in to comment.