Skip to content

Commit

Permalink
feat: add code completion for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AnWeber committed Feb 13, 2023
1 parent 58ae9d5 commit 30ba1aa
Show file tree
Hide file tree
Showing 22 changed files with 744 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 6.1.0 (2023-02-13)

#### Features

- add code completion for tests

## 6.0.0 (2023-02-12)

#### Breaking Changes
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"publisher": "AnWeber",
"description": "HTTP/REST CLI Client for *.http files",
"version": "6.0.0",
"version": "6.1.0",
"homepage": "https://github.com/AnWeber/httpyac",
"repository": {
"type": "git",
Expand Down
15 changes: 15 additions & 0 deletions src/io/completionItemProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as models from '../models';

export type CompletionItem = {
name: string;
description: string;
text?: string;
};

export const completionItemProvider: {
emptyLineProvider: Array<(text: string) => Array<CompletionItem>>;
requestHeaderProvider: Array<(request: models.Request) => Array<CompletionItem>>;
} = {
emptyLineProvider: [],
requestHeaderProvider: [],
};
5 changes: 3 additions & 2 deletions src/io/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './completionItemProvider';
export * from './fileProvider';
export * from './logger';
export * from './httpClientProvider';
export * from './javascriptProvider';
export * from './logger';
export * from './userInteractionProvider';
export * from './httpClientProvider';
36 changes: 36 additions & 0 deletions src/plugins/assert/completionItemProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { completionItemProvider } from '../../io';

completionItemProvider.emptyLineProvider.push(() => [
{
name: '?? status == ',
description: 'Status assert (200)',
},
{
name: '?? status == 200',
description: 'Status assert (200)',
},
{
name: '?? duration <',
description: 'Duration assert',
},
{
name: '?? body contains',
description: 'Body assert',
},
{
name: '?? body matches',
description: 'Body assert',
},
{
name: '?? body md5',
description: 'Body assert',
},
{
name: '?? body sh256',
description: 'Body assert',
},
{
name: '?? header',
description: 'Header assert',
},
]);
1 change: 1 addition & 0 deletions src/plugins/assert/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as models from '../../models';
import { parseAssertLine } from './assertHttpRegionParser';
import './completionItemProvider';
import { provideAssertValueDuration } from './provideAssertValueDuration';
import { provideAssertValueHeader } from './provideAssertValueHeader';
import { provideAssertValueJavascript } from './provideAssertValueJavascript';
Expand Down
30 changes: 30 additions & 0 deletions src/plugins/core/completionItemProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { completionItemProvider } from '../../io';

completionItemProvider.emptyLineProvider.push((text: string) => {
const result = [
{
name: '{{$prompt ',
description: 'Prompt',
},
{
name: '{{$input',
description: 'Input',
},
{
name: '{{$password',
description: 'Password',
},
{
name: '{{$pick <placeholder> $value:',
description: 'Password',
},
];
const index = text.lastIndexOf('{{');
if (index >= 0) {
return result.map(obj => ({
...obj,
text: `${text}${obj.name.slice(text.length - index)}`,
}));
}
return result;
});
1 change: 1 addition & 0 deletions src/plugins/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as models from '../../models';
import './completionItemProvider';
import { initProvideEnvironmentsHook } from './environments';
import { initExecuteInterceptor } from './execute';
import { initParseMetData } from './metaData';
Expand Down
17 changes: 17 additions & 0 deletions src/plugins/eventsource/completionItemProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { completionItemProvider } from '../../io';
import { isEventSourceRequest } from './eventSourceRequest';

completionItemProvider.emptyLineProvider.push(() => [
{
name: 'SSE',
description: 'Server Sent Event',
},
]);

completionItemProvider.requestHeaderProvider.push(request => {
const result = [];
if (isEventSourceRequest(request)) {
result.push(...[{ name: 'Event', description: 'Server Sent Events to add listener' }]);
}
return result;
});
28 changes: 28 additions & 0 deletions src/plugins/grpc/completionItemProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { completionItemProvider } from '../../io';
import { isGrpcRequest } from './grpcRequest';

completionItemProvider.emptyLineProvider.push(() => [
{
name: 'GRPC',
description: 'GRPC request',
},
{
name: 'proto < ./',
description: 'Proto Import',
},
]);

completionItemProvider.requestHeaderProvider.push(request => {
const result = [];
if (isGrpcRequest(request)) {
result.push(
...[
{
name: 'ChannelCredentials',
description: 'Channel credentials, which are attached to a Channel, such as SSL credentials.',
},
]
);
}
return result;
});
1 change: 1 addition & 0 deletions src/plugins/grpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as models from '../../models';
import { callOptionsRequestHook } from './callOptionsRequestHook';
import { channelCredentialsRequestHook } from './channelCredentialsRequestHook';
import { channelOptionsRequestHook } from './channelOptionsRequestHook';
import './completionItemProvider';
import { parseGrpcLine } from './grpcHttpRegionParser';
import { parseGrpcResponse } from './grpcResponseHttpRegionParser';
import { parseProtoImport } from './protoHttpRegionParser';
Expand Down
Loading

0 comments on commit 30ba1aa

Please sign in to comment.