-
-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(typescript-plugin): use named pipe servers more efficiently (#5070)
- Loading branch information
1 parent
06df71b
commit 3862e76
Showing
6 changed files
with
466 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,99 @@ | ||
import type { Request } from './server'; | ||
import { searchNamedPipeServerForFile, sendRequestWorker } from './utils'; | ||
import type { RequestData } from './server'; | ||
import { getBestServer } from './utils'; | ||
|
||
export function collectExtractProps( | ||
...args: Parameters<typeof import('./requests/collectExtractProps.js')['collectExtractProps']> | ||
) { | ||
return sendRequest<ReturnType<typeof import('./requests/collectExtractProps')['collectExtractProps']>>({ | ||
type: 'collectExtractProps', | ||
args, | ||
}); | ||
return sendRequest<ReturnType<typeof import('./requests/collectExtractProps')['collectExtractProps']>>( | ||
'collectExtractProps', | ||
...args | ||
); | ||
} | ||
|
||
export async function getImportPathForFile( | ||
...args: Parameters<typeof import('./requests/getImportPathForFile.js')['getImportPathForFile']> | ||
) { | ||
return await sendRequest<ReturnType<typeof import('./requests/getImportPathForFile')['getImportPathForFile']>>({ | ||
type: 'getImportPathForFile', | ||
args, | ||
}); | ||
return await sendRequest<ReturnType<typeof import('./requests/getImportPathForFile')['getImportPathForFile']>>( | ||
'getImportPathForFile', | ||
...args | ||
); | ||
} | ||
|
||
export async function getPropertiesAtLocation( | ||
...args: Parameters<typeof import('./requests/getPropertiesAtLocation.js')['getPropertiesAtLocation']> | ||
) { | ||
return await sendRequest<ReturnType<typeof import('./requests/getPropertiesAtLocation')['getPropertiesAtLocation']>>({ | ||
type: 'getPropertiesAtLocation', | ||
args, | ||
}); | ||
return await sendRequest<ReturnType<typeof import('./requests/getPropertiesAtLocation')['getPropertiesAtLocation']>>( | ||
'getPropertiesAtLocation', | ||
...args | ||
); | ||
} | ||
|
||
export function getQuickInfoAtPosition( | ||
...args: Parameters<typeof import('./requests/getQuickInfoAtPosition.js')['getQuickInfoAtPosition']> | ||
) { | ||
return sendRequest<ReturnType<typeof import('./requests/getQuickInfoAtPosition')['getQuickInfoAtPosition']>>({ | ||
type: 'getQuickInfoAtPosition', | ||
args, | ||
}); | ||
return sendRequest<ReturnType<typeof import('./requests/getQuickInfoAtPosition')['getQuickInfoAtPosition']>>( | ||
'getQuickInfoAtPosition', | ||
...args | ||
); | ||
} | ||
|
||
// Component Infos | ||
|
||
export function getComponentProps( | ||
...args: Parameters<typeof import('./requests/componentInfos.js')['getComponentProps']> | ||
) { | ||
return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getComponentProps']>>({ | ||
type: 'getComponentProps', | ||
args, | ||
}); | ||
export async function getComponentProps(fileName: string, componentName: string) { | ||
const server = await getBestServer(fileName); | ||
if (!server) { | ||
return; | ||
} | ||
const componentAndProps = await server.componentNamesAndProps.get(fileName); | ||
if (!componentAndProps) { | ||
return; | ||
} | ||
return componentAndProps[componentName]; | ||
} | ||
|
||
export function getComponentEvents( | ||
...args: Parameters<typeof import('./requests/componentInfos.js')['getComponentEvents']> | ||
) { | ||
return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getComponentEvents']>>({ | ||
type: 'getComponentEvents', | ||
args, | ||
}); | ||
return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getComponentEvents']>>( | ||
'getComponentEvents', | ||
...args | ||
); | ||
} | ||
|
||
export function getTemplateContextProps( | ||
...args: Parameters<typeof import('./requests/componentInfos.js')['getTemplateContextProps']> | ||
) { | ||
return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getTemplateContextProps']>>({ | ||
type: 'getTemplateContextProps', | ||
args, | ||
}); | ||
return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getTemplateContextProps']>>( | ||
'getTemplateContextProps', | ||
...args | ||
); | ||
} | ||
|
||
export function getComponentNames( | ||
...args: Parameters<typeof import('./requests/componentInfos.js')['getComponentNames']> | ||
) { | ||
return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getComponentNames']>>({ | ||
type: 'getComponentNames', | ||
args, | ||
}); | ||
export async function getComponentNames(fileName: string) { | ||
const server = await getBestServer(fileName); | ||
if (!server) { | ||
return; | ||
} | ||
const componentAndProps = server.componentNamesAndProps.get(fileName); | ||
if (!componentAndProps) { | ||
return; | ||
} | ||
return Object.keys(componentAndProps); | ||
} | ||
|
||
export function getElementAttrs( | ||
...args: Parameters<typeof import('./requests/componentInfos.js')['getElementAttrs']> | ||
) { | ||
return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getElementAttrs']>>({ | ||
type: 'getElementAttrs', | ||
args, | ||
}); | ||
return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getElementAttrs']>>( | ||
'getElementAttrs', | ||
...args | ||
); | ||
} | ||
|
||
async function sendRequest<T>(request: Request) { | ||
const server = (await searchNamedPipeServerForFile(request.args[0])); | ||
async function sendRequest<T>(requestType: RequestData[1], fileName: string, ...rest: any[]) { | ||
const server = await getBestServer(fileName); | ||
if (!server) { | ||
console.warn('[Vue Named Pipe Client] No server found for', request.args[0]); | ||
return; | ||
} | ||
const res = await sendRequestWorker<T>(request, server.socket); | ||
server.socket.end(); | ||
return res; | ||
return server.request<T>(requestType, fileName, ...rest); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.