8000 feat(language-service): support global directives completion by KazariEX · Pull Request #4989 · vuejs/language-tools · GitHub
[go: up one dir, main page]

Skip to content

feat(language-service): support global directives completion #4989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' of https://github.com/vuejs/language-tools into…
… feat/directive-completion
  • Loading branch information
KazariEX committed Dec 20, 2024
commit f9d4b200d88c7f2d2eea7727522357c1250147f4
3 changes: 1 addition & 2 deletions packages/language-core/lib/codegen/script/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ export function* generateTemplateDirectives(options: ScriptCodegenOptions): Gene
types.push(`typeof __VLS_directivesOption`);
}

exps.push(`{} as NonNullable<typeof __VLS_self extends { directives: infer D } ? D : {}>`);
exps.push(`{} as __VLS_PickDirectives<typeof __VLS_ctx>`);
types.push(`__VLS_PickDirectives<typeof __VLS_ctx>`);

yield `type __VLS_LocalDirectives =`;
for (const type of types) {
Expand Down
8 changes: 4 additions & 4 deletions packages/typescript-plugin/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export function getComponentEvents(
export function getComponentDirectives(
...args: Parameters<typeof import('./requests/componentInfos.js')['getComponentDirectives']>
) {
return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getComponentDirectives']>>({
type: 'getComponentDirectives',
args,
});
return sendRequest<ReturnType<typeof import('./requests/componentInfos')['getComponentDirectives']>>(
'getComponentDirectives',
...args
);
}

export function getTemplateContextProps(
Expand Down
100 changes: 28 additions & 72 deletions packages/typescript-plugin/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import type { Language } from '@vue/language-core';
import * as fs from 'node:fs';
import * as net from 'node:net';
import type * as ts from 'typescript';
import { getComponentDirectives } from './client';
import { collectExtractProps } from './requests/collectExtractProps';
import { getComponentDirectives, getComponentEvents, getComponentNames, getComponentProps, getElementAttrs, getTemplateContextProps } from './requests/componentInfos';
import { getComponentEvents, getComponentNames, getComponentProps, getElementAttrs, getTemplateContextProps } from './requests/componentInfos';
import { getImportPathForFile } from './requests/getImportPathForFile';
import { getPropertiesAtLocation } from './requests/getPropertiesAtLocation';
import { getQuickInfoAtPosition } from './requests/getQuickInfoAtPosition';
Expand Down Expand Up @@ -67,77 +68,28 @@ export async function startNamedPipeServer(
const componentNamesAndProps = new Map<string, string>();
const allConnections = new Set<net.Socket>();
const server = net.createServer(connection => {
connection.on('data', data => {
const text = data.toString();
if (text === 'ping') {
connection.write('pong');
return;
}
const request: Request = JSON.parse(text);
const fileName = request.args[0];
const requestContext: RequestContext = {
typescript: ts,
languageService: info.languageService,
languageServiceHost: info.languageServiceHost,
language: language,
isTsPlugin: true,
getFileId: (fileName: string) => fileName,
};
if (request.type === 'containsFile') {
sendResponse(
info.project.containsFile(ts.server.toNormalizedPath(fileName))
);
}
else if (request.type === 'projectInfo') {
sendResponse({
name: info.project.getProjectName(),
kind: info.project.projectKind,
currentDirectory: info.project.getCurrentDirectory(),
} satisfies ProjectInfo);
}
else if (request.type === 'collectExtractProps') {
const result = collectExtractProps.apply(requestContext, request.args as any);
sendResponse(result);
}
else if (request.type === 'getImportPathForFile') {
const result = getImportPathForFile.apply(requestContext, request.args as any);
sendResponse(result);
}
else if (request.type === 'getPropertiesAtLocation') {
const result = getPropertiesAtLocation.apply(requestContext, request.args as any);
sendResponse(result);
}
else if (request.type === 'getQuickInfoAtPosition') {
const result = getQuickInfoAtPosition.apply(requestContext, request.args as any);
sendResponse(result);
}
// Component Infos
else if (request.type === 'getComponentProps') {
const result = getComponentProps.apply(requestContext, request.args as any);
sendResponse(result);
}
else if (request.type === 'getComponentEvents') {
const result = getComponentEvents.apply(requestContext, request.args as any);
sendResponse(result);
}
else if (request.type === 'getComponentDirectives') {
const result = getComponentDirectives.apply(requestContext, request.args as any);
sendResponse(result);
}
else if (request.type === 'getTemplateContextProps') {
const result = getTemplateContextProps.apply(requestContext, request.args as any);
sendResponse(result);
}
else if (request.type === 'getComponentNames') {
const result = getComponentNames.apply(requestContext, request.args as any);
sendResponse(result);
}
else if (request.type === 'getElementAttrs') {
const result = getElementAttrs.apply(requestContext, request.args as any);
sendResponse(result);
}
else {
console.warn('[Vue Named Pipe Server] Unknown request type:', request.type);
allConnections.add(connection);

connection.on('end', () => {
allConnections.delete(connection);
});
connection.on('data', buffer => {
dataChunks.push(buffer);
const text = dataChunks.toString();
if (text.endsWith('\n\n')) {
dataChunks.length = 0;
const requests = text.split('\n\n');
for (let json of requests) {
json = json.trim();
if (!json) {
continue;
}
try {
onRequest(connection, JSON.parse(json));
} catch (e) {
console.error('[Vue Named Pipe Server] JSON parse error:', e);
}
}
}
});
connection.on('error', err => console.error('[Vue Named Pipe Server]', err.message));
Expand Down Expand Up @@ -269,6 +221,10 @@ export async function startNamedPipeServer(
const result = getComponentEvents.apply(requestContext, args as any);
sendResponse(result);
}
else if (requestType === 'getComponentDirectives') {
const result = getComponentDirectives.apply(requestContext, args as any);
sendResponse(result);
}
else if (requestType === 'getTemplateContextProps') {
const result = getTemplateContextProps.apply(requestContext, args as any);
sendResponse(result);
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.
0