Skip to content

Commit

Permalink
add endpoint to configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
fauna-chase committed Jul 25, 2023
1 parent d907a97 commit 754b1a7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"type": "string",
"default": "",
"description": "The secret to use to connnect to your fauna database."
},
"fauna.endpoint": {
"type": "string",
"default": "https://db.fauna.com",
"description": "The fauna endpoint to use."
}
}
},
Expand Down
9 changes: 8 additions & 1 deletion src/FQLConfigurationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class FQLConfigurationManager {
static readonly EMPTY_SECRET = "0";
static readonly FAUNA_CONFIG_PATH = "fauna";
static readonly SECRET_CONFIG_FIELD = "dbSecret";
static readonly ENDPOINT_CONFIG_FIELD = "endpoint";
static readonly SECRET_CONFIG_PATH = `${FQLConfigurationManager.FAUNA_CONFIG_PATH}.${FQLConfigurationManager.SECRET_CONFIG_FIELD}`;

static readonly config_error_dialogue = (message: string) => {
Expand All @@ -22,7 +23,7 @@ export class FQLConfigurationManager {


private dbSecret: string;
private endpoint: string = "http://localhost:8443";
private endpoint: string = "https://db.fauna.com";
/** Used to send notifications when extension configuration is updated. */
private subscriptions: ConfigurationChangeSubscription[] = [];

Expand All @@ -37,6 +38,11 @@ export class FQLConfigurationManager {
} else {
this.dbSecret = dbSecret;
}

const endpoint = config.get<string>(FQLConfigurationManager.ENDPOINT_CONFIG_FIELD);
if (endpoint !== undefined && endpoint !== "") {
this.endpoint = endpoint;
}
}

config(): FQLConfiguration {
Expand All @@ -51,6 +57,7 @@ export class FQLConfigurationManager {
}

async onConfigurationChange(event: vscode.ConfigurationChangeEvent) {
// todo: need to update endpoint here as well
if (event.affectsConfiguration(FQLConfigurationManager.SECRET_CONFIG_PATH)) {
const newSecret = vscode.workspace.getConfiguration(FQLConfigurationManager.FAUNA_CONFIG_PATH).get<string>(FQLConfigurationManager.SECRET_CONFIG_FIELD);
if (newSecret === undefined || newSecret === "") {
Expand Down
2 changes: 1 addition & 1 deletion src/LanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class LanguageService implements ConfigurationChangeSubscription {
}

async configChanged(updatedConfiguration: FQLConfiguration) {
const resp = await this.client.sendRequest("setFaunaSecret", { secret: updatedConfiguration.dbSecret }) as any;
const resp = await this.client.sendRequest("setFaunaConfig", { endpoint: updatedConfiguration.endpoint, secret: updatedConfiguration.dbSecret }) as any;
this.outputChannel.clear();
if (resp.status === "error") {
FQLConfigurationManager.config_error_dialogue(resp.message);
Expand Down
9 changes: 9 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ suite("Extension Test Suite", () => {
setup(async () => {
[fqlClient, secret] = await testHelper.clientWithFreshDB("VSCodeTest");
await setConfigSecret(secret);
if (fqlClient.clientConfiguration.endpoint) {
await setConfigEndpoint(fqlClient.clientConfiguration.endpoint.href);
}
});
test("should test completion items", async () => {
await fqlClient.query(fql`Collection.create({ name: "Cats" })`);
Expand All @@ -40,11 +43,17 @@ suite("Extension Test Suite", () => {
assert.ok(containsCollectionCompletionItem(completionList, "Cats"));
});

// todo: don't shadow
async function setConfigSecret(secret: string): Promise<void> {
const config = vscode.workspace.getConfiguration(FQLConfigurationManager.FAUNA_CONFIG_PATH);
await config.update(FQLConfigurationManager.SECRET_CONFIG_FIELD, secret, vscode.ConfigurationTarget.Global);
}

async function setConfigEndpoint(endpoint: string): Promise<void> {
const config = vscode.workspace.getConfiguration(FQLConfigurationManager.FAUNA_CONFIG_PATH);
await config.update(FQLConfigurationManager.ENDPOINT_CONFIG_FIELD, endpoint, vscode.ConfigurationTarget.Global);
}

function containsCollectionCompletionItem(completionItems: vscode.CompletionList, collectionName: string) {
return completionItems.items.some(item => {
return item.kind === vscode.CompletionItemKind.Module &&
Expand Down

0 comments on commit 754b1a7

Please sign in to comment.