Skip to content

Commit

Permalink
feat: add projectContext variable AnWeber/vscode-httpyac#165
Browse files Browse the repository at this point in the history
  • Loading branch information
AnWeber committed Jan 6, 2023
1 parent b4669a0 commit a8007da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/plugins/intellij/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as models from '../../models';
import { provideIntellijGlobalVariables } from './intellijGlobalVariableProvider';
import { parseIntellijScript } from './intellijHttpRegionParser';
import { replaceIntellijProjectContext } from './intellijProjectContextReplacer';
import { provideIntellijEnvironments, provideIntellijVariables } from './intellijVariableProvider';
import { replaceDynamicIntellijVariables } from './intellijVariableReplacer';

Expand All @@ -10,4 +11,5 @@ export function registerIntellijPlugin(api: models.HttpyacHooksApi) {
api.hooks.provideVariables.addHook('intellij', provideIntellijVariables);
api.hooks.provideVariables.addHook('intellij_global', provideIntellijGlobalVariables);
api.hooks.replaceVariable.addHook('intellijDynamic', replaceDynamicIntellijVariables, { before: ['name'] });
api.hooks.replaceVariable.addHook('intellijProjectContext', replaceIntellijProjectContext, { before: ['name'] });
}
15 changes: 15 additions & 0 deletions src/plugins/intellij/intellijProjectContextReplacer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as models from '../../models';
import * as utils from '../../utils';

export async function replaceIntellijProjectContext(
text: unknown,
_type: string,
context: models.ProcessorContext
): Promise<unknown> {
return utils.parseHandlebarsString(text, async (variable: string) => {
if (variable.trim() === '$projectRoot') {
return context.httpFile.rootDir;
}
return undefined;
});
}

0 comments on commit a8007da

Please sign in to comment.