Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | import * as vscode from 'vscode';
import { container } from 'tsyringe';
import { ServiceToken } from '@src/services/tokens';
import { ICredentialStorageService } from '@src/services/core';
import { MicrosoftAuthCredential } from '@src/services/core/credential';
import { ISparqlConnectionService } from '@src/languages/sparql/services';
import { SparqlConnection } from '@src/languages/sparql/services/sparql-connection';
import { SparqlConnectionMessages } from './sparql-connection-messages';
import { WebviewController } from '../webview-controller';
import { loginMicrosoftAuthProvider } from '@src/commands/login-microsoft-auth-provider';
import { getConfig } from '@src/utilities/vscode/config';
export class SparqlConnectionController extends WebviewController<SparqlConnectionMessages> {
private selectedConnection?: SparqlConnection;
constructor() {
super({
componentPath: 'sparql-connection-view.js',
panelId: 'sparqlConnectionPanel',
panelTitle: 'Edit Connection',
panelIcon: 'database',
});
}
/**
* Opens the SPARQL endpoint editor in the editor area and optionally preloads the endpoint.
*/
async edit(connection?: SparqlConnection) {
super.show(vscode.ViewColumn.Active);
this.selectedConnection = connection;
if (connection) {
this.postMessage({
id: 'GetSparqlConnectionResult',
connection: connection
});
}
}
protected async onDidReceiveMessage(message: SparqlConnectionMessages): Promise<boolean> {
switch (message.id) {
case 'ExecuteCommand': {
await super.onDidReceiveMessage(message);
if (message.command === 'mentor.command.deleteSparqlConnection') {
this.panel?.dispose();
}
return true;
}
case 'GetSparqlConnection': {
if (this.selectedConnection) {
this.postMessage({
id: 'GetSparqlConnectionResult',
connection: this.selectedConnection
});
} else {
const connectionService = container.resolve<ISparqlConnectionService>(ServiceToken.SparqlConnectionService);
// Note: This always returns at least one connection (the Mentor Store).
const connection = connectionService.getConnections()[0];
this.postMessage({
id: 'GetSparqlConnectionResult',
connection: connection
});
}
return true;
}
case 'GetSparqlConnectionCredential': {
const credentialService = container.resolve<ICredentialStorageService>(ServiceToken.CredentialStorageService);
const credential = await credentialService.getCredential(message.connectionId);
this.postMessage({
id: 'GetSparqlConnectionCredentialResult',
connectionId: message.connectionId,
credential
});
return true;
}
case 'SaveSparqlConnection': {
const connectionService = container.resolve<ISparqlConnectionService>(ServiceToken.SparqlConnectionService);
const credentialService = container.resolve<ICredentialStorageService>(ServiceToken.CredentialStorageService);
await connectionService.updateConnection(message.connection);
await connectionService.saveConfiguration();
if (message.credential) {
await credentialService.deleteCredential(message.connection.id);
await credentialService.saveCredential(message.connection.id, message.credential);
}
vscode.window.showInformationMessage(`SPARQL connection saved.`);
return true;
}
case 'UpdateSparqlConnection': {
const connectionService = container.resolve<ISparqlConnectionService>(ServiceToken.SparqlConnectionService);
await connectionService.updateConnection(message.connection);
return true;
}
case 'TestSparqlConnection': {
const connectionService = container.resolve<ISparqlConnectionService>(ServiceToken.SparqlConnectionService);
const result = await connectionService.testConnection(message.connection, message.credential);
this.postMessage({ id: 'TestSparqlConnectionResult', error: result });
return true;
}
case 'GetInferenceFeatureEnabled': {
const value = getConfig().get<boolean>('inference.enabled', false);
this.postMessage({ id: 'GetInferenceFeatureEnabledResult', value });
return true;
}
case 'ToggleSparqlConnectionInference': {
const connectionService = container.resolve<ISparqlConnectionService>(ServiceToken.SparqlConnectionService);
const newValue = await connectionService.toggleInferenceEnabled(message.connectionId);
this.postMessage({
id: 'ToggleSparqlConnectionInferenceResult',
connectionId: message.connectionId,
inferenceEnabled: newValue
});
return true;
}
case 'FetchMicrosoftAuthCredential': {
const command = loginMicrosoftAuthProvider.id;
const credential = await vscode.commands.executeCommand<MicrosoftAuthCredential | null>(command, message.scopes);
if (credential) {
this.postMessage({
id: 'FetchMicrosoftAuthCredentialResult',
connectionId: message.connectionId,
credential: credential
});
} else {
this.postMessage({
id: 'FetchMicrosoftAuthCredentialResult',
connectionId: message.connectionId,
credential: null
});
}
return true;
}
default:
return super.onDidReceiveMessage(message);
}
}
} |