@@ -44,7 +44,7 @@ import { IServiceHost } from '../../services/typescriptService/serviceHost';
44
44
45
45
// Todo: After upgrading to LS server 4.0, use CompletionContext for filtering trigger chars
46
46
// https://microsoft.github.io/language-server-protocol/specification#completion-request-leftwards_arrow_with_hook
47
- const NON_SCRIPT_TRIGGERS = [ '<' , '/' , ' *', ':' ] ;
47
+ const NON_SCRIPT_TRIGGERS = [ '<' , '*' , ':' ] ;
48
48
49
49
export async function getJavascriptMode (
50
50
serviceHost : IServiceHost ,
@@ -156,10 +156,12 @@ export async function getJavascriptMode(
156
156
isIncomplete : false ,
157
157
items : entries . map ( ( entry , index ) => {
158
158
const range = entry . replacementSpan && convertRange ( scriptDoc , entry . replacementSpan ) ;
159
+ const { label, detail } = calculateLabelAndDetailTextForPathImport ( entry ) ;
159
160
return {
160
161
uri : doc . uri ,
161
162
position,
162
- label : entry . name ,
163
+ label,
164
+ detail,
163
165
sortText : entry . sortText + index ,
164
166
kind : convertKind ( entry . kind ) ,
165
167
textEdit : range && TextEdit . replace ( range , entry . name ) ,
@@ -173,6 +175,30 @@ export async function getJavascriptMode(
173
175
} ;
174
176
} )
175
177
} ;
178
+
179
+ function calculateLabelAndDetailTextForPathImport ( entry : ts . CompletionEntry ) {
180
+ // Is import path completion
181
+ if ( entry . kind === ts . ScriptElementKind . scriptElement ) {
182
+ if ( entry . kindModifiers ) {
183
+ return {
184
+ label : entry . name ,
185
+ detail : entry . name + entry . kindModifiers
186
+ } ;
187
+ } else {
188
+ if ( entry . name . endsWith ( '.vue' ) ) {
189
+ return {
190
+ label : entry . name . slice ( 0 , - '.vue' . length ) ,
191
+ detail : entry . name
192
+ } ;
193
+ }
194
+ }
195
+ }
196
+
197
+ return {
198
+ label : entry . name ,
199
+ detail : undefined
200
+ } ;
201
+ }
176
202
} ,
177
203
doResolve ( doc : TextDocument , item : CompletionItem ) : CompletionItem {
178
204
const { service } = updateCurrentVueTextDocument ( doc ) ;
@@ -193,7 +219,7 @@ export async function getJavascriptMode(
193
219
includeCompletionsWithInsertText : true
194
220
}
195
221
) ;
196
- if ( details ) {
222
+ if ( details && item . kind !== CompletionItemKind . File && item . kind !== CompletionItemKind . Folder ) {
197
223
item . detail = tsModule . displayPartsToString ( details . displayParts ) ;
198
224
const documentation : MarkupContent = {
199
225
kind : 'markdown' ,
@@ -641,6 +667,10 @@ function convertKind(kind: ts.ScriptElementKind): CompletionItemKind {
641
667
return CompletionItemKind . Interface ;
642
668
case 'warning' :
643
669
return CompletionItemKind . File ;
670
+ case 'script' :
671
+ return CompletionItemKind . File ;
672
+ case 'directory' :
673
+ return CompletionItemKind . Folder ;
644
674
}
645
675
646
676
return CompletionItemKind . Property ;
0 commit comments