Skip to content

Commit b849de7

Browse files
committed
WIP
1 parent 5620804 commit b849de7

3 files changed

Lines changed: 13 additions & 27 deletions

File tree

packages/ts-plugin/src/index.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ const plugin = createLanguageServicePlugin((ts, info) => {
7979
ts.server.toNormalizedPath(request.arguments.fileName),
8080
true,
8181
);
82-
if (!project) {
83-
return { response: { result: [] } };
84-
}
82+
if (!project) return {};
8583
const languageService = project.getLanguageService();
8684
const { fileName, position } = request.arguments;
8785
const result = languageService.findRenameLocations(fileName, position, false, false, {});
@@ -92,9 +90,7 @@ const plugin = createLanguageServicePlugin((ts, info) => {
9290
ts.server.toNormalizedPath(request.arguments.fileName),
9391
true,
9492
);
95-
if (!project) {
96-
return { response: { result: { canRename: false, localizedErrorMessage: '' } as const } };
97-
}
93+
if (!project) return {};
9894
const languageService = project.getLanguageService();
9995
const { fileName, position } = request.arguments;
10096
const result = languageService.getRenameInfo(fileName, position, {});
@@ -105,9 +101,9 @@ const plugin = createLanguageServicePlugin((ts, info) => {
105101
ts.server.toNormalizedPath(request.arguments.fileName),
106102
true,
107103
);
108-
if (!project) return { response: { result: [] } };
104+
if (!project) return {};
109105
const language = projectToLanguage.get(project);
110-
if (!language) return { response: { result: [] } };
106+
if (!language) return {};
111107
const { fileName } = request.arguments;
112108
const script = language.scripts.get(fileName);
113109
const links: DocumentLink[] = [];

packages/ts-plugin/src/type.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ import type ts from 'typescript';
22

33
export interface CSSModulesKitRenameRequest extends ts.server.protocol.Request {
44
command: '_css-modules-kit:rename';
5-
arguments: {
6-
fileName: string;
7-
position: number;
8-
};
5+
arguments: { fileName: string; position: number };
96
}
107
export interface CSSModulesKitRenameHandlerResponse extends ts.server.HandlerResponse {
11-
response: { result: ReturnType<ts.LanguageService['findRenameLocations']> };
8+
response?: { result: ReturnType<ts.LanguageService['findRenameLocations']> };
129
}
1310
export interface CSSModulesKitRenameResponse extends ts.server.protocol.Response {
1411
command: '_css-modules-kit:rename';
@@ -17,13 +14,10 @@ export interface CSSModulesKitRenameResponse extends ts.server.protocol.Response
1714

1815
export interface CSSModulesKitRenameInfoRequest extends ts.server.protocol.Request {
1916
command: '_css-modules-kit:renameInfo';
20-
arguments: {
21-
fileName: string;
22-
position: number;
23-
};
17+
arguments: { fileName: string; position: number };
2418
}
2519
export interface CSSModulesKitRenameInfoHandlerResponse extends ts.server.HandlerResponse {
26-
response: { result: ReturnType<ts.LanguageService['getRenameInfo']> };
20+
response?: { result: ReturnType<ts.LanguageService['getRenameInfo']> };
2721
}
2822
export interface CSSModulesKitRenameInfoResponse extends ts.server.protocol.Response {
2923
command: '_css-modules-kit:renameInfo';
@@ -36,14 +30,10 @@ export interface DocumentLink {
3630
}
3731
export interface CSSModulesKitDocumentLinkRequest extends ts.server.protocol.Request {
3832
command: '_css-modules-kit:documentLink';
39-
arguments: {
40-
fileName: string;
41-
};
33+
arguments: { fileName: string };
4234
}
4335
export interface CSSModulesKitDocumentLinkHandlerResponse extends ts.server.HandlerResponse {
44-
response: {
45-
result: DocumentLink[];
46-
};
36+
response?: { result: DocumentLink[] };
4737
}
4838
export interface CSSModulesKitDocumentLinkResponse extends ts.server.protocol.Response {
4939
command: '_css-modules-kit:documentLink';

packages/vscode/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function activate(context: vscode.ExtensionContext) {
3535
} satisfies CSSModulesKitRenameRequest['arguments'],
3636
);
3737
// If the response does not contain any results, return undefined to fall back to standard CSS Language Server.
38-
if (!res.success || !res.body.result || res.body.result.length === 0) return;
38+
if (!res.success || !res.body || !res.body.result || res.body.result.length === 0) return;
3939
const edit = new vscode.WorkspaceEdit();
4040
for (const location of res.body.result) {
4141
// eslint-disable-next-line no-await-in-loop
@@ -56,7 +56,7 @@ export async function activate(context: vscode.ExtensionContext) {
5656
} satisfies CSSModulesKitRenameInfoRequest['arguments'],
5757
);
5858
// If the response does not contain any results, return undefined to fall back to standard CSS Language Server.
59-
if (!res.success || !res.body.result.canRename) return;
59+
if (!res.success || !res.body || !res.body.result.canRename) return;
6060
return new vscode.Range(
6161
document.positionAt(res.body.result.triggerSpan.start),
6262
document.positionAt(res.body.result.triggerSpan.start + res.body.result.triggerSpan.length),
@@ -76,7 +76,7 @@ export async function activate(context: vscode.ExtensionContext) {
7676
} satisfies CSSModulesKitDocumentLinkRequest['arguments'],
7777
);
7878
// If the response does not contain any results, return undefined to fall back to standard CSS Language Server.
79-
if (!res.success || !res.body.result || res.body.result.length === 0) return null;
79+
if (!res.success || !res.body || res.body.result.length === 0) return;
8080
return res.body.result.map((link) => {
8181
return new vscode.DocumentLink(
8282
new vscode.Range(

0 commit comments

Comments
 (0)