14
14
package com .redhat .devtools .lsp4ij .ui ;
15
15
16
16
import com .intellij .icons .AllIcons ;
17
+ import com .intellij .openapi .fileTypes .FileType ;
18
+ import com .intellij .openapi .fileTypes .FileTypeManager ;
19
+ import com .intellij .openapi .fileTypes .UnknownFileType ;
17
20
import com .intellij .openapi .util .IconLoader ;
18
21
import com .intellij .util .ui .ColorIcon ;
19
22
import org .eclipse .lsp4j .CompletionItem ;
28
31
import java .util .Map ;
29
32
import java .util .concurrent .ConcurrentHashMap ;
30
33
34
+ import static com .intellij .util .PathUtil .getFileExtension ;
35
+
31
36
/**
32
37
* Maps LSP4J kinds to Intellij Icons. See the <a href="https://jetbrains.design/intellij/resources/icons_list/" target="_blank">JetBrains icon list</a> for reference.
33
38
*/
@@ -54,12 +59,36 @@ private IconMapper(){
54
59
return null ;
55
60
}
56
61
Icon icon = null ;
57
- if (item .getKind () == CompletionItemKind .Color ) {
62
+ if (item .getKind () == CompletionItemKind .File ) {
63
+ icon = getFileIcon (item );
64
+ } else if (item .getKind () == CompletionItemKind .Color ) {
58
65
icon = getColorIcon (item );
59
66
}
60
67
return icon == null ? getIcon (item .getKind ()) : icon ;
61
68
}
62
69
70
+ private static Icon getFileIcon (CompletionItem item ) {
71
+ FileType fileType = getFileType (item .getLabel ());
72
+ if (fileType == null ) {
73
+ fileType = getFileType (item .getDetail ());
74
+ }
75
+ return fileType == null ? null : fileType .getIcon ();
76
+ }
77
+
78
+ private static FileType getFileType (String fileOrPathName ){
79
+ if (fileOrPathName == null || fileOrPathName .isBlank ()) {
80
+ return null ;
81
+ }
82
+ String extension = getFileExtension (fileOrPathName );
83
+ if (extension != null ) {
84
+ FileType fileType = FileTypeManager .getInstance ().getFileTypeByExtension (extension );
85
+ if (!UnknownFileType .INSTANCE .equals (fileType )) {
86
+ return fileType ;
87
+ }
88
+ }
89
+ return null ;
90
+ }
91
+
63
92
private static Icon getColorIcon (@ NotNull CompletionItem item ) {
64
93
//While this method is private, we already know this is a Color kind, no need to check again
65
94
String docString = getDocString (item .getDocumentation ());
0 commit comments