@@ -15,6 +15,7 @@ import { basename } from '../../../../../base/common/path.js';
15
15
import { basenameOrAuthority , isEqualAuthority } from '../../../../../base/common/resources.js' ;
16
16
import { ThemeIcon } from '../../../../../base/common/themables.js' ;
17
17
import { URI } from '../../../../../base/common/uri.js' ;
18
+ import { IRange } from '../../../../../editor/common/core/range.js' ;
18
19
import { localize , localize2 } from '../../../../../nls.js' ;
19
20
import { getFlatContextMenuActions } from '../../../../../platform/actions/browser/menuEntryActionViewItem.js' ;
20
21
import { MenuWorkbenchToolBar } from '../../../../../platform/actions/browser/toolbar.js' ;
@@ -31,7 +32,7 @@ import { IOpenerService } from '../../../../../platform/opener/common/opener.js'
31
32
import { IProductService } from '../../../../../platform/product/common/productService.js' ;
32
33
import { IThemeService } from '../../../../../platform/theme/common/themeService.js' ;
33
34
import { fillEditorsDragData } from '../../../../browser/dnd.js' ;
34
- import { IResourceLabel , ResourceLabels } from '../../../../browser/labels.js' ;
35
+ import { IResourceLabel , IResourceLabelProps , ResourceLabels } from '../../../../browser/labels.js' ;
35
36
import { ColorScheme } from '../../../../browser/web.api.js' ;
36
37
import { ResourceContextKey } from '../../../../common/contextkeys.js' ;
37
38
import { SETTINGS_AUTHORITY } from '../../../../services/preferences/common/preferences.js' ;
@@ -366,9 +367,7 @@ class CollapsibleListRenderer implements IListRenderer<IChatCollapsibleListItem,
366
367
const extraClasses = data . excluded ? [ 'excluded' ] : [ ] ;
367
368
if ( uri . scheme === 'https' && isEqualAuthority ( uri . authority , 'github.com' ) && uri . path . includes ( '/tree/' ) ) {
368
369
// Parse a nicer label for GitHub URIs that point at a particular commit + file
369
- const label = uri . path . split ( '/' ) . slice ( 1 , 3 ) . join ( '/' ) ;
370
- const description = uri . path . split ( '/' ) . slice ( 5 ) . join ( '/' ) ;
371
- templateData . label . setResource ( { resource : uri , name : label , description } , { icon : Codicon . github , title : data . title , strikethrough : data . excluded , extraClasses } ) ;
370
+ templateData . label . setResource ( getResourceLabelForGithubUri ( uri ) , { icon : Codicon . github , title : data . title , strikethrough : data . excluded , extraClasses } ) ;
372
371
} else if ( uri . scheme === this . productService . urlProtocol && isEqualAuthority ( uri . authority , SETTINGS_AUTHORITY ) ) {
373
372
// a nicer label for settings URIs
374
373
const settingId = uri . path . substring ( 1 ) ;
@@ -425,6 +424,49 @@ class CollapsibleListRenderer implements IListRenderer<IChatCollapsibleListItem,
425
424
}
426
425
}
427
426
427
+ function getResourceLabelForGithubUri ( uri : URI ) : IResourceLabelProps {
428
+ const repoPath = uri . path . split ( '/' ) . slice ( 1 , 3 ) . join ( '/' ) ;
429
+ const filePath = uri . path . split ( '/' ) . slice ( 5 ) ;
430
+ const fileName = filePath . at ( - 1 ) ;
431
+ const range = getLineRangeFromGithubUri ( uri ) ;
432
+ return {
433
+ resource : uri ,
434
+ name : fileName ?? filePath . join ( '/' ) ,
435
+ description : [ repoPath , ...filePath . slice ( 0 , - 1 ) ] . join ( '/' ) ,
436
+ range
437
+ } ;
438
+ }
439
+
440
+ function getLineRangeFromGithubUri ( uri : URI ) : IRange | undefined {
441
+ if ( ! uri . fragment ) {
442
+ return undefined ;
443
+ }
444
+
445
+ // Extract the line range from the fragment
446
+ // Github line ranges are 1-based
447
+ const match = uri . fragment . match ( / \b L ( \d + ) (?: - L ( \d + ) ) ? / ) ;
448
+ if ( ! match ) {
449
+ return undefined ;
450
+ }
451
+
452
+ const startLine = parseInt ( match [ 1 ] ) ;
453
+ if ( isNaN ( startLine ) ) {
454
+ return undefined ;
455
+ }
456
+
457
+ const endLine = match [ 2 ] ? parseInt ( match [ 2 ] ) : startLine ;
458
+ if ( isNaN ( endLine ) ) {
459
+ return undefined ;
460
+ }
461
+
462
+ return {
463
+ startLineNumber : startLine ,
464
+ startColumn : 1 ,
465
+ endLineNumber : endLine ,
466
+ endColumn : 1
467
+ } ;
468
+ }
469
+
428
470
function getResourceForElement ( element : IChatCollapsibleListItem ) : URI | null {
429
471
if ( element . kind === 'warning' ) {
430
472
return null ;
0 commit comments