@@ -8,7 +8,7 @@ import { Signal } from '@lumino/signaling';
8
8
import { ILSPLogConsole } from '../../tokens' ;
9
9
10
10
import { CompletionLabIntegration } from './completion' ;
11
- import { LazyCompletionItem } from './item' ;
11
+ import { LazyCompletionItem , IExtendedCompletionItem } from './item' ;
12
12
13
13
export interface ICompletionData {
14
14
item : LazyCompletionItem ;
@@ -31,6 +31,7 @@ export class LSPCompletionRenderer
31
31
32
32
protected ITEM_PLACEHOLDER_CLASS = 'lsp-detail-placeholder' ;
33
33
protected EXTRA_INFO_CLASS = 'jp-Completer-typeExtended' ;
34
+ protected LABEL_CLASS = 'jp-Completer-match' ;
34
35
35
36
constructor ( protected options : LSPCompletionRenderer . IOptions ) {
36
37
super ( ) ;
@@ -113,6 +114,7 @@ export class LSPCompletionRenderer
113
114
if ( extraText ) {
114
115
const extraElement = li . getElementsByClassName ( this . EXTRA_INFO_CLASS ) [ 0 ] ;
115
116
extraElement . textContent = extraText ;
117
+ this . _elideMark ( item , li ) ;
116
118
}
117
119
}
118
120
@@ -136,13 +138,50 @@ export class LSPCompletionRenderer
136
138
this . visibilityObserver . observe ( li ) ;
137
139
// TODO: build custom li from ground up
138
140
this . updateExtraInfo ( lsp_item , li ) ;
141
+ this . _elideMark ( lsp_item , li ) ;
139
142
} else {
140
143
this . updateExtraInfo ( item , li ) ;
144
+ this . _elideMark ( lsp_item , li ) ;
141
145
}
142
146
143
147
return li ;
144
148
}
145
149
150
+ private _elideMark ( item : IExtendedCompletionItem , li : HTMLLIElement ) {
151
+ if ( ! item || ! item . type ) {
152
+ return ;
153
+ }
154
+ const type = item . type . toLowerCase ( ) ;
155
+ if ( type !== 'file' && type !== 'path' ) {
156
+ // do not elide for non-paths.
157
+ return ;
158
+ }
159
+ const labelElement = li . getElementsByClassName ( this . LABEL_CLASS ) [ 0 ] ;
160
+ const originalHTMLLabel = labelElement . childNodes ;
161
+ let hasMark = false ;
162
+ for ( const node of originalHTMLLabel ) {
163
+ if ( node . nodeType === Node . ELEMENT_NODE ) {
164
+ const element = node as Element ;
165
+ const text = element . textContent ;
166
+ if ( element . tagName === 'MARK' && text ) {
167
+ const elidableElement = document . createElement ( 'bdo' ) ;
168
+ elidableElement . setAttribute ( 'dir' , 'ltr' ) ;
169
+ elidableElement . textContent = text ;
170
+ elidableElement . title = text ;
171
+ element . replaceChildren ( elidableElement ) ;
172
+ element . classList . add ( 'lsp-elide' ) ;
173
+ hasMark = true ;
174
+ }
175
+ }
176
+ }
177
+ if ( hasMark ) {
178
+ const wrapper = document . createElement ( 'div' ) ;
179
+ wrapper . className = 'lsp-elide-wrapper' ;
180
+ wrapper . replaceChildren ( ...labelElement . childNodes ) ;
181
+ labelElement . replaceChildren ( wrapper ) ;
182
+ }
183
+ }
184
+
146
185
createDocumentationNode ( item : LazyCompletionItem ) : HTMLElement {
147
186
// note: not worth trying to `fetchDocumentation()` as this is not
148
187
// invoked if documentation is empty (as of jlab 3.2)
0 commit comments