@@ -28,23 +28,38 @@ export class LensDecorations implements vscode.Disposable {
2828 public apply ( editor : vscode . TextEditor , usages : ComponentUsage [ ] ) : void {
2929 const clientDecorations : vscode . DecorationOptions [ ] = [ ]
3030 const serverDecorations : vscode . DecorationOptions [ ] = [ ]
31+ const editorDir = path . dirname ( editor . document . uri . fsPath )
32+ const displayPathCache = new Map < string , string > ( )
3133
3234 for ( const usage of usages ) {
33- for ( const range of usage . ranges ) {
34- const decoration : vscode . DecorationOptions = {
35- hoverMessage : new vscode . MarkdownString (
36- `${ usage . kind === 'client' ? 'Client' : 'Server' } component from \`${ toDisplayPath ( editor . document . uri , usage . sourceFilePath ) } \`` ,
37- ) ,
38- range : new vscode . Range (
39- editor . document . positionAt ( range . start ) ,
40- editor . document . positionAt ( range . end ) ,
41- ) ,
42- }
35+ let displayPath = displayPathCache . get ( usage . sourceFilePath )
36+ if ( displayPath === undefined ) {
37+ displayPath = toDisplayPath ( editorDir , usage . sourceFilePath )
38+ displayPathCache . set ( usage . sourceFilePath , displayPath )
39+ }
4340
41+ const label = usage . kind === 'client' ? 'Client' : 'Server'
42+ const hoverMessage = new vscode . MarkdownString (
43+ `${ label } component from \`${ displayPath } \`` ,
44+ )
45+
46+ for ( const range of usage . ranges ) {
4447 if ( usage . kind === 'client' ) {
45- clientDecorations . push ( decoration )
48+ clientDecorations . push ( {
49+ hoverMessage,
50+ range : new vscode . Range (
51+ editor . document . positionAt ( range . start ) ,
52+ editor . document . positionAt ( range . end ) ,
53+ ) ,
54+ } )
4655 } else {
47- serverDecorations . push ( decoration )
56+ serverDecorations . push ( {
57+ hoverMessage,
58+ range : new vscode . Range (
59+ editor . document . positionAt ( range . start ) ,
60+ editor . document . positionAt ( range . end ) ,
61+ ) ,
62+ } )
4863 }
4964 }
5065 }
@@ -64,14 +79,8 @@ export class LensDecorations implements vscode.Disposable {
6479 }
6580}
6681
67- function toDisplayPath (
68- documentUri : vscode . Uri ,
69- sourceFilePath : string ,
70- ) : string {
71- const relativePath = path . relative (
72- path . dirname ( documentUri . fsPath ) ,
73- sourceFilePath ,
74- )
82+ function toDisplayPath ( editorDir : string , sourceFilePath : string ) : string {
83+ const relativePath = path . relative ( editorDir , sourceFilePath )
7584 return relativePath . length > 0 ? relativePath : path . basename ( sourceFilePath )
7685}
7786
0 commit comments