| 9 | import adapterManager from '@/adapters/manager'; |
| 10 | |
| 11 | export class GitHub1sReferenceProvider implements vscode.ReferenceProvider, vscode.Disposable { |
| 12 | private static instance: GitHub1sReferenceProvider | null = null; |
| 13 | private readonly disposable: vscode.Disposable; |
| 14 | |
| 15 | private constructor() {} |
| 16 | |
| 17 | public static getInstance(): GitHub1sReferenceProvider { |
| 18 | if (GitHub1sReferenceProvider.instance) { |
| 19 | return GitHub1sReferenceProvider.instance; |
| 20 | } |
| 21 | return (GitHub1sReferenceProvider.instance = new GitHub1sReferenceProvider()); |
| 22 | } |
| 23 | |
| 24 | dispose() { |
| 25 | this.disposable?.dispose(); |
| 26 | } |
| 27 | |
| 28 | async provideReferences( |
| 29 | document: vscode.TextDocument, |
| 30 | position: vscode.Position, |
| 31 | _context: vscode.ReferenceContext, |
| 32 | _token: vscode.CancellationToken, |
| 33 | ): Promise<vscode.Location[]> { |
| 34 | const symbolRange = document.getWordRangeAtPosition(position); |
| 35 | const symbol = symbolRange ? document.getText(symbolRange) : ''; |
| 36 | |
| 37 | if (!symbol) { |
| 38 | return []; |
| 39 | } |
| 40 | |
| 41 | const authority = document.uri.authority || (await router.getAuthority()); |
| 42 | const [repo, ref] = authority.split('+').filter(Boolean); |
| 43 | const { scheme, path } = document.uri; |
| 44 | const { line, character } = position; |
| 45 | |
| 46 | const dataSource = await adapterManager.getCurrentAdapter().resolveDataSource(); |
| 47 | const symbolReferences = await dataSource.provideSymbolReferences(repo, ref, path, line, character, symbol); |
| 48 | |
| 49 | if (symbolReferences.length) { |
| 50 | showSourcegraphSymbolMessage(repo, ref, path, line, character); |
| 51 | } |
| 52 | |
| 53 | return symbolReferences.map(({ scope, path, range }) => { |
| 54 | const isSameRepo = !scope || (scope.scheme === scheme && scope.repo === repo); |
| 55 | // if the reference target and the searched symbol is in the same |
| 56 | // repository, just replace the `document.uri.path` with targetPath |
| 57 | // (so that the target file will open with expanding the file explorer) |
| 58 | const uri = isSameRepo |
| 59 | ? document.uri.with({ path: `/${path}` }) |
| 60 | : vscode.Uri.parse('').with({ |
| 61 | scheme: scope!.scheme, |
| 62 | authority: `${scope!.repo}+${scope!.ref}`, |
| 63 | path: `/${path}`, |
| 64 | }); |
| 65 | const { start, end } = range; |
| 66 | return { |
| 67 | uri, |
| 68 | range: new vscode.Range( |
nothing calls this directly
no outgoing calls
no test coverage detected