1
1
import type { RequestData } from './server' ;
2
2
import { getBestServer } from './utils' ;
3
3
4
- export function collectExtractProps (
5
- ...args : Parameters < typeof import ( './requests/collectExtractProps.js' ) [ 'collectExtractProps' ] >
6
- ) {
7
- return sendRequest < ReturnType < typeof import ( './requests/collectExtractProps' ) [ 'collectExtractProps' ] > > (
8
- 'collectExtractProps' ,
9
- ...args
10
- ) ;
11
- }
4
+ export const collectExtractProps = createRequest <
5
+ typeof import ( './requests/collectExtractProps.js' ) [ 'collectExtractProps' ]
6
+ > ( 'collectExtractProps' ) ;
12
7
13
- export async function getImportPathForFile (
14
- ...args : Parameters < typeof import ( './requests/getImportPathForFile.js' ) [ 'getImportPathForFile' ] >
15
- ) {
16
- return await sendRequest < ReturnType < typeof import ( './requests/getImportPathForFile' ) [ 'getImportPathForFile' ] > > (
17
- 'getImportPathForFile' ,
18
- ...args
19
- ) ;
20
- }
8
+ export const getImportPathForFile = createRequest <
9
+ typeof import ( './requests/getImportPathForFile.js' ) [ 'getImportPathForFile' ]
10
+ > ( 'getImportPathForFile' ) ;
21
11
22
- export async function getPropertiesAtLocation (
23
- ...args : Parameters < typeof import ( './requests/getPropertiesAtLocation.js' ) [ 'getPropertiesAtLocation' ] >
24
- ) {
25
- return await sendRequest < ReturnType < typeof import ( './requests/getPropertiesAtLocation' ) [ 'getPropertiesAtLocation' ] > > (
26
- 'getPropertiesAtLocation' ,
27
- ...args
28
- ) ;
29
- }
12
+ export const getPropertiesAtLocation = createRequest <
13
+ typeof import ( './requests/getPropertiesAtLocation.js' ) [ 'getPropertiesAtLocation' ]
14
+ > ( 'getPropertiesAtLocation' ) ;
30
15
31
- export function getQuickInfoAtPosition (
32
- ...args : Parameters < typeof import ( './requests/getQuickInfoAtPosition.js' ) [ 'getQuickInfoAtPosition' ] >
33
- ) {
34
- return sendRequest < ReturnType < typeof import ( './requests/getQuickInfoAtPosition' ) [ 'getQuickInfoAtPosition' ] > > (
35
- 'getQuickInfoAtPosition' ,
36
- ...args
37
- ) ;
38
- }
16
+ export const getQuickInfoAtPosition = createRequest <
17
+ typeof import ( './requests/getQuickInfoAtPosition.js' ) [ 'getQuickInfoAtPosition' ]
18
+ > ( 'getQuickInfoAtPosition' ) ;
39
19
40
20
// Component Infos
41
21
@@ -47,23 +27,13 @@ export async function getComponentProps(fileName: string, componentName: string)
47
27
return await server . getComponentProps ( fileName , componentName ) ;
48
28
}
49
29
50
- export function getComponentEvents (
51
- ...args : Parameters < typeof import ( './requests/componentInfos.js' ) [ 'getComponentEvents' ] >
52
- ) {
53
- return sendRequest < ReturnType < typeof import ( './requests/componentInfos' ) [ 'getComponentEvents' ] > > (
54
- 'getComponentEvents' ,
55
- ...args
56
- ) ;
57
- }
30
+ export const getComponentEvents = createRequest <
31
+ typeof import ( './requests/componentInfos.js' ) [ 'getComponentEvents' ]
32
+ > ( 'getComponentEvents' ) ;
58
33
59
- export function getTemplateContextProps (
60
- ...args : Parameters < typeof import ( './requests/componentInfos.js' ) [ 'getTemplateContextProps' ] >
61
- ) {
62
- return sendRequest < ReturnType < typeof import ( './requests/componentInfos' ) [ 'getTemplateContextProps' ] > > (
63
- 'getTemplateContextProps' ,
64
- ...args
65
- ) ;
66
- }
34
+ export const getComponentDirectives = createRequest <
35
+ typeof import ( './requests/componentInfos.js' ) [ 'getComponentDirectives' ]
36
+ > ( 'getComponentDirectives' ) ;
67
37
68
38
export async function getComponentNames ( fileName : string ) {
69
39
const server = await getBestServer ( fileName ) ;
@@ -77,19 +47,16 @@ export async function getComponentNames(fileName: string) {
77
47
return Object . keys ( componentAndProps ) ;
78
48
}
79
49
80
- export function getElementAttrs (
81
- ...args : Parameters < typeof import ( './requests/componentInfos.js' ) [ 'getElementAttrs' ] >
82
- ) {
83
- return sendRequest < ReturnType < typeof import ( './requests/componentInfos' ) [ 'getElementAttrs' ] > > (
84
- 'getElementAttrs' ,
85
- ...args
86
- ) ;
87
- }
50
+ export const getElementAttrs = createRequest <
51
+ typeof import ( './requests/componentInfos.js' ) [ 'getElementAttrs' ]
52
+ > ( 'getElementAttrs' ) ;
88
53
89
- async function sendRequest < T > ( requestType : RequestData [ 1 ] , fileName : string , ...rest : any [ ] ) {
90
- const server = await getBestServer ( fileName ) ;
91
- if ( ! server ) {
92
- return ;
93
- }
94
- return server . sendRequest < T > ( requestType , fileName , ...rest ) ;
54
+ function createRequest < T extends ( ...args : any ) => any > ( requestType : RequestData [ 1 ] ) {
55
+ return async function ( ...[ fileName , ...rest ] : Parameters < T > ) {
56
+ const server = await getBestServer ( fileName ) ;
57
+ if ( ! server ) {
58
+ return ;
59
+ }
60
+ return server . sendRequest < ReturnType < T > > ( requestType , fileName , ...rest ) ;
61
+ } ;
95
62
}
0 commit comments