Skip to content

Commit

Permalink
SLVSCODE-873 crawl directory before listFilesInFolder is called
Browse files Browse the repository at this point in the history
  • Loading branch information
sophio-japharidze-sonarsource committed Nov 25, 2024
1 parent b93fd9c commit 3696e03
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
3 changes: 0 additions & 3 deletions its/src/test/javaSuite/java.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ suite('Java Test Suite', () => {
const rangeInMiddleOfThrowsMyException = new vscode.Range(8, 54, 8, 54);
const codeActionsResult = (await vscode.commands.executeCommand<(vscode.Command | vscode.CodeAction)[]>('vscode.executeCodeActionProvider', document.uri, rangeInMiddleOfThrowsMyException, vscode.CodeActionKind.QuickFix.value));
// With old versions of VSCode, code actions are not necessarily filtered on kind
console.log('+++++++', codeActionsResult[0].title)
console.log('+++++++', codeActionsResult[2].title)
console.log('+++++++', codeActionsResult[1].title)
const expectedActionTitles = [
"SonarQube: Deactivate rule 'java:S1130'",
"SonarQube: Remove \"MyException\"",
Expand Down
5 changes: 4 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ export async function activate(context: VSCode.ExtensionContext) {
});
FixSuggestionService.init(languageClient);

VSCode.workspace.workspaceFolders?.map((folder) => {
FileSystemServiceImpl.instance.crawlDirectory(folder.uri);
});

installCustomRequestHandlers(context);

const referenceBranchStatusItem = VSCode.window.createStatusBarItem(VSCode.StatusBarAlignment.Left, 1);
Expand Down Expand Up @@ -568,7 +572,6 @@ function installCustomRequestHandlers(context: VSCode.ExtensionContext) {
languageClient.onNotification(protocol.ShowRuleDescriptionNotification.type, showRuleDescription(context));
languageClient.onNotification(protocol.SuggestBindingNotification.type, params => suggestBinding(params));
languageClient.onRequest(protocol.ListFilesInFolderRequest.type, async (params) => {
await FileSystemServiceImpl.instance.crawlDirectory(VSCode.Uri.parse(params.folderUri));
return AutoBindingService.instance.listAutobindingFilesInFolder(params);
}
);
Expand Down
4 changes: 2 additions & 2 deletions src/fileSystem/fileSystemServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class FileSystemServiceImpl implements FileSystemService {
}

public async crawlDirectory(uri: Uri) {
await this.listFilesRecursively(uri, uri);
this.listFilesRecursively(uri, uri);
}

private async listFilesRecursively(configScopeUri: Uri, currentDirectory: Uri) {
Expand All @@ -45,7 +45,7 @@ export class FileSystemServiceImpl implements FileSystemService {
}
// .sonarlint folder is already handled separately, skipping it in recursive crawl
if (type === vscode.FileType.Directory && name !== '.sonarlint') {
await this.listFilesRecursively(configScopeUri, fullFileUri);
this.listFilesRecursively(configScopeUri, fullFileUri);
}
}
} catch (error) {
Expand Down
3 changes: 3 additions & 0 deletions test/suite/autobinding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ suite('Auto Binding Test Suite', () => {
// crawl the directory
await FileSystemServiceImpl.instance.crawlDirectory(VSCode.Uri.parse(params.folderUri));

// make sure results get in place
await sleep(500);

const foundFiles: ListFilesInScopeResponse = await underTest.listAutobindingFilesInFolder(params);

expect(foundFiles.foundFiles).to.not.be.empty;
Expand Down
4 changes: 4 additions & 0 deletions test/suite/sharedConnectedModeSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ suite('Shared Connected Mode service test suite', () => {

// populate cache
await FileSystemServiceImpl.instance.crawlDirectory(workspaceFolderUri);
await sleep(200);

const result = await underTest.computeSharedConnectedModeFileName(workspaceFolderUri.toString());

Expand All @@ -74,6 +75,7 @@ suite('Shared Connected Mode service test suite', () => {
tempFiles.push(solutionFileUri);

await FileSystemServiceImpl.instance.crawlDirectory(workspaceFolder1.uri);
await sleep(200);

const result = await underTest.computeSharedConnectedModeFileName(workspaceFolder1.uri.toString());

Expand All @@ -90,6 +92,7 @@ suite('Shared Connected Mode service test suite', () => {
tempFiles.push(solutionFileUri1, solutionFileUri2);

await FileSystemServiceImpl.instance.crawlDirectory(workspaceFolder1.uri);
await sleep(200);

const resultPromise = underTest.computeSharedConnectedModeFileName(workspaceFolder1.uri.toString());
await selectFirstQuickPickItem();
Expand All @@ -110,6 +113,7 @@ suite('Shared Connected Mode service test suite', () => {
}

await FileSystemServiceImpl.instance.crawlDirectory(workspaceFolder.uri);
await sleep(200);

await underTest.createSharedConnectedModeSettingsFile(workspaceFolder);

Expand Down

0 comments on commit 3696e03

Please sign in to comment.