@@ -8,7 +8,7 @@ import { Signal } from '@lumino/signaling';
88import { ILSPLogConsole } from '../../tokens' ;
99
1010import { CompletionLabIntegration } from './completion' ;
11- import { LazyCompletionItem } from './item' ;
11+ import { LazyCompletionItem , IExtendedCompletionItem } from './item' ;
1212
1313export interface ICompletionData {
1414 item : LazyCompletionItem ;
@@ -31,6 +31,7 @@ export class LSPCompletionRenderer
3131
3232 protected ITEM_PLACEHOLDER_CLASS = 'lsp-detail-placeholder' ;
3333 protected EXTRA_INFO_CLASS = 'jp-Completer-typeExtended' ;
34+ protected LABEL_CLASS = 'jp-Completer-match' ;
3435
3536 constructor ( protected options : LSPCompletionRenderer . IOptions ) {
3637 super ( ) ;
@@ -113,6 +114,7 @@ export class LSPCompletionRenderer
113114 if ( extraText ) {
114115 const extraElement = li . getElementsByClassName ( this . EXTRA_INFO_CLASS ) [ 0 ] ;
115116 extraElement . textContent = extraText ;
117+ this . _elideMark ( item , li ) ;
116118 }
117119 }
118120
@@ -136,13 +138,50 @@ export class LSPCompletionRenderer
136138 this . visibilityObserver . observe ( li ) ;
137139 // TODO: build custom li from ground up
138140 this . updateExtraInfo ( lsp_item , li ) ;
141+ this . _elideMark ( lsp_item , li ) ;
139142 } else {
140143 this . updateExtraInfo ( item , li ) ;
144+ this . _elideMark ( lsp_item , li ) ;
141145 }
142146
143147 return li ;
144148 }
145149
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+
146185 createDocumentationNode ( item : LazyCompletionItem ) : HTMLElement {
147186 // note: not worth trying to `fetchDocumentation()` as this is not
148187 // invoked if documentation is empty (as of jlab 3.2)
0 commit comments