Skip to content

Commit

Permalink
Optim: use RelativePattern for findFiles linkProvider
Browse files Browse the repository at this point in the history
The rg command is very slow when searching for files in the whole
workspace. This patch uses RelativePattern to limit the search to the
recipe directory and the files directory.
  • Loading branch information
deribaucourt committed Dec 14, 2023
1 parent abbff85 commit f160e46
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions client/src/documentLinkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ export class BitbakeDocumentLinkProvider implements vscode.DocumentLinkProvider
const filenames = linksData.map(link => link.value.split(';')[0])
const filenamesRegex = '{' + filenames.join(',') + '}'
const parentDir = document.uri.path.split('/').slice(0, -1).join('/')
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri)
const pnDir = path.join(parentDir, extractRecipeName(document.uri.path) as string)
const pnDirRelative = pnDir.replace(workspaceFolder?.uri.path + '/', '')
const filesDir = path.join(parentDir, 'files')
const filesDirRelative = filesDir.replace(workspaceFolder?.uri.path + '/', '')
return [...(await vscode.workspace.findFiles(pnDirRelative + '/**/' + filenamesRegex, undefined, filenames.length, token)),
...(await vscode.workspace.findFiles(filesDirRelative + '/**/' + filenamesRegex, undefined, filenames.length, token))]
return [...(await vscode.workspace.findFiles(new vscode.RelativePattern(pnDir, '**/' + filenamesRegex), undefined, filenames.length, token)),
...(await vscode.workspace.findFiles(new vscode.RelativePattern(filesDir, '**/' + filenamesRegex), undefined, filenames.length, token))]
}

async provideDocumentLinks (document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.DocumentLink[]> {
Expand Down

0 comments on commit f160e46

Please sign in to comment.