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

Commit dede888

Browse files
authored
Merge pull request #131 from m-lnrs/suggestion-type-enum-issue-130
Fix auto import for enums
2 parents c0379ef + 8167ff7 commit dede888

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/providers/autoImportActionProvider.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ function getImportChoice(missingType, editor, typeRange, languageClient) {
118118
function buildImportSuggestion(autocompleteSuggestion) {
119119
switch (autocompleteSuggestion.type) {
120120
case 'class':
121+
case 'enum':
121122
const { displayText } = autocompleteSuggestion
122123
const [ typeName, pkgName ] = displayText.split('-').map(s => s.trim())
123124

test/autoImportActionProvider.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ describe.only('autoImportActionProvider', () => {
7878
})
7979
})
8080

81+
describe('Suggestion Type: `enum`', () => {
82+
it('should build the correct import package path', () => {
83+
const suggestion = {
84+
type: 'enum',
85+
displayText: 'Month - java.time'
86+
}
87+
88+
expect(buildImportSuggestion(suggestion)).to.equal('java.time.Month')
89+
})
90+
91+
it('should throw error if type or package name is missing', () => {
92+
try {
93+
expect.fail('Should have thrown error')
94+
} catch (error) {
95+
expect(error).not.to.be.null
96+
}
97+
})
98+
})
99+
81100
it('should throw error for unknown suggestion type', () => {
82101
try {
83102
buildImportSuggestion({ type: 'unknown type' })

0 commit comments

Comments
 (0)