1+ import getImportPath from '../utils/getImportPath'
12import { sharedCompletionContext } from './sharedContext'
23
34export default ( entries : ts . CompletionEntry [ ] ) => {
@@ -9,24 +10,13 @@ export default (entries: ts.CompletionEntry[]) => {
910 for ( const entry of entries ) {
1011 const { symbol } = entry
1112 if ( ! symbol ) continue
12- const [ node ] = symbol . declarations ?? [ ]
13- if ( ! node ) continue
14- let importDeclaration : ts . ImportDeclaration | undefined
15- if ( ts . isImportSpecifier ( node ) && ts . isNamedImports ( node . parent ) && ts . isImportDeclaration ( node . parent . parent . parent ) ) {
16- importDeclaration = node . parent . parent . parent
17- } else if ( ts . isImportClause ( node ) && ts . isImportDeclaration ( node . parent ) ) {
18- importDeclaration = node . parent
19- } else if ( ts . isNamespaceImport ( node ) && ts . isImportClause ( node . parent ) && ts . isImportDeclaration ( node . parent . parent ) ) {
20- // todo-low(builtin) maybe reformat text
21- importDeclaration = node . parent . parent
22- }
23- if ( importDeclaration ) {
24- prevCompletionsMap [ entry . name ] ??= { }
25- let importPath = importDeclaration . moduleSpecifier . getText ( )
26- const symbolsLimit = 40
27- if ( importPath . length > symbolsLimit ) importPath = `${ importPath . slice ( 0 , symbolsLimit / 2 ) } ...${ importPath . slice ( - symbolsLimit / 2 ) } `
28- const detailPrepend = displayImportedInfo === 'short-format' ? `(from ${ importPath } ) ` : `Imported from ${ importPath } \n\n`
29- prevCompletionsMap [ entry . name ] ! . detailPrepend = detailPrepend
30- }
13+ let { quotedPath : importPath } = getImportPath ( symbol ) ?? { }
14+ if ( ! importPath ) continue
15+
16+ prevCompletionsMap [ entry . name ] ??= { }
17+ const symbolsLimit = 40
18+ if ( importPath . length > symbolsLimit ) importPath = `${ importPath . slice ( 0 , symbolsLimit / 2 ) } ...${ importPath . slice ( - symbolsLimit / 2 ) } `
19+ const detailPrepend = displayImportedInfo === 'short-format' ? `(from ${ importPath } ) ` : `Imported from ${ importPath } \n\n`
20+ prevCompletionsMap [ entry . name ] ! . detailPrepend = detailPrepend
3121 }
3222}
0 commit comments