Skip to content

Commit 4c90746

Browse files
committed
fix: update lsp validate limition
1 parent 2ecd521 commit 4c90746

7 files changed

+19
-9
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ node_modules
22
client/out
33
client/node_modules
44
server/out
5-
server/node_modules
6-
react-intl-linter-0.0.1.vsix
5+
server/node_modules

client/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "client",
33
"displayName": "React-Intl-Linter - Client",
4-
"version": "0.0.1",
4+
"version": "0.0.2",
55
"description": "vscode linter extension for react-intl",
66
"repository": "[email protected]:Styx11/react-intl-linter.git",
77
"author": "styx11 <[email protected]>",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-intl-linter",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"publisher": "styx11",
55
"description": "vscode linter extension for react-intl",
66
"repository": "[email protected]:Styx11/react-intl-linter.git",

react-intl-linter-0.0.2.vsix

1.02 MB
Binary file not shown.

server/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "server",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "vscode linter extension for react-intl",
55
"repository": "[email protected]:Styx11/react-intl-linter.git",
66
"author": "styx11 <[email protected]>",

server/src/lib/validator.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import * as isChinese from 'is-chinese'
44

55
import { StringReg, DiagnosticMessage } from "./util";
66

7+
const MaxDiagnosticCount = 100
8+
79
/**
810
* 在服务端校验文本,所有字符串内的中文文本会作为错误传出
911
*
@@ -12,6 +14,9 @@ import { StringReg, DiagnosticMessage } from "./util";
1214
*/
1315
export const validateMessage = (textDocument: TextDocument): Diagnostic[] =>
1416
{
17+
// 出于性能考虑,需对错误信息数量做限制
18+
let limitDiagnosticCount = 0
19+
1520
// 校验器会检查所有的大写单词是否超过 2 个字母
1621
const text = textDocument.getText();
1722

@@ -20,7 +25,7 @@ export const validateMessage = (textDocument: TextDocument): Diagnostic[] =>
2025

2126
const diagnostics: Diagnostic[] = [];
2227

23-
while ((match = StringReg.exec(text)))
28+
while ((match = StringReg.exec(text)) && limitDiagnosticCount <= MaxDiagnosticCount)
2429
{
2530
// 匹配的全部字符串
2631
const rawString = match[0]
@@ -30,6 +35,8 @@ export const validateMessage = (textDocument: TextDocument): Diagnostic[] =>
3035

3136
if (!isChinese(string)) continue
3237

38+
limitDiagnosticCount++
39+
3340
// 错误信息
3441
const diagnostic: Diagnostic = {
3542
severity: DiagnosticSeverity.Warning,

server/src/server.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ connection.onInitialize(() =>
2828
change: TextDocumentSyncKind.Incremental
2929
},
3030
executeCommandProvider: {
31-
commands: ['sample.fixMe']
31+
commands: ['react-intl-linter.extract']
3232
}
3333
}
3434
};
@@ -71,14 +71,18 @@ connection.onCodeAction((params: CodeActionParams) =>
7171

7272
// 点击 CodeAction 后发出的指令会被 client middleware 捕获并处理
7373
return [
74-
CodeAction.create(codeActionMessage, Command.create(codeActionMessage, 'sample.fixMe', textDocument.uri, rawMessage), CodeActionKind.QuickFix)
74+
CodeAction.create(
75+
codeActionMessage,
76+
Command.create(codeActionMessage, 'react-intl-linter.extract', textDocument.uri, rawMessage),
77+
CodeActionKind.QuickFix,
78+
)
7579
];
7680
});
7781

7882
// Code Action 指令经 client middleware 处理后执行
7983
connection.onExecuteCommand(async (params: ExecuteCommandParams) =>
8084
{
81-
if (params.command !== 'sample.fixMe' || params.arguments === undefined)
85+
if (params.command !== 'react-intl-linter.extract' || params.arguments === undefined)
8286
{
8387
return;
8488
}

0 commit comments

Comments
 (0)