Skip to content

Commit

Permalink
fix: default of setting testRunAlwaysUseEnvis null (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnWeber committed Oct 2, 2023
1 parent fbc533b commit c7794b5
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 16 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## [Unreleased]
## [6.7.1]

### Fix

- default of setting `testRunAlwaysUseEnv`is null (Anweber/vscode-httpyac#230)
- testRunner uses latest activeEnvironemnt (Anweber/vscode-httpyac#230)

## [6.7.0] (2023-10-01)

### Feature

Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1020,12 +1020,17 @@
"description": "reset environment before a test run is executed"
},
"httpyac.testRunAlwaysUseEnv": {
"type": "array",
"type": [
"array",
"null"
],
"required": false,
"items": {
"type": "string"
},
"scope": "window",
"description": "use this environment on a test run"
"description": "use this environment on a test run",
"default": null
}
}
},
Expand Down
24 changes: 22 additions & 2 deletions src/documentStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type HttpFileChangedEvent =

export class DocumentStore extends utils.DisposeProvider implements IDocumentStore {
activeEnvironment: Array<string> | undefined;
private fileEnvironments: Record<string, Array<string> | undefined> = {};

public getDocumentPathLike: (document: vscode.TextDocument) => httpyac.PathLike;

Expand Down Expand Up @@ -227,8 +228,7 @@ export class DocumentStore extends utils.DisposeProvider implements IDocumentSto
if (!context.config) {
context.config = config;
}
context.activeEnvironment =
context.activeEnvironment || context.httpFile.activeEnvironment || this.activeEnvironment;
context.activeEnvironment = context.activeEnvironment || this.getActiveEnvironment(context.httpFile);
const result = await httpyac.send(context);
this.variables = context.variables;
return result;
Expand All @@ -254,4 +254,24 @@ export class DocumentStore extends utils.DisposeProvider implements IDocumentSto
}
return undefined;
}

public getActiveEnvironment(httpFile: httpyac.HttpFile) {
const key = httpyac.io.fileProvider.toString(httpFile.fileName);
if (this.fileEnvironments[key]) {
return this.fileEnvironments[key];
}
this.fileEnvironments[key] = this.activeEnvironment;

return this.activeEnvironment;
}

public setActiveEnvironment(httpFile: httpyac.HttpFile, env: Array<string> | undefined) {
const key = httpyac.io.fileProvider.toString(httpFile.fileName);
if (!env) {
delete this.fileEnvironments[key];
} else {
this.fileEnvironments[key] = env;
}
this.activeEnvironment = env;
}
}
1 change: 1 addition & 0 deletions src/extensionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface ResponseOutputProcessor {
export interface DocumentStore {
readonly httpFileStore: httpyac.store.HttpFileStore;
activeEnvironment: Array<string> | undefined;
getActiveEnvironment(httpFile: httpyac.HttpFile): Array<string> | undefined;
getDocumentPathLike: (document: vscode.TextDocument) => httpyac.PathLike;
getHttpFile(document: vscode.TextDocument): Promise<httpyac.HttpFile | undefined>;
getAll(): Array<httpyac.HttpFile>;
Expand Down
13 changes: 5 additions & 8 deletions src/provider/storeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class StoreController extends utils.DisposeProvider implements vscode.Cod
new vscode.CodeLens(new vscode.Range(0, 0, 0, 0), {
command: commands.toggleEnv,
arguments: args,
title: `env: ${this.getEnvironmentTitle(httpFile.activeEnvironment)}`,
title: `env: ${this.getEnvironmentTitle(this.documentStore.getActiveEnvironment(httpFile))}`,
})
);
}
Expand Down Expand Up @@ -117,7 +117,7 @@ export class StoreController extends utils.DisposeProvider implements vscode.Cod
const config = getConfigSetting();

if (config.environmentShowStatusBarItem) {
const env = this.getEnvironmentTitle(httpFile.activeEnvironment);
const env = this.getEnvironmentTitle(this.documentStore.getActiveEnvironment(httpFile));
this.envStatusBarItem.text = env;
this.envStatusBarItem.tooltip = 'Select httpYac Environment';
this.envStatusBarItem.command = {
Expand Down Expand Up @@ -170,7 +170,7 @@ export class StoreController extends utils.DisposeProvider implements vscode.Cod
const httpFile = await this.documentStore.getHttpFile(editor.document);
if (httpFile) {
const env = await this.showQuickPickEnvironments(httpFile);
httpFile.activeEnvironment = env;
this.selectEnvironment(env, httpFile);
this.refreshEnvStatusBarItem(httpFile);
}
}
Expand Down Expand Up @@ -232,11 +232,8 @@ export class StoreController extends utils.DisposeProvider implements vscode.Cod
return activeEnvironment;
}

public async selectEnvironment(activeEnvironment: string[] | undefined, httpFile?: httpyac.HttpFile) {
if (httpFile) {
httpFile.activeEnvironment = activeEnvironment;
}
this.documentStore.activeEnvironment = activeEnvironment;
public async selectEnvironment(activeEnvironment: string[] | undefined, httpFile: httpyac.HttpFile) {
this.documentStore.setActiveEnvironment(httpFile, activeEnvironment);
this.environmentChangedEmitter.fire(activeEnvironment);
if (getConfigSetting().environmentStoreSelectedOnStart) {
const config = vscode.workspace.getConfiguration(APP_NAME);
Expand Down
2 changes: 1 addition & 1 deletion src/provider/test/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class TestRunner {
const line = testItem.range?.start.line || 0;
const httpRegion = httpFile.httpRegions.find(obj => obj.symbol.startLine <= line && obj.symbol.endLine >= line);
const context: httpyac.HttpFileSendContext | httpyac.HttpRegionSendContext = {
activeEnvironment: config.testRunAlwaysUseEnv || httpFile.activeEnvironment,
activeEnvironment: config.testRunAlwaysUseEnv || this.documentStore.getActiveEnvironment(httpFile),
httpFile,
httpRegion,
};
Expand Down
2 changes: 1 addition & 1 deletion src/provider/variablesHoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export class VariablesHoverProvider extends DisposeProvider implements vscode.Ho
(await httpyac.getVariables({
httpFile: {
...httpFile,
activeEnvironment: httpFile.activeEnvironment,
},
activeEnvironment: this.documentStore.getActiveEnvironment(httpFile),
config: await getEnvironmentConfig(httpFile.fileName),
}))
);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/httpRegionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function getHttpRegionFromLine(
);
if (httpRegion) {
return {
activeEnvironment: httpFile.activeEnvironment || documentStore.activeEnvironment,
activeEnvironment: documentStore.getActiveEnvironment(httpFile),
httpRegion,
httpFile,
};
Expand Down

0 comments on commit c7794b5

Please sign in to comment.