|
1 |
| -import type { Request } from './server'; |
2 |
| -import { searchNamedPipeServerForFile, sendRequestWorker } from './utils'; |
| 1 | +import type { RequestData } from './server'; |
| 2 | +import { getBestServer } from './utils'; |
3 | 3 |
|
4 | 4 | export function collectExtractProps(
|
5 | 5 | ...args: Parameters<typeof import('./requests/collectExtractProps.js')['collectExtractProps']>
|
6 | 6 | ) {
|
7 |
| - return sendRequest<ReturnType<typeof import('./requests/collectExtractProps')['collectExtractProps']>>({ |
8 |
| - type: 'collectExtractProps', |
9 |
| - args, |
10 |
| - }); |
| 7 | + return sendRequest<ReturnType<typeof import('./requests/collectExtractProps')['collectExtractProps']>>( |
| 8 | + 'collectExtractProps', |
| 9 | + ...args |
| 10 | + ); |
11 | 11 | }
|
12 | 12 |
|
13 | 13 | export async function getImportPathForFile(
|
14 | 14 | ...args: Parameters<typeof import('./requests/getImportPathForFile.js')['getImportPathForFile']>
|
15 | 15 | ) {
|
16 |
| - return await sendRequest<ReturnType<typeof import('./requests/getImportPathForFile')['getImportPathForFile']>>({ |
17 |
| - type: 'getImportPathForFile', |
18 |
| - args, |
19 |
| - }); |
| 16 | + return await sendRequest<ReturnType<typeof import('./requests/getImportPathForFile')['getImportPathForFile']>>( |
| 17 | + 'getImportPathForFile', |
| 18 | + ...args |
| 19 | + ); |
20 | 20 | }
|
21 | 21 |
|
22 | 22 | export async function getPropertiesAtLocation(
|
23 | 23 | ...args: Parameters<typeof import('./requests/getPropertiesAtLocation.js')['getPropertiesAtLocation']>
|
24 | 24 | ) {
|
25 |
| - return await sendRequest<ReturnType<typeof import('./requests/getPropertiesAtLocation')['getPropertiesAtLocation']>>({ |
26 |
| - type: 'getPropertiesAtLocation', |
27 |
| - args, |
28 |
| - }); |
| 25 | + return await sendRequest<ReturnType<typeof import('./requests/getPropertiesAtLocation')['getPropertiesAtLocation']>>( |
| 26 | + 'getPropertiesAtLocation', |
| 27 | + ...args |
| 28 | + ); |
29 | 29 | }
|
30 | 30 |
|
31 | 31 | export function getQuickInfoAtPosition(
|
32 | 32 | ...args: Parameters<typeof import('./requests/getQuickInfoAtPosition.js')['getQuickInfoAtPosition']>
|
33 | 33 | ) {
|
34 |
| - return sendRequest<ReturnType<typeof import('./requests/getQuickInfoAtPosition')['getQuickInfoAtPosition']>>({ |
35 |
| - type: 'getQuickInfoAtPosition', |
36 |
| - args, |
37 |
| - }); |
| 34 | + return sendRequest<ReturnType<typeof import('./requests/getQuickInfoAtPosition')['getQuickInfoAtPosition']>>( |
| 35 | + 'getQuickInfoAtPosition', |
| 36 | + ...args |
| 37 | + ); |
38 | 38 | }
|
39 | 39 |
|
40 | 40 | // Component Infos
|
41 | 41 |
|
42 |
| -export function getComponentProps( |
43 |
| - ...args: Parameters<typeof import('./requests/componentInfos.js')['getComponentProps']> |
44 |
| -) { |
45 |
| - return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getComponentProps']>>({ |
46 |
| - type: 'getComponentProps', |
47 |
| - args, |
48 |
| - }); |
| 42 | +export async function getComponentProps(fileName: string, componentName: string) { |
| 43 | + const server = await getBestServer(fileName); |
| 44 | + if (!server) { |
| 45 | + return; |
| 46 | + } |
| 47 | + const componentAndProps = await server.componentNamesAndProps.get(fileName); |
| 48 | + if (!componentAndProps) { |
| 49 | + return; |
| 50 | + } |
| 51 | + return componentAndProps[componentName]; |
49 | 52 | }
|
50 | 53 |
|
51 | 54 | export function getComponentEvents(
|
52 | 55 | ...args: Parameters<typeof import('./requests/componentInfos.js')['getComponentEvents']>
|
53 | 56 | ) {
|
54 |
| - return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getComponentEvents']>>({ |
55 |
| - type: 'getComponentEvents', |
56 |
| - args, |
57 |
| - }); |
| 57 | + return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getComponentEvents']>>( |
| 58 | + 'getComponentEvents', |
| 59 | + ...args |
| 60 | + ); |
58 | 61 | }
|
59 | 62 |
|
60 | 63 | export function getTemplateContextProps(
|
61 | 64 | ...args: Parameters<typeof import('./requests/componentInfos.js')['getTemplateContextProps']>
|
62 | 65 | ) {
|
63 |
| - return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getTemplateContextProps']>>({ |
64 |
| - type: 'getTemplateContextProps', |
65 |
| - args, |
66 |
| - }); |
| 66 | + return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getTemplateContextProps']>>( |
| 67 | + 'getTemplateContextProps', |
| 68 | + ...args |
| 69 | + ); |
67 | 70 | }
|
68 | 71 |
|
69 |
| -export function getComponentNames( |
70 |
| - ...args: Parameters<typeof import('./requests/componentInfos.js')['getComponentNames']> |
71 |
| -) { |
72 |
| - return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getComponentNames']>>({ |
73 |
| - type: 'getComponentNames', |
74 |
| - args, |
75 |
| - }); |
| 72 | +export async function getComponentNames(fileName: string) { |
| 73 | + const server = await getBestServer(fileName); |
| 74 | + if (!server) { |
| 75 | + return; |
| 76 | + } |
| 77 | + const componentAndProps = server.componentNamesAndProps.get(fileName); |
| 78 | + if (!componentAndProps) { |
| 79 | + return; |
| 80 | + } |
| 81 | + return Object.keys(componentAndProps); |
76 | 82 | }
|
77 | 83 |
|
78 | 84 | export function getElementAttrs(
|
79 | 85 | ...args: Parameters<typeof import('./requests/componentInfos.js')['getElementAttrs']>
|
80 | 86 | ) {
|
81 |
| - return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getElementAttrs']>>({ |
82 |
| - type: 'getElementAttrs', |
83 |
| - args, |
84 |
| - }); |
| 87 | + return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getElementAttrs']>>( |
| 88 | + 'getElementAttrs', |
| 89 | + ...args |
| 90 | + ); |
85 | 91 | }
|
86 | 92 |
|
87 |
| -async function sendRequest<T>(request: Request) { |
88 |
| - const server = (await searchNamedPipeServerForFile(request.args[0])); |
| 93 | +async function sendRequest<T>(requestType: RequestData[1], fileName: string, ...rest: any[]) { |
| 94 | + const server = await getBestServer(fileName); |
89 | 95 | if (!server) {
|
90 |
| - console.warn('[Vue Named Pipe Client] No server found for', request.args[0]); |
91 | 96 | return;
|
92 | 97 | }
|
93 |
| - const res = await sendRequestWorker<T>(request, server.socket); |
94 |
| - server.socket.end(); |
95 |
| - return res; |
| 98 | + return server.request<T>(requestType, fileName, ...rest); |
96 | 99 | }
|
0 commit comments