Skip to content

Commit ae8093a

Browse files
committed
refactor(typescript-plugin): explicitly annotate requests with type
1 parent a2b2bb3 commit ae8093a

File tree

11 files changed

+30
-29
lines changed

11 files changed

+30
-29
lines changed

packages/language-service/lib/plugins/vue-document-drop.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,13 @@ export function create(
6464
serviceScript.code.snapshot,
6565
);
6666
const preferences = await getUserPreferences(context, tsDocument);
67-
const importPathRequest = await getImportPathForFile(
68-
root.fileName,
69-
incomingFileName,
70-
preferences,
71-
);
72-
if (importPathRequest) {
73-
importPath = importPathRequest;
74-
}
67+
importPath = (
68+
await getImportPathForFile(
69+
root.fileName,
70+
incomingFileName,
71+
preferences,
72+
) ?? {}
73+
).path;
7574
}
7675

7776
if (!importPath) {

packages/typescript-plugin/lib/requests/collectExtractProps.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import { isSemanticTokensEnabled, VueVirtualCode } from '@vue/language-core';
22
import type { RequestContext } from './types';
33

4+
interface ExtractPropsInfo {
5+
name: string;
6+
type: string;
7+
model: boolean;
8+
}
9+
410
export function collectExtractProps(
511
this: RequestContext,
612
fileName: string,
713
templateCodeRange: [number, number],
8-
) {
14+
): ExtractPropsInfo[] {
915
const { typescript: ts, languageService, language } = this;
1016

1117
const sourceScript = language.scripts.get(fileName);
@@ -14,11 +20,7 @@ export function collectExtractProps(
1420
return [];
1521
}
1622

17-
const result = new Map<string, {
18-
name: string;
19-
type: string;
20-
model: boolean;
21-
}>();
23+
const result = new Map<string, ExtractPropsInfo>();
2224
const program = languageService.getProgram()!;
2325
const sourceFile = program.getSourceFile(fileName)!;
2426
const checker = program.getTypeChecker();

packages/typescript-plugin/lib/requests/getComponentDirectives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const builtInDirectives = new Set([
1414
export function getComponentDirectives(
1515
this: RequestContext,
1616
fileName: string,
17-
) {
17+
): string[] {
1818
const { typescript: ts, language, languageService } = this;
1919

2020
const sourceScript = language.scripts.get(fileName);

packages/typescript-plugin/lib/requests/getComponentEvents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function getComponentEvents(
66
this: RequestContext,
77
fileName: string,
88
tag: string,
9-
) {
9+
): string[] {
1010
const { typescript: ts, language, languageService } = this;
1111

1212
const sourceScript = language.scripts.get(fileName);

packages/typescript-plugin/lib/requests/getComponentNames.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getSelfComponentName, getVariableType } from './utils';
55
export function getComponentNames(
66
this: RequestContext,
77
fileName: string,
8-
) {
8+
): string[] {
99
const { typescript: ts, language, languageService } = this;
1010

1111
const sourceScript = language.scripts.get(fileName);

packages/typescript-plugin/lib/requests/getComponentProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function getComponentProps(
1616
this: RequestContext,
1717
fileName: string,
1818
tag: string,
19-
) {
19+
): ComponentPropInfo[] {
2020
const { typescript: ts, language, languageService } = this;
2121

2222
const sourceScript = language.scripts.get(fileName);

packages/typescript-plugin/lib/requests/getComponentSlots.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getVariableType } from './utils';
55
export function getComponentSlots(
66
this: RequestContext,
77
fileName: string,
8-
) {
8+
): string[] {
99
const { typescript: ts, language, languageService } = this;
1010

1111
const sourceScript = language.scripts.get(fileName);
@@ -16,7 +16,7 @@ export function getComponentSlots(
1616

1717
const codegen = tsCodegen.get(root.sfc);
1818
if (!codegen) {
19-
return;
19+
return [];
2020
}
2121

2222
const assignName = codegen.getSetupSlotsAssignName() ?? `__VLS_slots`;

packages/typescript-plugin/lib/requests/getElementAttrs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function getElementAttrs(
66
this: RequestContext,
77
fileName: string,
88
tagName: string,
9-
) {
9+
): string[] {
1010
const { typescript: ts, language, languageService } = this;
1111

1212
const sourceScript = language.scripts.get(fileName);

packages/typescript-plugin/lib/requests/getElementNames.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getVariableType } from './utils';
55
export function getElementNames(
66
this: RequestContext,
77
fileName: string,
8-
) {
8+
): string[] {
99
const { typescript: ts, language, languageService } = this;
1010

1111
const sourceScript = language.scripts.get(fileName);

packages/typescript-plugin/lib/requests/getImportPathForFile.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ export function getImportPathForFile(
66
fileName: string,
77
incomingFileName: string,
88
preferences: ts.UserPreferences,
9-
) {
9+
): { path?: string } {
1010
const { typescript: ts, languageService, languageServiceHost } = this;
1111
const program = languageService.getProgram();
1212
const incomingFile = program?.getSourceFile(incomingFileName);
1313
const sourceFile = program?.getSourceFile(fileName);
1414
if (!program || !sourceFile || !incomingFile) {
15-
return;
15+
return {};
1616
}
1717

1818
const getModuleSpecifiersWithCacheInfo: (
@@ -28,7 +28,7 @@ export function getImportPathForFile(
2828
computedWithoutCache: boolean;
2929
} = (ts as any).moduleSpecifiers.getModuleSpecifiersWithCacheInfo;
3030
const resolutionHost = (ts as any).createModuleSpecifierResolutionHost(program, languageServiceHost);
31-
const moduleSpecifiers = getModuleSpecifiersWithCacheInfo(
31+
const { moduleSpecifiers } = getModuleSpecifiersWithCacheInfo(
3232
(incomingFile as any).symbol,
3333
program.getTypeChecker(),
3434
languageServiceHost.getCompilationSettings(),
@@ -37,7 +37,7 @@ export function getImportPathForFile(
3737
preferences,
3838
);
3939

40-
for (const moduleSpecifier of moduleSpecifiers.moduleSpecifiers) {
41-
return moduleSpecifier;
42-
}
40+
return {
41+
path: moduleSpecifiers[0],
42+
};
4343
}

0 commit comments

Comments
 (0)