Skip to content

Commit

Permalink
SLVSCODE-746 Use non trivial ID for first level nodes of connected mo…
Browse files Browse the repository at this point in the history
…de view (SonarSource#676)
  • Loading branch information
jblievremont authored Jan 10, 2025
1 parent 4221ab7 commit 2006d43
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
20 changes: 11 additions & 9 deletions src/connected/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ export class Connection extends VSCode.TreeItem {
}
}

type ConnectionType = '__sonarqube__' | '__sonarcloud__';

export class ConnectionGroup extends VSCode.TreeItem {
constructor(
public readonly id: 'sonarqube' | 'sonarcloud',
public readonly id: ConnectionType,
public readonly label: 'SonarQube Server' | 'SonarQube Cloud',
public readonly contextValue: 'sonarQubeGroup' | 'sonarCloudGroup'
) {
Expand All @@ -89,13 +91,13 @@ export class AllConnectionsTreeDataProvider implements VSCode.TreeDataProvider<C

constructor(private readonly client: SonarLintExtendedLanguageClient) {}

async getConnections(type: string): Promise<Connection[]> {
const contextValue = type === 'sonarqube' ? 'sonarqubeConnection' : 'sonarcloudConnection';
async getConnections(type: ConnectionType): Promise<Connection[]> {
const contextValue = type === '__sonarqube__' ? 'sonarqubeConnection' : 'sonarcloudConnection';
const labelKey = 'connectionId';
const alternativeLabelKey = type === 'sonarqube' ? 'serverUrl' : 'organizationKey';
const alternativeLabelKey = type === '__sonarqube__' ? 'serverUrl' : 'organizationKey';

const connectionsFromSettings: BaseConnection[] =
type === 'sonarqube'
type === '__sonarqube__'
? ConnectionSettingsService.instance.getSonarQubeConnections()
: ConnectionSettingsService.instance.getSonarCloudConnections();
const connections = await Promise.all(
Expand Down Expand Up @@ -141,9 +143,9 @@ export class AllConnectionsTreeDataProvider implements VSCode.TreeDataProvider<C
if (!element) {
return this.getInitialState();
} else if (element.contextValue === 'sonarQubeGroup') {
return this.getConnections('sonarqube');
return this.getConnections('__sonarqube__');
} else if (element.contextValue === 'sonarCloudGroup') {
return this.getConnections('sonarcloud');
return this.getConnections('__sonarcloud__');
} else if (element.contextValue === 'sonarqubeConnection' || element.contextValue === 'sonarcloudConnection') {
const connection = element as Connection;
const serverType = element.contextValue === 'sonarqubeConnection' ? 'SonarQube' : 'SonarCloud';
Expand Down Expand Up @@ -181,8 +183,8 @@ export class AllConnectionsTreeDataProvider implements VSCode.TreeDataProvider<C
const sqConnections = ConnectionSettingsService.instance.getSonarQubeConnections();
const scConnections = ConnectionSettingsService.instance.getSonarCloudConnections();
return [
sqConnections.length > 0 ? new ConnectionGroup('sonarqube', 'SonarQube Server', 'sonarQubeGroup') : null,
scConnections.length > 0 ? new ConnectionGroup('sonarcloud', 'SonarQube Cloud', 'sonarCloudGroup') : null
sqConnections.length > 0 ? new ConnectionGroup('__sonarqube__', 'SonarQube Server', 'sonarQubeGroup') : null,
scConnections.length > 0 ? new ConnectionGroup('__sonarcloud__', 'SonarQube Cloud', 'sonarCloudGroup') : null
];
}

Expand Down
14 changes: 7 additions & 7 deletions test/suite/connections.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,30 @@ suite('Connected Mode Test Suite', () => {
});

suite('getConnections()', () => {
let underTest;
let underTest: AllConnectionsTreeDataProvider;
setup(() => {
underTest = new AllConnectionsTreeDataProvider(mockClient);
});

test('should return same number of sonarqube settings as in config file', async () => {
const connectionConfig = vscode.workspace.getConfiguration('sonarlint.connectedMode.connections');
expect(connectionConfig.sonarqube.length).to.equal((await underTest.getConnections('sonarqube')).length);
expect(connectionConfig.sonarqube.length).to.equal((await underTest.getConnections('__sonarqube__')).length);
});

test('should return no sq/sc connections when config is blank', async () => {
expect((await underTest.getConnections('sonarqube')).length).to.equal(0);
expect((await underTest.getConnections('sonarcloud')).length).to.equal(0);
expect((await underTest.getConnections('__sonarqube__')).length).to.equal(0);
expect((await underTest.getConnections('__sonarcloud__')).length).to.equal(0);
});

test('should return same number of sonarcloud settings as in config file', async () => {
const connectionConfig = vscode.workspace.getConfiguration('sonarlint.connectedMode.connections');
expect(connectionConfig.sonarcloud.length).to.equal((await underTest.getConnections('sonarcloud')).length);
expect(connectionConfig.sonarcloud.length).to.equal((await underTest.getConnections('__sonarcloud__')).length);
});
});

suite('ConnectedMode TreeView', () => {
const SQGroup = new ConnectionGroup('sonarqube', 'SonarQube Server', 'sonarQubeGroup');
const SCGroup = new ConnectionGroup('sonarcloud', 'SonarQube Cloud', 'sonarCloudGroup');
const SQGroup = new ConnectionGroup('__sonarqube__', 'SonarQube Server', 'sonarQubeGroup');
const SCGroup = new ConnectionGroup('__sonarcloud__', 'SonarQube Cloud', 'sonarCloudGroup');

test('should return empty lists when expanding SQ and SC tabs and no connections exist', async () => {
const underTest = new AllConnectionsTreeDataProvider(mockClient);
Expand Down

0 comments on commit 2006d43

Please sign in to comment.